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

Side by Side Diff: test/cctest/test-access-checks.cc

Issue 2550423002: Propagate exceptions thrown by access check interceptors. (Closed)
Patch Set: Created 4 years 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
« src/objects.cc ('K') | « src/objects.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project 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 <stdlib.h> 5 #include <stdlib.h>
6 6
7 #include "test/cctest/cctest.h" 7 #include "test/cctest/cctest.h"
8 8
9 namespace { 9 namespace {
10 10
(...skipping 16 matching lines...) Expand all
27 v8::Isolate* isolate = info.GetIsolate(); 27 v8::Isolate* isolate = info.GetIsolate();
28 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 28 v8::Local<v8::Context> context = isolate->GetCurrentContext();
29 if (!property->Equals(context, v8_str("cross_context_int")).FromJust()) 29 if (!property->Equals(context, v8_str("cross_context_int")).FromJust())
30 return; 30 return;
31 if (value->IsInt32()) { 31 if (value->IsInt32()) {
32 g_cross_context_int = value->ToInt32(context).ToLocalChecked()->Value(); 32 g_cross_context_int = value->ToInt32(context).ToLocalChecked()->Value();
33 } 33 }
34 info.GetReturnValue().Set(value); 34 info.GetReturnValue().Set(value);
35 } 35 }
36 36
37 void NamedSetterThrowsException(
38 v8::Local<v8::Name> property, v8::Local<v8::Value> value,
39 const v8::PropertyCallbackInfo<v8::Value>& info) {
40 info.GetIsolate()->ThrowException(v8_str("exception"));
41 }
42
37 void NamedQuery(v8::Local<v8::Name> property, 43 void NamedQuery(v8::Local<v8::Name> property,
38 const v8::PropertyCallbackInfo<v8::Integer>& info) { 44 const v8::PropertyCallbackInfo<v8::Integer>& info) {
39 CHECK(g_expect_interceptor_call); 45 CHECK(g_expect_interceptor_call);
40 v8::Isolate* isolate = info.GetIsolate(); 46 v8::Isolate* isolate = info.GetIsolate();
41 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 47 v8::Local<v8::Context> context = isolate->GetCurrentContext();
42 if (!property->Equals(context, v8_str("cross_context_int")).FromJust()) 48 if (!property->Equals(context, v8_str("cross_context_int")).FromJust())
43 return; 49 return;
44 info.GetReturnValue().Set(v8::DontDelete); 50 info.GetReturnValue().Set(v8::DontDelete);
45 } 51 }
46 52
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 180 }
175 181
176 // Intercepted properties are accessible, however. 182 // Intercepted properties are accessible, however.
177 ExpectInt32("this.other.cross_context_int", 23); 183 ExpectInt32("this.other.cross_context_int", 23);
178 CompileRunChecked(isolate, "this.other.cross_context_int = 42"); 184 CompileRunChecked(isolate, "this.other.cross_context_int = 42");
179 ExpectInt32("this.other[7]", 42); 185 ExpectInt32("this.other[7]", 42);
180 ExpectString("JSON.stringify(Object.getOwnPropertyNames(this.other))", 186 ExpectString("JSON.stringify(Object.getOwnPropertyNames(this.other))",
181 "[\"7\",\"cross_context_int\"]"); 187 "[\"7\",\"cross_context_int\"]");
182 } 188 }
183 189
190 void CheckCrossContextSetterWithException(
191 v8::Isolate* isolate, v8::Local<v8::Context> accessing_context,
192 v8::Local<v8::Object> accessed_object) {
193 v8::HandleScope handle_scope(isolate);
194 accessing_context->Global()
195 ->Set(accessing_context, v8_str("other"), accessed_object)
196 .FromJust();
197 v8::Context::Scope context_scope(accessing_context);
198
199 v8::TryCatch try_catch(isolate);
200 CompileRun("this.other.should_throw = 8");
201 CHECK(try_catch.HasCaught());
202 CHECK(try_catch.Exception()->IsString());
203 CHECK(v8_str("exception")
204 ->Equals(accessing_context, try_catch.Exception())
205 .FromJust());
206 }
207
184 void Ctor(const v8::FunctionCallbackInfo<v8::Value>& info) { 208 void Ctor(const v8::FunctionCallbackInfo<v8::Value>& info) {
185 CHECK(info.IsConstructCall()); 209 CHECK(info.IsConstructCall());
186 } 210 }
187 211
188 } // namespace 212 } // namespace
189 213
190 TEST(AccessCheckWithInterceptor) { 214 TEST(AccessCheckWithInterceptor) {
191 v8::Isolate* isolate = CcTest::isolate(); 215 v8::Isolate* isolate = CcTest::isolate();
192 v8::HandleScope scope(isolate); 216 v8::HandleScope scope(isolate);
193 v8::Local<v8::ObjectTemplate> global_template = 217 v8::Local<v8::ObjectTemplate> global_template =
(...skipping 14 matching lines...) Expand all
208 v8::Local<v8::Context> context0 = 232 v8::Local<v8::Context> context0 =
209 v8::Context::New(isolate, nullptr, global_template); 233 v8::Context::New(isolate, nullptr, global_template);
210 CheckCanRunScriptInContext(isolate, context0); 234 CheckCanRunScriptInContext(isolate, context0);
211 235
212 // Create another context. 236 // Create another context.
213 v8::Local<v8::Context> context1 = 237 v8::Local<v8::Context> context1 =
214 v8::Context::New(isolate, nullptr, global_template); 238 v8::Context::New(isolate, nullptr, global_template);
215 CheckCrossContextAccess(isolate, context1, context0->Global()); 239 CheckCrossContextAccess(isolate, context1, context0->Global());
216 } 240 }
217 241
242 TEST(AccessCheckWithExceptionThrowingSetterInterceptor) {
243 v8::Isolate* isolate = CcTest::isolate();
244 isolate->SetFailedAccessCheckCallbackFunction([](v8::Local<v8::Object> target,
245 v8::AccessType type,
246 v8::Local<v8::Value> data) {
247 CHECK(false); // This should never be called.
248 });
249
250 v8::HandleScope scope(isolate);
251 v8::Local<v8::ObjectTemplate> global_template =
252 v8::ObjectTemplate::New(isolate);
253 global_template->SetAccessCheckCallbackAndHandler(
254 AccessCheck, v8::NamedPropertyHandlerConfiguration(
255 NamedGetter, NamedSetterThrowsException),
256 v8::IndexedPropertyHandlerConfiguration());
257
258 // Create two contexts.
259 v8::Local<v8::Context> context0 =
260 v8::Context::New(isolate, nullptr, global_template);
261 v8::Local<v8::Context> context1 =
262 v8::Context::New(isolate, nullptr, global_template);
263
264 // Try setting a cross-context property, which should throw an exception but
265 // not invoke the access failed callback.
266 CheckCrossContextSetterWithException(isolate, context1, context0->Global());
267 }
268
218 TEST(NewRemoteContext) { 269 TEST(NewRemoteContext) {
219 v8::Isolate* isolate = CcTest::isolate(); 270 v8::Isolate* isolate = CcTest::isolate();
220 v8::HandleScope scope(isolate); 271 v8::HandleScope scope(isolate);
221 v8::Local<v8::ObjectTemplate> global_template = 272 v8::Local<v8::ObjectTemplate> global_template =
222 v8::ObjectTemplate::New(isolate); 273 v8::ObjectTemplate::New(isolate);
223 global_template->SetAccessCheckCallbackAndHandler( 274 global_template->SetAccessCheckCallbackAndHandler(
224 AccessCheck, 275 AccessCheck,
225 v8::NamedPropertyHandlerConfiguration( 276 v8::NamedPropertyHandlerConfiguration(
226 NamedGetter, NamedSetter, NamedQuery, NamedDeleter, NamedEnumerator), 277 NamedGetter, NamedSetter, NamedQuery, NamedDeleter, NamedEnumerator),
227 v8::IndexedPropertyHandlerConfiguration(IndexedGetter, IndexedSetter, 278 v8::IndexedPropertyHandlerConfiguration(IndexedGetter, IndexedSetter,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 IndexedEnumerator)); 347 IndexedEnumerator));
297 tmpl->SetNativeDataProperty( 348 tmpl->SetNativeDataProperty(
298 v8_str("all_can_read"), Return42, nullptr, v8::Local<v8::Value>(), 349 v8_str("all_can_read"), Return42, nullptr, v8::Local<v8::Value>(),
299 v8::None, v8::Local<v8::AccessorSignature>(), v8::ALL_CAN_READ); 350 v8::None, v8::Local<v8::AccessorSignature>(), v8::ALL_CAN_READ);
300 351
301 v8::Local<v8::Object> obj = tmpl->NewRemoteInstance().ToLocalChecked(); 352 v8::Local<v8::Object> obj = tmpl->NewRemoteInstance().ToLocalChecked();
302 353
303 v8::Local<v8::Context> context = v8::Context::New(isolate); 354 v8::Local<v8::Context> context = v8::Context::New(isolate);
304 CheckCrossContextAccess(isolate, context, obj); 355 CheckCrossContextAccess(isolate, context, obj);
305 } 356 }
OLDNEW
« src/objects.cc ('K') | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698