diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/Object/values')
22 files changed, 560 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Object/values/browser.js b/js/src/tests/test262/built-ins/Object/values/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/values/browser.js diff --git a/js/src/tests/test262/built-ins/Object/values/exception-during-enumeration.js b/js/src/tests/test262/built-ins/Object/values/exception-during-enumeration.js new file mode 100644 index 0000000000..fa6c9c73bc --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/values/exception-during-enumeration.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.values +description: Object.values should terminate if getting a value throws an exception +author: Jordan Harband +---*/ + +var trappedKey = { + get a() { + throw new RangeError('This error should be re-thrown'); + }, + get b() { + throw new Test262Error('Should not try to get the second element'); + } +}; + +assert.throws(RangeError, function() { + Object.values(trappedKey); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/values/exception-not-object-coercible.js b/js/src/tests/test262/built-ins/Object/values/exception-not-object-coercible.js new file mode 100644 index 0000000000..f52d333010 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/values/exception-not-object-coercible.js @@ -0,0 +1,18 @@ +// Copyright (C) 2015 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.values +description: Object.values should fail if given a null or undefined value +author: Jordan Harband +---*/ + +assert.throws(TypeError, function() { + Object.values(null); +}); + +assert.throws(TypeError, function() { + Object.values(undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/values/function-length.js b/js/src/tests/test262/built-ins/Object/values/function-length.js new file mode 100644 index 0000000000..bb3ede0e3c --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/values/function-length.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.values +description: Object.values should have length 1 +author: Jordan Harband +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Object.values.length, 1, 'Expected Object.values.length to be 1'); + +verifyNotEnumerable(Object.values, 'length'); +verifyNotWritable(Object.values, 'length'); +verifyConfigurable(Object.values, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/values/function-name.js b/js/src/tests/test262/built-ins/Object/values/function-name.js new file mode 100644 index 0000000000..6535fd2db4 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/values/function-name.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.values +description: Object.values should have name property with value 'values' +author: Jordan Harband +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Object.values.name, + 'values', + 'Expected Object.values.name to be "values"' +); + +verifyNotEnumerable(Object.values, 'name'); +verifyNotWritable(Object.values, 'name'); +verifyConfigurable(Object.values, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/values/function-property-descriptor.js b/js/src/tests/test262/built-ins/Object/values/function-property-descriptor.js new file mode 100644 index 0000000000..ebd062c347 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/values/function-property-descriptor.js @@ -0,0 +1,15 @@ +// Copyright (C) 2015 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.values +description: Object.values should be writable, non-enumerable, and configurable +author: Jordan Harband +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(Object, 'values'); +verifyWritable(Object, 'values'); +verifyConfigurable(Object, 'values'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/values/getter-adding-key.js b/js/src/tests/test262/built-ins/Object/values/getter-adding-key.js new file mode 100644 index 0000000000..e4beea017a --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/values/getter-adding-key.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.values +description: Object.values does not see a new element added by a getter that is hit during iteration +author: Jordan Harband +---*/ + +var bAddsC = { + a: 'A', + get b() { + this.c = 'C'; + return 'B'; + } +}; + +var result = Object.values(bAddsC); + +assert.sameValue(Array.isArray(result), true, 'result is an array'); +assert.sameValue(result.length, 2, 'result has 2 items'); + +assert.sameValue(result[0], 'A', 'first value is "A"'); +assert.sameValue(result[1], 'B', 'second value is "B"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/values/getter-making-future-key-nonenumerable.js b/js/src/tests/test262/built-ins/Object/values/getter-making-future-key-nonenumerable.js new file mode 100644 index 0000000000..a1ee5fab2a --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/values/getter-making-future-key-nonenumerable.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.values +description: Object.values does not see an element made non-enumerable by a getter that is hit during iteration +author: Jordan Harband +---*/ + +var bDeletesC = { + a: 'A', + get b() { + Object.defineProperty(this, 'c', { + enumerable: false + }); + return 'B'; + }, + c: 'C' +}; + +var result = Object.values(bDeletesC); + +assert.sameValue(Array.isArray(result), true, 'result is an array'); +assert.sameValue(result.length, 2, 'result has 2 items'); + +assert.sameValue(result[0], 'A', 'first value is "A"'); +assert.sameValue(result[1], 'B', 'second value is "B"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/values/getter-removing-future-key.js b/js/src/tests/test262/built-ins/Object/values/getter-removing-future-key.js new file mode 100644 index 0000000000..dab41f8536 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/values/getter-removing-future-key.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.values +description: Object.values does not see an element removed by a getter that is hit during iteration +author: Jordan Harband +---*/ + +var bDeletesC = { + a: 'A', + get b() { + delete this.c; + return 'B'; + }, + c: 'C' +}; + +var result = Object.values(bDeletesC); + +assert.sameValue(Array.isArray(result), true, 'result is an array'); +assert.sameValue(result.length, 2, 'result has 2 items'); + +assert.sameValue(result[0], 'A', 'first value is "A"'); +assert.sameValue(result[1], 'B', 'second value is "B"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/values/inherited-properties-omitted.js b/js/src/tests/test262/built-ins/Object/values/inherited-properties-omitted.js new file mode 100644 index 0000000000..e5a18c0f21 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/values/inherited-properties-omitted.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.values +description: Object.values does not see inherited properties. +author: Jordan Harband +---*/ + +var F = function G() {}; +F.prototype.a = {}; +F.prototype.b = {}; + +var f = new F(); +f.b = {}; // shadow the prototype +f.c = {}; // solely an own property + +var result = Object.values(f); + +assert.sameValue(Array.isArray(result), true, 'result is an array'); +assert.sameValue(result.length, 2, 'result has 2 items'); + +assert.sameValue(result[0], f.b, 'first value is f.b'); +assert.sameValue(result[1], f.c, 'second value is f.c'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/values/not-a-constructor.js b/js/src/tests/test262/built-ins/Object/values/not-a-constructor.js new file mode 100644 index 0000000000..632d285a49 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/values/not-a-constructor.js @@ -0,0 +1,31 @@ +// 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.values 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.values), false, 'isConstructor(Object.values) must return false'); + +assert.throws(TypeError, () => { + new Object.values({}); +}, '`new Object.values({})` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/values/observable-operations.js b/js/src/tests/test262/built-ins/Object/values/observable-operations.js new file mode 100644 index 0000000000..a1dc4baa5f --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/values/observable-operations.js @@ -0,0 +1,46 @@ +// Copyright (C) 2015 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: 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 = allowProxyTraps({ + get: function(target, propertyKey, receiver) { + assert.sameValue(target, object, "get target"); + assert.sameValue(receiver, proxy, "get receiver"); + log += "|get:" + propertyKey; + return target[propertyKey]; + }, + 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.values(proxy); +assert.sameValue(log, "|ownKeys|getOwnPropertyDescriptor:a|get:a|getOwnPropertyDescriptor:b|get:b|getOwnPropertyDescriptor:c|get:c", log); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/values/order-after-define-property.js b/js/src/tests/test262/built-ins/Object/values/order-after-define-property.js new file mode 100644 index 0000000000..ac1da3174e --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/values/order-after-define-property.js @@ -0,0 +1,57 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.values +description: > + Property names are returned in ascending chronological order of creation + that is unaffected by [[DefineOwnProperty]]. +info: | + Object.values ( O ) + + [...] + 2. Let nameList be ? EnumerableOwnPropertyNames(obj, value). + 3. Return CreateArrayFromList(nameList). + + EnumerableOwnPropertyNames ( O, kind ) + + [...] + 2. Let ownKeys be ? O.[[OwnPropertyKeys]](). + [...] + + 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. + [...] + 5. Return keys. +includes: [compareArray.js] +---*/ + +var obj = {}; +Object.defineProperty(obj, "a", { + get: function() {}, + enumerable: true, + configurable: true, +}); +obj.b = "b"; +Object.defineProperty(obj, "a", { + get: function() { + return "a"; + }, +}); +assert.compareArray(Object.values(obj), ["a", "b"]); + +var proxy = new Proxy({}, {}); +Object.defineProperty(proxy, "a", { + get: function() {}, + enumerable: true, + configurable: true, +}); +proxy.b = "b"; +Object.defineProperty(proxy, "a", {value: "a"}); +assert.compareArray(Object.values(proxy), ["a", "b"]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/values/primitive-booleans.js b/js/src/tests/test262/built-ins/Object/values/primitive-booleans.js new file mode 100644 index 0000000000..da224c2163 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/values/primitive-booleans.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.values +description: Object.values accepts boolean primitives. +author: Jordan Harband +---*/ + +var trueResult = Object.values(true); + +assert.sameValue(Array.isArray(trueResult), true, 'trueResult is an array'); +assert.sameValue(trueResult.length, 0, 'trueResult has 0 items'); + +var falseResult = Object.values(false); + +assert.sameValue(Array.isArray(falseResult), true, 'falseResult is an array'); +assert.sameValue(falseResult.length, 0, 'falseResult has 0 items'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/values/primitive-numbers.js b/js/src/tests/test262/built-ins/Object/values/primitive-numbers.js new file mode 100644 index 0000000000..2ed4fe4758 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/values/primitive-numbers.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.values +description: Object.values accepts number primitives. +author: Jordan Harband +---*/ + +assert.sameValue(Object.values(0).length, 0, '0 has zero values'); +assert.sameValue(Object.values(-0).length, 0, '-0 has zero values'); +assert.sameValue(Object.values(Infinity).length, 0, 'Infinity has zero values'); +assert.sameValue(Object.values(-Infinity).length, 0, '-Infinity has zero values'); +assert.sameValue(Object.values(NaN).length, 0, 'NaN has zero values'); +assert.sameValue(Object.values(Math.PI).length, 0, 'Math.PI has zero values'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/values/primitive-strings.js b/js/src/tests/test262/built-ins/Object/values/primitive-strings.js new file mode 100644 index 0000000000..c7beaf6ef6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/values/primitive-strings.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.values +description: Object.values accepts string primitives. +author: Jordan Harband +---*/ + +var result = Object.values('abc'); + +assert.sameValue(Array.isArray(result), true, 'result is an array'); +assert.sameValue(result.length, 3, 'result has 3 items'); + +assert.sameValue(result[0], 'a', 'first value is "a"'); +assert.sameValue(result[1], 'b', 'second value is "b"'); +assert.sameValue(result[2], 'c', 'third value is "c"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/values/primitive-symbols.js b/js/src/tests/test262/built-ins/Object/values/primitive-symbols.js new file mode 100644 index 0000000000..3696dc3e99 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/values/primitive-symbols.js @@ -0,0 +1,16 @@ +// Copyright (C) 2015 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.values +description: Object.values accepts Symbol primitives. +author: Jordan Harband +features: [Symbol] +---*/ + +var result = Object.values(Symbol()); + +assert.sameValue(Array.isArray(result), true, 'result is an array'); +assert.sameValue(result.length, 0, 'result has 0 items'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/values/return-order.js b/js/src/tests/test262/built-ins/Object/values/return-order.js new file mode 100644 index 0000000000..073baf8b38 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/values/return-order.js @@ -0,0 +1,43 @@ +// Copyright 2019 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.values +description: Object.values enumeration order +features: [for-in-order] +includes: [compareArray.js] +---*/ + +var o = { + p1: 'p1', + p2: 'p2', + p3: 'p3', +}; + +// This getter will be triggered during enumeration, but the property it adds should not be enumerated. +Object.defineProperty(o, 'add', { + enumerable: true, + get: function () { + o.extra = 'extra'; + return 'add'; + } +}); + +o.p4 = 'p4'; + +o[2] = '2'; +o[0] = '0'; +o[1] = '1'; + +delete o.p1; +delete o.p3; +o.p1 = 'p1'; + + +var actual = Object.values(o); + +var expected = ['0', '1', '2', 'p2', 'add', 'p4', 'p1']; + +assert.compareArray(actual, expected); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/values/shell.js b/js/src/tests/test262/built-ins/Object/values/shell.js new file mode 100644 index 0000000000..bc72493f03 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/values/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/values/symbols-omitted.js b/js/src/tests/test262/built-ins/Object/values/symbols-omitted.js new file mode 100644 index 0000000000..2ac7d22bfa --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/values/symbols-omitted.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.values +description: Object.values does not include Symbol keys. +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.values(obj); + +assert.sameValue(Array.isArray(result), true, 'result is an array'); +assert.sameValue(result.length, 1, 'result has 1 item'); + +assert.sameValue(result[0], symValue, 'first value is `symValue`'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/values/tamper-with-global-object.js b/js/src/tests/test262/built-ins/Object/values/tamper-with-global-object.js new file mode 100644 index 0000000000..d7bda78351 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/values/tamper-with-global-object.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.values +description: > + Object.values should not have its behavior impacted by modifications to the global property Object +author: Jordan Harband +---*/ + +function fakeObject() { + throw new Test262Error('The overriden version of Object was called!'); +} +fakeObject.values = Object.values; + +var global = Function('return this;')(); +global.Object = fakeObject; + +assert.sameValue(Object, fakeObject, 'Sanity check failed: could not modify the global Object'); +assert.sameValue(Object.values(1).length, 0, 'Expected number primitive to have zero values'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/values/tamper-with-object-keys.js b/js/src/tests/test262/built-ins/Object/values/tamper-with-object-keys.js new file mode 100644 index 0000000000..66c1047004 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/values/tamper-with-object-keys.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.values +description: > + Object.values should not have its behavior impacted by modifications to Object.keys +author: Jordan Harband +---*/ + +function fakeObjectKeys() { + throw new Test262Error('The overriden version of Object.keys was called!'); +} + +Object.keys = fakeObjectKeys; + +assert.sameValue(Object.keys, fakeObjectKeys, 'Sanity check failed: could not modify the global Object.keys'); +assert.sameValue(Object.values({ + a: 1 +}).length, 1, 'Expected object with 1 key to have 1 value'); + +reportCompare(0, 0); |