mirror of
https://github.com/tc39/test262.git
synced 2025-05-03 14:30:27 +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)
73 lines
1.6 KiB
JavaScript
73 lines
1.6 KiB
JavaScript
C = class extends Promise { }
|
|
N = class { }
|
|
N[Symbol.species] = function() { throw "this should never be called"; }
|
|
|
|
function id(x) { return x; }
|
|
|
|
testFunctions = [
|
|
[Promise.prototype.then, [id]]
|
|
];
|
|
|
|
objProp = Object.defineProperty;
|
|
|
|
function funcThrows(func, args) {
|
|
try {
|
|
func.call(...args)
|
|
return false;
|
|
} catch (e) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
function makeC() {
|
|
return new C(function(resolve) { resolve(1); });
|
|
}
|
|
|
|
function test(testData) {
|
|
"use strict";
|
|
let [protoFunction, args] = testData;
|
|
let foo = makeC()
|
|
let n = new N();
|
|
|
|
// Test promise defaults cases.
|
|
foo = makeC();
|
|
|
|
objProp(C, Symbol.species, { value: undefined, writable: true});
|
|
let bar = protoFunction.call(foo, ...args);
|
|
if (!(bar instanceof Promise) || bar instanceof C)
|
|
throw Error();
|
|
|
|
C[Symbol.species] = null;
|
|
bar = protoFunction.call(foo, ...args);
|
|
if (!(bar instanceof Promise) || bar instanceof C)
|
|
throw Error();
|
|
|
|
// Test species is custom constructor.
|
|
let called = false;
|
|
function species() {
|
|
called = true;
|
|
return new C(...arguments);
|
|
}
|
|
|
|
C[Symbol.species] = species;
|
|
bar = protoFunction.call(foo, ...args);
|
|
|
|
if (!(bar instanceof Promise) || !(bar instanceof C) || !called)
|
|
throw Error("failed on " + protoFunction);
|
|
|
|
function speciesThrows() {
|
|
throw Error();
|
|
}
|
|
|
|
C[Symbol.species] = speciesThrows;
|
|
if (!funcThrows(protoFunction, [foo, ...args]))
|
|
throw "didn't throw";
|
|
|
|
C[Symbol.species] = true;
|
|
if (!funcThrows(protoFunction, [foo, ...args]))
|
|
throw "didn't throw";
|
|
|
|
}
|
|
|
|
testFunctions.forEach(test);
|