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

Side by Side Diff: test/cctest/test-api.cc

Issue 1219663009: [strong] Add tests for loading from super, loading with access checks (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 5 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 | « no previous file | test/mjsunit/strong/load-builtins.js » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 21331 matching lines...) Expand 10 before | Expand all | Expand 10 after
21342 v8::HandleScope handle_scope(isolate); 21342 v8::HandleScope handle_scope(isolate);
21343 21343
21344 // Should work 21344 // Should work
21345 v8::Local<v8::Object> obj = v8::Object::New(isolate); 21345 v8::Local<v8::Object> obj = v8::Object::New(isolate);
21346 21346
21347 USE(obj); 21347 USE(obj);
21348 } 21348 }
21349 } 21349 }
21350 21350
21351 21351
21352 static bool access_was_called = false;
21353
21354
21355 static bool AccessAlwaysAllowedWithFlag(Local<v8::Object> global,
21356 Local<Value> name, v8::AccessType type,
21357 Local<Value> data) {
21358 access_was_called = true;
21359 return true;
21360 }
21361
21362
21363 static bool AccessAlwaysBlockedWithFlag(Local<v8::Object> global,
21364 Local<Value> name, v8::AccessType type,
21365 Local<Value> data) {
21366 access_was_called = true;
21367 return false;
21368 }
21369
21370
21371 TEST(StrongModeAccessCheckAllowed) {
21372 i::FLAG_strong_mode = true;
21373 v8::Isolate* isolate = CcTest::isolate();
21374 v8::HandleScope handle_scope(isolate);
21375 v8::Handle<Value> value;
21376 access_was_called = false;
21377
21378 v8::Handle<v8::ObjectTemplate> obj_template =
21379 v8::ObjectTemplate::New(isolate);
21380
21381 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42));
21382 obj_template->SetAccessCheckCallbacks(AccessAlwaysAllowedWithFlag, NULL);
21383
21384 // Create an environment
21385 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template);
21386 context0->Enter();
21387 v8::Handle<v8::Object> global0 = context0->Global();
21388 global0->Set(v8_str("object"), obj_template->NewInstance());
21389 {
21390 v8::TryCatch try_catch(isolate);
21391 value = CompileRun("'use strong'; object.x");
21392 CHECK(!try_catch.HasCaught());
21393 CHECK(!access_was_called);
21394 CHECK_EQ(42, value->Int32Value());
21395 }
21396 {
21397 v8::TryCatch try_catch(isolate);
21398 value = CompileRun("'use strong'; object.foo");
21399 CHECK(try_catch.HasCaught());
21400 CHECK(!access_was_called);
21401 }
21402 {
21403 v8::TryCatch try_catch(isolate);
21404 value = CompileRun("'use strong'; object[10]");
21405 CHECK(try_catch.HasCaught());
21406 CHECK(!access_was_called);
21407 }
21408
21409 // Create an environment
21410 v8::Local<Context> context1 = Context::New(isolate);
21411 context1->Enter();
21412 v8::Handle<v8::Object> global1 = context1->Global();
21413 global1->Set(v8_str("object"), obj_template->NewInstance());
21414 {
21415 v8::TryCatch try_catch(isolate);
21416 value = CompileRun("'use strong'; object.x");
21417 CHECK(!try_catch.HasCaught());
21418 CHECK(access_was_called);
21419 CHECK_EQ(42, value->Int32Value());
21420 }
21421 access_was_called = false;
21422 {
21423 v8::TryCatch try_catch(isolate);
21424 value = CompileRun("'use strong'; object.foo");
21425 CHECK(try_catch.HasCaught());
21426 CHECK(access_was_called);
21427 }
21428 access_was_called = false;
21429 {
21430 v8::TryCatch try_catch(isolate);
21431 value = CompileRun("'use strong'; object[10]");
21432 CHECK(try_catch.HasCaught());
21433 CHECK(access_was_called);
21434 }
21435
21436 context1->Exit();
21437 context0->Exit();
21438 }
21439
21440
21441 TEST(StrongModeAccessCheckBlocked) {
21442 i::FLAG_strong_mode = true;
21443 v8::Isolate* isolate = CcTest::isolate();
21444 v8::HandleScope handle_scope(isolate);
21445 v8::Handle<Value> value;
21446 access_was_called = false;
21447
21448 v8::Handle<v8::ObjectTemplate> obj_template =
21449 v8::ObjectTemplate::New(isolate);
21450
21451 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42));
21452 obj_template->SetAccessCheckCallbacks(AccessAlwaysBlockedWithFlag, NULL);
21453
21454 // Create an environment
21455 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template);
21456 context0->Enter();
21457 v8::Handle<v8::Object> global0 = context0->Global();
21458 global0->Set(v8_str("object"), obj_template->NewInstance());
21459 {
21460 v8::TryCatch try_catch(isolate);
21461 value = CompileRun("'use strong'; object.x");
21462 CHECK(!try_catch.HasCaught());
21463 CHECK(!access_was_called);
21464 CHECK_EQ(42, value->Int32Value());
21465 }
21466 {
21467 v8::TryCatch try_catch(isolate);
21468 value = CompileRun("'use strong'; object.foo");
21469 CHECK(try_catch.HasCaught());
21470 CHECK(!access_was_called);
21471 }
21472 {
21473 v8::TryCatch try_catch(isolate);
21474 value = CompileRun("'use strong'; object[10]");
21475 CHECK(try_catch.HasCaught());
21476 CHECK(!access_was_called);
21477 }
21478
21479 // Create an environment
21480 v8::Local<Context> context1 = Context::New(isolate);
21481 context1->Enter();
21482 v8::Handle<v8::Object> global1 = context1->Global();
21483 global1->Set(v8_str("object"), obj_template->NewInstance());
21484 {
21485 v8::TryCatch try_catch(isolate);
21486 value = CompileRun("'use strong'; object.x");
21487 CHECK(try_catch.HasCaught());
21488 CHECK(access_was_called);
21489 }
21490 access_was_called = false;
21491 {
21492 v8::TryCatch try_catch(isolate);
21493 value = CompileRun("'use strong'; object.foo");
21494 CHECK(try_catch.HasCaught());
21495 CHECK(access_was_called);
21496 }
21497 access_was_called = false;
21498 {
21499 v8::TryCatch try_catch(isolate);
21500 value = CompileRun("'use strong'; object[10]");
21501 CHECK(try_catch.HasCaught());
21502 CHECK(access_was_called);
21503 }
21504
21505 context1->Exit();
21506 context0->Exit();
21507 }
21508
21509
21352 TEST(StrongModeArityCallFromApi) { 21510 TEST(StrongModeArityCallFromApi) {
21353 i::FLAG_strong_mode = true; 21511 i::FLAG_strong_mode = true;
21354 LocalContext env; 21512 LocalContext env;
21355 v8::Isolate* isolate = env->GetIsolate(); 21513 v8::Isolate* isolate = env->GetIsolate();
21356 v8::HandleScope scope(isolate); 21514 v8::HandleScope scope(isolate);
21357 Local<Function> fun; 21515 Local<Function> fun;
21358 { 21516 {
21359 v8::TryCatch try_catch(isolate); 21517 v8::TryCatch try_catch(isolate);
21360 fun = Local<Function>::Cast(CompileRun( 21518 fun = Local<Function>::Cast(CompileRun(
21361 "function f(x) { 'use strong'; }" 21519 "function f(x) { 'use strong'; }"
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
21580 CHECK(set->Has(env.local(), set).FromJust()); 21738 CHECK(set->Has(env.local(), set).FromJust());
21581 21739
21582 CHECK(set->Delete(env.local(), set).FromJust()); 21740 CHECK(set->Delete(env.local(), set).FromJust());
21583 CHECK_EQ(2U, set->Size()); 21741 CHECK_EQ(2U, set->Size());
21584 CHECK(!set->Has(env.local(), set).FromJust()); 21742 CHECK(!set->Has(env.local(), set).FromJust());
21585 CHECK(!set->Delete(env.local(), set).FromJust()); 21743 CHECK(!set->Delete(env.local(), set).FromJust());
21586 21744
21587 set->Clear(); 21745 set->Clear();
21588 CHECK_EQ(0U, set->Size()); 21746 CHECK_EQ(0U, set->Size());
21589 } 21747 }
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/strong/load-builtins.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698