diff options
author | Jason Ginchereau <jasongin@microsoft.com> | 2017-09-09 14:04:35 -0700 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-09-14 17:39:05 +0200 |
commit | 1a0727d85ef09845cd0eda0f2303066a6a0aa054 (patch) | |
tree | b26c26be84daf80c3d93be46c7cba93d6eff5589 /src | |
parent | 2509c3478278e7a48f1f11f48eb4bc8562f1f110 (diff) | |
download | android-node-v8-1a0727d85ef09845cd0eda0f2303066a6a0aa054.tar.gz android-node-v8-1a0727d85ef09845cd0eda0f2303066a6a0aa054.tar.bz2 android-node-v8-1a0727d85ef09845cd0eda0f2303066a6a0aa054.zip |
n-api: change async resource name to napi_value
PR-URL: https://github.com/nodejs/node/pull/14697
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/async-wrap.cc | 15 | ||||
-rw-r--r-- | src/node.h | 15 | ||||
-rw-r--r-- | src/node_api.cc | 17 | ||||
-rw-r--r-- | src/node_api.h | 2 |
4 files changed, 37 insertions, 12 deletions
diff --git a/src/async-wrap.cc b/src/async-wrap.cc index e08b2adc35..b678f1500b 100644 --- a/src/async-wrap.cc +++ b/src/async-wrap.cc @@ -643,6 +643,16 @@ async_context EmitAsyncInit(Isolate* isolate, Local<Object> resource, const char* name, async_id trigger_async_id) { + Local<String> type = + String::NewFromUtf8(isolate, name, v8::NewStringType::kInternalized) + .ToLocalChecked(); + return EmitAsyncInit(isolate, resource, type, trigger_async_id); +} + +async_context EmitAsyncInit(Isolate* isolate, + Local<Object> resource, + v8::Local<v8::String> name, + async_id trigger_async_id) { Environment* env = Environment::GetCurrent(isolate); // Initialize async context struct @@ -655,10 +665,7 @@ async_context EmitAsyncInit(Isolate* isolate, }; // Run init hooks - Local<String> type = - String::NewFromUtf8(isolate, name, v8::NewStringType::kInternalized) - .ToLocalChecked(); - AsyncWrap::EmitAsyncInit(env, resource, type, context.async_id, + AsyncWrap::EmitAsyncInit(env, resource, name, context.async_id, context.trigger_async_id); return context; diff --git a/src/node.h b/src/node.h index 6558a9ee6d..8d93fea7dc 100644 --- a/src/node.h +++ b/src/node.h @@ -566,6 +566,11 @@ NODE_EXTERN async_context EmitAsyncInit(v8::Isolate* isolate, const char* name, async_id trigger_async_id = -1); +NODE_EXTERN async_context EmitAsyncInit(v8::Isolate* isolate, + v8::Local<v8::Object> resource, + v8::Local<v8::String> name, + async_id trigger_async_id = -1); + /* Emit the destroy() callback. */ NODE_EXTERN void EmitAsyncDestroy(v8::Isolate* isolate, async_context asyncContext); @@ -647,6 +652,16 @@ class AsyncResource { trigger_async_id); } + AsyncResource(v8::Isolate* isolate, + v8::Local<v8::Object> resource, + v8::Local<v8::String> name, + async_id trigger_async_id = -1) + : isolate_(isolate), + resource_(isolate, resource) { + async_context_ = EmitAsyncInit(isolate, resource, name, + trigger_async_id); + } + ~AsyncResource() { EmitAsyncDestroy(isolate_, async_context_); } diff --git a/src/node_api.cc b/src/node_api.cc index f49dd6da68..8f84de7879 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -3250,7 +3250,7 @@ class Work : public node::AsyncResource { private: explicit Work(napi_env env, v8::Local<v8::Object> async_resource, - const char* async_resource_name, + v8::Local<v8::String> async_resource_name, napi_async_execute_callback execute, napi_async_complete_callback complete = nullptr, void* data = nullptr) @@ -3270,7 +3270,7 @@ class Work : public node::AsyncResource { public: static Work* New(napi_env env, v8::Local<v8::Object> async_resource, - const char* async_resource_name, + v8::Local<v8::String> async_resource_name, napi_async_execute_callback execute, napi_async_complete_callback complete, void* data) { @@ -3340,7 +3340,7 @@ class Work : public node::AsyncResource { napi_status napi_create_async_work(napi_env env, napi_value async_resource, - const char* async_resource_name, + napi_value async_resource_name, napi_async_execute_callback execute, napi_async_complete_callback complete, void* data, @@ -3349,17 +3349,20 @@ napi_status napi_create_async_work(napi_env env, CHECK_ARG(env, execute); CHECK_ARG(env, result); + v8::Local<v8::Context> context = env->isolate->GetCurrentContext(); + v8::Local<v8::Object> resource; if (async_resource != nullptr) { - auto value = v8impl::V8LocalValueFromJsValue(async_resource); - RETURN_STATUS_IF_FALSE(env, value->IsObject(), napi_invalid_arg); - resource = value.As<v8::Object>(); + CHECK_TO_OBJECT(env, context, resource, async_resource); } else { resource = v8::Object::New(env->isolate); } + v8::Local<v8::String> resource_name; + CHECK_TO_STRING(env, context, resource_name, async_resource_name); + uvimpl::Work* work = - uvimpl::Work::New(env, resource, async_resource_name, + uvimpl::Work::New(env, resource, resource_name, execute, complete, data); *result = reinterpret_cast<napi_async_work>(work); diff --git a/src/node_api.h b/src/node_api.h index 227f26a2ff..b127fd7fe8 100644 --- a/src/node_api.h +++ b/src/node_api.h @@ -525,7 +525,7 @@ NAPI_EXTERN napi_status napi_get_dataview_info(napi_env env, NAPI_EXTERN napi_status napi_create_async_work(napi_env env, napi_value async_resource, - const char* async_resource_name, + napi_value async_resource_name, napi_async_execute_callback execute, napi_async_complete_callback complete, void* data, |