From c78a6fa7d4d3e828290e5c95dd0573b843158a13 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 11 Jan 2017 17:49:41 -0800 Subject: [PATCH] Support setting read-only property value --- native_mate/dictionary.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/native_mate/dictionary.h b/native_mate/dictionary.h index 38927c85374f..2eb52922d268 100644 --- a/native_mate/dictionary.h +++ b/native_mate/dictionary.h @@ -93,6 +93,19 @@ class Dictionary { return !result.IsNothing() && result.FromJust(); } + template + bool SetReadOnly(const base::StringPiece& key, T val) { + v8::Local v8_value; + if (!TryConvertToV8(isolate_, val, &v8_value)) + return false; + v8::Maybe result = + GetHandle()->DefineOwnProperty(isolate_->GetCurrentContext(), + StringToV8(isolate_, key), + v8_value, + v8::ReadOnly); + return !result.IsNothing() && result.FromJust(); + } + template bool SetMethod(const base::StringPiece& key, const T& callback) { return GetHandle()->Set(