/* global verifyPromiseGlobal, getPromise, isXrayArgumentTest */
var label = "parent";
function passBasicPromise() { var p1 = Promise.resolve();
verifyPromiseGlobal(p1, window, "Promise.resolve return value 1"); var p2 = getPromise(window, p1);
is(p1, p2, "Basic promise should just pass on through"); return p2;
}
function passPrimitive(global) { var p = getPromise(global, 5);
verifyPromiseGlobal(p, global, "Promise wrapping primitive"); return p.then(function (arg) {
is(arg, 5, "Should have the arg we passed in");
});
}
function passThenable(global) { var called = false; var thenable = {
then(f) {
called = true;
f(7);
},
}; var p = getPromise(global, thenable);
verifyPromiseGlobal(p, global, "Promise wrapping thenable"); return p.then(function (arg) {
ok(called, "Thenable should have been called");
is(arg, 7, "Should have the arg our thenable passed in");
});
}
function passWrongPromiseWithMatchingConstructor() { var p1 = Promise.resolve();
verifyPromiseGlobal(p1, window, "Promise.resolve() return value 2");
p1.constructor = frames[0].Promise; var p2 = getPromise(frames[0], p1); // The behavior here will depend on whether we're touching frames[0] via Xrays // or not. If we are not, the current compartment while getting our promise // will be that of frames[0]. If we are, it will be our window's compartment. if (isXrayArgumentTest) {
isnot(
p1,
p2, "Should have wrapped the Promise in a new promise, because its constructor is not matching the current-compartment Promise constructor"
);
verifyPromiseGlobal(
p2,
window, "Promise wrapping xrayed promise with therefore non-matching constructor"
);
} else {
is(
p1,
p2, "Should have left the Promise alone because its constructor matched"
);
} return p2;
}
function passCorrectPromiseWithMismatchedConstructor() { var p1 = Promise.resolve(9);
verifyPromiseGlobal(p1, window, "Promise.resolve() return value 3");
p1.constructor = frames[0].Promise; var p2 = getPromise(window, p1);
isnot(
p1,
p2, "Should have wrapped promise in a new promise, since its .constructor was wrong"
);
verifyPromiseGlobal(
p2,
window, "Promise wrapping passed-in promise with mismatched constructor"
); return p2.then(function (arg) {
is(arg, 9, "Should have propagated along our resolution value");
});
}
function passPromiseToOtherGlobal() { var p1 = Promise.resolve();
verifyPromiseGlobal(p1, window, "Promise.resolve() return value 4"); var p2 = getPromise(frames[0], p1); // The behavior here will depend on whether we're touching frames[0] via Xrays // or not. If we are not, the current compartment while getting our promise // will be that of frames[0]. If we are, it will be our window's compartment. if (isXrayArgumentTest) {
is(
p1,
p2, "Should have left the Promise alone, because its constructor matches the current compartment's constructor"
);
} else {
isnot(
p1,
p2, "Should have wrapped promise in a promise from the other global"
);
verifyPromiseGlobal(
p2,
frames[0], "Promise wrapping passed-in basic promise"
);
} return p2;
}
function passPromiseSubclass() { class PromiseSubclass extends Promise {
constructor(func) { super(func);
}
}
var p1 = PromiseSubclass.resolve(11);
verifyPromiseGlobal(p1, window, "PromiseSubclass.resolve() return value"); var p2 = getPromise(window, p1);
isnot(p1, p2, "Should have wrapped promise subclass in a new promise");
verifyPromiseGlobal(
p2,
window, "Promise wrapping passed-in promise subclass"
); return p2.then(function (arg) {
is(
arg, 11, "Should have propagated along our resolution value from subclass"
);
});
}
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.62Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-08-23)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.