diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2018-12-31 23:35:07 +0800 |
---|---|---|
committer | Daniel Bevenius <daniel.bevenius@gmail.com> | 2019-01-09 05:49:29 +0100 |
commit | e54d11e2f64aadc74ea52185b4430afbe034f09b (patch) | |
tree | 47ca84358a59f19b25cbf69c656e6202bbbd99dd /src/node.cc | |
parent | b406c9c4e95e6e90c43df843512a4c761ad9affa (diff) | |
download | android-node-v8-e54d11e2f64aadc74ea52185b4430afbe034f09b.tar.gz android-node-v8-e54d11e2f64aadc74ea52185b4430afbe034f09b.tar.bz2 android-node-v8-e54d11e2f64aadc74ea52185b4430afbe034f09b.zip |
src: move InternalMakeCallback and MakeCallback
This commit moves InternalMakeCallback and MakeCallback into
callback_scope.cc. Since these are just wrappers on top of
`InternalCallbackScope`, this makes the implementations easier to find.
https://github.com/nodejs/node/pull/25299
PR-URL: https://github.com/nodejs/node/pull/25299
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node.cc')
-rw-r--r-- | src/node.cc | 133 |
1 files changed, 0 insertions, 133 deletions
diff --git a/src/node.cc b/src/node.cc index 24b0167b89..3a1a6a9d6c 100644 --- a/src/node.cc +++ b/src/node.cc @@ -109,7 +109,6 @@ using v8::Array; using v8::Boolean; using v8::Context; using v8::DEFAULT; -using v8::EscapableHandleScope; using v8::Exception; using v8::Function; using v8::FunctionCallbackInfo; @@ -556,138 +555,6 @@ void RemoveEnvironmentCleanupHook(Isolate* isolate, env->RemoveCleanupHook(fun, arg); } -MaybeLocal<Value> InternalMakeCallback(Environment* env, - Local<Object> recv, - const Local<Function> callback, - int argc, - Local<Value> argv[], - async_context asyncContext) { - CHECK(!recv.IsEmpty()); - InternalCallbackScope scope(env, recv, asyncContext); - if (scope.Failed()) { - return MaybeLocal<Value>(); - } - - Local<Function> domain_cb = env->domain_callback(); - MaybeLocal<Value> ret; - if (asyncContext.async_id != 0 || domain_cb.IsEmpty() || recv.IsEmpty()) { - ret = callback->Call(env->context(), recv, argc, argv); - } else { - std::vector<Local<Value>> args(1 + argc); - args[0] = callback; - std::copy(&argv[0], &argv[argc], args.begin() + 1); - ret = domain_cb->Call(env->context(), recv, args.size(), &args[0]); - } - - if (ret.IsEmpty()) { - scope.MarkAsFailed(); - return MaybeLocal<Value>(); - } - - scope.Close(); - if (scope.Failed()) { - return MaybeLocal<Value>(); - } - - return ret; -} - - -// Public MakeCallback()s - - -MaybeLocal<Value> MakeCallback(Isolate* isolate, - Local<Object> recv, - const char* method, - int argc, - Local<Value> argv[], - async_context asyncContext) { - Local<String> method_string = - String::NewFromUtf8(isolate, method, NewStringType::kNormal) - .ToLocalChecked(); - return MakeCallback(isolate, recv, method_string, argc, argv, asyncContext); -} - - -MaybeLocal<Value> MakeCallback(Isolate* isolate, - Local<Object> recv, - Local<String> symbol, - int argc, - Local<Value> argv[], - async_context asyncContext) { - Local<Value> callback_v = recv->Get(isolate->GetCurrentContext(), - symbol).ToLocalChecked(); - if (callback_v.IsEmpty()) return Local<Value>(); - if (!callback_v->IsFunction()) return Local<Value>(); - Local<Function> callback = callback_v.As<Function>(); - return MakeCallback(isolate, recv, callback, argc, argv, asyncContext); -} - - -MaybeLocal<Value> MakeCallback(Isolate* isolate, - Local<Object> recv, - Local<Function> callback, - int argc, - Local<Value> argv[], - async_context asyncContext) { - // Observe the following two subtleties: - // - // 1. The environment is retrieved from the callback function's context. - // 2. The context to enter is retrieved from the environment. - // - // Because of the AssignToContext() call in src/node_contextify.cc, - // the two contexts need not be the same. - Environment* env = Environment::GetCurrent(callback->CreationContext()); - CHECK_NOT_NULL(env); - Context::Scope context_scope(env->context()); - MaybeLocal<Value> ret = InternalMakeCallback(env, recv, callback, - argc, argv, asyncContext); - if (ret.IsEmpty() && env->makecallback_depth() == 0) { - // This is only for legacy compatiblity and we may want to look into - // removing/adjusting it. - return Undefined(env->isolate()); - } - return ret; -} - - -// Legacy MakeCallback()s - -Local<Value> MakeCallback(Isolate* isolate, - Local<Object> recv, - const char* method, - int argc, - Local<Value>* argv) { - EscapableHandleScope handle_scope(isolate); - return handle_scope.Escape( - MakeCallback(isolate, recv, method, argc, argv, {0, 0}) - .FromMaybe(Local<Value>())); -} - - -Local<Value> MakeCallback(Isolate* isolate, - Local<Object> recv, - Local<String> symbol, - int argc, - Local<Value>* argv) { - EscapableHandleScope handle_scope(isolate); - return handle_scope.Escape( - MakeCallback(isolate, recv, symbol, argc, argv, {0, 0}) - .FromMaybe(Local<Value>())); -} - - -Local<Value> MakeCallback(Isolate* isolate, - Local<Object> recv, - Local<Function> callback, - int argc, - Local<Value>* argv) { - EscapableHandleScope handle_scope(isolate); - return handle_scope.Escape( - MakeCallback(isolate, recv, callback, argc, argv, {0, 0}) - .FromMaybe(Local<Value>())); -} - static void WaitForInspectorDisconnect(Environment* env) { #if HAVE_INSPECTOR if (env->inspector_agent()->IsActive()) { |