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

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

Issue 2677653002: Fix receiver checks for v8::Function on a remote context. (Closed)
Patch Set: . Created 3 years, 10 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
« no previous file with comments | « src/bootstrapper.cc ('k') | test/unittests/api/remote-object-unittest.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 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 95
96 void IndexedEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info) { 96 void IndexedEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info) {
97 CHECK(g_expect_interceptor_call); 97 CHECK(g_expect_interceptor_call);
98 v8::Isolate* isolate = info.GetIsolate(); 98 v8::Isolate* isolate = info.GetIsolate();
99 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 99 v8::Local<v8::Context> context = isolate->GetCurrentContext();
100 v8::Local<v8::Array> names = v8::Array::New(isolate, 1); 100 v8::Local<v8::Array> names = v8::Array::New(isolate, 1);
101 names->Set(context, 0, v8_str("7")).FromJust(); 101 names->Set(context, 0, v8_str("7")).FromJust();
102 info.GetReturnValue().Set(names); 102 info.GetReturnValue().Set(names);
103 } 103 }
104 104
105 void MethodGetter(v8::Local<v8::Name> property,
106 const v8::PropertyCallbackInfo<v8::Value>& info) {
107 v8::Isolate* isolate = info.GetIsolate();
108 v8::Local<v8::Context> context = isolate->GetCurrentContext();
109
110 v8::Local<v8::External> data = info.Data().As<v8::External>();
111 v8::Local<v8::FunctionTemplate>& function_template =
112 *reinterpret_cast<v8::Local<v8::FunctionTemplate>*>(data->Value());
113
114 info.GetReturnValue().Set(
115 function_template->GetFunction(context).ToLocalChecked());
116 }
117
118 void MethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
119 info.GetReturnValue().Set(8);
120 }
121
105 void NamedGetterThrowsException( 122 void NamedGetterThrowsException(
106 v8::Local<v8::Name> property, 123 v8::Local<v8::Name> property,
107 const v8::PropertyCallbackInfo<v8::Value>& info) { 124 const v8::PropertyCallbackInfo<v8::Value>& info) {
108 info.GetIsolate()->ThrowException(v8_str("exception")); 125 info.GetIsolate()->ThrowException(v8_str("exception"));
109 } 126 }
110 127
111 void NamedSetterThrowsException( 128 void NamedSetterThrowsException(
112 v8::Local<v8::Name> property, v8::Local<v8::Value> value, 129 v8::Local<v8::Name> property, v8::Local<v8::Value> value,
113 const v8::PropertyCallbackInfo<v8::Value>& info) { 130 const v8::PropertyCallbackInfo<v8::Value>& info) {
114 info.GetIsolate()->ThrowException(v8_str("exception")); 131 info.GetIsolate()->ThrowException(v8_str("exception"));
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 v8::Local<v8::Context> context0 = 298 v8::Local<v8::Context> context0 =
282 v8::Context::New(isolate, nullptr, global_template); 299 v8::Context::New(isolate, nullptr, global_template);
283 CheckCanRunScriptInContext(isolate, context0); 300 CheckCanRunScriptInContext(isolate, context0);
284 301
285 // Create another context. 302 // Create another context.
286 v8::Local<v8::Context> context1 = 303 v8::Local<v8::Context> context1 =
287 v8::Context::New(isolate, nullptr, global_template); 304 v8::Context::New(isolate, nullptr, global_template);
288 CheckCrossContextAccess(isolate, context1, context0->Global()); 305 CheckCrossContextAccess(isolate, context1, context0->Global());
289 } 306 }
290 307
308 TEST(CallFunctionWithRemoteContextReceiver) {
309 v8::Isolate* isolate = CcTest::isolate();
310 v8::HandleScope scope(isolate);
311 v8::Local<v8::FunctionTemplate> global_template =
312 v8::FunctionTemplate::New(isolate);
313
314 v8::Local<v8::Signature> signature =
315 v8::Signature::New(isolate, global_template);
316 v8::Local<v8::FunctionTemplate> function_template = v8::FunctionTemplate::New(
317 isolate, MethodCallback, v8::External::New(isolate, &function_template),
318 signature);
319
320 global_template->InstanceTemplate()->SetAccessCheckCallbackAndHandler(
321 AccessCheck, v8::NamedPropertyHandlerConfiguration(
322 MethodGetter, nullptr, nullptr, nullptr, nullptr,
323 v8::External::New(isolate, &function_template)),
324 v8::IndexedPropertyHandlerConfiguration());
325
326 v8::Local<v8::Object> accessed_object =
327 v8::Context::NewRemoteContext(isolate,
328 global_template->InstanceTemplate())
329 .ToLocalChecked();
330 v8::Local<v8::Context> accessing_context =
331 v8::Context::New(isolate, nullptr, global_template->InstanceTemplate());
332
333 v8::HandleScope handle_scope(isolate);
334 accessing_context->Global()
335 ->Set(accessing_context, v8_str("other"), accessed_object)
336 .FromJust();
337 v8::Context::Scope context_scope(accessing_context);
338
339 {
340 v8::TryCatch try_catch(isolate);
341 ExpectInt32("this.other.method()", 8);
342 CHECK(!try_catch.HasCaught());
343 }
344 }
345
291 TEST(AccessCheckWithExceptionThrowingInterceptor) { 346 TEST(AccessCheckWithExceptionThrowingInterceptor) {
292 v8::Isolate* isolate = CcTest::isolate(); 347 v8::Isolate* isolate = CcTest::isolate();
293 isolate->SetFailedAccessCheckCallbackFunction([](v8::Local<v8::Object> target, 348 isolate->SetFailedAccessCheckCallbackFunction([](v8::Local<v8::Object> target,
294 v8::AccessType type, 349 v8::AccessType type,
295 v8::Local<v8::Value> data) { 350 v8::Local<v8::Value> data) {
296 CHECK(false); // This should never be called. 351 CHECK(false); // This should never be called.
297 }); 352 });
298 353
299 v8::HandleScope scope(isolate); 354 v8::HandleScope scope(isolate);
300 v8::Local<v8::ObjectTemplate> global_template = 355 v8::Local<v8::ObjectTemplate> global_template =
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 IndexedEnumerator)); 450 IndexedEnumerator));
396 tmpl->SetNativeDataProperty( 451 tmpl->SetNativeDataProperty(
397 v8_str("all_can_read"), Return42, nullptr, v8::Local<v8::Value>(), 452 v8_str("all_can_read"), Return42, nullptr, v8::Local<v8::Value>(),
398 v8::None, v8::Local<v8::AccessorSignature>(), v8::ALL_CAN_READ); 453 v8::None, v8::Local<v8::AccessorSignature>(), v8::ALL_CAN_READ);
399 454
400 v8::Local<v8::Object> obj = tmpl->NewRemoteInstance().ToLocalChecked(); 455 v8::Local<v8::Object> obj = tmpl->NewRemoteInstance().ToLocalChecked();
401 456
402 v8::Local<v8::Context> context = v8::Context::New(isolate); 457 v8::Local<v8::Context> context = v8::Context::New(isolate);
403 CheckCrossContextAccess(isolate, context, obj); 458 CheckCrossContextAccess(isolate, context, obj);
404 } 459 }
OLDNEW
« no previous file with comments | « src/bootstrapper.cc ('k') | test/unittests/api/remote-object-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698