diff --git a/harness/proxyTrapsHelper.js b/harness/proxyTrapsHelper.js new file mode 100644 index 0000000000000000000000000000000000000000..04a504b85ef60f81b259d9e3915a0b225bcf5e7b --- /dev/null +++ b/harness/proxyTrapsHelper.js @@ -0,0 +1,22 @@ +function allowProxyTraps(overrides) { + function throwTest262Error(msg) { + return function () { throw new Test262Error(msg); }; + } + if (!overrides) { overrides = {}; } + return { + getPrototypeOf: overrides.getPrototypeOf || throwTest262Error('[[GetPrototypeOf]] trap called'), + setPrototypeOf: overrides.setPrototypeOf || throwTest262Error('[[SetPrototypeOf]] trap called'), + isExtensible: overrides.isExtensible || throwTest262Error('[[IsExtensible]] trap called'), + preventExtensions: overrides.preventExtensions || throwTest262Error('[[PreventExtensions]] trap called'), + getOwnPropertyDescriptor: overrides.getOwnPropertyDescriptor || throwTest262Error('[[GetOwnProperty]] trap called'), + has: overrides.has || throwTest262Error('[[HasProperty]] trap called'), + get: overrides.get || throwTest262Error('[[Get]] trap called'), + set: overrides.set || throwTest262Error('[[Set]] trap called'), + deleteProperty: overrides.deleteProperty || throwTest262Error('[[Delete]] trap called'), + defineProperty: overrides.defineProperty || throwTest262Error('[[DefineOwnProperty]] trap called'), + enumerate: throwTest262Error('[[Enumerate]] trap called: this trap has been removed'), + ownKeys: overrides.ownKeys || throwTest262Error('[[OwnPropertyKeys]] trap called'), + apply: overrides.apply || throwTest262Error('[[Call]] trap called'), + construct: overrides.construct || throwTest262Error('[[Construct]] trap called') + }; +} diff --git a/test/built-ins/Object/entries/observable-operations.js b/test/built-ins/Object/entries/observable-operations.js index f8916c285d591f10e0b50a0ea6ebccb1979222fb..f1c4b41b2e26c9c32d373a576a66ed9f2b8bb230 100644 --- a/test/built-ins/Object/entries/observable-operations.js +++ b/test/built-ins/Object/entries/observable-operations.js @@ -6,11 +6,12 @@ id: sec-object.entries description: Object.entries should perform observable operations in the correct order author: Jordan Harband features: [Proxy] +includes: [proxyTrapsHelper.js] ---*/ var log = ""; var object = { a: 0, b: 0, c: 0 }; -var handler = { +var handler = allowProxyTraps({ get: function (target, propertyKey, receiver) { assert.sameValue(target, object, "get target"); assert.sameValue(receiver, proxy, "get receiver"); @@ -26,23 +27,14 @@ var handler = { assert.sameValue(target, object, "ownKeys"); log += "|ownKeys"; return Object.getOwnPropertyNames(target); - }, - deleteProperty: function (oTarget, sKey) { - throw new Test262Error('properties should not be deleted'); - }, - defineProperty: function (oTarget, sKey, oDesc) { - throw new Test262Error('properties should not be defined'); - }, - set: function (oTarget, sKey, vValue) { - throw new Test262Error('properties should not be assigned'); } -}; -var check = { +}); +var check = allowProxyTraps({ get: function (target, propertyKey, receiver) { assert(propertyKey in target, "handler check: " + propertyKey); return target[propertyKey]; } -}; +}); var proxy = new Proxy(object, new Proxy(handler, check)); var result = Object.entries(proxy); assert.sameValue(log, "|ownKeys|getOwnPropertyDescriptor:a|get:a|getOwnPropertyDescriptor:b|get:b|getOwnPropertyDescriptor:c|get:c", log); diff --git a/test/built-ins/Object/getOwnPropertyDescriptors/duplicate-keys.js b/test/built-ins/Object/getOwnPropertyDescriptors/duplicate-keys.js new file mode 100644 index 0000000000000000000000000000000000000000..c272fe0a958850bf5f1e4b63b133292213d1f861 --- /dev/null +++ b/test/built-ins/Object/getOwnPropertyDescriptors/duplicate-keys.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Object.getOwnPropertyDescriptors on a proxy with duplicate ownKeys should work +id: pending +author: Jordan Harband +features: [Proxy] +---*/ + +var i = 0; +var descriptors = [ + { enumerable: false, value: "A1", writable: true, configurable: true }, + { enumerable: true, value: "A2", writable: true, configurable: true } +]; +var log = ''; +var proxy = new Proxy({}, { + ownKeys() { + log += 'ownKeys|'; + return ['DUPLICATE', 'DUPLICATE', 'DUPLICATE']; + }, + getOwnPropertyDescriptor(t, name) { + log += 'getOwnPropertyDescriptor:' + name + '|'; + return descriptors[i++]; + } +}); + +var result = Object.getOwnPropertyDescriptors(proxy); +assert.sameValue(result.hasOwnProperty('DUPLICATE'), true); +assert.sameValue(result.DUPLICATE, undefined); +assert.sameValue(log, 'ownKeys|getOwnPropertyDescriptor:DUPLICATE|getOwnPropertyDescriptor:DUPLICATE|getOwnPropertyDescriptor:DUPLICATE'); diff --git a/test/built-ins/Object/getOwnPropertyDescriptors/exception-not-object-coercible.js b/test/built-ins/Object/getOwnPropertyDescriptors/exception-not-object-coercible.js new file mode 100644 index 0000000000000000000000000000000000000000..301be92bbc92784c5e68f57be865fb8317c2b697 --- /dev/null +++ b/test/built-ins/Object/getOwnPropertyDescriptors/exception-not-object-coercible.js @@ -0,0 +1,16 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Object.getOwnPropertyDescriptors should fail if given a null or undefined value +id: pending +author: Jordan Harband +---*/ + +assert.throws(TypeError, function () { + Object.getOwnPropertyDescriptors(null); +}); + +assert.throws(TypeError, function () { + Object.getOwnPropertyDescriptors(undefined); +}); diff --git a/test/built-ins/Object/getOwnPropertyDescriptors/function-length.js b/test/built-ins/Object/getOwnPropertyDescriptors/function-length.js new file mode 100644 index 0000000000000000000000000000000000000000..d6ac0ad77dbe95cfb4eddce301e5307b5db432e3 --- /dev/null +++ b/test/built-ins/Object/getOwnPropertyDescriptors/function-length.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Object.getOwnPropertyDescriptors should have length 1 +id: pending +author: Jordan Harband +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Object.getOwnPropertyDescriptors.length, 1, 'Expected Object.getOwnPropertyDescriptors.length to be 1'); + +verifyNotEnumerable(Object.getOwnPropertyDescriptors, 'length'); +verifyNotWritable(Object.getOwnPropertyDescriptors, 'length'); +verifyConfigurable(Object.getOwnPropertyDescriptors, 'length'); diff --git a/test/built-ins/Object/getOwnPropertyDescriptors/function-name.js b/test/built-ins/Object/getOwnPropertyDescriptors/function-name.js new file mode 100644 index 0000000000000000000000000000000000000000..db48946476fdd5cfbac31b8e498dd05fa10103d1 --- /dev/null +++ b/test/built-ins/Object/getOwnPropertyDescriptors/function-name.js @@ -0,0 +1,19 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Object.getOwnPropertyDescriptors should have name property with value 'getOwnPropertyDescriptors' +id: pending +author: Jordan Harband +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Object.getOwnPropertyDescriptors.name, + 'getOwnPropertyDescriptors', + 'Expected Object.getOwnPropertyDescriptors.name to be "getOwnPropertyDescriptors"' +); + +verifyNotEnumerable(Object.getOwnPropertyDescriptors, 'name'); +verifyNotWritable(Object.getOwnPropertyDescriptors, 'name'); +verifyConfigurable(Object.getOwnPropertyDescriptors, 'name'); diff --git a/test/built-ins/Object/getOwnPropertyDescriptors/function-property-descriptor.js b/test/built-ins/Object/getOwnPropertyDescriptors/function-property-descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..9a94c083d78bb937561e5e5e5d4aa81cac8c6c37 --- /dev/null +++ b/test/built-ins/Object/getOwnPropertyDescriptors/function-property-descriptor.js @@ -0,0 +1,13 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Object.getOwnPropertyDescriptors should be writable, non-enumerable, and configurable +id: pending +author: Jordan Harband +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(Object, 'getOwnPropertyDescriptors'); +verifyWritable(Object, 'getOwnPropertyDescriptors'); +verifyConfigurable(Object, 'getOwnPropertyDescriptors'); diff --git a/test/built-ins/Object/getOwnPropertyDescriptors/inherited-properties-omitted.js b/test/built-ins/Object/getOwnPropertyDescriptors/inherited-properties-omitted.js new file mode 100644 index 0000000000000000000000000000000000000000..b981e7461459fa5b08e35679c7be5817e9f42a1d --- /dev/null +++ b/test/built-ins/Object/getOwnPropertyDescriptors/inherited-properties-omitted.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Object.getOwnPropertyDescriptors does not see inherited properties. +id: pending +author: Jordan Harband +---*/ + +var F = function () {}; +F.prototype.a = {}; +F.prototype.b = {}; + +var f = new F(); +var bValue = {}; +f.b = bValue; // shadow the prototype +Object.defineProperty(f, 'c', { + enumerable: false, + configurable: true, + writable: false, + value: {} +}); // solely an own property + +var result = Object.getOwnPropertyDescriptors(f); + +assert.sameValue(!!result.b, true, 'b has a descriptor'); +assert.sameValue(!!result.c, true, 'c has a descriptor'); + +assert.sameValue(result.b.enumerable, true, 'b is enumerable'); +assert.sameValue(result.b.configurable, true, 'b is configurable'); +assert.sameValue(result.b.writable, true, 'b is writable'); +assert.sameValue(result.b.value, bValue, 'b’s value is `bValue`'); + +assert.sameValue(result.c.enumerable, false, 'c is enumerable'); +assert.sameValue(result.c.configurable, true, 'c is configurable'); +assert.sameValue(result.c.writable, false, 'c is writable'); +assert.sameValue(result.c.value, f.c, 'c’s value is `f.c`'); + +assert.sameValue( + Object.keys(result).length, + 2, + 'result has same number of own property names as f' +); diff --git a/test/built-ins/Object/getOwnPropertyDescriptors/normal-object.js b/test/built-ins/Object/getOwnPropertyDescriptors/normal-object.js new file mode 100644 index 0000000000000000000000000000000000000000..cfad4a9d7c8d3eee8c71e7d08d9310c3bc082303 --- /dev/null +++ b/test/built-ins/Object/getOwnPropertyDescriptors/normal-object.js @@ -0,0 +1,13 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Object.getOwnPropertyDescriptors should produce a normal object inheriting from Object.prototype +id: pending +author: Jordan Harband +---*/ + +assert.sameValue( + Object.getPrototypeOf(Object.getOwnPropertyDescriptors({})), + Object.prototype +); diff --git a/test/built-ins/Object/getOwnPropertyDescriptors/observable-operations.js b/test/built-ins/Object/getOwnPropertyDescriptors/observable-operations.js new file mode 100644 index 0000000000000000000000000000000000000000..c5af08299865fdb2e14278e4c13e12c9c58219c2 --- /dev/null +++ b/test/built-ins/Object/getOwnPropertyDescriptors/observable-operations.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Object.getOwnPropertyDescriptors should perform observable operations in the correct order +id: pending +author: Jordan Harband +features: [Proxy] +includes: [proxyTrapsHelper.js] +---*/ + +var log = ""; +var object = { a: 0, b: 0, c: 0 }; +var handler = allowProxyTraps({ + getOwnPropertyDescriptor: function (target, propertyKey) { + assert.sameValue(target, object, "getOwnPropertyDescriptor"); + log += "|getOwnPropertyDescriptor:" + propertyKey; + return Object.getOwnPropertyDescriptor(target, propertyKey); + }, + ownKeys: function (target) { + assert.sameValue(target, object, "ownKeys"); + log += "|ownKeys"; + return Object.getOwnPropertyNames(target); + } +}); +var check = allowProxyTraps({ + get: function (target, propertyKey, receiver) { + assert(propertyKey in target, "handler check: " + propertyKey); + return target[propertyKey]; + } +}); +var proxy = new Proxy(object, new Proxy(handler, check)); +var result = Object.getOwnPropertyDescriptors(proxy); +assert.sameValue(log, "|ownKeys|getOwnPropertyDescriptor:a|getOwnPropertyDescriptor:b|getOwnPropertyDescriptor:c", 'log'); diff --git a/test/built-ins/Object/getOwnPropertyDescriptors/primitive-booleans.js b/test/built-ins/Object/getOwnPropertyDescriptors/primitive-booleans.js new file mode 100644 index 0000000000000000000000000000000000000000..b105f4ad975f15e11bd3801ec613aa82f6689876 --- /dev/null +++ b/test/built-ins/Object/getOwnPropertyDescriptors/primitive-booleans.js @@ -0,0 +1,16 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Object.getOwnPropertyDescriptors accepts boolean primitives. +id: pending +author: Jordan Harband +---*/ + +var trueResult = Object.getOwnPropertyDescriptors(true); + +assert.sameValue(Object.keys(trueResult).length, 0, 'trueResult has 0 items'); + +var falseResult = Object.getOwnPropertyDescriptors(false); + +assert.sameValue(Object.keys(falseResult).length, 0, 'falseResult has 0 items'); diff --git a/test/built-ins/Object/getOwnPropertyDescriptors/primitive-numbers.js b/test/built-ins/Object/getOwnPropertyDescriptors/primitive-numbers.js new file mode 100644 index 0000000000000000000000000000000000000000..2ed6bc68f15145cc840826a31f9dac107a1fd2cf --- /dev/null +++ b/test/built-ins/Object/getOwnPropertyDescriptors/primitive-numbers.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Object.getOwnPropertyDescriptors accepts number primitives. +id: pending +author: Jordan Harband +---*/ + +assert.sameValue(Object.keys(Object.getOwnPropertyDescriptors(0)).length, 0, '0 has zero descriptors'); +assert.sameValue(Object.keys(Object.getOwnPropertyDescriptors(-0)).length, 0, '-0 has zero descriptors'); +assert.sameValue(Object.keys(Object.getOwnPropertyDescriptors(Infinity)).length, 0, 'Infinity has zero descriptors'); +assert.sameValue(Object.keys(Object.getOwnPropertyDescriptors(-Infinity)).length, 0, '-Infinity has zero descriptors'); +assert.sameValue(Object.keys(Object.getOwnPropertyDescriptors(NaN)).length, 0, 'NaN has zero descriptors'); +assert.sameValue(Object.keys(Object.getOwnPropertyDescriptors(Math.PI)).length, 0, 'Math.PI has zero descriptors'); diff --git a/test/built-ins/Object/getOwnPropertyDescriptors/primitive-strings.js b/test/built-ins/Object/getOwnPropertyDescriptors/primitive-strings.js new file mode 100644 index 0000000000000000000000000000000000000000..ac44ef2b6dd9c2a8552a008e856b5b315f088ad2 --- /dev/null +++ b/test/built-ins/Object/getOwnPropertyDescriptors/primitive-strings.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Object.getOwnPropertyDescriptors accepts string primitives. +id: pending +author: Jordan Harband +---*/ + +var result = Object.getOwnPropertyDescriptors('abc'); + +assert.sameValue(Object.keys(result).length, 4, 'string has 4 descriptors'); + +assert.sameValue(result.length.configurable, false, 'length is not configurable'); +assert.sameValue(result.length.enumerable, false, 'length is not enumerable'); +assert.sameValue(result.length.writable, false, 'length is not writable'); +assert.sameValue(result.length.value, 3, 'length is 3'); + +assert.sameValue(result[0].configurable, false, 'index 0 is not configurable'); +assert.sameValue(result[0].enumerable, true, 'index 0 is enumerable'); +assert.sameValue(result[0].writable, false, 'index 0 is not writable'); +assert.sameValue(result[0].value, 'a', 'index 0 is "a"'); + +assert.sameValue(result[1].configurable, false, 'index 1 is not configurable'); +assert.sameValue(result[1].enumerable, true, 'index 1 is enumerable'); +assert.sameValue(result[1].writable, false, 'index 1 is not writable'); +assert.sameValue(result[1].value, 'b', 'index 1 is "b"'); + +assert.sameValue(result[2].configurable, false, 'index 2 is not configurable'); +assert.sameValue(result[2].enumerable, true, 'index 2 is enumerable'); +assert.sameValue(result[2].writable, false, 'index 2 is not writable'); +assert.sameValue(result[2].value, 'c', 'index 2 is "c"'); + diff --git a/test/built-ins/Object/getOwnPropertyDescriptors/primitive-symbols.js b/test/built-ins/Object/getOwnPropertyDescriptors/primitive-symbols.js new file mode 100644 index 0000000000000000000000000000000000000000..ea7b27b331cb4a1f293a6e93a741cfd1d26640cb --- /dev/null +++ b/test/built-ins/Object/getOwnPropertyDescriptors/primitive-symbols.js @@ -0,0 +1,13 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Object.getOwnPropertyDescriptors accepts Symbol primitives. +id: pending +author: Jordan Harband +features: [Symbol] +---*/ + +var result = Object.getOwnPropertyDescriptors(Symbol()); + +assert.sameValue(Object.keys(result).length, 0, 'symbol primitive has no descriptors'); diff --git a/test/built-ins/Object/getOwnPropertyDescriptors/symbols-included.js b/test/built-ins/Object/getOwnPropertyDescriptors/symbols-included.js new file mode 100644 index 0000000000000000000000000000000000000000..97d8b2ac5e005ba9113cd001a220ab386c659aa7 --- /dev/null +++ b/test/built-ins/Object/getOwnPropertyDescriptors/symbols-included.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Object.getOwnPropertyDescriptors includes Symbol keys. +id: pending +author: Jordan Harband +features: [Symbol] +---*/ + +var value = {}; +var enumSym = Symbol('enum'); +var nonEnumSym = Symbol('nonenum'); +var symValue = Symbol('value'); + +var obj = { key: symValue }; +obj[enumSym] = value; +Object.defineProperty(obj, nonEnumSym, { enumerable: false, value: value }); + +var result = Object.getOwnPropertyDescriptors(obj); + +assert.sameValue(Object.keys(result).length, 3, 'obj has 3 descriptors'); + +assert.sameValue(result.key.configurable, true, 'result.key is configurable'); +assert.sameValue(result.key.enumerable, true, 'result.key is enumerable'); +assert.sameValue(result.key.writable, true, 'result.key is writable'); +assert.sameValue(result.key.value, symValue, 'result.key has value symValue'); + +assert.sameValue(result[enumSym].configurable, true, 'result[enumSym] is configurable'); +assert.sameValue(result[enumSym].enumerable, true, 'result[enumSym] is enumerable'); +assert.sameValue(result[enumSym].writable, true, 'result[enumSym] is writable'); +assert.sameValue(result[enumSym].value, value, 'result[enumSym] has value `value`'); + +assert.sameValue(result[nonEnumSym].configurable, true, 'result[nonEnumSym] is configurable'); +assert.sameValue(result[nonEnumSym].enumerable, false, 'result[nonEnumSym] is not enumerable'); +assert.sameValue(result[nonEnumSym].writable, true, 'result[nonEnumSym] is writable'); +assert.sameValue(result[nonEnumSym].value, value, 'result[nonEnumSym] has value `value`'); diff --git a/test/built-ins/Object/getOwnPropertyDescriptors/tamper-with-global-object.js b/test/built-ins/Object/getOwnPropertyDescriptors/tamper-with-global-object.js new file mode 100644 index 0000000000000000000000000000000000000000..a68a534745579ceae379bba2dffa172aa84476b5 --- /dev/null +++ b/test/built-ins/Object/getOwnPropertyDescriptors/tamper-with-global-object.js @@ -0,0 +1,22 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Object.getOwnPropertyDescriptors should not have its behavior impacted by modifications to the global property Object +id: pending +author: Jordan Harband +includes: [fnGlobalObject.js] +---*/ + +function fakeObject() { + $ERROR('The overriden version of Object was called!'); +} +fakeObject.getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors; +fakeObject.keys = Object.keys; + +var global = fnGlobalObject(); +global.Object = fakeObject; + +assert.sameValue(Object, fakeObject, 'Sanity check failed: could not modify the global Object'); +assert.sameValue(Object.keys(Object.getOwnPropertyDescriptors('a')).length, 2, 'Expected string primitive to have 2 descriptors'); diff --git a/test/built-ins/Object/getOwnPropertyDescriptors/tamper-with-object-keys.js b/test/built-ins/Object/getOwnPropertyDescriptors/tamper-with-object-keys.js new file mode 100644 index 0000000000000000000000000000000000000000..588298ed2504b08eb1e6b84ba4f30a72ca3d398b --- /dev/null +++ b/test/built-ins/Object/getOwnPropertyDescriptors/tamper-with-object-keys.js @@ -0,0 +1,22 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Object.getOwnPropertyDescriptors should not have its behavior impacted by modifications to Object.getOwnPropertyDescriptor +id: pending +author: Jordan Harband +---*/ + +function fakeObjectGetOwnPropertyDescriptor() { + $ERROR('The overriden version of Object.getOwnPropertyDescriptor was called!'); +} +Object.getOwnPropertyDescriptor = fakeObjectGetOwnPropertyDescriptor; + +assert.sameValue( + Object.getOwnPropertyDescriptor, + fakeObjectGetOwnPropertyDescriptor, + 'Sanity check failed: could not modify the global Object.getOwnPropertyDescriptor' +); + +assert.sameValue(Object.keys(Object.getOwnPropertyDescriptors({ a: 1 })).length, 1, 'Expected object with 1 key to have 1 descriptor'); diff --git a/test/built-ins/Object/values/observable-operations.js b/test/built-ins/Object/values/observable-operations.js index c68ca98334f9391cee6102d6fb728629f55bf009..b3f0ab4581bdb07c998a789ea05523128acbef3c 100644 --- a/test/built-ins/Object/values/observable-operations.js +++ b/test/built-ins/Object/values/observable-operations.js @@ -6,11 +6,12 @@ id: sec-object.values description: Object.values should perform observable operations in the correct order author: Jordan Harband features: [Proxy] +includes: [proxyTrapsHelper.js] ---*/ var log = ""; var object = { a: 0, b: 0, c: 0 }; -var handler = { +var handler = allowProxyTraps({ get: function (target, propertyKey, receiver) { assert.sameValue(target, object, "get target"); assert.sameValue(receiver, proxy, "get receiver"); @@ -26,23 +27,14 @@ var handler = { assert.sameValue(target, object, "ownKeys"); log += "|ownKeys"; return Object.getOwnPropertyNames(target); - }, - deleteProperty: function (oTarget, sKey) { - throw new Test262Error('properties should not be deleted'); - }, - defineProperty: function (oTarget, sKey, oDesc) { - throw new Test262Error('properties should not be defined'); - }, - set: function (oTarget, sKey, vValue) { - throw new Test262Error('properties should not be assigned'); } -}; -var check = { +}); +var check = allowProxyTraps({ get: function (target, propertyKey, receiver) { assert(propertyKey in target, "handler check: " + propertyKey); return target[propertyKey]; } -}; +}); var proxy = new Proxy(object, new Proxy(handler, check)); var result = Object.values(proxy); assert.sameValue(log, "|ownKeys|getOwnPropertyDescriptor:a|get:a|getOwnPropertyDescriptor:b|get:b|getOwnPropertyDescriptor:c|get:c", log); diff --git a/test/harness/proxytrapshelper-default.js b/test/harness/proxytrapshelper-default.js new file mode 100644 index 0000000000000000000000000000000000000000..a4613f6824bd1e60d9468a9535d763192a7b29b9 --- /dev/null +++ b/test/harness/proxytrapshelper-default.js @@ -0,0 +1,40 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: allowProxyTraps helper should default throw on all the proxy trap named methods being invoked +id: pending +author: Jordan Harband +includes: [proxyTrapsHelper.js] +---*/ + +var traps = allowProxyTraps(); + +function assertTrapThrows(trap) { + if (typeof traps[trap] !== 'function') { + throw new Test262Error('trap ' + trap + ' is not a function'); + } + var failedToThrow = false; + try { + traps[trap](); + failedToThrow = true; + } catch (e) {} + if (failedToThrow) { + throw new Test262Error('trap ' + trap + ' did not throw an error'); + } +} + +assertTrapThrows('getPrototypeOf'); +assertTrapThrows('setPrototypeOf'); +assertTrapThrows('isExtensible'); +assertTrapThrows('preventExtensions'); +assertTrapThrows('getOwnPropertyDescriptor'); +assertTrapThrows('has'); +assertTrapThrows('get'); +assertTrapThrows('set'); +assertTrapThrows('deleteProperty'); +assertTrapThrows('defineProperty'); +assertTrapThrows('enumerate'); +assertTrapThrows('ownKeys'); +assertTrapThrows('apply'); +assertTrapThrows('construct'); diff --git a/test/harness/proxytrapshelper-overrides.js b/test/harness/proxytrapshelper-overrides.js new file mode 100644 index 0000000000000000000000000000000000000000..4abf5730e51fd2c287592d9e279b0a1efad62986 --- /dev/null +++ b/test/harness/proxytrapshelper-overrides.js @@ -0,0 +1,75 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: allowProxyTraps helper should default throw on all the proxy trap named methods being invoked +id: pending +author: Jordan Harband +includes: [proxyTrapsHelper.js] +---*/ +var overrides = { + getPrototypeOf: function () {}, + setPrototypeOf: function () {}, + isExtensible: function () {}, + preventExtensions: function () {}, + getOwnPropertyDescriptor: function () {}, + has: function () {}, + get: function () {}, + set: function () {}, + deleteProperty: function () {}, + defineProperty: function () {}, + enumerate: function () {}, + ownKeys: function () {}, + apply: function () {}, + construct: function () {}, +}; +var traps = allowProxyTraps(overrides); + +function assertTrapSucceeds(trap) { + if (typeof traps[trap] !== 'function') { + throw new Test262Error('trap ' + trap + ' is not a function'); + } + if (traps[trap] !== overrides[trap]) { + throw new Test262Error('trap ' + trap + ' was not overriden in allowProxyTraps'); + } + var threw = false; + try { + traps[trap](); + } catch (e) { + threw = true; + } + if (threw) { + throw new Test262Error('trap ' + trap + ' threw an error'); + } +} + +function assertTrapThrows(trap) { + if (typeof traps[trap] !== 'function') { + throw new Test262Error('trap ' + trap + ' is not a function'); + } + var failedToThrow = false; + try { + traps[trap](); + failedToThrow = true; + } catch (e) {} + if (failedToThrow) { + throw new Test262Error('trap ' + trap + ' did not throw an error'); + } +} + +assertTrapSucceeds('getPrototypeOf'); +assertTrapSucceeds('setPrototypeOf'); +assertTrapSucceeds('isExtensible'); +assertTrapSucceeds('preventExtensions'); +assertTrapSucceeds('getOwnPropertyDescriptor'); +assertTrapSucceeds('has'); +assertTrapSucceeds('get'); +assertTrapSucceeds('set'); +assertTrapSucceeds('deleteProperty'); +assertTrapSucceeds('defineProperty'); +assertTrapSucceeds('ownKeys'); +assertTrapSucceeds('apply'); +assertTrapSucceeds('construct'); + +// enumerate should always throw because the trap has been removed +assertTrapThrows('enumerate');