diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/built-ins/Proxy/ownKeys | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Proxy/ownKeys')
29 files changed, 935 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/browser.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/browser.js diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/call-parameters-object-getownpropertynames.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/call-parameters-object-getownpropertynames.js new file mode 100644 index 0000000000..556ad71dfd --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/call-parameters-object-getownpropertynames.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + [[OwnPropertyKeys]] ( ) + + 7. Let trapResultArray be ? Call(trap, handler, « target »). +features: [Proxy] +---*/ + +var _target, _handler; +var target = { + foo: 1, + bar: 2 +}; + +var handler = { + ownKeys: function(t) { + _handler = this; + _target = t; + return Object.getOwnPropertyNames(t); + } +} +var p = new Proxy(target, handler); + +var names = Object.getOwnPropertyNames(p); + +assert.sameValue(names[0], "foo"); +assert.sameValue(names[1], "bar"); +assert.sameValue(names.length, 2); +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/call-parameters-object-getownpropertysymbols.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/call-parameters-object-getownpropertysymbols.js new file mode 100644 index 0000000000..6b79a2fb70 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/call-parameters-object-getownpropertysymbols.js @@ -0,0 +1,38 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + [[OwnPropertyKeys]] ( ) + + 7. Let trapResultArray be ? Call(trap, handler, « target »). + +features: [Proxy, Symbol] +---*/ + +var _target, _handler; +var target = {}; +var a = Symbol('a'); +var b = Symbol('b'); + +target[a] = 1; +target[b] = 2; + +var handler = { + ownKeys: function(t) { + _handler = this; + _target = t; + return Object.getOwnPropertySymbols(t); + } +} +var p = new Proxy(target, handler); + +var symbols = Object.getOwnPropertySymbols(p); + +assert.sameValue(symbols[0], a); +assert.sameValue(symbols[1], b); +assert.sameValue(symbols.length, 2); +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/call-parameters-object-keys.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/call-parameters-object-keys.js new file mode 100644 index 0000000000..6277f0c8cd --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/call-parameters-object-keys.js @@ -0,0 +1,34 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + [[OwnPropertyKeys]] ( ) + + 7. Let trapResultArray be ? Call(trap, handler, « target »). +features: [Proxy] +---*/ + +var _target, _handler; +var target = { + foo: 1, + bar: 2 +}; +var handler = { + ownKeys: function(t) { + _handler = this; + _target = t; + return Object.keys(t); + } +}; +var p = new Proxy(target, handler); + +var keys = Object.keys(p); + +assert.sameValue(keys[0], "foo"); +assert.sameValue(keys[1], "bar"); +assert.sameValue(keys.length, 2); +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/extensible-return-trap-result-absent-not-configurable-keys.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/extensible-return-trap-result-absent-not-configurable-keys.js new file mode 100644 index 0000000000..8037edd33e --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/extensible-return-trap-result-absent-not-configurable-keys.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + If target is extensible, return the non-falsy trap result if target doesn't + contain any non-configurable keys. +info: | + [[OwnPropertyKeys]] ( ) + + ... + 15. If extensibleTarget is true and targetNonconfigurableKeys is empty, then + a. Return trapResult. +features: [Proxy] +---*/ + +var p = new Proxy({ + attr: 42 +}, { + ownKeys: function() { + return ["foo", "bar"]; + } +}); + +var keys = Object.getOwnPropertyNames(p); + +assert.sameValue(keys[0], "foo"); +assert.sameValue(keys[1], "bar"); + +assert.sameValue(keys.length, 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/extensible-return-trap-result.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/extensible-return-trap-result.js new file mode 100644 index 0000000000..e4f43ddd44 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/extensible-return-trap-result.js @@ -0,0 +1,37 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + If target is extensible, return the non-falsy trap result if it contains all + of target's non-configurable keys. +info: | + [[OwnPropertyKeys]] ( ) + + ... + 18. If extensibleTarget is true, return trapResult. +features: [Proxy] +---*/ + +var target = {}; + +Object.defineProperty(target, "foo", { + configurable: false, + enumerable: true, + value: true +}); + +var p = new Proxy(target, { + ownKeys: function() { + return ["foo", "bar"]; + } +}); + +var keys = Object.getOwnPropertyNames(p); + +assert.sameValue(keys[0], "foo"); +assert.sameValue(keys[1], "bar"); + +assert.sameValue(keys.length, 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/not-extensible-missing-keys-throws.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/not-extensible-missing-keys-throws.js new file mode 100644 index 0000000000..c18605198c --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/not-extensible-missing-keys-throws.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + If target is not extensible, the result must contain all the keys of the own + properties of the target object. +info: | + [[OwnPropertyKeys]] ( ) + + ... + 19. For each key that is an element of targetConfigurableKeys, do + a. If key is not an element of uncheckedResultKeys, throw a TypeError + exception. +features: [Proxy] +---*/ + +var target = { + foo: 1, + bar: 2 +}; + +var p = new Proxy(target, { + ownKeys: function() { + return ["foo"]; + } +}); + +Object.preventExtensions(target); + +assert.throws(TypeError, function() { + Object.keys(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/not-extensible-new-keys-throws.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/not-extensible-new-keys-throws.js new file mode 100644 index 0000000000..dda61a8aab --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/not-extensible-new-keys-throws.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + If target is not extensible, the result can't contain keys names not + contained in the target object. +info: | + [[OwnPropertyKeys]] ( ) + + ... + 20. If uncheckedResultKeys is not empty, throw a TypeError exception. +features: [Proxy] +---*/ + +var target = { + foo: 1 +}; + +var p = new Proxy(target, { + ownKeys: function() { + return ["foo", "bar"]; + } +}); + +Object.preventExtensions(target); + +assert.throws(TypeError, function() { + Object.keys(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/not-extensible-return-keys.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/not-extensible-return-keys.js new file mode 100644 index 0000000000..640264b8b0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/not-extensible-return-keys.js @@ -0,0 +1,36 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + If target is not extensible, the result must contain all the keys of the own + properties of the target object and no other values +info: | + [[OwnPropertyKeys]] ( ) + + ... + 21. Return trapResult. +features: [Proxy] +---*/ + +var target = { + foo: 1, + bar: 2 +}; + +var p = new Proxy(target, { + ownKeys: function() { + return ["foo", "bar"]; + } +}); + +Object.preventExtensions(target); + +var keys = Object.getOwnPropertyNames(p); + +assert.sameValue(keys[0], "foo"); +assert.sameValue(keys[1], "bar"); + +assert.sameValue(keys.length, 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/null-handler.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/null-handler.js new file mode 100644 index 0000000000..f28f8ec52f --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/null-handler.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + [[OwnPropertyKeys]] ( ) + + 2. If handler is null, throw a TypeError exception. +features: [Proxy] +---*/ + +var p = Proxy.revocable({}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + Object.keys(p.proxy); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/return-all-non-configurable-keys.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/return-all-non-configurable-keys.js new file mode 100644 index 0000000000..e14b210b12 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/return-all-non-configurable-keys.js @@ -0,0 +1,39 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + The result List must contain the keys of all non-configurable own properties + of the target object. +info: | + [[OwnPropertyKeys]] ( ) + + ... + 17. For each key that is an element of targetNonconfigurableKeys, do + a. If key is not an element of uncheckedResultKeys, throw a TypeError + exception. + +features: [Proxy] +---*/ + +var target = { + foo: 1 +}; + +Object.defineProperty(target, "attr", { + configurable: false, + enumerable: true, + value: true +}); + +var p = new Proxy(target, { + ownKeys: function() { + return ["foo"]; + } +}); + +assert.throws(TypeError, function() { + Object.keys(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/return-duplicate-entries-throws.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/return-duplicate-entries-throws.js new file mode 100644 index 0000000000..a1c2c8aad6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/return-duplicate-entries-throws.js @@ -0,0 +1,25 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + The returned list must not contain any duplicate entries. +info: | + [[OwnPropertyKeys]] ( ) + + ... + 9. If trapResult contains any duplicate entries, throw a TypeError exception. +features: [Proxy] +---*/ + +var p = new Proxy({}, { + ownKeys: function() { + return ["a", "a"]; + } +}); + +assert.throws(TypeError, function() { + Object.keys(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/return-duplicate-symbol-entries-throws.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/return-duplicate-symbol-entries-throws.js new file mode 100644 index 0000000000..09d2697890 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/return-duplicate-symbol-entries-throws.js @@ -0,0 +1,26 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + The returned list must not contain any duplicate entries. +info: | + [[OwnPropertyKeys]] ( ) + + ... + 9. If trapResult contains any duplicate entries, throw a TypeError exception. +features: [Proxy, Symbol] +---*/ + +var s = Symbol(); +var p = new Proxy({}, { + ownKeys: function() { + return [s, s]; + } +}); + +assert.throws(TypeError, function() { + Object.keys(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/return-is-abrupt.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/return-is-abrupt.js new file mode 100644 index 0000000000..673d40ec0a --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/return-is-abrupt.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + Trap returns abrupt. +info: | + [[OwnPropertyKeys]] ( ) + + ... + 7. Let trapResultArray be ? Call(trap, handler, « target »). + 8. Let trapResult be ? CreateListFromArrayLike(trapResultArray, « String, Symbol »). + +features: [Proxy] +---*/ + +var p = new Proxy({}, { + ownKeys: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Object.keys(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/return-not-list-object-throws-realm.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/return-not-list-object-throws-realm.js new file mode 100644 index 0000000000..efe0aabcd5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/return-not-list-object-throws-realm.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + If return is not a list object, throw a TypeError exception (honoring + the Realm of the current execution context) +info: | + ... + 7. Let trapResultArray be ? Call(trap, handler, « target »). + 8. Let trapResult be ? CreateListFromArrayLike(trapResultArray, « String, + Symbol »). + ... + + #sec-createlistfromarraylike + 7.3.17 CreateListFromArrayLike (obj [, elementTypes] ) + + 2. If Type(obj) is not Object, throw a TypeError exception. + +features: [cross-realm, Proxy, Symbol] +---*/ + +var other = $262.createRealm().global; +var p = new other.Proxy({}, { + ownKeys: function() { + return undefined; + } +}); + +assert.throws(TypeError, function() { + Object.keys(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/return-not-list-object-throws.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/return-not-list-object-throws.js new file mode 100644 index 0000000000..858ca75c89 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/return-not-list-object-throws.js @@ -0,0 +1,34 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + If return is not a list object, throw a TypeError exception +info: | + [[OwnPropertyKeys]] ( ) + + 7. Let trapResultArray be ? Call(trap, handler, « target »). + 8. Let trapResult be ? CreateListFromArrayLike(trapResultArray, « String, + Symbol »). + ... + + #sec-createlistfromarraylike + 7.3.17 CreateListFromArrayLike (obj [, elementTypes] ) + + 2. If Type(obj) is not Object, throw a TypeError exception. + +features: [Proxy, Symbol] +---*/ + +var target = {}; +var p = new Proxy(target, { + ownKeys: function() { + return undefined; + } +}); + +assert.throws(TypeError, function() { + Object.keys(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/return-type-throws-array.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/return-type-throws-array.js new file mode 100644 index 0000000000..37fb021f30 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/return-type-throws-array.js @@ -0,0 +1,39 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + The returned list must not have entries whose type does not match + « String, Symbol ». +info: | + [[OwnPropertyKeys]] ( ) + + ... + 7. Let trapResultArray be ? Call(trap, handler, « target »). + 8. Let trapResult be ? + CreateListFromArrayLike(trapResultArray, « String, Symbol »). + ... + + CreateListFromArrayLike ( obj [ , elementTypes ] ) + + ... + 6. Repeat, while index < len + ... + d. If Type(next) is not an element of elementTypes, + throw a TypeError exception. +features: [Proxy] +---*/ + +var p = new Proxy({}, { + ownKeys: function() { + return [ + [] + ]; + } +}); + +assert.throws(TypeError, function() { + Object.keys(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/return-type-throws-boolean.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/return-type-throws-boolean.js new file mode 100644 index 0000000000..b4755c9f9d --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/return-type-throws-boolean.js @@ -0,0 +1,37 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + The returned list must not have entries whose type does not match + « String, Symbol ». +info: | + [[OwnPropertyKeys]] ( ) + + ... + 7. Let trapResultArray be ? Call(trap, handler, « target »). + 8. Let trapResult be ? + CreateListFromArrayLike(trapResultArray, « String, Symbol »). + ... + + CreateListFromArrayLike ( obj [ , elementTypes ] ) + + ... + 6. Repeat, while index < len + ... + d. If Type(next) is not an element of elementTypes, + throw a TypeError exception. +features: [Proxy] +---*/ + +var p = new Proxy({}, { + ownKeys: function() { + return [true]; + } +}); + +assert.throws(TypeError, function() { + Object.keys(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/return-type-throws-null.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/return-type-throws-null.js new file mode 100644 index 0000000000..3bb2aac425 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/return-type-throws-null.js @@ -0,0 +1,37 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + The returned list must not have entries whose type does not match + « String, Symbol ». +info: | + [[OwnPropertyKeys]] ( ) + + ... + 7. Let trapResultArray be ? Call(trap, handler, « target »). + 8. Let trapResult be ? + CreateListFromArrayLike(trapResultArray, « String, Symbol »). + ... + + CreateListFromArrayLike ( obj [ , elementTypes ] ) + + ... + 6. Repeat, while index < len + ... + d. If Type(next) is not an element of elementTypes, + throw a TypeError exception. +features: [Proxy] +---*/ + +var p = new Proxy({}, { + ownKeys: function() { + return [null]; + } +}); + +assert.throws(TypeError, function() { + Object.keys(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/return-type-throws-number.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/return-type-throws-number.js new file mode 100644 index 0000000000..b576e027ec --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/return-type-throws-number.js @@ -0,0 +1,37 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + The returned list must not have entries whose type does not match + « String, Symbol ». +info: | + [[OwnPropertyKeys]] ( ) + + ... + 7. Let trapResultArray be ? Call(trap, handler, « target »). + 8. Let trapResult be ? + CreateListFromArrayLike(trapResultArray, « String, Symbol »). + ... + + CreateListFromArrayLike ( obj [ , elementTypes ] ) + + ... + 6. Repeat, while index < len + ... + d. If Type(next) is not an element of elementTypes, + throw a TypeError exception. +features: [Proxy] +---*/ + +var p = new Proxy({}, { + ownKeys: function() { + return [1]; + } +}); + +assert.throws(TypeError, function() { + Object.keys(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/return-type-throws-object.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/return-type-throws-object.js new file mode 100644 index 0000000000..18d80e88a7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/return-type-throws-object.js @@ -0,0 +1,37 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + The returned list must not have entries whose type does not match + « String, Symbol ». +info: | + [[OwnPropertyKeys]] ( ) + + ... + 7. Let trapResultArray be ? Call(trap, handler, « target »). + 8. Let trapResult be ? + CreateListFromArrayLike(trapResultArray, « String, Symbol »). + ... + + CreateListFromArrayLike ( obj [ , elementTypes ] ) + + ... + 6. Repeat, while index < len + ... + d. If Type(next) is not an element of elementTypes, + throw a TypeError exception. +features: [Proxy] +---*/ + +var p = new Proxy({}, { + ownKeys: function() { + return [{}]; + } +}); + +assert.throws(TypeError, function() { + Object.keys(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/return-type-throws-undefined.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/return-type-throws-undefined.js new file mode 100644 index 0000000000..bd1e8be030 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/return-type-throws-undefined.js @@ -0,0 +1,37 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + The returned list must not have entries whose type does not match + « String, Symbol ». +info: | + [[OwnPropertyKeys]] ( ) + + ... + 7. Let trapResultArray be ? Call(trap, handler, « target »). + 8. Let trapResult be ? + CreateListFromArrayLike(trapResultArray, « String, Symbol »). + ... + + CreateListFromArrayLike ( obj [ , elementTypes ] ) + + ... + 6. Repeat, while index < len + ... + d. If Type(next) is not an element of elementTypes, + throw a TypeError exception. +features: [Proxy] +---*/ + +var p = new Proxy({}, { + ownKeys: function() { + return [undefined]; + } +}); + +assert.throws(TypeError, function() { + Object.keys(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/shell.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/shell.js diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/trap-is-missing-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/trap-is-missing-target-is-proxy.js new file mode 100644 index 0000000000..0d189524f2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/trap-is-missing-target-is-proxy.js @@ -0,0 +1,48 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + If "ownKeys" trap is null or undefined, [[OwnPropertyKeys]] call is + properly forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[OwnPropertyKeys]] ( ) + + [...] + 4. Let target be O.[[ProxyTarget]]. + 5. Let trap be ? GetMethod(handler, "ownKeys"). + 6. If trap is undefined, then + a. Return ? target.[[OwnPropertyKeys]](). + + [[OwnPropertyKeys]] ( ) + + 1. Let keys be a new empty List. + [...] + 5. For each integer i starting with 0 such that i < len, in ascending order, do + a. Add ! ToString(i) as the last element of keys. + [...] + 7. 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. + 8. 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. + 9. Return keys. +includes: [compareArray.js] +features: [Symbol, Proxy, Reflect] +---*/ + +var sym = Symbol(); +var string = new String("str"); +string[sym] = 1; + +var stringTarget = new Proxy(string, {}); +var stringProxy = new Proxy(stringTarget, {}); + +assert.compareArray( + Reflect.ownKeys(stringProxy), + ["0", "1", "2", "length", sym] +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/trap-is-not-callable-realm.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/trap-is-not-callable-realm.js new file mode 100644 index 0000000000..df9f37abdf --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/trap-is-not-callable-realm.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + Throws if trap is not callable (honoring the Realm of the current execution + context) +info: | + [[OwnPropertyKeys]] ( ) + + 5. Let trap be GetMethod(handler, "ownKeys"). + ... + + #sec-getmethod + 7.3.9 GetMethod (O, P) + + 4. If IsCallable(func) is false, throw a TypeError exception. +features: [cross-realm, Proxy] +---*/ + +var OProxy = $262.createRealm().global.Proxy; +var p = new OProxy({ + attr: 1 +}, { + ownKeys: {} +}); + +assert.throws(TypeError, function() { + Object.keys(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/trap-is-not-callable.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/trap-is-not-callable.js new file mode 100644 index 0000000000..fefd983c8d --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/trap-is-not-callable.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + Trap is not callable. +info: | + [[OwnPropertyKeys]] ( ) + + 5. Let trap be ? GetMethod(handler, "ownKeys"). + ... + + #sec-getmethod + 7.3.9 GetMethod (O, P) + + 4. If IsCallable(func) is false, throw a TypeError exception. +features: [Proxy] +---*/ + +var p = new Proxy({ + attr: 1 +}, { + ownKeys: {} +}); + +assert.throws(TypeError, function() { + Object.keys(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/trap-is-null-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/trap-is-null-target-is-proxy.js new file mode 100644 index 0000000000..ea5a1ddb08 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/trap-is-null-target-is-proxy.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-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + If "ownKeys" trap is null or undefined, [[OwnPropertyKeys]] call is + properly forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[OwnPropertyKeys]] ( ) + + [...] + 4. Let target be O.[[ProxyTarget]]. + 5. Let trap be ? GetMethod(handler, "ownKeys"). + 6. If trap is undefined, then + a. Return ? target.[[OwnPropertyKeys]](). + + OrdinaryOwnPropertyKeys ( O ) + + 1. Let keys be a new empty List. + 2. For each own property key P of O that is an array index, + in ascending numeric index order, do + a. Add P as the last element of keys. + 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] +features: [Proxy] +---*/ + +var plainObject = { + foo: 1, + "0": 2, + get bar() {}, + "1": 4, +}; + +var plainObjectTarget = new Proxy(plainObject, {}); +var plainObjectProxy = new Proxy(plainObjectTarget, { + ownKeys: null, +}); + +assert.compareArray( + Object.keys(plainObjectProxy), + ["0", "1", "foo", "bar"] +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/trap-is-undefined-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/trap-is-undefined-target-is-proxy.js new file mode 100644 index 0000000000..1ffb92a119 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/trap-is-undefined-target-is-proxy.js @@ -0,0 +1,42 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + If "ownKeys" trap is null or undefined, [[OwnPropertyKeys]] call is + properly forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[OwnPropertyKeys]] ( ) + + [...] + 4. Let target be O.[[ProxyTarget]]. + 5. Let trap be ? GetMethod(handler, "ownKeys"). + 6. If trap is undefined, then + a. Return ? target.[[OwnPropertyKeys]](). + + [[OwnPropertyKeys]] ( ) + + [...] + 7. Let trapResultArray be ? Call(trap, handler, « target »). + 8. Let trapResult be ? CreateListFromArrayLike(trapResultArray, « String, Symbol »). + [...] + 23. Return trapResult. +includes: [compareArray.js] +features: [Symbol, Proxy, Reflect] +---*/ + +var trapResult = [Symbol(), "length", "foo", "0"]; +var target = new Proxy([], { + ownKeys: function(_target) { + return trapResult; + }, +}); + +var proxy = new Proxy(target, { + ownKeys: undefined, +}); + +assert.compareArray(Reflect.ownKeys(proxy), trapResult); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/ownKeys/trap-is-undefined.js b/js/src/tests/test262/built-ins/Proxy/ownKeys/trap-is-undefined.js new file mode 100644 index 0000000000..84e2db2098 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/ownKeys/trap-is-undefined.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys +description: > + [[OwnPropertyKeys]] ( ) + + 6. If trap is undefined, then Return target.[[OwnPropertyKeys]]() +features: [Proxy] +---*/ + +var target = { + foo: 1, + bar: 2 +}; +var p = new Proxy(target, {}); + +var keys = Object.getOwnPropertyNames(p); + +assert.sameValue(keys[0], "foo"); +assert.sameValue(keys[1], "bar"); + +assert.sameValue(keys.length, 2); + +reportCompare(0, 0); |