-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
[v8.x] async_hooks: C++ Embedder API overhaul #14109
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
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 |
|---|---|---|
|
|
@@ -634,9 +634,10 @@ void AsyncWrap::AsyncReset(bool silent) { | |
|
|
||
| if (silent) return; | ||
|
|
||
| EmitAsyncInit(env(), object(), | ||
| env()->async_hooks()->provider_string(provider_type()), | ||
| async_id_, trigger_id_); | ||
| AsyncWrap::EmitAsyncInit( | ||
| env(), object(), | ||
| env()->async_hooks()->provider_string(provider_type()), | ||
| async_id_, trigger_id_); | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -791,3 +792,56 @@ void EmitAsyncDestroy(Isolate* isolate, async_context asyncContext) { | |
| } // namespace node | ||
|
|
||
| NODE_MODULE_CONTEXT_AWARE_BUILTIN(async_wrap, node::AsyncWrap::Initialize) | ||
|
|
||
|
|
||
| // Only legacy public API below this line. | ||
|
|
||
| namespace node { | ||
|
|
||
| MaybeLocal<Value> MakeCallback(Isolate* isolate, | ||
| Local<Object> recv, | ||
| Local<Function> callback, | ||
| int argc, | ||
| Local<Value>* argv, | ||
| async_id asyncId, | ||
| async_id triggerAsyncId) { | ||
| return MakeCallback(isolate, recv, callback, argc, argv, | ||
| {asyncId, triggerAsyncId}); | ||
| } | ||
|
|
||
| MaybeLocal<Value> MakeCallback(Isolate* isolate, | ||
| Local<Object> recv, | ||
| const char* method, | ||
| int argc, | ||
| Local<Value>* argv, | ||
| async_id asyncId, | ||
| async_id triggerAsyncId) { | ||
| return MakeCallback(isolate, recv, method, argc, argv, | ||
| {asyncId, triggerAsyncId}); | ||
| } | ||
|
|
||
| MaybeLocal<Value> MakeCallback(Isolate* isolate, | ||
| Local<Object> recv, | ||
| Local<String> symbol, | ||
| int argc, | ||
| Local<Value>* argv, | ||
| async_id asyncId, | ||
| async_id triggerAsyncId) { | ||
| return MakeCallback(isolate, recv, symbol, argc, argv, | ||
| {asyncId, triggerAsyncId}); | ||
| } | ||
|
|
||
| // Undo the Node-8.x-only alias from node.h | ||
| #undef EmitAsyncInit | ||
|
|
||
| async_uid EmitAsyncInit(Isolate* isolate, | ||
|
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. Should this not be
Member
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. Maybe? I can change it if you like. 😄 |
||
| Local<Object> resource, | ||
| const char* name, | ||
| async_id trigger_async_id) { | ||
| return EmitAsyncInit__New(isolate, | ||
| resource, | ||
| name, | ||
| trigger_async_id).async_id; | ||
| } | ||
|
|
||
| } // namespace node | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
|
|
||
| #include "base-object.h" | ||
| #include "v8.h" | ||
| #include "node.h" | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -521,8 +521,16 @@ typedef double async_id; | |
| struct async_context { | ||
| ::node::async_id async_id; | ||
| ::node::async_id trigger_async_id; | ||
|
|
||
| // Legacy, Node 8.x only. | ||
| NODE_DEPRECATED("Use async_context directly as returned by EmitAsyncInit()", | ||
| operator ::node::async_id() const { | ||
| return async_id; | ||
| }); | ||
| }; | ||
|
|
||
| typedef async_id async_uid; // Legacy, Node 8.x only | ||
|
|
||
| /* Registers an additional v8::PromiseHook wrapper. This API exists because V8 | ||
| * itself supports only a single PromiseHook. */ | ||
| NODE_EXTERN void AddPromiseHook(v8::Isolate* isolate, | ||
|
|
@@ -544,6 +552,15 @@ NODE_EXTERN async_id AsyncHooksGetTriggerAsyncId(v8::Isolate* isolate); | |
| NODE_EXTERN NODE_DEPRECATED("Use AsyncHooksGetTriggerAsyncId(isolate)", | ||
| async_id AsyncHooksGetTriggerId(v8::Isolate* isolate)); | ||
|
|
||
| // This is a legacy overload of EmitAsyncInit that has to remain for ABI | ||
| // compatibility during Node 8.x. Do not use. | ||
| NODE_EXTERN async_uid EmitAsyncInit(v8::Isolate* isolate, | ||
| v8::Local<v8::Object> resource, | ||
| const char* name, | ||
| async_id trigger_async_id); | ||
|
|
||
| // From now on EmitAsyncInit always refers to the proper, new version. | ||
| #define EmitAsyncInit EmitAsyncInit__New | ||
|
|
||
| /* If the native API doesn't inherit from the helper class then the callbacks | ||
| * must be triggered manually. This triggers the init() callback. The return | ||
|
|
@@ -593,6 +610,33 @@ v8::MaybeLocal<v8::Value> MakeCallback(v8::Isolate* isolate, | |
| v8::Local<v8::Value>* argv, | ||
| async_context asyncContext); | ||
|
|
||
| // Legacy, Node 8.x only. | ||
|
|
||
| NODE_EXTERN | ||
| v8::MaybeLocal<v8::Value> MakeCallback(v8::Isolate* isolate, | ||
|
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. Should we not deprecate these too?
Member
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. Yes, thanks for pointing that out. |
||
| v8::Local<v8::Object> recv, | ||
| v8::Local<v8::Function> callback, | ||
| int argc, | ||
| v8::Local<v8::Value>* argv, | ||
| async_id asyncId, | ||
| async_id triggerAsyncId); | ||
| NODE_EXTERN | ||
| v8::MaybeLocal<v8::Value> MakeCallback(v8::Isolate* isolate, | ||
| v8::Local<v8::Object> recv, | ||
| const char* method, | ||
| int argc, | ||
| v8::Local<v8::Value>* argv, | ||
| async_id asyncId, | ||
| async_id triggerAsyncId); | ||
| NODE_EXTERN | ||
| v8::MaybeLocal<v8::Value> MakeCallback(v8::Isolate* isolate, | ||
| v8::Local<v8::Object> recv, | ||
| v8::Local<v8::String> symbol, | ||
| int argc, | ||
| v8::Local<v8::Value>* argv, | ||
| async_id asyncId, | ||
| async_id triggerAsyncId); | ||
|
|
||
| /* Helper class users can optionally inherit from. If | ||
| * `AsyncResource::MakeCallback()` is used, then all four callbacks will be | ||
| * called automatically. */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,9 +17,17 @@ void GetTriggerAsyncId(const FunctionCallbackInfo<Value>& args) { | |
| node::AsyncHooksGetTriggerAsyncId(args.GetIsolate())); | ||
| } | ||
|
|
||
| void EmitAsyncInit(const FunctionCallbackInfo<Value>& args) { | ||
| assert(args[0]->IsObject()); | ||
| node::async_uid uid = | ||
| node::EmitAsyncInit(args.GetIsolate(), args[0].As<Object>(), "foobar"); | ||
|
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. The Also, is
Member
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.
Yes, the latter. The old one is not really exposed through our API anymore, it’s just the symbol that has to keep being exported so already-compiled libraries can reference it.
Yes, everywhere else in the tests we use |
||
| args.GetReturnValue().Set(uid); | ||
| } | ||
|
|
||
| void Initialize(Local<Object> exports) { | ||
| NODE_SET_METHOD(exports, "getExecutionAsyncId", GetExecutionAsyncId); | ||
| NODE_SET_METHOD(exports, "getTriggerAsyncId", GetTriggerAsyncId); | ||
| NODE_SET_METHOD(exports, "emitAsyncInit", EmitAsyncInit); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
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.
Why are these not in
node.cc?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.
No particular reason, except maybe that it kind of belongs to the rest of the legacy code here.
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.
All
MakeCallbackfunctions are innode.ccincluding the legacy ones. But since this won't land in master I don't care that much.