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

Unified Diff: gin/interceptor_unittest.cc

Issue 467243002: [gin] Allow interceptors to signal whether a they intercepted something (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | « gin/interceptor.cc ('k') | gin/object_template_builder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gin/interceptor_unittest.cc
diff --git a/gin/interceptor_unittest.cc b/gin/interceptor_unittest.cc
index 965ad6c57f39092d3a9f28da6ff056cd757332da..e25005b4e0ef44053601da8b66f54f765d974e1c 100644
--- a/gin/interceptor_unittest.cc
+++ b/gin/interceptor_unittest.cc
@@ -42,12 +42,14 @@ class MyInterceptor : public Wrappable<MyInterceptor>,
return v8::Local<v8::Value>();
}
}
- virtual void SetNamedProperty(v8::Isolate* isolate,
+ virtual bool SetNamedProperty(v8::Isolate* isolate,
const std::string& property,
v8::Local<v8::Value> value) OVERRIDE {
- if (property != "value")
- return;
- ConvertFromV8(isolate, value, &value_);
+ if (property == "value") {
+ ConvertFromV8(isolate, value, &value_);
+ return true;
+ }
+ return false;
}
virtual std::vector<std::string> EnumerateNamedProperties(
v8::Isolate* isolate) OVERRIDE {
@@ -64,12 +66,15 @@ class MyInterceptor : public Wrappable<MyInterceptor>,
return ConvertToV8(isolate, value_);
return v8::Local<v8::Value>();
}
- virtual void SetIndexedProperty(v8::Isolate* isolate,
+ virtual bool SetIndexedProperty(v8::Isolate* isolate,
uint32_t index,
v8::Local<v8::Value> value) OVERRIDE {
- if (index != 0)
- return;
- ConvertFromV8(isolate, value, &value_);
+ if (index == 0) {
+ ConvertFromV8(isolate, value, &value_);
+ return true;
+ }
+ // Don't allow bypassing the interceptor.
+ return true;
}
virtual std::vector<uint32_t> EnumerateIndexedProperties(v8::Isolate* isolate)
OVERRIDE {
@@ -172,4 +177,20 @@ TEST_F(InterceptorTest, IndexedInterceptor) {
" else obj[0] = 191; })");
}
+TEST_F(InterceptorTest, BypassInterceptorAllowed) {
+ RunInterceptorTest(
+ "(function (obj) {"
+ " obj.value = 191 /* make test happy */;"
+ " obj.foo = 23;"
+ " if (obj.foo !== 23) throw 'FAIL'; })");
+}
+
+TEST_F(InterceptorTest, BypassInterceptorForbidden) {
+ RunInterceptorTest(
+ "(function (obj) {"
+ " obj.value = 191 /* make test happy */;"
+ " obj[1] = 23;"
+ " if (obj[1] === 23) throw 'FAIL'; })");
+}
+
} // namespace gin
« no previous file with comments | « gin/interceptor.cc ('k') | gin/object_template_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698