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 0000000000..1b7ae316c9 --- /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 +es7id: 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 0000000000..7746b98bb7 --- /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 +es7id: 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 0000000000..6a6243f50a --- /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' +es7id: 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 0000000000..1830cadf7c --- /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 +es7id: 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 0000000000..6dd82d8d69 --- /dev/null +++ b/test/built-ins/Object/getOwnPropertyDescriptors/inherited-properties-omitted.js @@ -0,0 +1,42 @@ +// 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. +es7id: pending +author: Jordan Harband +---*/ + +var F = function G() {}; +F.prototype.a = {}; +F.prototype.b = {}; + +var f = new F(); +f.b = {}; // 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, f.b, 'b’s value is f.b'); + +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, + Object.getOwnPropertyNames(f).length, + 'result has same number of own property names as f' +); 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 0000000000..752f914ea9 --- /dev/null +++ b/test/built-ins/Object/getOwnPropertyDescriptors/observable-operations.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 should perform observable operations in the correct order +es7id: pending +author: Jordan Harband +features: [Proxy] +---*/ + +var log = ""; +var object = { a: 0, b: 0, c: 0 }; +var handler = { + get: function (target, propertyKey, receiver) { + throw new Test262Error('no values should be retrieved via [[Get]]'); + }, + 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); + }, + 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 = { + 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 0000000000..bb136c4bfb --- /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. +es7id: 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 0000000000..93d1ae7e64 --- /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. +es7id: 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 0000000000..a5f59ca171 --- /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. +es7id: 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 0000000000..cbc5e825d2 --- /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. +es7id: 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-omitted.js b/test/built-ins/Object/getOwnPropertyDescriptors/symbols-omitted.js new file mode 100644 index 0000000000..6cd608db2a --- /dev/null +++ b/test/built-ins/Object/getOwnPropertyDescriptors/symbols-omitted.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 does not include Symbol keys. +es7id: 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 0000000000..d09d1872fb --- /dev/null +++ b/test/built-ins/Object/getOwnPropertyDescriptors/tamper-with-global-object.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 not have its behavior impacted by modifications to the global property Object +es7id: pending +author: Jordan Harband +---*/ + +function fakeObject() { + $ERROR('The overriden version of Object was called!'); +} +fakeObject.getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors; +fakeObject.keys = Object.keys; + +var global = Function('return 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'); 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 0000000000..1c6c4cf834 --- /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 +es7id: 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');