Skip to content

Commit 8881c0b

Browse files
addaleaxrvagg
authored andcommitted
src: simplify InspectorConsoleCall
Instead of a JS object, set the is-in-console-call flag as a boolean in C++. PR-URL: #26168 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Eugene Ostroukhov <[email protected]>
1 parent c6d5af5 commit 8881c0b

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

lib/internal/util/inspector.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ function installConsoleExtensions(commandLineApi) {
3333

3434
// Wrap a console implemented by Node.js with features from the VM inspector
3535
function wrapConsole(consoleFromNode, consoleFromVM) {
36-
const config = {};
3736
const { consoleCall } = internalBinding('inspector');
3837
for (const key of Object.keys(consoleFromVM)) {
3938
// If global console has the same method as inspector console,
@@ -42,8 +41,7 @@ function wrapConsole(consoleFromNode, consoleFromVM) {
4241
if (consoleFromNode.hasOwnProperty(key)) {
4342
consoleFromNode[key] = consoleCall.bind(consoleFromNode,
4443
consoleFromVM[key],
45-
consoleFromNode[key],
46-
config);
44+
consoleFromNode[key]);
4745
} else {
4846
// Add additional console APIs from the inspector
4947
consoleFromNode[key] = consoleFromVM[key];

src/env-inl.h

+10
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,16 @@ inline void Environment::TryLoadAddon(
404404
}
405405
}
406406

407+
#if HAVE_INSPECTOR
408+
inline bool Environment::is_in_inspector_console_call() const {
409+
return is_in_inspector_console_call_;
410+
}
411+
412+
inline void Environment::set_is_in_inspector_console_call(bool value) {
413+
is_in_inspector_console_call_ = value;
414+
}
415+
#endif
416+
407417
inline Environment::AsyncHooks* Environment::async_hooks() {
408418
return &async_hooks_;
409419
}

src/env.h

+4
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,9 @@ class Environment {
874874
inline inspector::Agent* inspector_agent() const {
875875
return inspector_agent_.get();
876876
}
877+
878+
inline bool is_in_inspector_console_call() const;
879+
inline void set_is_in_inspector_console_call(bool value);
877880
#endif
878881

879882
typedef ListHead<HandleWrap, &HandleWrap::handle_wrap_queue_> HandleWrapQueue;
@@ -1043,6 +1046,7 @@ class Environment {
10431046

10441047
#if HAVE_INSPECTOR
10451048
std::unique_ptr<inspector::Agent> inspector_agent_;
1049+
bool is_in_inspector_console_call_ = false;
10461050
#endif
10471051

10481052
// handle_wrap_queue_ and req_wrap_queue_ needs to be at a fixed offset from

src/inspector_js_api.cc

+8-17
Original file line numberDiff line numberDiff line change
@@ -149,31 +149,22 @@ void InspectorConsoleCall(const FunctionCallbackInfo<Value>& info) {
149149
Environment* env = Environment::GetCurrent(info);
150150
Isolate* isolate = env->isolate();
151151
Local<Context> context = isolate->GetCurrentContext();
152-
CHECK_LT(2, info.Length());
153-
SlicedArguments call_args(info, /* start */ 3);
152+
CHECK_GE(info.Length(), 2);
153+
SlicedArguments call_args(info, /* start */ 2);
154154
if (InspectorEnabled(env)) {
155155
Local<Value> inspector_method = info[0];
156156
CHECK(inspector_method->IsFunction());
157-
Local<Value> config_value = info[2];
158-
CHECK(config_value->IsObject());
159-
Local<Object> config_object = config_value.As<Object>();
160-
Local<String> in_call_key = FIXED_ONE_BYTE_STRING(isolate, "in_call");
161-
bool has_in_call;
162-
if (!config_object->Has(context, in_call_key).To(&has_in_call))
163-
return;
164-
if (!has_in_call) {
165-
if (config_object->Set(context,
166-
in_call_key,
167-
v8::True(isolate)).IsNothing() ||
157+
if (!env->is_in_inspector_console_call()) {
158+
env->set_is_in_inspector_console_call(true);
159+
MaybeLocal<Value> ret =
168160
inspector_method.As<Function>()->Call(context,
169161
info.Holder(),
170162
call_args.length(),
171-
call_args.out()).IsEmpty()) {
163+
call_args.out());
164+
env->set_is_in_inspector_console_call(false);
165+
if (ret.IsEmpty())
172166
return;
173-
}
174167
}
175-
if (config_object->Delete(context, in_call_key).IsNothing())
176-
return;
177168
}
178169

179170
Local<Value> node_method = info[1];

0 commit comments

Comments
 (0)