diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors')
20 files changed, 556 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/browser.js b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/browser.js diff --git a/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/exception-not-object-coercible.js b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/exception-not-object-coercible.js new file mode 100644 index 0000000000..4dbc6672d3 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/exception-not-object-coercible.js @@ -0,0 +1,18 @@ +// 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 +esid: sec-object.getownpropertydescriptors +author: Jordan Harband +---*/ + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptors(null); +}); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptors(undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/function-length.js b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/function-length.js new file mode 100644 index 0000000000..8c1746ba9c --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/function-length.js @@ -0,0 +1,17 @@ +// 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 +esid: sec-object.getownpropertydescriptors +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/function-name.js b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/function-name.js new file mode 100644 index 0000000000..7037128d72 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/function-name.js @@ -0,0 +1,21 @@ +// 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' +esid: sec-object.getownpropertydescriptors +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/function-property-descriptor.js b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/function-property-descriptor.js new file mode 100644 index 0000000000..2182f1234b --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/function-property-descriptor.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 be writable, non-enumerable, and configurable +esid: sec-object.getownpropertydescriptors +author: Jordan Harband +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(Object, 'getOwnPropertyDescriptors'); +verifyWritable(Object, 'getOwnPropertyDescriptors'); +verifyConfigurable(Object, 'getOwnPropertyDescriptors'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/inherited-properties-omitted.js b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/inherited-properties-omitted.js new file mode 100644 index 0000000000..68dc936d86 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/inherited-properties-omitted.js @@ -0,0 +1,45 @@ +// 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. +esid: sec-object.getownpropertydescriptors +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' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/normal-object.js b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/normal-object.js new file mode 100644 index 0000000000..44faa13b10 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/normal-object.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 produce a normal object inheriting from Object.prototype +esid: sec-object.getownpropertydescriptors +author: Jordan Harband +---*/ + +assert.sameValue( + Object.getPrototypeOf(Object.getOwnPropertyDescriptors({})), + Object.prototype +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/not-a-constructor.js b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/not-a-constructor.js new file mode 100644 index 0000000000..3d03780e66 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/not-a-constructor.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Object.getOwnPropertyDescriptors does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(Object.getOwnPropertyDescriptors), + false, + 'isConstructor(Object.getOwnPropertyDescriptors) must return false' +); + +assert.throws(TypeError, () => { + new Object.getOwnPropertyDescriptors({}); +}, '`new Object.getOwnPropertyDescriptors({})` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/observable-operations.js b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/observable-operations.js new file mode 100644 index 0000000000..20074b01e9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/observable-operations.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: Object.getOwnPropertyDescriptors should perform observable operations in the correct order +esid: sec-object.getownpropertydescriptors +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/order-after-define-property.js b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/order-after-define-property.js new file mode 100644 index 0000000000..336d47a3ca --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/order-after-define-property.js @@ -0,0 +1,50 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.getownpropertydescriptors +description: > + Property names are returned in ascending chronological order of creation + that is unaffected by [[DefineOwnProperty]]. +info: | + Object.getOwnPropertyDescriptors ( O ) + + [...] + 2. Let ownKeys be ? obj.[[OwnPropertyKeys]](). + 3. Let descriptors be ! OrdinaryObjectCreate(%Object.prototype%). + 4. For each element key of ownKeys in List order, do + [...] + c. If descriptor is not undefined, + perform ! CreateDataPropertyOrThrow(descriptors, key, descriptor). + 5. Return descriptors. + + OrdinaryOwnPropertyKeys ( O ) + + [...] + 3. For each own property key P of O that is a String but is not an array index, + in ascending chronological order of property creation, do + a. Add P as the last element of keys. + 4. For each own property key P of O that is a Symbol, in ascending + chronological order of property creation, do + a. Add P as the last element of keys. + 5. Return keys. +features: [Symbol, Reflect] +includes: [compareArray.js] +---*/ + +var obj = {}; +var symA = Symbol("a"); +var symB = Symbol("b"); +obj[symA] = 1; +obj[symB] = 2; +Object.defineProperty(obj, symA, {configurable: false}); +var objDescs = Object.getOwnPropertyDescriptors(obj); +assert.compareArray(Reflect.ownKeys(objDescs), [symA, symB]); + +var re = /(?:)/g; +re.a = 1; +Object.defineProperty(re, "lastIndex", {value: 2}); +var reDescs = Object.getOwnPropertyDescriptors(re); +assert.compareArray(Reflect.ownKeys(reDescs), ["lastIndex", "a"]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/primitive-booleans.js b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/primitive-booleans.js new file mode 100644 index 0000000000..32ddcc0f99 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/primitive-booleans.js @@ -0,0 +1,18 @@ +// 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. +esid: sec-object.getownpropertydescriptors +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/primitive-numbers.js b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/primitive-numbers.js new file mode 100644 index 0000000000..5dbdf62524 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/primitive-numbers.js @@ -0,0 +1,17 @@ +// 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. +esid: sec-object.getownpropertydescriptors +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/primitive-strings.js b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/primitive-strings.js new file mode 100644 index 0000000000..a17d1d9102 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/primitive-strings.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 accepts string primitives. +esid: sec-object.getownpropertydescriptors +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"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/primitive-symbols.js b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/primitive-symbols.js new file mode 100644 index 0000000000..56c1ed54ad --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/primitive-symbols.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 Symbol primitives. +esid: sec-object.getownpropertydescriptors +author: Jordan Harband +features: [Symbol] +---*/ + +var result = Object.getOwnPropertyDescriptors(Symbol()); + +assert.sameValue(Object.keys(result).length, 0, 'symbol primitive has no descriptors'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/proxy-no-ownkeys-returned-keys-order.js b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/proxy-no-ownkeys-returned-keys-order.js new file mode 100644 index 0000000000..7ae003b27b --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/proxy-no-ownkeys-returned-keys-order.js @@ -0,0 +1,53 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-object.getownpropertydescriptors +description: > + If Proxy "ownKeys" trap is missing, keys are sorted by type in ascending + chronological order. +info: | + Object.getOwnPropertyDescriptors ( O ) + + [...] + 2. Let ownKeys be ? obj.[[OwnPropertyKeys]](). + [...] + 4. For each element key of ownKeys in List order, do + a. Let desc be ? obj.[[GetOwnProperty]](key). + + [[OwnPropertyKeys]] ( ) + + [...] + 6. If trap is undefined, then + a. Return ? target.[[OwnPropertyKeys]](). + + OrdinaryOwnPropertyKeys ( O ) + + [...] + 3. For each own property key P of O such that Type(P) is String and P is + not an array index, in ascending chronological order of property creation, do + a. Add P as the last element of keys. + 4. For each own property key P of O such that Type(P) is Symbol, + in ascending chronological order of property creation, do + a. Add P as the last element of keys. + 5. Return keys. +features: [Proxy, Symbol] +includes: [compareArray.js] +---*/ + +var target = {}; +var sym = Symbol(); +target[sym] = 1; +target.foo = 2; +target[0] = 3; + +var getOwnKeys = []; +var proxy = new Proxy(target, { + getOwnPropertyDescriptor: function(_target, key) { + getOwnKeys.push(key); + }, +}); + +Object.getOwnPropertyDescriptors(proxy); +assert.compareArray(getOwnKeys, ["0", "foo", sym]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/proxy-undefined-descriptor.js b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/proxy-undefined-descriptor.js new file mode 100644 index 0000000000..a00b10470c --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/proxy-undefined-descriptor.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 filter out undefined OwnPropertyDescriptors +esid: sec-object.getownpropertydescriptors +author: Jordan Harband +features: [Proxy] +includes: [proxyTrapsHelper.js] +---*/ + +var key = "a"; +var ownKeys = [key]; +var badProxyHandlers = allowProxyTraps({ + getOwnPropertyDescriptor: function() {}, + ownKeys: function() { + return ownKeys; + } +}); +var proxy = new Proxy({}, badProxyHandlers); + +var keys = Reflect.ownKeys(proxy); +assert.notSameValue(keys, ownKeys, 'Object.keys returns a new Array'); +assert.sameValue(Array.isArray(keys), true, 'Object.keys returns an Array'); +assert.sameValue(keys.length, ownKeys.length, 'keys and ownKeys have the same length'); +assert.sameValue(keys[0], ownKeys[0], 'keys and ownKeys have the same contents'); + +var descriptor = Object.getOwnPropertyDescriptor(proxy, key); +assert.sameValue(descriptor, undefined, "Descriptor matches result of [[GetOwnPropertyDescriptor]] trap"); + +var result = Object.getOwnPropertyDescriptors(proxy); +assert.sameValue(key in result, false, "key is not present in result"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/shell.js b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/shell.js new file mode 100644 index 0000000000..bc72493f03 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/shell.js @@ -0,0 +1,33 @@ +// GENERATED, DO NOT EDIT +// file: proxyTrapsHelper.js +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Used to assert the correctness of object behavior in the presence + and context of Proxy objects. +defines: [allowProxyTraps] +---*/ + +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/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/symbols-included.js b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/symbols-included.js new file mode 100644 index 0000000000..8b5fe011fc --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/symbols-included.js @@ -0,0 +1,47 @@ +// 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. +esid: sec-object.getownpropertydescriptors +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, { + writable: true, + enumerable: false, + configurable: true, + value: value +}); + +var result = Object.getOwnPropertyDescriptors(obj); + +assert.sameValue(Object.keys(result).length, 1, 'obj has 1 string-keyed descriptor'); +assert.sameValue(Object.getOwnPropertySymbols(result).length, 2, 'obj has 2 symbol-keyed 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`'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/tamper-with-global-object.js b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/tamper-with-global-object.js new file mode 100644 index 0000000000..b3abe012aa --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/tamper-with-global-object.js @@ -0,0 +1,23 @@ +// 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 +esid: sec-object.getownpropertydescriptors +author: Jordan Harband +---*/ + +function fakeObject() { + throw new Test262Error('The overriden version of Object was called!'); +} +fakeObject.getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors; +fakeObject.keys = Object.keys; + +var global = this; +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/tamper-with-object-keys.js b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/tamper-with-object-keys.js new file mode 100644 index 0000000000..57b63193ab --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/getOwnPropertyDescriptors/tamper-with-object-keys.js @@ -0,0 +1,26 @@ +// 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 +esid: sec-object.getownpropertydescriptors +author: Jordan Harband +---*/ + +function fakeObjectGetOwnPropertyDescriptor() { + throw new Test262Error('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'); + +reportCompare(0, 0); |