mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 14:17:36 +00:00
LibJS: Let Object::get_own_properties() return both strings and symbols
The new default return_type argument is GetOwnPropertyReturnType::All, which returns properties with both string and symbol keys (which is also the default for [[OwnPropertyKeys]]). This means that in some cases we need to iterate the ordered property table twice, as we don't store string and symbol properties separately but symbols must - there's certainly room for (performance) improvements here. On the other hand this makes Reflect.ownKeys() return symbol properties now :^)
This commit is contained in:
parent
1416027486
commit
abc7b31079
3 changed files with 38 additions and 20 deletions
|
@ -23,12 +23,14 @@ describe("normal behavior", () => {
|
|||
});
|
||||
|
||||
test("regular object with some properties has own keys", () => {
|
||||
var objectOwnKeys = Reflect.ownKeys({ foo: "bar", bar: "baz", 0: 42 });
|
||||
var symbol = Symbol("symbol");
|
||||
var objectOwnKeys = Reflect.ownKeys({ foo: "bar", [symbol]: "qux", bar: "baz", 0: 42 });
|
||||
expect(objectOwnKeys instanceof Array).toBeTrue();
|
||||
expect(objectOwnKeys).toHaveLength(3);
|
||||
expect(objectOwnKeys).toHaveLength(4);
|
||||
expect(objectOwnKeys[0]).toBe("0");
|
||||
expect(objectOwnKeys[1]).toBe("foo");
|
||||
expect(objectOwnKeys[2]).toBe("bar");
|
||||
expect(objectOwnKeys[3]).toBe(symbol);
|
||||
});
|
||||
|
||||
test("empty array has only 'length' own key", () => {
|
||||
|
@ -38,7 +40,7 @@ describe("normal behavior", () => {
|
|||
expect(arrayOwnKeys[0]).toBe("length");
|
||||
});
|
||||
|
||||
test("array with some values has 'lenght' and indices own keys", () => {
|
||||
test("array with some values has 'length' and indices own keys", () => {
|
||||
var arrayOwnKeys = Reflect.ownKeys(["foo", [], 123, undefined]);
|
||||
expect(arrayOwnKeys instanceof Array).toBeTrue();
|
||||
expect(arrayOwnKeys).toHaveLength(5);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue