Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: backport 1f8555 from v8's upstream #1395

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions deps/v8/include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,24 @@ class ScriptOrigin {
Handle<Integer> script_id_;
};

class V8_EXPORT SealHandleScope {
public:
SealHandleScope(Isolate* isolate);
~SealHandleScope();

private:
// Make it hard to create heap-allocated or illegal handle scopes by
// disallowing certain operations.
SealHandleScope(const SealHandleScope&);
void operator=(const SealHandleScope&);
void* operator new(size_t size);
void operator delete(void*, size_t);

internal::Isolate* isolate_;
int prev_level_;
internal::Object** prev_limit_;
};


/**
* A compiled JavaScript script, not yet tied to a Context.
Expand Down
21 changes: 21 additions & 0 deletions deps/v8/src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,27 @@ i::Object** EscapableHandleScope::Escape(i::Object** escape_value) {
}


SealHandleScope::SealHandleScope(Isolate* isolate) {
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);

isolate_ = internal_isolate;
i::HandleScopeData* current = internal_isolate->handle_scope_data();
prev_limit_ = current->limit;
current->limit = current->next;
prev_level_ = current->level;
current->level = 0;
}


SealHandleScope::~SealHandleScope() {
i::HandleScopeData* current = isolate_->handle_scope_data();
DCHECK_EQ(0, current->level);
current->level = prev_level_;
DCHECK_EQ(current->next, current->limit);
current->limit = prev_limit_;
}


void Context::Enter() {
i::Handle<i::Context> env = Utils::OpenHandle(this);
i::Isolate* isolate = env->GetIsolate();
Expand Down
5 changes: 1 addition & 4 deletions deps/v8/src/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -650,17 +650,14 @@ void HandleScopeImplementer::DeleteExtensions(internal::Object** prev_limit) {
while (!blocks_.is_empty()) {
internal::Object** block_start = blocks_.last();
internal::Object** block_limit = block_start + kHandleBlockSize;
#ifdef DEBUG

// SealHandleScope may make the prev_limit to point inside the block.
if (block_start <= prev_limit && prev_limit <= block_limit) {
#ifdef ENABLE_HANDLE_ZAPPING
internal::HandleScope::ZapRange(prev_limit, block_limit);
#endif
break;
}
#else
if (prev_limit == block_limit) break;
#endif

blocks_.RemoveLast();
#ifdef ENABLE_HANDLE_ZAPPING
Expand Down
1 change: 1 addition & 0 deletions deps/v8/test/cctest/cctest.status
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
# they don't fail then test.py has failed.
'test-serialize/TestThatAlwaysFails': [FAIL],
'test-serialize/DependentTestThatAlwaysFails': [FAIL],
'test-api/SealHandleScope': [FAIL],

# This test always fails. It tests that LiveEdit causes abort when turned off.
'test-debug/LiveEditDisabled': [FAIL],
Expand Down
32 changes: 32 additions & 0 deletions deps/v8/test/cctest/test-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21895,6 +21895,38 @@ void CallCompletedCallbackException() {
}


TEST(SealHandleScope) {
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handle_scope(isolate);
LocalContext env;

v8::SealHandleScope seal(isolate);

// Should fail
v8::Local<v8::Object> obj = v8::Object::New(isolate);

USE(obj);
}


TEST(SealHandleScopeNested) {
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handle_scope(isolate);
LocalContext env;

v8::SealHandleScope seal(isolate);

{
v8::HandleScope handle_scope(isolate);

// Should work
v8::Local<v8::Object> obj = v8::Object::New(isolate);

USE(obj);
}
}


TEST(CallCompletedCallbackOneException) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
Expand Down
32 changes: 18 additions & 14 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ using v8::ObjectTemplate;
using v8::Promise;
using v8::PromiseRejectMessage;
using v8::PropertyCallbackInfo;
using v8::SealHandleScope;
using v8::String;
using v8::TryCatch;
using v8::Uint32;
Expand Down Expand Up @@ -3822,22 +3823,25 @@ static void StartNodeInstance(void* arg) {
if (instance_data->use_debug_agent())
EnableDebug(env);

bool more;
do {
v8::platform::PumpMessageLoop(default_platform, isolate);
more = uv_run(env->event_loop(), UV_RUN_ONCE);

if (more == false) {
{
SealHandleScope seal(isolate);
bool more;
do {
v8::platform::PumpMessageLoop(default_platform, isolate);
EmitBeforeExit(env);
more = uv_run(env->event_loop(), UV_RUN_ONCE);

// Emit `beforeExit` if the loop became alive either after emitting
// event, or after running some callbacks.
more = uv_loop_alive(env->event_loop());
if (uv_run(env->event_loop(), UV_RUN_NOWAIT) != 0)
more = true;
}
} while (more == true);
if (more == false) {
v8::platform::PumpMessageLoop(default_platform, isolate);
EmitBeforeExit(env);

// Emit `beforeExit` if the loop became alive either after emitting
// event, or after running some callbacks.
more = uv_loop_alive(env->event_loop());
if (uv_run(env->event_loop(), UV_RUN_NOWAIT) != 0)
more = true;
}
} while (more == true);
}

int exit_code = EmitExit(env);
if (instance_data->is_main())
Expand Down