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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gin/interceptor.cc ('k') | gin/object_template_builder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/logging.h" 5 #include "base/logging.h"
6 #include "gin/arguments.h" 6 #include "gin/arguments.h"
7 #include "gin/handle.h" 7 #include "gin/handle.h"
8 #include "gin/interceptor.h" 8 #include "gin/interceptor.h"
9 #include "gin/object_template_builder.h" 9 #include "gin/object_template_builder.h"
10 #include "gin/per_isolate_data.h" 10 #include "gin/per_isolate_data.h"
(...skipping 24 matching lines...) Expand all
35 const std::string& property) 35 const std::string& property)
36 OVERRIDE { 36 OVERRIDE {
37 if (property == "value") { 37 if (property == "value") {
38 return ConvertToV8(isolate, value_); 38 return ConvertToV8(isolate, value_);
39 } else if (property == "func") { 39 } else if (property == "func") {
40 return GetFunctionTemplate(isolate, "func")->GetFunction(); 40 return GetFunctionTemplate(isolate, "func")->GetFunction();
41 } else { 41 } else {
42 return v8::Local<v8::Value>(); 42 return v8::Local<v8::Value>();
43 } 43 }
44 } 44 }
45 virtual void SetNamedProperty(v8::Isolate* isolate, 45 virtual bool SetNamedProperty(v8::Isolate* isolate,
46 const std::string& property, 46 const std::string& property,
47 v8::Local<v8::Value> value) OVERRIDE { 47 v8::Local<v8::Value> value) OVERRIDE {
48 if (property != "value") 48 if (property == "value") {
49 return; 49 ConvertFromV8(isolate, value, &value_);
50 ConvertFromV8(isolate, value, &value_); 50 return true;
51 }
52 return false;
51 } 53 }
52 virtual std::vector<std::string> EnumerateNamedProperties( 54 virtual std::vector<std::string> EnumerateNamedProperties(
53 v8::Isolate* isolate) OVERRIDE { 55 v8::Isolate* isolate) OVERRIDE {
54 std::vector<std::string> result; 56 std::vector<std::string> result;
55 result.push_back("func"); 57 result.push_back("func");
56 result.push_back("value"); 58 result.push_back("value");
57 return result; 59 return result;
58 } 60 }
59 61
60 // gin::IndexedPropertyInterceptor 62 // gin::IndexedPropertyInterceptor
61 virtual v8::Local<v8::Value> GetIndexedProperty(v8::Isolate* isolate, 63 virtual v8::Local<v8::Value> GetIndexedProperty(v8::Isolate* isolate,
62 uint32_t index) OVERRIDE { 64 uint32_t index) OVERRIDE {
63 if (index == 0) 65 if (index == 0)
64 return ConvertToV8(isolate, value_); 66 return ConvertToV8(isolate, value_);
65 return v8::Local<v8::Value>(); 67 return v8::Local<v8::Value>();
66 } 68 }
67 virtual void SetIndexedProperty(v8::Isolate* isolate, 69 virtual bool SetIndexedProperty(v8::Isolate* isolate,
68 uint32_t index, 70 uint32_t index,
69 v8::Local<v8::Value> value) OVERRIDE { 71 v8::Local<v8::Value> value) OVERRIDE {
70 if (index != 0) 72 if (index == 0) {
71 return; 73 ConvertFromV8(isolate, value, &value_);
72 ConvertFromV8(isolate, value, &value_); 74 return true;
75 }
76 // Don't allow bypassing the interceptor.
77 return true;
73 } 78 }
74 virtual std::vector<uint32_t> EnumerateIndexedProperties(v8::Isolate* isolate) 79 virtual std::vector<uint32_t> EnumerateIndexedProperties(v8::Isolate* isolate)
75 OVERRIDE { 80 OVERRIDE {
76 std::vector<uint32_t> result; 81 std::vector<uint32_t> result;
77 result.push_back(0); 82 result.push_back(0);
78 return result; 83 return result;
79 } 84 }
80 85
81 private: 86 private:
82 explicit MyInterceptor(v8::Isolate* isolate) 87 explicit MyInterceptor(v8::Isolate* isolate)
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 " })"); 170 " })");
166 } 171 }
167 172
168 TEST_F(InterceptorTest, IndexedInterceptor) { 173 TEST_F(InterceptorTest, IndexedInterceptor) {
169 RunInterceptorTest( 174 RunInterceptorTest(
170 "(function (obj) {" 175 "(function (obj) {"
171 " if (obj[0] !== 42) throw 'FAIL';" 176 " if (obj[0] !== 42) throw 'FAIL';"
172 " else obj[0] = 191; })"); 177 " else obj[0] = 191; })");
173 } 178 }
174 179
180 TEST_F(InterceptorTest, BypassInterceptorAllowed) {
181 RunInterceptorTest(
182 "(function (obj) {"
183 " obj.value = 191 /* make test happy */;"
184 " obj.foo = 23;"
185 " if (obj.foo !== 23) throw 'FAIL'; })");
186 }
187
188 TEST_F(InterceptorTest, BypassInterceptorForbidden) {
189 RunInterceptorTest(
190 "(function (obj) {"
191 " obj.value = 191 /* make test happy */;"
192 " obj[1] = 23;"
193 " if (obj[1] === 23) throw 'FAIL'; })");
194 }
195
175 } // namespace gin 196 } // namespace gin
OLDNEW
« 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