test262/implementation-contributed/javascriptcore/stress/for-in-invalidation-for-any-write.js
test262-automation e9a5a7f918 [javascriptcore-test262-automation] changes from git@github.com:WebKit/webkit.git at sha 949e26452cfa153a7f4afe593da97e2fe9e1b706 on Tue Jul 03 2018 14:35:15 GMT-0400 (Eastern Daylight Time) (#1620)
* [javascriptcore-test262-automation] changes from git@github.com:WebKit/webkit.git at sha 949e26452cfa153a7f4afe593da97e2fe9e1b706 on Tue Jul 03 2018 14:35:15 GMT-0400 (Eastern Daylight Time)
2018-07-03 15:59:58 -04:00

147 lines
3.2 KiB
JavaScript

function assert(b) {
if (!b)
throw new Error("Bad assertion");
}
noInline(assert);
function test(f) {
noInline(f);
for (let i = 0; i < 1000; ++i)
f();
}
test(function() {
let o = {xx: 42};
for (let i in o) {
for (let j = 0; j < 2; j++) {
let r = o[i];
if (i === "xx")
assert(r === 42);
i = function() { }
}
}
});
test(function() {
let o = {xx: 42};
for (let i in {xx: 0}) {
for (let j = 0; j < 2; j++) {
let r = o[i];
if (i === "xx")
assert(r === 42);
i = new Uint32Array([0, 1, 0x777777, 0, 0]);
}
}
});
test(function() {
let o = {xx: 42};
for (let i in {xx: 0}) {
for (let j = 0; j < 2; j++) {
let r = o[i];
if (i === "xx")
assert(r === 42);
([i] = [new Uint32Array([0, 1, 0x777777, 0, 0])]);
}
}
});
test(function() {
let o = {xx: 42};
for (let i in {xx: 0}) {
for (let j = 0; j < 2; j++) {
let r = o[i];
if (i === "xx")
assert(r === 42);
({xyz: i} = {xyz: new Uint32Array([0, 1, 0x777777, 0, 0])});
}
}
});
test(function() {
let o = [1,2,3];
let toStringCalls = 0;
let first;
let num = 0;
let total = 0;
for (let i in o) {
first = true;
for (let j = 0; j < 3; j++) {
let r = o[i];
if (first)
assert(r === o[num]);
else
assert(r === undefined);
first = false;
i = {
toString() {
++toStringCalls;
return "hello!";
}
}
}
++num;
}
// Should be called twice per outer for-in loop.
assert(toStringCalls === o.length * 2);
});
test(function() {
let o = [1,2,3];
let toStringCalls = 0;
let first;
let num = 0;
let total = 0;
for (let i in o) {
first = true;
for (let j = 0; j < 3; j++) {
let r = o[i];
if (first)
assert(r === o[num]);
else
assert(r === undefined);
first = false;
([i] = [{
toString() {
++toStringCalls;
return "hello!";
}
}]);
}
++num;
}
// Should be called twice per outer for-in loop.
assert(toStringCalls === o.length * 2);
});
test(function() {
let o = [1,2,3];
let toStringCalls = 0;
let first;
let num = 0;
let total = 0;
for (let i in o) {
first = true;
for (let j = 0; j < 3; j++) {
let r = o[i];
if (first)
assert(r === o[num]);
else
assert(r === undefined);
first = false;
({xyz: i} = {xyz: {
toString() {
++toStringCalls;
return "hello!";
}
}});
}
++num;
}
// Should be called twice per outer for-in loop.
assert(toStringCalls === o.length * 2);
});