Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Don't NULL-check GlobalHandle::Node::object_
Browse files Browse the repository at this point in the history
If it's Smi::FromInt(0), the NULL check would trigger. Instead, use the
handle-zap value to mean "not set".

BUG=v8:3647,chromium:580651
[email protected]
LOG=y

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

Cr-Commit-Position: refs/heads/master@{#33492}
  • Loading branch information
jeisinger authored and Commit bot committed Jan 25, 2016
1 parent 5259af6 commit 85f32f1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/global-handles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class GlobalHandles::Node {
#endif

void Initialize(int index, Node** first_free) {
object_ = reinterpret_cast<Object*>(kGlobalHandleZapValue);
index_ = static_cast<uint8_t>(index);
DCHECK(static_cast<int>(index_) == index);
set_state(FREE);
Expand Down Expand Up @@ -250,9 +251,9 @@ class GlobalHandles::Node {
}

void MakeWeak(void* parameter, WeakCallback weak_callback) {
DCHECK(weak_callback != NULL);
DCHECK(weak_callback != nullptr);
DCHECK(IsInUse());
CHECK(object_ != NULL);
CHECK_NE(object_, reinterpret_cast<Object*>(kGlobalHandleZapValue));
set_state(WEAK);
set_weakness_type(NORMAL_WEAK);
set_parameter(parameter);
Expand All @@ -264,7 +265,7 @@ class GlobalHandles::Node {
v8::WeakCallbackType type) {
DCHECK(phantom_callback != nullptr);
DCHECK(IsInUse());
CHECK(object_ != nullptr);
CHECK_NE(object_, reinterpret_cast<Object*>(kGlobalHandleZapValue));
set_state(WEAK);
switch (type) {
case v8::WeakCallbackType::kParameter:
Expand Down
16 changes: 16 additions & 0 deletions test/cctest/test-global-handles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,19 @@ TEST(PersistentBaseGetLocal) {
CHECK(o == g.Get(isolate));
CHECK(v8::Local<v8::Object>::New(isolate, g) == g.Get(isolate));
}


void WeakCallback(const v8::WeakCallbackInfo<void>& data) {}


TEST(WeakPersistentSmi) {
CcTest::InitializeVM();
v8::Isolate* isolate = CcTest::isolate();

v8::HandleScope scope(isolate);
v8::Local<v8::Number> n = v8::Number::New(isolate, 0);
v8::Global<v8::Number> g(isolate, n);

// Should not crash.
g.SetWeak<void>(nullptr, &WeakCallback, v8::WeakCallbackType::kParameter);
}

0 comments on commit 85f32f1

Please sign in to comment.