зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1289318 - Part 1: Store contents of spec-defined `capabilities` struct in Promise reaction jobs directly. r=efaust
No need to keep create an additional object for this. MozReview-Commit-ID: Hj8kpaBe6fL
This commit is contained in:
Родитель
c7a771a5ba
Коммит
9a23b3933f
|
@ -267,20 +267,13 @@ PromiseObject::dependentPromises(JSContext* cx, MutableHandle<GCVector<Value>> v
|
|||
if (!values.growBy(keys.length()))
|
||||
return false;
|
||||
|
||||
RootedAtom capabilitiesAtom(cx, Atomize(cx, "capabilities", strlen("capabilities")));
|
||||
if (!capabilitiesAtom)
|
||||
return false;
|
||||
RootedId capabilitiesId(cx, AtomToId(capabilitiesAtom));
|
||||
|
||||
// Each reaction is an internally-created object with the structure:
|
||||
// {
|
||||
// capabilities: {
|
||||
// promise: [the promise this reaction resolves],
|
||||
// resolve: [the `resolve` callback content code provided],
|
||||
// reject: [the `reject` callback content code provided],
|
||||
// },
|
||||
// handler: [the internal handler that fulfills/rejects the promise]
|
||||
// }
|
||||
// promise: [the promise this reaction resolves],
|
||||
// resolve: [the `resolve` callback content code provided],
|
||||
// reject: [the `reject` callback content code provided],
|
||||
// handler: [the internal handler that fulfills/rejects the promise]
|
||||
// }
|
||||
//
|
||||
// In the following loop we collect the `capabilities.promise` values for
|
||||
// each reaction.
|
||||
|
@ -289,10 +282,7 @@ PromiseObject::dependentPromises(JSContext* cx, MutableHandle<GCVector<Value>> v
|
|||
if (!GetProperty(cx, rejectReactions, rejectReactions, keys[i], val))
|
||||
return false;
|
||||
RootedObject reaction(cx, &val.toObject());
|
||||
if (!GetProperty(cx, reaction, reaction, capabilitiesId, val))
|
||||
return false;
|
||||
RootedObject capabilities(cx, &val.toObject());
|
||||
if (!GetProperty(cx, capabilities, capabilities, cx->runtime()->commonNames->promise, val))
|
||||
if (!GetProperty(cx, reaction, reaction, cx->runtime()->commonNames->promise, val))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -226,12 +226,11 @@ function TriggerPromiseReactions(reactions, argument) {
|
|||
|
||||
// ES6, 25.4.2.1.
|
||||
function EnqueuePromiseReactionJob(reaction, argument) {
|
||||
let capabilities = reaction.capabilities;
|
||||
_EnqueuePromiseReactionJob(reaction.handler,
|
||||
argument,
|
||||
capabilities.resolve,
|
||||
capabilities.reject,
|
||||
capabilities.promise,
|
||||
reaction.resolve,
|
||||
reaction.reject,
|
||||
reaction.promise,
|
||||
reaction.incumbentGlobal || null);
|
||||
}
|
||||
|
||||
|
@ -650,12 +649,9 @@ function AddPromiseReaction(slot, dependentPromise, onResolve, onReject, handler
|
|||
}
|
||||
_DefineDataProperty(reactions, reactions.length, {
|
||||
__proto__: PromiseReactionRecordProto,
|
||||
capabilities: {
|
||||
__proto__: PromiseCapabilityRecordProto,
|
||||
promise: dependentPromise,
|
||||
reject: onReject,
|
||||
resolve: onResolve
|
||||
},
|
||||
promise: dependentPromise,
|
||||
reject: onReject,
|
||||
resolve: onResolve,
|
||||
handler: handler
|
||||
});
|
||||
}
|
||||
|
@ -753,9 +749,9 @@ function Promise_then(onFulfilled, onRejected) {
|
|||
*
|
||||
* Used internally to implement DOM functionality.
|
||||
*
|
||||
* Note: the reactions pushed using this function contain a `capabilities`
|
||||
* object whose `promise` field can contain null. That field is only ever used
|
||||
* by devtools, which have to treat these reactions specially.
|
||||
* Note: the reactions pushed using this function contain a `promise` field
|
||||
* that can contain null. That field is only ever used by devtools, which have
|
||||
* to treat these reactions specially.
|
||||
*/
|
||||
function EnqueuePromiseReactions(promise, dependentPromise, onFulfilled, onRejected) {
|
||||
let isWrappedPromise = false;
|
||||
|
@ -891,7 +887,9 @@ function PerformPromiseThen(promise, onFulfilled, onRejected, resultCapability)
|
|||
// Step 5.
|
||||
let fulfillReaction = {
|
||||
__proto__: PromiseReactionRecordProto,
|
||||
capabilities: resultCapability,
|
||||
resolve: resultCapability.resolve,
|
||||
reject: resultCapability.reject,
|
||||
promise: resultCapability.promise,
|
||||
handler: onFulfilled,
|
||||
incumbentGlobal
|
||||
};
|
||||
|
@ -899,7 +897,9 @@ function PerformPromiseThen(promise, onFulfilled, onRejected, resultCapability)
|
|||
// Step 6.
|
||||
let rejectReaction = {
|
||||
__proto__: PromiseReactionRecordProto,
|
||||
capabilities: resultCapability,
|
||||
resolve: resultCapability.resolve,
|
||||
reject: resultCapability.reject,
|
||||
promise: resultCapability.promise,
|
||||
handler: onRejected,
|
||||
incumbentGlobal
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче