| 18 | } |
| 19 | |
| 20 | function testDefineProperties (nameType) { |
| 21 | const obj = {}; |
| 22 | binding.object.defineProperties(obj, nameType); |
| 23 | |
| 24 | // accessors |
| 25 | assertPropertyIsNot(obj, 'readonlyAccessor', 'enumerable'); |
| 26 | assertPropertyIsNot(obj, 'readonlyAccessor', 'configurable'); |
| 27 | assert.strictEqual(obj.readonlyAccessor, true); |
| 28 | |
| 29 | assertPropertyIsNot(obj, 'readonlyAccessorWithUserData', 'enumerable'); |
| 30 | assertPropertyIsNot(obj, 'readonlyAccessorWithUserData', 'configurable'); |
| 31 | assert.strictEqual(obj.readonlyAccessorWithUserData, 1234, nameType); |
| 32 | |
| 33 | assertPropertyIsNot(obj, 'readwriteAccessor', 'enumerable'); |
| 34 | assertPropertyIsNot(obj, 'readwriteAccessor', 'configurable'); |
| 35 | obj.readwriteAccessor = false; |
| 36 | assert.strictEqual(obj.readwriteAccessor, false); |
| 37 | obj.readwriteAccessor = true; |
| 38 | assert.strictEqual(obj.readwriteAccessor, true); |
| 39 | |
| 40 | assertPropertyIsNot(obj, 'readwriteAccessorWithUserData', 'enumerable'); |
| 41 | assertPropertyIsNot(obj, 'readwriteAccessorWithUserData', 'configurable'); |
| 42 | obj.readwriteAccessorWithUserData = 2; |
| 43 | assert.strictEqual(obj.readwriteAccessorWithUserData, 2); |
| 44 | obj.readwriteAccessorWithUserData = -14; |
| 45 | assert.strictEqual(obj.readwriteAccessorWithUserData, -14); |
| 46 | |
| 47 | // templated accessors |
| 48 | assertPropertyIsNot(obj, 'readonlyAccessorT', 'enumerable'); |
| 49 | assertPropertyIsNot(obj, 'readonlyAccessorT', 'configurable'); |
| 50 | assert.strictEqual(obj.readonlyAccessorT, true); |
| 51 | |
| 52 | assertPropertyIsNot(obj, 'readonlyAccessorWithUserDataT', 'enumerable'); |
| 53 | assertPropertyIsNot(obj, 'readonlyAccessorWithUserDataT', 'configurable'); |
| 54 | assert.strictEqual(obj.readonlyAccessorWithUserDataT, -14, nameType); |
| 55 | |
| 56 | assertPropertyIsNot(obj, 'readwriteAccessorT', 'enumerable'); |
| 57 | assertPropertyIsNot(obj, 'readwriteAccessorT', 'configurable'); |
| 58 | obj.readwriteAccessorT = false; |
| 59 | assert.strictEqual(obj.readwriteAccessorT, false); |
| 60 | obj.readwriteAccessorT = true; |
| 61 | assert.strictEqual(obj.readwriteAccessorT, true); |
| 62 | |
| 63 | assertPropertyIsNot(obj, 'readwriteAccessorWithUserDataT', 'enumerable'); |
| 64 | assertPropertyIsNot(obj, 'readwriteAccessorWithUserDataT', 'configurable'); |
| 65 | obj.readwriteAccessorWithUserDataT = 2; |
| 66 | assert.strictEqual(obj.readwriteAccessorWithUserDataT, 2); |
| 67 | obj.readwriteAccessorWithUserDataT = -14; |
| 68 | assert.strictEqual(obj.readwriteAccessorWithUserDataT, -14); |
| 69 | |
| 70 | // values |
| 71 | assertPropertyIsNot(obj, 'readonlyValue', 'writable'); |
| 72 | assertPropertyIsNot(obj, 'readonlyValue', 'enumerable'); |
| 73 | assertPropertyIsNot(obj, 'readonlyValue', 'configurable'); |
| 74 | assert.strictEqual(obj.readonlyValue, true); |
| 75 | |
| 76 | assertPropertyIs(obj, 'readwriteValue', 'writable'); |
| 77 | assertPropertyIsNot(obj, 'readwriteValue', 'enumerable'); |