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)
93 lines
2.5 KiB
JavaScript
93 lines
2.5 KiB
JavaScript
var testCase = function (actual, expected, message) {
|
|
if (actual !== expected) {
|
|
throw message + ". Expected '" + expected + "', but was '" + actual + "'";
|
|
}
|
|
};
|
|
|
|
var functionConstructor = function () {
|
|
this.func = () => this;
|
|
};
|
|
|
|
var instance = new functionConstructor();
|
|
|
|
testCase(instance.func() === instance, true, "Error: this is not lexically binded inside of the arrow function #2");
|
|
|
|
var obj = {
|
|
method: function () {
|
|
return () => this;
|
|
}
|
|
};
|
|
|
|
noInline(obj.method);
|
|
|
|
for (var i=0; i < 10000; i++) {
|
|
testCase(obj.method()() === obj, true, "Error: this is not lexically binded inside of the arrow function #3");
|
|
}
|
|
|
|
var fake = {steal: obj.method()};
|
|
noInline(fake.steal);
|
|
|
|
for (var i=0; i < 10000; i++) {
|
|
testCase(fake.steal() === obj, true, "Error: this is not lexically binded inside of the arrow function #4");
|
|
}
|
|
|
|
var real = {borrow: obj.method};
|
|
noInline(real.borrow);
|
|
|
|
for (var i=0; i < 10000; i++) {
|
|
testCase(real.borrow()() === real, true, "Error: this is not lexically binded inside of the arrow function #5");
|
|
}
|
|
|
|
// Force create the lexical env inside of arrow function
|
|
|
|
var functionConstructorWithEval = function () {
|
|
this._id = 'old-value';
|
|
this.func = () => {
|
|
var f;
|
|
eval('10==10');
|
|
this._id = 'new-value';
|
|
return this._id;
|
|
};
|
|
};
|
|
|
|
var arrowWithEval = new functionConstructorWithEval();
|
|
|
|
for (var i=0; i < 10000; i++) {
|
|
testCase(arrowWithEval.func() === 'new-value', true, "Error: this is not lexically binded inside of the arrow function #6");
|
|
}
|
|
|
|
function foo() {
|
|
let arr = () => {
|
|
var x = 123;
|
|
function bas() {
|
|
return x;
|
|
};
|
|
this._id = '12345';
|
|
return bas();
|
|
};
|
|
this.arr = arr;
|
|
};
|
|
|
|
var fooObject = new foo();
|
|
|
|
function fooDefault() {
|
|
let arr = (that = this) => {
|
|
var x = 123;
|
|
function bas() {
|
|
return x;
|
|
};
|
|
that._id = '12345';
|
|
return bas();
|
|
};
|
|
this.arr = arr;
|
|
};
|
|
|
|
var fooDefaultObject = new fooDefault();
|
|
|
|
for (var i=0; i < 10000; i++) {
|
|
testCase(fooObject.arr() === 123, true, "Error: this is not lexically binded inside of the arrow function #7");
|
|
testCase(fooObject._id === '12345', true, "Error: this is not lexically binded inside of the arrow function #8");
|
|
testCase(fooDefaultObject.arr() === 123, true, "Error: this is not lexically binded inside of the arrow function #7");
|
|
testCase(fooDefaultObject._id === '12345', true, "Error: this is not lexically binded inside of the arrow function #8");
|
|
}
|