-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
async_wrap,src: promise hook integration #13000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
ef35de1
563c1b0
4aaadc0
70f9675
0afbcfc
833ad39
5717d75
34ee31f
e0c194b
e1c11e7
d47e97a
012171a
4e38bda
13313bb
9b9c310
81ff7f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -276,16 +276,6 @@ class PromiseWrap : public AsyncWrap { | |
| }; | ||
|
|
||
|
|
||
| static void GetPromiseDomain(Local<v8::Name> name, | ||
| const v8::PropertyCallbackInfo<v8::Value>& info) { | ||
| Local<Context> context = info.GetIsolate()->GetCurrentContext(); | ||
| Environment* env = Environment::GetCurrent(context); | ||
| info.GetReturnValue().Set( | ||
| info.Data().As<Object>()->Get(context, | ||
| env->domain_string()).ToLocalChecked()); | ||
| } | ||
|
|
||
|
|
||
| static void PromiseHook(PromiseHookType type, Local<Promise> promise, | ||
| Local<Value> parent, void* arg) { | ||
| Local<Context> context = promise->CreationContext(); | ||
|
|
@@ -307,12 +297,6 @@ static void PromiseHook(PromiseHookType type, Local<Promise> promise, | |
| promise->DefineOwnProperty(context, | ||
| env->promise_async_tag(), | ||
| obj, v8::PropertyAttribute::DontEnum).FromJust(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want the user to be able to alter these? In v8::PropertyAttribute ReadOnlyDontDelete =
static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete);Though I probably should have added
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This property will be going away as soon as we move to an internal property on promises (blocked on #13175). I can modify this but I intend to get the promise internal property refactoring in before 8.0.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added this for now. |
||
| if (env->in_domain()) { | ||
| obj->Set(context, env->domain_string(), | ||
| env->domain_array()->Get(context, 0).ToLocalChecked()).FromJust(); | ||
| promise->SetAccessor(context, env->domain_string(), | ||
| GetPromiseDomain, NULL, obj).FromJust(); | ||
| } | ||
| } else if (type == PromiseHookType::kResolve) { | ||
| // TODO(matthewloring): need to expose this through the async hooks api. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, there is also the actual event but that information can be inferred when
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yep :)
You’d think so, wouldn’t you? 😄 This isn’t called when the promise is resolved, it’s at the beginning of when the I’m not actually sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if a promise's
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Haha, that was actually what I meant, when
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This was perhaps the most discussed thing in the I think adding the async id that called
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an example scenario that almost captures all the possibilities that Promises and async hooks can interact: (function runner() {
const p = new Promise(function p_fn0(res) {
setImmediate(function si0() {
res('foo')
});
}).then(function then0(val) {
return Fn(val);
});
setImmediate(function si0() {
p.catch(function catch0(err) {
printLongErrorStack(err); // not defined
});
});
function Fn(val) {
if (val === 'foo') throw new Error('bam');
}
})();If each Promise executor, onFulfilled or onRejected only collect the stack when Though it would be helpful to produce the following long stack: I've had some lengthy discussions about this and, though I don't remember with whom, I recall agreeing that the logical place to execute the So for this PR the first stack above is expected, but we should also address how to produce the second. IIRC the API in in place to allow watching for
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, this conversation was with me and I think it captures the concern with attaching the async id to the promise resource at resolution time so that it can be read in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @matthewloring Adding another type that fires at a different time wouldn't be a problem.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
While it is not a technical issue to add another type (I assume you mean event type and not resource type), I think it would be better to do in a future PR where we have a better chance to evaluate the needs for such event type for other cases than promises. So far the only concern mentioned in the EPS has been regarding context across async boundaries, which "attaching the async id to the promise resource" does solve, although not in a particularly nice way.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressing this in a follow on seems fine to me. |
||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is
promise_async_tag()used for, preventing garbage collection? If so I think a comment should be added.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only reference to it is held by the promise. We use its lifespan to approximate when the promise was garbage collected. I've added a comment describing this.