Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Unified Diff: extensions/renderer/v8_helpers.h

Issue 1748943002: [Extensions] Harden against bindings interception (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/renderer/module_system.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/v8_helpers.h
diff --git a/extensions/renderer/v8_helpers.h b/extensions/renderer/v8_helpers.h
index 2a6fa9c06de7de37cfe49c9f132ccd6656bc4f68..3017772081c73aa1bce6b5d5d315ae77fad6a040 100644
--- a/extensions/renderer/v8_helpers.h
+++ b/extensions/renderer/v8_helpers.h
@@ -60,6 +60,9 @@ inline bool IsEmptyOrUndefied(v8::Local<v8::Value> value) {
// SetProperty() family wraps V8::Object::DefineOwnProperty().
// Returns true on success.
+// NOTE: Think about whether you want this or SetPrivateProperty() below.
+// TODO(devlin): Sort through more of the callers of this and see if we can
+// convert more to be private.
inline bool SetProperty(v8::Local<v8::Context> context,
v8::Local<v8::Object> object,
v8::Local<v8::String> key,
@@ -84,8 +87,29 @@ inline bool SetProperty(v8::Local<v8::Context> context,
return SetProperty(context, object, base::UintToString(index).c_str(), value);
}
+// Wraps v8::Object::SetPrivate(). When possible, prefer this to SetProperty().
+inline bool SetPrivateProperty(v8::Local<v8::Context> context,
+ v8::Local<v8::Object> object,
+ v8::Local<v8::String> key,
+ v8::Local<v8::Value> value) {
+ return IsTrue(object->SetPrivate(
+ context, v8::Private::ForApi(context->GetIsolate(), key), value));
+}
+
+inline bool SetPrivateProperty(v8::Local<v8::Context> context,
+ v8::Local<v8::Object> object,
+ const char* key,
+ v8::Local<v8::Value> value) {
+ v8::Local<v8::String> v8_key;
+ return ToV8String(context->GetIsolate(), key, &v8_key) &&
+ IsTrue(object->SetPrivate(
+ context, v8::Private::ForApi(context->GetIsolate(), v8_key),
+ value));
+}
+
// GetProperty() family calls V8::Object::Get() and extracts a value from
// returned MaybeLocal. Returns true on success.
+// NOTE: Think about whether you want this or GetPrivateProperty() below.
template <typename Key>
inline bool GetProperty(v8::Local<v8::Context> context,
v8::Local<v8::Object> object,
@@ -104,6 +128,25 @@ inline bool GetProperty(v8::Local<v8::Context> context,
return GetProperty(context, object, v8_key, out);
}
+// Wraps v8::Object::GetPrivate(). When possible, prefer this to GetProperty().
+inline bool GetPrivateProperty(v8::Local<v8::Context> context,
+ v8::Local<v8::Object> object,
+ v8::Local<v8::String> key,
+ v8::Local<v8::Value>* out) {
+ return object
+ ->GetPrivate(context, v8::Private::ForApi(context->GetIsolate(), key))
+ .ToLocal(out);
+}
+
+inline bool GetPrivateProperty(v8::Local<v8::Context> context,
+ v8::Local<v8::Object> object,
+ const char* key,
+ v8::Local<v8::Value>* out) {
+ v8::Local<v8::String> v8_key;
+ return ToV8String(context->GetIsolate(), key, &v8_key) &&
+ GetPrivateProperty(context, object, v8_key, out);
+}
+
// GetPropertyUnsafe() family wraps v8::Object::Get(). They crash when an
// exception is thrown.
inline v8::Local<v8::Value> GetPropertyUnsafe(v8::Local<v8::Context> context,
« no previous file with comments | « extensions/renderer/module_system.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698