Merge pull request #4 from deepak1556/dictionary_patch

use v8::private symbols as identifiers for object properties
This commit is contained in:
Cheng Zhao 2016-03-31 10:18:26 +09:00
commit 553326b006

View file

@ -56,9 +56,16 @@ class Dictionary {
template<typename T>
bool GetHidden(const base::StringPiece& key, T* out) const {
v8::Local<v8::Value> val =
GetHandle()->GetHiddenValue(StringToV8(isolate_, key));
return ConvertFromV8(isolate_, val, out);
v8::Local<v8::Context> context = isolate_->GetCurrentContext();
v8::Local<v8::Private> privateKey =
v8::Private::ForApi(isolate_, StringToV8(isolate_, key));
v8::Local<v8::Value> value;
v8::Maybe<bool> result =
GetHandle()->HasPrivate(context, privateKey);
if (internal::IsTrue(result) &&
GetHandle()->GetPrivate(context, privateKey).ToLocal(&value))
return ConvertFromV8(isolate_, value, out);
return false;
}
template<typename T>
@ -78,7 +85,12 @@ class Dictionary {
v8::Local<v8::Value> v8_value;
if (!TryConvertToV8(isolate_, val, &v8_value))
return false;
return GetHandle()->SetHiddenValue(StringToV8(isolate_, key), v8_value);
v8::Local<v8::Context> context = isolate_->GetCurrentContext();
v8::Local<v8::Private> privateKey =
v8::Private::ForApi(isolate_, StringToV8(isolate_, key));
v8::Maybe<bool> result =
GetHandle()->SetPrivate(context, privateKey, v8_value);
return !result.IsNothing() && result.FromJust();
}
template<typename T>