Skip to content

Commit 170e196

Browse files
addaleaxBridgeAR
authored andcommitted
src: forbid handle allocations from Platform tasks
Platform tasks should have their own handle scopes, rather than leak into outer ones. PR-URL: #26376 Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 9c277c0 commit 170e196

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Diff for: src/inspector/main_thread_interface.cc

+8
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,14 @@ void MainThreadInterface::DispatchMessages() {
268268
MessageQueue::value_type task;
269269
std::swap(dispatching_message_queue_.front(), task);
270270
dispatching_message_queue_.pop_front();
271+
272+
// TODO(addaleax): The V8 inspector code currently sometimes allocates
273+
// handles that leak to the outside scope, rendering a HandleScope here
274+
// necessary. This handle scope can be removed/turned into a
275+
// SealHandleScope once/if
276+
// https://chromium-review.googlesource.com/c/v8/v8/+/1484304 makes it
277+
// into our copy of V8, maybe guarded with #ifdef DEBUG if we want.
278+
v8::HandleScope handle_scope(isolate_);
271279
task->Call(this);
272280
}
273281
} while (had_messages);

Diff for: src/node_platform.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
namespace node {
1010

11-
using v8::HandleScope;
1211
using v8::Isolate;
1312
using v8::Local;
1413
using v8::Object;
1514
using v8::Platform;
15+
using v8::SealHandleScope;
1616
using v8::Task;
1717
using node::tracing::TracingController;
1818

@@ -332,7 +332,9 @@ int NodePlatform::NumberOfWorkerThreads() {
332332

333333
void PerIsolatePlatformData::RunForegroundTask(std::unique_ptr<Task> task) {
334334
Isolate* isolate = Isolate::GetCurrent();
335-
HandleScope scope(isolate);
335+
#ifdef DEBUG
336+
SealHandleScope scope(isolate);
337+
#endif
336338
Environment* env = Environment::GetCurrent(isolate);
337339
if (env != nullptr) {
338340
InternalCallbackScope cb_scope(env, Local<Object>(), { 0, 0 },

0 commit comments

Comments
 (0)