test262/implementation-contributed/javascriptcore/stress/arrowfunction-lexical-bind-supercall-1.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

68 lines
1.5 KiB
JavaScript

var testCase = function (actual, expected, message) {
if (actual !== expected) {
throw message + ". Expected '" + expected + "', but was '" + actual + "'";
}
};
var testValue = 'test-value';
var A = class A {
constructor() {
this.idValue = testValue;
}
};
var B = class B extends A {
constructor (inArrowFuction, inConstructor) {
var arrow = () => {
if (inArrowFuction) {
super();
testCase(this.idValue, testValue, "Error: super() should create this and put value into idValue property");
}
}
if (inArrowFuction)
arrow();
if (inConstructor)
super();
testCase(this.idValue, testValue, "Error: arrow function should return this to constructor");
}
};
for (var i = 0; i < 1000; i++) {
new B(true, false);
new B(false, true);
}
var testException = function (value1, value2, index) {
var exception;
try {
new B(value1, value2);
} catch (e) {
exception = e;
if (!(e instanceof ReferenceError))
throw "Exception thrown was not a reference error";
}
if (!exception)
throw "Exception not thrown for an unitialized this at iteration " + index;
}
for (var i=0; i < 1000; i++) {
testException(false, false, i);
}
var C = class C extends A {
constructor() {
eval("var x = 20");
super();
let f = () => this;
let xf = f();
xf.id = 'test-id';
}
};
var c = new C();