|
28 | 28 |
|
29 | 29 | #include "v8.h" |
30 | 30 |
|
31 | | -// TODO(mcollina): should this be moved in a more public space? |
32 | | -// embedders will not be able to use this field |
33 | | -#define EXECUTION_RESOURCE_FIELD 10 |
34 | | - |
35 | 31 | using v8::Context; |
36 | 32 | using v8::DontDelete; |
37 | 33 | using v8::EscapableHandleScope; |
@@ -152,7 +148,7 @@ void AsyncWrap::EmitTraceEventBefore() { |
152 | 148 | void AsyncWrap::EmitBefore(Environment* env, double async_id, |
153 | 149 | v8::Local<v8::Object> resource) { |
154 | 150 | v8::Local<v8::Context> context = env->isolate()->GetCurrentContext(); |
155 | | - context->SetEmbedderData(EXECUTION_RESOURCE_FIELD, resource); |
| 151 | + env->async_hooks()->set_execution_async_resource(resource); |
156 | 152 |
|
157 | 153 | Emit(env, async_id, AsyncHooks::kBefore, |
158 | 154 | env->async_hooks_before_function()); |
@@ -184,7 +180,7 @@ void AsyncWrap::EmitAfter(Environment* env, double async_id) { |
184 | 180 | Emit(env, async_id, AsyncHooks::kAfter, |
185 | 181 | env->async_hooks_after_function()); |
186 | 182 |
|
187 | | - context->SetEmbedderData(EXECUTION_RESOURCE_FIELD, v8::Null(isolate)); |
| 183 | + env->async_hooks()->clear_execution_async_resource(); |
188 | 184 | } |
189 | 185 |
|
190 | 186 | class PromiseWrap : public AsyncWrap { |
@@ -270,7 +266,7 @@ static void PromiseHook(PromiseHookType type, Local<Promise> promise, |
270 | 266 |
|
271 | 267 | // needed for async functions :/ |
272 | 268 | // the top level will not emit before and after |
273 | | - env->context()->SetEmbedderData(EXECUTION_RESOURCE_FIELD, wrap->object()); |
| 269 | + env->async_hooks()->set_execution_async_resource(wrap->object()); |
274 | 270 | } |
275 | 271 | } |
276 | 272 |
|
@@ -401,14 +397,16 @@ static void RegisterDestroyHook(const FunctionCallbackInfo<Value>& args) { |
401 | 397 |
|
402 | 398 | static void GetExecutionAsyncResource(const FunctionCallbackInfo<Value>& args) { |
403 | 399 | Isolate* isolate = args.GetIsolate(); |
| 400 | + Environment* env = Environment::GetCurrent(args); |
404 | 401 | v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
405 | | - args.GetReturnValue().Set(context->GetEmbedderData(EXECUTION_RESOURCE_FIELD)); |
| 402 | + args.GetReturnValue().Set(env->async_hooks()->get_execution_async_resource()); |
406 | 403 | } |
407 | 404 |
|
408 | 405 | static void SetExecutionAsyncResource(const FunctionCallbackInfo<Value>& args) { |
409 | 406 | Isolate* isolate = args.GetIsolate(); |
| 407 | + Environment* env = Environment::GetCurrent(args); |
410 | 408 | v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
411 | | - context->SetEmbedderData(EXECUTION_RESOURCE_FIELD, args[0]); |
| 409 | + env->async_hooks()->set_execution_async_resource(args[0]); |
412 | 410 | } |
413 | 411 |
|
414 | 412 | void AsyncWrap::GetAsyncId(const FunctionCallbackInfo<Value>& args) { |
@@ -502,7 +500,7 @@ void AsyncWrap::Initialize(Local<Object> target, |
502 | 500 | env->SetMethod(target, "setExecutionAsyncResource", |
503 | 501 | SetExecutionAsyncResource); |
504 | 502 |
|
505 | | - context->SetEmbedderData(EXECUTION_RESOURCE_FIELD, v8::Null(isolate)); |
| 503 | + env->async_hooks()->clear_execution_async_resource(); |
506 | 504 |
|
507 | 505 | PropertyAttribute ReadOnlyDontDelete = |
508 | 506 | static_cast<PropertyAttribute>(ReadOnly | DontDelete); |
|
0 commit comments