mirror of
https://github.com/tc39/test262.git
synced 2025-05-03 22:40:28 +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)
105 lines
2.7 KiB
JavaScript
105 lines
2.7 KiB
JavaScript
var testCase = function (actual, expected, message) {
|
|
if (actual !== expected) {
|
|
throw message + ". Expected '" + expected + "', but was '" + actual + "'";
|
|
}
|
|
};
|
|
|
|
let testValue = 'test-value';
|
|
|
|
var f_this = function () {
|
|
let value = 'value';
|
|
if (true) {
|
|
let someValue = 'someValue';
|
|
if (true) {
|
|
let = anotherValue = 'value';
|
|
return () => () => () => this.value;
|
|
}
|
|
}
|
|
|
|
return () => value;
|
|
}
|
|
|
|
for (let i = 0; i < 10000; i++) {
|
|
testCase(f_this.call({value : testValue})()()(), testValue);
|
|
}
|
|
|
|
var f_this_eval = function () {
|
|
if (true) {
|
|
let someValue = '';
|
|
if (true) {
|
|
let = anotherValue = 'value';
|
|
return () => () => () => eval('this.value');
|
|
}
|
|
}
|
|
|
|
return () => 'no-value';
|
|
}
|
|
|
|
for (let i = 0; i < 10000; i++) {
|
|
testCase(f_this_eval.call({value : testValue}, false)()()(), testValue);
|
|
}
|
|
|
|
|
|
function f_this_branches (branch, returnThis) {
|
|
let value = 'value';
|
|
if (branch === 'A') {
|
|
let someValue = 'someValue';
|
|
if (true) {
|
|
let = anotherValue = 'value';
|
|
return () => () => () => {
|
|
if (returnThis)
|
|
return this.value;
|
|
else
|
|
return anotherValue;
|
|
}
|
|
}
|
|
}
|
|
|
|
return () => value;
|
|
}
|
|
|
|
for (let i = 0; i < 10000; i++) {
|
|
testCase(f_this_branches.call({value : testValue}, 'B')() == testValue, false);
|
|
testCase(f_this_branches.call({value : testValue}, 'A', false)()()() == testValue, false);
|
|
testCase(f_this_branches.call({value : testValue}, 'A', true)()()(), testValue);
|
|
}
|
|
|
|
function f_this_eval_branches (branch, returnThis) {
|
|
let value = 'value';
|
|
if (branch === 'A') {
|
|
let someValue = 'someValue';
|
|
if (true) {
|
|
let = anotherValue = 'value';
|
|
return () => () => () => {
|
|
if (returnThis)
|
|
return eval('this.value');
|
|
else
|
|
return anotherValue;
|
|
}
|
|
}
|
|
}
|
|
|
|
return () => value;
|
|
}
|
|
|
|
for (let i = 0; i < 10000; i++) {
|
|
testCase(f_this_eval_branches.call({value : testValue}, 'B')() == testValue, false);
|
|
testCase(f_this_eval_branches.call({value : testValue}, 'A', false)()()() == testValue, false);
|
|
testCase(f_this_eval_branches.call({value : testValue}, 'A', true)()()(), testValue);
|
|
}
|
|
|
|
let self = this;
|
|
|
|
let arrow = () => {
|
|
testCase(self, this, "Error: Wrong lexical bind of this");
|
|
};
|
|
|
|
for (let i = 0; i < 10000; i++) {
|
|
arrow();
|
|
}
|
|
|
|
|
|
for (let i = 0; i < 10000; i++) {
|
|
eval("let _self=this;(()=>testCase(self, this, 'Error: Wrong lexical bind of this in eval'))();");
|
|
}
|