mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
src: disallow JS execution inside FreeEnvironment
This addresses a TODO comment, and aligns the behavior between worker threads and the main thread. The primary motivation for this change is to more strictly enforce the invariant that no JS runs after the `'exit'` event is emitted. PR-URL: https://github.com/nodejs/node/pull/33874 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Shelley Vohr <codebytere@gmail.com>
This commit is contained in:
1 parent
409fdba6d5
commit
0fb91acedf
3 files changed
+21
-6
No files matched your search
@@ -27,6 +27,7 @@ using v8::Object;
|
||||
using v8::ObjectTemplate;
|
||||
using v8::Private;
|
||||
using v8::PropertyDescriptor;
|
||||
using v8::SealHandleScope;
|
||||
using v8::String;
|
||||
using v8::Value;
|
||||
|
||||
@@ -378,10 +379,13 @@ Environment* CreateEnvironment(
|
||||
}
|
||||
|
||||
void FreeEnvironment(Environment* env) {
|
||||
Isolate::DisallowJavascriptExecutionScope disallow_js(env->isolate(),
|
||||
Isolate::DisallowJavascriptExecutionScope::THROW_ON_FAILURE);
|
||||
{
|
||||
// TODO(addaleax): This should maybe rather be in a SealHandleScope.
|
||||
HandleScope handle_scope(env->isolate());
|
||||
HandleScope handle_scope(env->isolate()); // For env->context().
|
||||
Context::Scope context_scope(env->context());
|
||||
SealHandleScope seal_handle_scope(env->isolate());
|
||||
|
||||
env->set_stopping(true);
|
||||
env->stop_sub_worker_contexts();
|
||||
env->RunCleanup();
|
||||
|
||||
@@ -274,10 +274,6 @@ void Worker::Run() {
|
||||
this->env_ = nullptr;
|
||||
}
|
||||
|
||||
// TODO(addaleax): Try moving DisallowJavascriptExecutionScope into
|
||||
// FreeEnvironment().
|
||||
Isolate::DisallowJavascriptExecutionScope disallow_js(isolate_,
|
||||
Isolate::DisallowJavascriptExecutionScope::THROW_ON_FAILURE);
|
||||
env_.reset();
|
||||
});
|
||||
|
||||
|
||||
@@ -6,10 +6,13 @@
|
||||
#include <uv.h>
|
||||
|
||||
using v8::Context;
|
||||
using v8::Function;
|
||||
using v8::HandleScope;
|
||||
using v8::Isolate;
|
||||
using v8::Local;
|
||||
using v8::MaybeLocal;
|
||||
using v8::Object;
|
||||
using v8::String;
|
||||
using v8::Value;
|
||||
|
||||
size_t count = 0;
|
||||
@@ -31,6 +34,18 @@ void Dummy(void*) {
|
||||
|
||||
void Cleanup(void* str) {
|
||||
printf("%s ", static_cast<const char*>(str));
|
||||
|
||||
// Check that calling into JS fails.
|
||||
Isolate* isolate = Isolate::GetCurrent();
|
||||
HandleScope handle_scope(isolate);
|
||||
assert(isolate->InContext());
|
||||
Local<Context> context = isolate->GetCurrentContext();
|
||||
MaybeLocal<Value> call_result =
|
||||
context->Global()->Get(
|
||||
context, String::NewFromUtf8Literal(isolate, "Object"))
|
||||
.ToLocalChecked().As<Function>()->Call(
|
||||
context, v8::Null(isolate), 0, nullptr);
|
||||
assert(call_result.IsEmpty());
|
||||
}
|
||||
|
||||
void Initialize(Local<Object> exports,
|
||||
|
||||
Reference in new issue
Block a user