Skip to content

Commit

Permalink
src: simplify InspectorConsoleCall
Browse files Browse the repository at this point in the history
Instead of a JS object, set the is-in-console-call flag as
a boolean in C++.

PR-URL: #26168
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
  • Loading branch information
addaleax authored and rvagg committed Feb 28, 2019
1 parent c6d5af5 commit 8881c0b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
4 changes: 1 addition & 3 deletions lib/internal/util/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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];
Expand Down
10 changes: 10 additions & 0 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,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_;
}
Expand Down
4 changes: 4 additions & 0 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,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<HandleWrap, &HandleWrap::handle_wrap_queue_> HandleWrapQueue;
Expand Down Expand Up @@ -1043,6 +1046,7 @@ class Environment {

#if HAVE_INSPECTOR
std::unique_ptr<inspector::Agent> 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
Expand Down
25 changes: 8 additions & 17 deletions src/inspector_js_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,31 +149,22 @@ void InspectorConsoleCall(const FunctionCallbackInfo<Value>& info) {
Environment* env = Environment::GetCurrent(info);
Isolate* isolate = env->isolate();
Local<Context> 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<Value> inspector_method = info[0];
CHECK(inspector_method->IsFunction());
Local<Value> config_value = info[2];
CHECK(config_value->IsObject());
Local<Object> config_object = config_value.As<Object>();
Local<String> 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<Value> ret =
inspector_method.As<Function>()->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<Value> node_method = info[1];
Expand Down

0 comments on commit 8881c0b

Please sign in to comment.