Merge pull request #8 from electron/set-read-only

Support setting read-only property value
This commit is contained in:
Cheng Zhao 2017-01-16 06:53:42 +09:00 committed by GitHub
commit 400d6c3de5

View file

@ -93,6 +93,19 @@ class Dictionary {
return !result.IsNothing() && result.FromJust();
}
template<typename T>
bool SetReadOnly(const base::StringPiece& key, T val) {
v8::Local<v8::Value> v8_value;
if (!TryConvertToV8(isolate_, val, &v8_value))
return false;
v8::Maybe<bool> result =
GetHandle()->DefineOwnProperty(isolate_->GetCurrentContext(),
StringToV8(isolate_, key),
v8_value,
v8::ReadOnly);
return !result.IsNothing() && result.FromJust();
}
template<typename T>
bool SetMethod(const base::StringPiece& key, const T& callback) {
return GetHandle()->Set(