Skip to content

Commit 8d1d7b6

Browse files
authored
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: #21917 Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com> PR-URL: #65818 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent b4c83f5 commit 8d1d7b6

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎src/inspector_agent.cc‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,9 @@ class NodeInspectorClient : public V8InspectorClient {
864864
}
865865

866866
double currentTimeMS() override {
867-
return env_->isolate_data()->platform()->CurrentClockTimeMillis();
867+
MultiIsolatePlatform* platform = env_->isolate_data()->platform();
868+
if (platform == nullptr) return GetCurrentTimeInMicroseconds() / 1000;
869+
return platform->CurrentClockTimeMillis();
868870
}
869871

870872
std::unique_ptr<StringBuffer> resourceNameToUrl(

‎test/cctest/test_environment.cc‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,34 @@ TEST_F(EnvironmentTest, InspectorMultipleEmbeddedEnvironments) {
702702
CHECK_EQ(data.extracted_value, 42);
703703
CHECK_EQ(from_inspector->IntegerValue(context).FromJust(), 42);
704704
}
705+
706+
TEST_F(EnvironmentTest, InspectorWithoutPlatform) {
707+
const v8::HandleScope handle_scope(isolate_);
708+
const Argv argv;
709+
node::IsolateData* isolate_data = node::CreateIsolateData(
710+
isolate_, &NodeTestFixture::current_loop, nullptr);
711+
v8::Local<v8::Context> context = node::NewContext(isolate_);
712+
v8::Context::Scope context_scope(context);
713+
std::vector<std::string> args(*argv, *argv + 1);
714+
node::Environment* env =
715+
node::CreateEnvironment(isolate_data, context, args, args);
716+
CHECK_NOT_NULL(env);
717+
718+
v8::Local<v8::Value> result =
719+
node::LoadEnvironment(env,
720+
"const { Session } = require('inspector');\n"
721+
"const session = new Session();\n"
722+
"session.connect();\n"
723+
"console.time('t'); console.timeEnd('t');\n"
724+
"session.disconnect();\n"
725+
"return 42;")
726+
.ToLocalChecked();
727+
EXPECT_EQ(result->Int32Value(context).FromJust(), 42);
728+
729+
node::FreeEnvironment(env);
730+
node::FreeIsolateData(isolate_data);
731+
}
732+
705733
#endif // HAVE_INSPECTOR
706734

707735
TEST_F(EnvironmentTest, ExitHandlerTest) {

0 commit comments

Comments
 (0)