test262/implementation-contributed/javascriptcore/stress/get-from-scope-dynamic-onto-proxy.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

107 lines
2.5 KiB
JavaScript

function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error(`bad value: ${String(actual)}`);
}
function shouldThrow(func, errorMessage) {
var errorThrown = false;
var error = null;
try {
func();
} catch (e) {
errorThrown = true;
error = e;
}
if (!errorThrown)
throw new Error('not thrown');
if (String(error) !== errorMessage)
throw new Error(`bad error: ${String(error)}`);
}
// LLInt slow path operation.
shouldThrow(function () {
var target = {};
var handler = {
has: function (receiver, name)
{
return name === 'i';
},
get: function (target, name, receiver)
{
if (name === 'i')
throw new Error("NG");
return 42;
}
};
var proxy = new Proxy(target, handler);
with (proxy) {
i;
}
}, `Error: NG`);
// Baseline JIT operation.
shouldThrow(function () {
var flag = false;
var target = {};
var handler = {
has: function (receiver, name)
{
return name === 'i';
},
get: function (target, name, receiver)
{
if (name === 'i' && flag)
throw new Error("NG");
return 42;
}
};
var proxy = new Proxy(target, handler);
for (var i = 0; i < 1e4; ++i) {
with (proxy) {
i;
}
if (i === 1e3)
flag = true;
}
}, `Error: NG`);
// DFG JIT operation.
var thrown = null;
try {
(() => {
var flag = false;
var target = {
__proto__: null
};
var handler = {
has: function (receiver, name)
{
return name === 'arguments';
},
get: function (target, name, receiver)
{
if (name === 'arguments' && flag)
throw new Error("NG");
return 42;
}
};
var proxy = new Proxy(target, handler);
proxy.__proto__ = null;
Object.prototype.__proto__ = {
__proto__: proxy,
};
(() => {
for (var i = 0; i < 1e4; ++i) {
arguments;
if (i === (1e4 - 2))
flag = true;
}
})();
})();
} catch (e) {
thrown = e;
}
Object.prototype.__proto__ = null;
shouldBe(String(thrown), `TypeError: Cannot set prototype of immutable prototype object`);