inspector: fix crash when the IsolateData has no platform

An embedder that creates its IsolateData without a MultiIsolatePlatform
(allowed; node.h says only Workers need one) and keeps the inspector
segfaulted on the first `console.log()`, `console.time()` or profiler
use after a `node:inspector` session was connected: V8 calls the
inspector client's `currentTimeMS()` there, and
`NodeInspectorClient::currentTimeMS()` dereferenced
`isolate_data()->platform()` unconditionally.

Fall back to the wall clock when there is no platform, which is what
`NodePlatform::CurrentClockTimeMillis()` returns anyway.

Refs: https://github.com/nodejs/node/pull/21917
Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/65818
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
This commit is contained in:
Shelley Vohr authored and Antoine du Hamel committed 2026-09-16 21:12:04 +02:00
1 parent f24a495b36
commit 9fd3e6caa4
2 files changed
+31 -1

No files matched your search

+3 -1
View File
@@ -808,7 +808,9 @@ class NodeInspectorClient : public V8InspectorClient {
}
double currentTimeMS() override {
return env_->isolate_data()->platform()->CurrentClockTimeMillis();
MultiIsolatePlatform* platform = env_->isolate_data()->platform();
if (platform == nullptr) return GetCurrentTimeInMicroseconds() / 1000;
return platform->CurrentClockTimeMillis();
}
std::unique_ptr<StringBuffer> resourceNameToUrl(
+28
View File
@@ -698,6 +698,34 @@ TEST_F(EnvironmentTest, InspectorMultipleEmbeddedEnvironments) {
CHECK_EQ(data.extracted_value, 42);
CHECK_EQ(from_inspector->IntegerValue(context).FromJust(), 42);
}
TEST_F(EnvironmentTest, InspectorWithoutPlatform) {
const v8::HandleScope handle_scope(isolate_);
const Argv argv;
node::IsolateData* isolate_data = node::CreateIsolateData(
isolate_, &NodeTestFixture::current_loop, nullptr);
v8::Local<v8::Context> context = node::NewContext(isolate_);
v8::Context::Scope context_scope(context);
std::vector<std::string> args(*argv, *argv + 1);
node::Environment* env =
node::CreateEnvironment(isolate_data, context, args, args);
CHECK_NOT_NULL(env);
v8::Local<v8::Value> result =
node::LoadEnvironment(env,
"const { Session } = require('inspector');\n"
"const session = new Session();\n"
"session.connect();\n"
"console.time('t'); console.timeEnd('t');\n"
"session.disconnect();\n"
"return 42;")
.ToLocalChecked();
EXPECT_EQ(result->Int32Value(context).FromJust(), 42);
node::FreeEnvironment(env);
node::FreeIsolateData(isolate_data);
}
#endif // HAVE_INSPECTOR
TEST_F(EnvironmentTest, ExitHandlerTest) {