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

49 lines
1.3 KiB
JavaScript

// Check frozen Array.of and Array.from don't modify unwritable/unconfigurable entries.
let totalFailed = 0;
function shouldEqual(testId, iteration, actual, expected) {
if (actual != expected) {
throw "Test #" + testId + ", iteration " + iteration + ", ERROR: expected \"" + expected + "\", got \"" + actual + "\"";
}
}
function makeUnwriteableUnconfigurableObject()
{
return Object.defineProperty([], 0, {value: "frozen", writable: false, configurable: false});
}
function testArrayOf(obj)
{
Array.of.call(function() { return obj; }, "no longer frozen");
}
noInline(testArrayOf);
function testArrayFrom(obj)
{
Array.from.call(function() { return obj; }, ["no longer frozen"]);
}
noInline(testArrayFrom);
let numIterations = 10000;
function runTest(testId, test, sourceMaker, expectedException) {
for (var i = 0; i < numIterations; i++) {
var exception = "No exception";
var obj = sourceMaker();
try {
test(obj);
} catch (e) {
exception = "" + e;
exception = exception.substr(0, 10); // Search for "TypeError:".
}
shouldEqual(testId, i, exception, expectedException);
}
}
runTest(1, testArrayOf, makeUnwriteableUnconfigurableObject, "TypeError:");
runTest(2, testArrayFrom, makeUnwriteableUnconfigurableObject, "TypeError:");