diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-13 17:12:55 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-13 17:14:32 +0000 |
commit | d656f872a560f84de872b747f6e54d32a88fd4b9 (patch) | |
tree | 3ef81c47c136da564630f0fba743cb98a5a68cd0 /gin/interceptor_unittest.cc | |
parent | 075f95461d912cb6b5a552cb0c4506e3bc8ad657 (diff) | |
download | chromium_src-d656f872a560f84de872b747f6e54d32a88fd4b9.zip chromium_src-d656f872a560f84de872b747f6e54d32a88fd4b9.tar.gz chromium_src-d656f872a560f84de872b747f6e54d32a88fd4b9.tar.bz2 |
[gin] Allow interceptors to signal whether a they intercepted something
TEST=InterceptorTest.BypassInterceptor*
R=abarth@chromium.org,raymes@chromium.org
BUG=none
Review URL: https://codereview.chromium.org/467243002
Cr-Commit-Position: refs/heads/master@{#289325}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289325 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gin/interceptor_unittest.cc')
-rw-r--r-- | gin/interceptor_unittest.cc | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/gin/interceptor_unittest.cc b/gin/interceptor_unittest.cc index 965ad6c..e25005b4 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 |