mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-10 05:02:54 +00:00
This implements the missing step 6a of 14.7.5.6 ForIn/OfHeadEvaluation: a. If exprValue is undefined or null, then i. Return Completion { [[Type]]: break, [[Value]]: empty, [[Target]]: empty }. In other words, this should just do nothing instead of throwing during the undefined to object coercion: for (const x in undefined);
51 lines
1.1 KiB
JavaScript
51 lines
1.1 KiB
JavaScript
test("iterate through empty string", () => {
|
|
const a = [];
|
|
for (const property in "") {
|
|
a.push(property);
|
|
}
|
|
expect(a).toEqual([]);
|
|
});
|
|
|
|
test("iterate through number", () => {
|
|
const a = [];
|
|
for (const property in 123) {
|
|
a.push(property);
|
|
}
|
|
expect(a).toEqual([]);
|
|
});
|
|
|
|
test("iterate through empty object", () => {
|
|
const a = [];
|
|
for (const property in {}) {
|
|
a.push(property);
|
|
}
|
|
expect(a).toEqual([]);
|
|
});
|
|
|
|
test("iterate through string", () => {
|
|
const a = [];
|
|
for (const property in "hello") {
|
|
a.push(property);
|
|
}
|
|
expect(a).toEqual(["0", "1", "2", "3", "4"]);
|
|
});
|
|
|
|
test("iterate through object", () => {
|
|
const a = [];
|
|
for (const property in { a: 1, b: 2, c: 2 }) {
|
|
a.push(property);
|
|
}
|
|
expect(a).toEqual(["a", "b", "c"]);
|
|
});
|
|
|
|
test("iterate through undefined", () => {
|
|
for (const property in undefined) {
|
|
expect.fail();
|
|
}
|
|
});
|
|
|
|
test("use already-declared variable", () => {
|
|
var property;
|
|
for (property in "abc");
|
|
expect(property).toBe("2");
|
|
});
|