summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/realms/promise-then.js
blob: a12c2c6d82254d5d12bc1893e06c2b8ed1d8df49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
load(libdir + "asserts.js");

ignoreUnhandledRejections();

const g = newGlobal({sameCompartmentAs: this});

let resolve, reject;
let promise = new Promise((resolveFn, rejectFn) => {
    resolve = resolveFn;
    reject = rejectFn;
});

// Set to a built-in Promise.prototype.then function, but from a different realm.
promise.then = g.Promise.prototype.then;

// Make SpeciesConstructor throw a TypeError exception.
promise.constructor = {
    [Symbol.species]: "not a constructor"
};

async function f(p) {
    await p;
}

let error;
f(promise).catch(e => { error = e; });

resolve(promise);

drainJobQueue();

assertEq(error.constructor === g.TypeError, true);