mirror of
https://github.com/tc39/test262.git
synced 2025-05-03 14:30:27 +02:00
* [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)
76 lines
2.0 KiB
JavaScript
76 lines
2.0 KiB
JavaScript
//@ runFTLNoCJIT
|
|
|
|
function shouldEqual(testId, actual, expected) {
|
|
if (actual != expected) {
|
|
throw testId + ": ERROR: expect " + expected + ", actual " + actual;
|
|
}
|
|
}
|
|
|
|
function frozenArrayReviver(k, v) {
|
|
if (k === "a") {
|
|
this.b = Object.freeze(["unmodifiable"]);
|
|
return v;
|
|
}
|
|
if (k === "0")
|
|
return "modified";
|
|
return v;
|
|
}
|
|
|
|
function frozenArrayLikeObjectReviver(k, v) {
|
|
if (k === "a") {
|
|
var obj = {};
|
|
obj[0] = 'unmodifiable';
|
|
obj.length = 1;
|
|
this.b = Object.freeze(obj);
|
|
return v;
|
|
}
|
|
if (k === "0")
|
|
return "modified";
|
|
return v;
|
|
}
|
|
|
|
function frozenArrayReviverWithDelete(k, v) {
|
|
if (k === "a") {
|
|
this.b = Object.freeze(["unmodifiable"]);
|
|
return v;
|
|
}
|
|
if (k === "0")
|
|
return undefined;
|
|
return v;
|
|
}
|
|
|
|
function frozenArrayLikeObjectReviverWithDelete(k, v) {
|
|
if (k === "a") {
|
|
var obj = {};
|
|
obj[0] = 'unmodifiable';
|
|
obj.length = 1;
|
|
this.b = Object.freeze(obj);
|
|
return v;
|
|
}
|
|
if (k === "0")
|
|
return undefined;
|
|
return v;
|
|
}
|
|
|
|
function runTest(testId, reviver, expectedValue, expectedException) {
|
|
let numIterations = 10000;
|
|
for (var i = 0; i < numIterations; i++) {
|
|
var exception = undefined;
|
|
|
|
var obj;
|
|
try {
|
|
obj = JSON.parse('{ "a": 0, "b": 0 }', reviver);
|
|
} catch (e) {
|
|
exception = "" + e;
|
|
exception = exception.substr(0, 10); // Search for "TypeError:".
|
|
}
|
|
shouldEqual(testId, exception, expectedException);
|
|
shouldEqual(testId, obj.b[0], expectedValue);
|
|
}
|
|
}
|
|
|
|
runTest(10000, frozenArrayReviver, "unmodifiable", undefined);
|
|
runTest(10001, frozenArrayLikeObjectReviver, "unmodifiable", undefined);
|
|
runTest(10002, frozenArrayReviverWithDelete, "unmodifiable", undefined);
|
|
runTest(10003, frozenArrayLikeObjectReviverWithDelete, "unmodifiable", undefined);
|