From 9e88bb9a45ee8fc5e75f097f5c39857da27d023a Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Fri, 4 Aug 2017 11:59:05 -0400 Subject: [PATCH] Proxy, [[OwnPropertyKeys]]: If trapResult contains any duplicate entries, throw a TypeError Ref: https://github.com/tc39/ecma262/pull/833 --- .../return-duplicate-entries-throws.js | 22 ++++++++++++++++++ .../return-duplicate-symbol-entries-throws.js | 23 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 test/built-ins/Proxy/ownKeys/return-duplicate-entries-throws.js create mode 100644 test/built-ins/Proxy/ownKeys/return-duplicate-symbol-entries-throws.js diff --git a/test/built-ins/Proxy/ownKeys/return-duplicate-entries-throws.js b/test/built-ins/Proxy/ownKeys/return-duplicate-entries-throws.js new file mode 100644 index 0000000000..8bd1512d03 --- /dev/null +++ b/test/built-ins/Proxy/ownKeys/return-duplicate-entries-throws.js @@ -0,0 +1,22 @@ +// 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. +---*/ + +var p = new Proxy({}, { + ownKeys() { + return ["a", "a"]; + } +}); + +assert.throws(TypeError, function() { + Object.keys(p); +}); diff --git a/test/built-ins/Proxy/ownKeys/return-duplicate-symbol-entries-throws.js b/test/built-ins/Proxy/ownKeys/return-duplicate-symbol-entries-throws.js new file mode 100644 index 0000000000..dfe27205c0 --- /dev/null +++ b/test/built-ins/Proxy/ownKeys/return-duplicate-symbol-entries-throws.js @@ -0,0 +1,23 @@ +// 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. +---*/ + +var s = Symbol(); +var p = new Proxy({}, { + ownKeys() { + return [s, s]; + } +}); + +assert.throws(TypeError, function() { + Object.keys(p); +});