mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-30 08:18:49 +00:00
LibJS: Object index properties have descriptors; Handle sparse indices
This patch adds an IndexedProperties object for storing indexed properties within an Object. This accomplishes two goals: indexed properties now have an associated descriptor, and objects now gracefully handle sparse properties. The IndexedProperties class is a wrapper around two other classes, one for simple indexed properties storage, and one for general indexed property storage. Simple indexed property storage is the common-case, and is simply a vector of properties which all have attributes of default_attributes (writable, enumerable, and configurable). General indexed property storage is for a collection of indexed properties where EITHER one or more properties have attributes other than default_attributes OR there is a property with a large index (in particular, large is '200' or higher). Indexed properties are now treated relatively the same as storage within the various Object methods. Additionally, there is a custom iterator class for IndexedProperties which makes iteration easy. The iterator skips empty values by default, but can be configured otherwise. Likewise, it evaluates getters by default, but can be set not to.
This commit is contained in:
parent
cc54974431
commit
5ae9419a06
Notes:
sideshowbarker
2024-07-19 06:02:11 +09:00
Author: https://github.com/mattco98
Commit: 5ae9419a06
Pull-request: https://github.com/SerenityOS/serenity/pull/2420
Issue: https://github.com/SerenityOS/serenity/issues/2330
23 changed files with 800 additions and 160 deletions
|
@ -40,6 +40,23 @@ try {
|
|||
assert(a[4] === undefined);
|
||||
assert(a[5] === 3);
|
||||
|
||||
a = [1,,2,,,3,];
|
||||
Object.defineProperty(a, 1, {
|
||||
get() {
|
||||
return this.secret_prop;
|
||||
},
|
||||
set(value) {
|
||||
this.secret_prop = value;
|
||||
},
|
||||
});
|
||||
assert(a.length === 6);
|
||||
assert(a.toString() === "1,,2,,,3");
|
||||
assert(a.secret_prop === undefined);
|
||||
a[1] = 20;
|
||||
assert(a.length === 6);
|
||||
assert(a.toString() === "1,20,2,,,3");
|
||||
assert(a.secret_prop === 20);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue