Commit 32979cf6 authored by yangguo's avatar yangguo Committed by Commit bot

Use locker when creating snapshot if necessary.

R=vogelheim@chromium.org

Review URL: https://codereview.chromium.org/962963007

Cr-Commit-Position: refs/heads/master@{#26964}
parent 8d29cc11
......@@ -590,10 +590,14 @@ void HandleScope::Initialize(Isolate* isolate) {
// We do not want to check the correct usage of the Locker class all over the
// place, so we do it only here: Without a HandleScope, an embedder can do
// almost nothing, so it is enough to check in this central place.
Utils::ApiCheck(!v8::Locker::IsActive() ||
internal_isolate->thread_manager()->IsLockedByCurrentThread(),
"HandleScope::HandleScope",
"Entering the V8 API without proper locking in place");
// We make an exception if the serializer is enabled, which means that the
// Isolate is exclusively used to create a snapshot.
Utils::ApiCheck(
!v8::Locker::IsActive() ||
internal_isolate->thread_manager()->IsLockedByCurrentThread() ||
internal_isolate->serializer_enabled(),
"HandleScope::HandleScope",
"Entering the V8 API without proper locking in place");
i::HandleScopeData* current = internal_isolate->handle_scope_data();
isolate_ = internal_isolate;
prev_next_ = current->next;
......
......@@ -748,6 +748,42 @@ TEST(PerIsolateSnapshotBlobs) {
}
TEST(PerIsolateSnapshotBlobsWithLocker) {
// Disable experimental natives that are loaded after deserialization.
FLAG_harmony_shipping = false;
FlagList::EnforceFlagImplications();
v8::Isolate* isolate0 = v8::Isolate::New();
{
v8::Locker locker(isolate0);
v8::Isolate::Scope i_scope(isolate0);
v8::HandleScope h_scope(isolate0);
v8::Local<v8::Context> context = v8::Context::New(isolate0);
v8::Context::Scope c_scope(context);
CHECK_EQ(1, CompileRun("Math.cos(0)")->ToInt32(isolate0)->Int32Value());
}
isolate0->Dispose();
const char* source1 = "function f() { return 42; }";
v8::StartupData data1 = v8::V8::CreateSnapshotDataBlob(source1);
v8::Isolate::CreateParams params1;
params1.snapshot_blob = &data1;
v8::Isolate* isolate1 = v8::Isolate::New(params1);
{
v8::Locker locker(isolate1);
v8::Isolate::Scope i_scope(isolate1);
v8::HandleScope h_scope(isolate1);
v8::Local<v8::Context> context = v8::Context::New(isolate1);
delete[] data1.data; // We can dispose of the snapshot blob now.
v8::Context::Scope c_scope(context);
CHECK_EQ(42, CompileRun("f()")->ToInt32(isolate1)->Int32Value());
}
isolate1->Dispose();
}
TEST(TestThatAlwaysSucceeds) {
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment