Skip to content

Commit

Permalink
Add setter to Isolate for allowing Atomics.wait
Browse files Browse the repository at this point in the history
This makes it easier to set the value for embedders where it is
difficult to plumb through to the Isolate constructor.

BUG=chromium:711809
[email protected]

Review-Url: https://codereview.chromium.org/2829223002
Cr-Commit-Position: refs/heads/master@{#44813}
  • Loading branch information
binji authored and Commit bot committed Apr 24, 2017
1 parent a71c338 commit 3cc8845
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
9 changes: 8 additions & 1 deletion include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -6619,7 +6619,7 @@ class V8_EXPORT Isolate {

/**
* Whether calling Atomics.wait (a function that may block) is allowed in
* this isolate.
* this isolate. This can also be configured via SetAllowAtomicsWait.
*/
bool allow_atomics_wait;

Expand Down Expand Up @@ -7479,6 +7479,13 @@ class V8_EXPORT Isolate {
*/
bool IsInUse();

/**
* Set whether calling Atomics.wait (a function that may block) is allowed in
* this isolate. This can also be configured via
* CreateParams::allow_atomics_wait.
*/
void SetAllowAtomicsWait(bool allow);

Isolate() = delete;
~Isolate() = delete;
Isolate(const Isolate&) = delete;
Expand Down
4 changes: 4 additions & 0 deletions src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8942,6 +8942,10 @@ void Isolate::VisitWeakHandles(PersistentHandleVisitor* visitor) {
isolate->global_handles()->IterateWeakRootsInNewSpaceWithClassIds(visitor);
}

void Isolate::SetAllowAtomicsWait(bool allow) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
isolate->set_allow_atomics_wait(allow);
}

MicrotasksScope::MicrotasksScope(Isolate* isolate, MicrotasksScope::Type type)
: isolate_(reinterpret_cast<i::Isolate*>(isolate)),
Expand Down
15 changes: 15 additions & 0 deletions test/cctest/test-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26557,3 +26557,18 @@ TEST(DeterministicRandomNumberGeneration) {

v8::internal::FLAG_random_seed = previous_seed;
}

UNINITIALIZED_TEST(AllowAtomicsWait) {
using namespace i;
v8::Isolate::CreateParams create_params;
create_params.allow_atomics_wait = false;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate);
{
CHECK_EQ(false, i_isolate->allow_atomics_wait());
isolate->SetAllowAtomicsWait(true);
CHECK_EQ(true, i_isolate->allow_atomics_wait());
}
isolate->Dispose();
}

0 comments on commit 3cc8845

Please sign in to comment.