-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds
NewPromiseCapability
abstract operation (#43)
This PR introduces the `NewPromiseCapability` abstract operation. As part of this, it uses the new abstract operation in the `Promise.withResolvers` polyfill.
- Loading branch information
Showing
4 changed files
with
74 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
dependencies = [ | ||
"_ESAbstract.Construct", | ||
"_ESAbstract.IsCallable", | ||
"_ESAbstract.IsConstructor", | ||
] | ||
spec = "https://tc39.es/ecma262/#sec-newpromisecapability" | ||
|
||
[browsers] | ||
android = "*" | ||
bb = "*" | ||
chrome = "*" | ||
edge = "*" | ||
edge_mob = "*" | ||
firefox = "*" | ||
firefox_mob = "*" | ||
ie = "*" | ||
ie_mob = "*" | ||
opera = "*" | ||
op_mob = "*" | ||
op_mini = "*" | ||
safari = "*" | ||
ios_saf = "*" | ||
samsung_mob = "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* global Construct, IsCallable, IsConstructor */ | ||
// 27.2.1.5 NewPromiseCapability ( C ) | ||
// eslint-disable-next-line no-unused-vars | ||
function NewPromiseCapability(C) { | ||
// 1. If IsConstructor(C) is false, throw a TypeError exception. | ||
if (IsConstructor(C) === false) { | ||
throw new TypeError("C must be a constructor"); | ||
} | ||
// 2. NOTE: C is assumed to be a constructor function that supports the parameter conventions of the Promise constructor (see 27.2.3.1). | ||
// 3. Let resolvingFunctions be the Record { [[Resolve]]: undefined, [[Reject]]: undefined }. | ||
var resolvingFunctions = { | ||
"[[Resolve]]": undefined, | ||
"[[Reject]]": undefined | ||
}; | ||
// 4. Let executorClosure be a new Abstract Closure with parameters (resolve, reject) that captures resolvingFunctions and performs the following steps when called: | ||
// 5. Let executor be CreateBuiltinFunction(executorClosure, 2, "", « »). | ||
var executor = function (resolve, reject) { | ||
// a. If resolvingFunctions.[[Resolve]] is not undefined, throw a TypeError exception. | ||
if (resolvingFunctions["[[Resolve]]"] !== undefined) { | ||
throw new TypeError("[[Resolve]] is not undefined"); | ||
} | ||
// b. If resolvingFunctions.[[Reject]] is not undefined, throw a TypeError exception. | ||
if (resolvingFunctions["[[Reject]]"] !== undefined) { | ||
throw new TypeError("[[Reject]] is not undefined"); | ||
} | ||
// c. Set resolvingFunctions.[[Resolve]] to resolve. | ||
resolvingFunctions["[[Resolve]]"] = resolve; | ||
// d. Set resolvingFunctions.[[Reject]] to reject. | ||
resolvingFunctions["[[Reject]]"] = reject; | ||
// e. Return undefined. | ||
}; | ||
// 6. Let promise be ? Construct(C, « executor »). | ||
var promise = Construct(C, [executor]); | ||
// 7. If IsCallable(resolvingFunctions.[[Resolve]]) is false, throw a TypeError exception. | ||
if (IsCallable(resolvingFunctions["[[Resolve]]"]) === false) { | ||
throw new TypeError("[[Resolve]] is not callable"); | ||
} | ||
// 8. If IsCallable(resolvingFunctions.[[Reject]]) is false, throw a TypeError exception. | ||
if (IsCallable(resolvingFunctions["[[Reject]]"]) === false) { | ||
throw new TypeError("[[Reject]] is not callable"); | ||
} | ||
// 9. Return the PromiseCapability Record { [[Promise]]: promise, [[Resolve]]: resolvingFunctions.[[Resolve]], [[Reject]]: resolvingFunctions.[[Reject]] }. | ||
return { | ||
"[[Promise]]": promise, | ||
"[[Resolve]]": resolvingFunctions["[[Resolve]]"], | ||
"[[Reject]]": resolvingFunctions["[[Reject]]"] | ||
}; | ||
} |