From b7106e16881cd2b72a486a469180535f73546ec2 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 17 Feb 2019 18:05:55 +0100 Subject: [PATCH] src: simplify InspectorConsoleCall Instead of a JS object, set the is-in-console-call flag as a boolean in C++. --- lib/internal/util/inspector.js | 4 +--- src/env-inl.h | 10 ++++++++++ src/env.h | 4 ++++ src/inspector_js_api.cc | 25 ++++++++----------------- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/lib/internal/util/inspector.js b/lib/internal/util/inspector.js index e237db16a64800..579f93d540faa3 100644 --- a/lib/internal/util/inspector.js +++ b/lib/internal/util/inspector.js @@ -33,7 +33,6 @@ function installConsoleExtensions(commandLineApi) { // Wrap a console implemented by Node.js with features from the VM inspector function wrapConsole(consoleFromNode, consoleFromVM) { - const config = {}; const { consoleCall } = internalBinding('inspector'); for (const key of Object.keys(consoleFromVM)) { // If global console has the same method as inspector console, @@ -42,8 +41,7 @@ function wrapConsole(consoleFromNode, consoleFromVM) { if (consoleFromNode.hasOwnProperty(key)) { consoleFromNode[key] = consoleCall.bind(consoleFromNode, consoleFromVM[key], - consoleFromNode[key], - config); + consoleFromNode[key]); } else { // Add additional console APIs from the inspector consoleFromNode[key] = consoleFromVM[key]; diff --git a/src/env-inl.h b/src/env-inl.h index 60dafc04e16516..32120f24d23256 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -402,6 +402,16 @@ inline void Environment::TryLoadAddon( } } +#if HAVE_INSPECTOR +inline bool Environment::is_in_inspector_console_call() const { + return is_in_inspector_console_call_; +} + +inline void Environment::set_is_in_inspector_console_call(bool value) { + is_in_inspector_console_call_ = value; +} +#endif + inline Environment::AsyncHooks* Environment::async_hooks() { return &async_hooks_; } diff --git a/src/env.h b/src/env.h index 5cf2ee2c8b493e..146daa7a51e6d2 100644 --- a/src/env.h +++ b/src/env.h @@ -857,6 +857,9 @@ class Environment { inline inspector::Agent* inspector_agent() const { return inspector_agent_.get(); } + + inline bool is_in_inspector_console_call() const; + inline void set_is_in_inspector_console_call(bool value); #endif typedef ListHead HandleWrapQueue; @@ -1026,6 +1029,7 @@ class Environment { #if HAVE_INSPECTOR std::unique_ptr inspector_agent_; + bool is_in_inspector_console_call_ = false; #endif // handle_wrap_queue_ and req_wrap_queue_ needs to be at a fixed offset from diff --git a/src/inspector_js_api.cc b/src/inspector_js_api.cc index e94f42c18eb827..c2e80d93fd944a 100644 --- a/src/inspector_js_api.cc +++ b/src/inspector_js_api.cc @@ -149,31 +149,22 @@ void InspectorConsoleCall(const FunctionCallbackInfo& info) { Environment* env = Environment::GetCurrent(info); Isolate* isolate = env->isolate(); Local context = isolate->GetCurrentContext(); - CHECK_LT(2, info.Length()); - SlicedArguments call_args(info, /* start */ 3); + CHECK_GE(info.Length(), 2); + SlicedArguments call_args(info, /* start */ 2); if (InspectorEnabled(env)) { Local inspector_method = info[0]; CHECK(inspector_method->IsFunction()); - Local config_value = info[2]; - CHECK(config_value->IsObject()); - Local config_object = config_value.As(); - Local in_call_key = FIXED_ONE_BYTE_STRING(isolate, "in_call"); - bool has_in_call; - if (!config_object->Has(context, in_call_key).To(&has_in_call)) - return; - if (!has_in_call) { - if (config_object->Set(context, - in_call_key, - v8::True(isolate)).IsNothing() || + if (!env->is_in_inspector_console_call()) { + env->set_is_in_inspector_console_call(true); + MaybeLocal ret = inspector_method.As()->Call(context, info.Holder(), call_args.length(), - call_args.out()).IsEmpty()) { + call_args.out()); + env->set_is_in_inspector_console_call(false); + if (ret.IsEmpty()) return; - } } - if (config_object->Delete(context, in_call_key).IsNothing()) - return; } Local node_method = info[1];