mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
This matches our coding style recommendation in CodingStyle.md, and matches our python formatting.
66 lines
2.2 KiB
JavaScript
66 lines
2.2 KiB
JavaScript
test("null/undefined object", () => {
|
|
[null, undefined].forEach(value => {
|
|
let foo = value;
|
|
|
|
expect(() => {
|
|
foo.bar;
|
|
}).toThrowWithMessage(TypeError, `Cannot access property "bar" on ${value} object "foo"`);
|
|
|
|
expect(() => {
|
|
foo.bar = 1;
|
|
}).toThrowWithMessage(TypeError, `Cannot access property "bar" on ${value} object "foo"`);
|
|
|
|
expect(() => {
|
|
foo[0];
|
|
}).toThrowWithMessage(TypeError, `Cannot access property "0" on ${value} object "foo"`);
|
|
|
|
expect(() => {
|
|
foo[0] = 1;
|
|
}).toThrowWithMessage(TypeError, `Cannot access property "0" on ${value} object "foo"`);
|
|
});
|
|
});
|
|
|
|
test("null/undefined object key", () => {
|
|
[null, undefined].forEach(value => {
|
|
let foo = { bar: value };
|
|
|
|
expect(() => {
|
|
foo.bar.baz;
|
|
}).toThrowWithMessage(TypeError, `Cannot access property "baz" on ${value} object "foo.bar"`);
|
|
|
|
expect(() => {
|
|
foo.bar.baz = 1;
|
|
}).toThrowWithMessage(TypeError, `Cannot access property "baz" on ${value} object "foo.bar"`);
|
|
|
|
expect(() => {
|
|
foo["bar"].baz;
|
|
}).toThrowWithMessage(TypeError, `Cannot access property "baz" on ${value} object "foo['bar']"`);
|
|
|
|
expect(() => {
|
|
foo["bar"].baz = 1;
|
|
}).toThrowWithMessage(TypeError, `Cannot access property "baz" on ${value} object "foo['bar']"`);
|
|
});
|
|
});
|
|
|
|
test("null/undefined array index", () => {
|
|
[null, undefined].forEach(value => {
|
|
let foo = [value];
|
|
let index = 0;
|
|
|
|
expect(() => {
|
|
foo[0].bar;
|
|
}).toThrowWithMessage(TypeError, `Cannot access property "bar" on ${value} object "foo[0]"`);
|
|
|
|
expect(() => {
|
|
foo[0].bar = 1;
|
|
}).toThrowWithMessage(TypeError, `Cannot access property "bar" on ${value} object "foo[0]"`);
|
|
|
|
expect(() => {
|
|
foo[index].bar;
|
|
}).toThrowWithMessage(TypeError, `Cannot access property "bar" on ${value} object "foo[index]"`);
|
|
|
|
expect(() => {
|
|
foo[index].bar = 1;
|
|
}).toThrowWithMessage(TypeError, `Cannot access property "bar" on ${value} object "foo[index]"`);
|
|
});
|
|
});
|