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

Commit

Permalink
chakrashim: fix Object::SetInternalField …
Browse files Browse the repository at this point in the history
When use SetInternalField with Interger will assert:

// assert this
object->SetInternalField(0, v8::Integer::New(env->isolate(), 6));
object->GetInternalField(0)->IsInt32();

Becasue ObjectData::FieldValue will change ref pointer with a mask , and then will not revert to a normal int value.

Soloution:
Add a bool flag to ObjectData::FieldValue to demined a FieldValue is JsValueRef or not.
  • Loading branch information
mybios authored and Jianchun Xu committed Sep 14, 2015
1 parent f017c07 commit 189df5f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 2 additions & 3 deletions deps/chakrashim/src/v8chakra.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct ObjectData {
public:
struct FieldValue {
public:
FieldValue() : value(nullptr) {}
FieldValue() : value(nullptr), isRefValue(false){}
~FieldValue() { Reset(); }

void SetRef(JsValueRef ref);
Expand All @@ -46,10 +46,9 @@ struct ObjectData {
void* GetPointer() const;

private:
static const UINT_PTR kValueRefTag = 1;
static const UINT_PTR kValueRefMask = ~kValueRefTag;
void Reset();

bool isRefValue;
void* value;
};

Expand Down
9 changes: 6 additions & 3 deletions deps/chakrashim/src/v8objecttemplate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,25 @@ void ObjectData::FieldValue::SetRef(JsValueRef ref) {
}

value = reinterpret_cast<void*>(
reinterpret_cast<UINT_PTR>(ref) | kValueRefTag);
reinterpret_cast<UINT_PTR>(ref));
isRefValue = true;
CHAKRA_ASSERT(GetRef() == ref);
}

JsValueRef ObjectData::FieldValue::GetRef() const {
CHAKRA_ASSERT(IsRef() || !value);
return reinterpret_cast<JsValueRef>(
reinterpret_cast<UINT_PTR>(value) & kValueRefMask);
reinterpret_cast<UINT_PTR>(value));
}

bool ObjectData::FieldValue::IsRef() const {
return (reinterpret_cast<UINT_PTR>(value) & kValueRefTag) != 0;
return isRefValue;
}

void ObjectData::FieldValue::SetPointer(void* ptr) {
Reset();
value = ptr;
isRefValue = false;
CHAKRA_ASSERT(GetPointer() == ptr);
}

Expand All @@ -120,6 +122,7 @@ void ObjectData::FieldValue::Reset() {
if (IsRef()) {
JsRelease(GetRef(), nullptr);
}
isRefValue = false;
value = nullptr;
}

Expand Down

0 comments on commit 189df5f

Please sign in to comment.