mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-28 07:18:51 +00:00
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.
48 lines
1.1 KiB
JavaScript
48 lines
1.1 KiB
JavaScript
load("test-common.js");
|
|
|
|
try {
|
|
assert(Array.length === 1);
|
|
assert(Array.name === "Array");
|
|
assert(Array.prototype.length === 0);
|
|
|
|
assert(typeof Array() === "object");
|
|
assert(typeof new Array() === "object");
|
|
|
|
var a;
|
|
|
|
a = new Array(5);
|
|
assert(a.length === 5);
|
|
|
|
a = new Array("5");
|
|
assert(a.length === 1);
|
|
assert(a[0] === "5");
|
|
|
|
a = new Array(1, 2, 3);
|
|
assert(a.length === 3);
|
|
assert(a[0] === 1);
|
|
assert(a[1] === 2);
|
|
assert(a[2] === 3);
|
|
|
|
a = new Array([1, 2, 3]);
|
|
assert(a.length === 1);
|
|
assert(a[0][0] === 1);
|
|
assert(a[0][1] === 2);
|
|
assert(a[0][2] === 3);
|
|
|
|
a = new Array(1, 2, 3);
|
|
Object.defineProperty(a, 3, { get() { return 10; } });
|
|
assert(a.toString() === "1,2,3,10");
|
|
|
|
[-1, -100, -0.1, 0.1, 1.23, Infinity, -Infinity, NaN].forEach(value => {
|
|
assertThrowsError(() => {
|
|
new Array(value);
|
|
}, {
|
|
error: TypeError,
|
|
message: "Invalid array length"
|
|
});
|
|
});
|
|
|
|
console.log("PASS");
|
|
} catch (e) {
|
|
console.log("FAIL: " + e);
|
|
}
|