- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 33.6k
[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
          
     Closed
      
      
            addaleax
  wants to merge
  3
  commits into
  nodejs:v8.x-staging
from
addaleax:v8.x-async-wrap-cpp-overhaul
  
      
      
   
      
    
  
     Closed
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or 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 | 
|---|---|---|
|  | @@ -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_); | ||
| } | ||
|  | ||
|  | ||
|  | @@ -741,42 +742,106 @@ Local<Value> AsyncWrap::MakeCallback(const Local<Function> cb, | |
| /* Public C++ embedder API */ | ||
|  | ||
|  | ||
| async_uid AsyncHooksGetExecutionAsyncId(Isolate* isolate) { | ||
| async_id AsyncHooksGetExecutionAsyncId(Isolate* isolate) { | ||
| return Environment::GetCurrent(isolate)->current_async_id(); | ||
| } | ||
|  | ||
| async_uid AsyncHooksGetCurrentId(Isolate* isolate) { | ||
| async_id AsyncHooksGetCurrentId(Isolate* isolate) { | ||
| return AsyncHooksGetExecutionAsyncId(isolate); | ||
| } | ||
|  | ||
|  | ||
| async_uid AsyncHooksGetTriggerAsyncId(Isolate* isolate) { | ||
| return Environment::GetCurrent(isolate)->get_init_trigger_id(); | ||
| async_id AsyncHooksGetTriggerAsyncId(Isolate* isolate) { | ||
| return Environment::GetCurrent(isolate)->trigger_id(); | ||
| } | ||
|  | ||
| async_uid AsyncHooksGetTriggerId(Isolate* isolate) { | ||
| async_id AsyncHooksGetTriggerId(Isolate* isolate) { | ||
| return AsyncHooksGetTriggerAsyncId(isolate); | ||
| } | ||
|  | ||
|  | ||
| async_uid EmitAsyncInit(Isolate* isolate, | ||
| Local<Object> resource, | ||
| const char* name, | ||
| async_uid trigger_id) { | ||
| async_context EmitAsyncInit(Isolate* isolate, | ||
| Local<Object> resource, | ||
| const char* name, | ||
| async_id trigger_async_id) { | ||
| Environment* env = Environment::GetCurrent(isolate); | ||
| async_uid async_id = env->new_async_id(); | ||
|  | ||
| // Initialize async context struct | ||
| if (trigger_async_id == -1) | ||
| trigger_async_id = env->get_init_trigger_id(); | ||
|  | ||
| async_context context = { | ||
| env->new_async_id(), // async_id_ | ||
| trigger_async_id // trigger_async_id_ | ||
| }; | ||
|  | ||
| // Run init hooks | ||
| Local<String> type = | ||
| String::NewFromUtf8(isolate, name, v8::NewStringType::kInternalized) | ||
| .ToLocalChecked(); | ||
| AsyncWrap::EmitAsyncInit(env, resource, type, async_id, trigger_id); | ||
| return async_id; | ||
| AsyncWrap::EmitAsyncInit(env, resource, type, context.async_id, | ||
| context.trigger_async_id); | ||
|  | ||
| return context; | ||
| } | ||
|  | ||
| void EmitAsyncDestroy(Isolate* isolate, async_uid id) { | ||
| PushBackDestroyId(Environment::GetCurrent(isolate), id); | ||
| void EmitAsyncDestroy(Isolate* isolate, async_context asyncContext) { | ||
| PushBackDestroyId(Environment::GetCurrent(isolate), asyncContext.async_id); | ||
| } | ||
|  | ||
| } // 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, | ||
|          | ||
| Local<Object> resource, | ||
| const char* name, | ||
| async_id trigger_async_id) { | ||
| return EmitAsyncInit__New(isolate, | ||
| resource, | ||
| name, | ||
| trigger_async_id).async_id; | ||
| } | ||
|  | ||
| } // namespace node | ||
  
    
      This file contains hidden or 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 | 
|---|---|---|
|  | @@ -26,6 +26,7 @@ | |
|  | ||
| #include "base-object.h" | ||
| #include "v8.h" | ||
| #include "node.h" | ||
|  | ||
| #include <stdint.h> | ||
|  | ||
|  | ||
  
    
      This file contains hidden or 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 hidden or 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
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
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.