-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed resolving when Promise is inherited.
Previously, njs_promise_resolve() might return njs_object_t instead of njs_promise_t. Later an instance of njs_object_t was put into a NJS_PROMISE value. Whereas njs_promise_t is always expected to be inside of a NJS_PROMISE value. This closes #813 issue on Github.
- Loading branch information
Showing
4 changed files
with
52 additions
and
29 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
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,34 @@ | ||
/*--- | ||
includes: [] | ||
flags: [async] | ||
---*/ | ||
|
||
var inherits = (child, parent) => { | ||
child.prototype = Object.create(parent.prototype, { | ||
constructor: { | ||
value: child, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
Object.setPrototypeOf(child, parent); | ||
}; | ||
|
||
function BoxedPromise(executor) { | ||
var context, args; | ||
new Promise(wrappedExecutor); | ||
executor.apply(context, args); | ||
|
||
function wrappedExecutor(resolve, reject) { | ||
context = this; | ||
args = [v => resolve(v),v => reject(v)]; | ||
} | ||
} | ||
|
||
inherits(BoxedPromise, Promise); | ||
|
||
Promise.resolve() | ||
.then(() => BoxedPromise.resolve()) | ||
.catch(e => assert.sameValue(e.constructor, TypeError)) | ||
.then($DONE, $DONE); |