Commit d656f872 authored by jochen@chromium.org's avatar jochen@chromium.org

[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
parent 075f9546
......@@ -26,9 +26,11 @@ v8::Local<v8::Value> NamedPropertyInterceptor::GetNamedProperty(
return v8::Local<v8::Value>();
}
void NamedPropertyInterceptor::SetNamedProperty(v8::Isolate* isolate,
bool NamedPropertyInterceptor::SetNamedProperty(v8::Isolate* isolate,
const std::string& property,
v8::Local<v8::Value> value) {}
v8::Local<v8::Value> value) {
return false;
}
std::vector<std::string> NamedPropertyInterceptor::EnumerateNamedProperties(
v8::Isolate* isolate) {
......@@ -51,10 +53,12 @@ v8::Local<v8::Value> IndexedPropertyInterceptor::GetIndexedProperty(
return v8::Local<v8::Value>();
}
void IndexedPropertyInterceptor::SetIndexedProperty(
bool IndexedPropertyInterceptor::SetIndexedProperty(
v8::Isolate* isolate,
uint32_t index,
v8::Local<v8::Value> value) {}
v8::Local<v8::Value> value) {
return false;
}
std::vector<uint32_t> IndexedPropertyInterceptor::EnumerateIndexedProperties(
v8::Isolate* isolate) {
......
......@@ -25,7 +25,8 @@ class GIN_EXPORT NamedPropertyInterceptor {
virtual v8::Local<v8::Value> GetNamedProperty(v8::Isolate* isolate,
const std::string& property);
virtual void SetNamedProperty(v8::Isolate* isolate,
// Return true if the set was interecepted.
virtual bool SetNamedProperty(v8::Isolate* isolate,
const std::string& property,
v8::Local<v8::Value> value);
virtual std::vector<std::string> EnumerateNamedProperties(
......@@ -45,7 +46,8 @@ class GIN_EXPORT IndexedPropertyInterceptor {
virtual v8::Local<v8::Value> GetIndexedProperty(v8::Isolate* isolate,
uint32_t index);
virtual void SetIndexedProperty(v8::Isolate* isolate,
// Return true if the set was interecepted.
virtual bool SetIndexedProperty(v8::Isolate* isolate,
uint32_t index,
v8::Local<v8::Value> value);
virtual std::vector<uint32_t> EnumerateIndexedProperties(
......
......@@ -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
......@@ -69,7 +69,8 @@ void NamedPropertySetter(v8::Local<v8::String> property,
return;
std::string name;
ConvertFromV8(isolate, property, &name);
interceptor->SetNamedProperty(isolate, name, value);
if (interceptor->SetNamedProperty(isolate, name, value))
info.GetReturnValue().Set(value);
}
void NamedPropertyQuery(v8::Local<v8::String> property,
......@@ -114,7 +115,8 @@ void IndexedPropertySetter(uint32_t index,
IndexedInterceptorFromV8(isolate, info.Holder());
if (!interceptor)
return;
interceptor->SetIndexedProperty(isolate, index, value);
if (interceptor->SetIndexedProperty(isolate, index, value))
info.GetReturnValue().Set(value);
}
void IndexedPropertyEnumerator(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment