Skip to content

Commit 400d6c3

Browse files
authored
Merge pull request adamlaska#8 from electron/set-read-only
Support setting read-only property value
2 parents 6b7e73d + c78a6fa commit 400d6c3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

native_mate/dictionary.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,19 @@ class Dictionary {
9393
return !result.IsNothing() && result.FromJust();
9494
}
9595

96+
template<typename T>
97+
bool SetReadOnly(const base::StringPiece& key, T val) {
98+
v8::Local<v8::Value> v8_value;
99+
if (!TryConvertToV8(isolate_, val, &v8_value))
100+
return false;
101+
v8::Maybe<bool> result =
102+
GetHandle()->DefineOwnProperty(isolate_->GetCurrentContext(),
103+
StringToV8(isolate_, key),
104+
v8_value,
105+
v8::ReadOnly);
106+
return !result.IsNothing() && result.FromJust();
107+
}
108+
96109
template<typename T>
97110
bool SetMethod(const base::StringPiece& key, const T& callback) {
98111
return GetHandle()->Set(

0 commit comments

Comments
 (0)