fune/testing/web-platform/tests/webidl/ecmascript-binding/observable-array-ownkeys.window.js
Yuki Shiino e854427754 Bug 1755892 [wpt PR 32872] - bindings: Fix ObservableArray's ownKeys trap, a=testonly
Automatic update from web-platform-tests
bindings: Fix ObservableArray's ownKeys trap

Fixes the 'ownKeys' trap of observable arrays so that it
enumerates not only enumerable properties but also
non-enumerable string properties and symbol properties.

https://webidl.spec.whatwg.org/#es-observable-array-ownKeys
3.10.6. ownKeys
step 6. Extend keys with ! O.[[OwnPropertyKeys]]().
then,
https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-ownpropertykeys
then,
https://tc39.es/ecma262/#sec-ordinaryownpropertykeys
This requires not only enumerable but also non-enumerable,
plus not only string but also symbol properties.

Bug: 1295410
Change-Id: Ibd720aa2a9c5df3327ae8cf3487a200b5221fde2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3449738
Reviewed-by: Raphael Kubo Da Costa <raphael.kubo.da.costa@intel.com>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/main@{#972844}

--

wpt-commits: a82394afb1654b379809e6b38a0d9138293b1b46
wpt-pr: 32872
2022-03-21 06:50:23 +00:00

34 lines
1.2 KiB
JavaScript

"use strict";
test(() => {
const observableArray = document.adoptedStyleSheets;
assert_array_equals(
Object.getOwnPropertyNames(observableArray),
["length"],
"Initially only \"length\".");
observableArray["zzz"] = true;
observableArray["aaa"] = true;
assert_array_equals(
Object.getOwnPropertyNames(observableArray),
["length", "zzz", "aaa"],
"Own properties whose key is a string have been added.");
observableArray[0] = new CSSStyleSheet();
observableArray[1] = new CSSStyleSheet();
assert_array_equals(
Object.getOwnPropertyNames(observableArray),
["0", "1", "length", "zzz", "aaa"],
"Own properties whose key is an array index have been added.");
observableArray[Symbol.toStringTag] = "string_tag";
observableArray[Symbol.toPrimitive] = "primitive";
assert_array_equals(
Object.getOwnPropertyNames(observableArray),
["0", "1", "length", "zzz", "aaa"],
"Own properties whose key is a symbol have been added (non-symbol).");
assert_array_equals(
Object.getOwnPropertySymbols(observableArray),
[Symbol.toStringTag, Symbol.toPrimitive],
"Own properties whose key is a symbol have been added (symbol).");
}, "ObservableArray's ownKeys trap");