mirror of
https://github.com/tc39/test262.git
synced 2025-05-04 15:00:42 +02:00
33 lines
709 B
JavaScript
33 lines
709 B
JavaScript
function shouldBe(actual, expected) {
|
|
if (actual !== expected)
|
|
throw new Error('bad value: ' + actual);
|
|
}
|
|
|
|
class A {
|
|
get cocoa() {
|
|
return "Cocoa";
|
|
}
|
|
|
|
get cappuccino() {
|
|
return "Cappuccino";
|
|
}
|
|
}
|
|
|
|
let a = new A();
|
|
shouldBe(JSON.stringify(a), `{}`);
|
|
shouldBe(JSON.stringify(a, ["cocoa", "cappuccino"]), `{"cocoa":"Cocoa","cappuccino":"Cappuccino"}`);
|
|
|
|
let array = [0, 1, 2, 3, 4];
|
|
Object.defineProperty(array.__proto__, 1, {
|
|
get: function () {
|
|
return "Cocoa";
|
|
}
|
|
});
|
|
Object.defineProperty(array, 0, {
|
|
get: function () {
|
|
delete array[1];
|
|
return "Cappuccino";
|
|
}
|
|
});
|
|
shouldBe(JSON.stringify(array), `["Cappuccino","Cocoa",2,3,4]`);
|