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

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

Issue 1218123003: Revert of [strong] Add tests for loading from proxy, super, 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 21406 matching lines...) Expand 10 before | Expand all | Expand 10 after
21417 v8::HandleScope handle_scope(isolate); 21417 v8::HandleScope handle_scope(isolate);
21418 21418
21419 // Should work 21419 // Should work
21420 v8::Local<v8::Object> obj = v8::Object::New(isolate); 21420 v8::Local<v8::Object> obj = v8::Object::New(isolate);
21421 21421
21422 USE(obj); 21422 USE(obj);
21423 } 21423 }
21424 } 21424 }
21425 21425
21426 21426
21427 static bool access_was_called = false;
21428
21429
21430 static bool AccessAlwaysAllowedWithFlag(Local<v8::Object> global,
21431 Local<Value> name, v8::AccessType type,
21432 Local<Value> data) {
21433 access_was_called = true;
21434 return true;
21435 }
21436
21437
21438 static bool AccessAlwaysBlockedWithFlag(Local<v8::Object> global,
21439 Local<Value> name, v8::AccessType type,
21440 Local<Value> data) {
21441 access_was_called = true;
21442 return false;
21443 }
21444
21445
21446 TEST(StrongModeAccessCheckAllowed) {
21447 i::FLAG_strong_mode = true;
21448 v8::Isolate* isolate = CcTest::isolate();
21449 v8::HandleScope handle_scope(isolate);
21450 v8::Handle<Value> value;
21451 access_was_called = false;
21452
21453 v8::Handle<v8::ObjectTemplate> obj_template =
21454 v8::ObjectTemplate::New(isolate);
21455
21456 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42));
21457 obj_template->SetAccessCheckCallbacks(AccessAlwaysAllowedWithFlag, NULL);
21458
21459 // Create an environment
21460 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template);
21461 context0->Enter();
21462 v8::Handle<v8::Object> global0 = context0->Global();
21463 global0->Set(v8_str("object"), obj_template->NewInstance());
21464 {
21465 v8::TryCatch try_catch(isolate);
21466 value = CompileRun("'use strong'; object.x");
21467 CHECK(!try_catch.HasCaught());
21468 CHECK(!access_was_called);
21469 CHECK_EQ(42, value->Int32Value());
21470 }
21471 {
21472 v8::TryCatch try_catch(isolate);
21473 value = CompileRun("'use strong'; object.foo");
21474 CHECK(try_catch.HasCaught());
21475 CHECK(!access_was_called);
21476 }
21477 {
21478 v8::TryCatch try_catch(isolate);
21479 value = CompileRun("'use strong'; object[10]");
21480 CHECK(try_catch.HasCaught());
21481 CHECK(!access_was_called);
21482 }
21483
21484 // Create an environment
21485 v8::Local<Context> context1 = Context::New(isolate);
21486 context1->Enter();
21487 v8::Handle<v8::Object> global1 = context1->Global();
21488 global1->Set(v8_str("object"), obj_template->NewInstance());
21489 {
21490 v8::TryCatch try_catch(isolate);
21491 value = CompileRun("'use strong'; object.x");
21492 CHECK(!try_catch.HasCaught());
21493 CHECK(access_was_called);
21494 CHECK_EQ(42, value->Int32Value());
21495 }
21496 access_was_called = false;
21497 {
21498 v8::TryCatch try_catch(isolate);
21499 value = CompileRun("'use strong'; object.foo");
21500 CHECK(try_catch.HasCaught());
21501 CHECK(access_was_called);
21502 }
21503 access_was_called = false;
21504 {
21505 v8::TryCatch try_catch(isolate);
21506 value = CompileRun("'use strong'; object[10]");
21507 CHECK(try_catch.HasCaught());
21508 CHECK(access_was_called);
21509 }
21510
21511 context1->Exit();
21512 context0->Exit();
21513 }
21514
21515
21516 TEST(StrongModeAccessCheckBlocked) {
21517 i::FLAG_strong_mode = true;
21518 v8::Isolate* isolate = CcTest::isolate();
21519 v8::HandleScope handle_scope(isolate);
21520 v8::Handle<Value> value;
21521 access_was_called = false;
21522
21523 v8::Handle<v8::ObjectTemplate> obj_template =
21524 v8::ObjectTemplate::New(isolate);
21525
21526 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42));
21527 obj_template->SetAccessCheckCallbacks(AccessAlwaysBlockedWithFlag, NULL);
21528
21529 // Create an environment
21530 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template);
21531 context0->Enter();
21532 v8::Handle<v8::Object> global0 = context0->Global();
21533 global0->Set(v8_str("object"), obj_template->NewInstance());
21534 {
21535 v8::TryCatch try_catch(isolate);
21536 value = CompileRun("'use strong'; object.x");
21537 CHECK(!try_catch.HasCaught());
21538 CHECK(!access_was_called);
21539 CHECK_EQ(42, value->Int32Value());
21540 }
21541 {
21542 v8::TryCatch try_catch(isolate);
21543 value = CompileRun("'use strong'; object.foo");
21544 CHECK(try_catch.HasCaught());
21545 CHECK(!access_was_called);
21546 }
21547 {
21548 v8::TryCatch try_catch(isolate);
21549 value = CompileRun("'use strong'; object[10]");
21550 CHECK(try_catch.HasCaught());
21551 CHECK(!access_was_called);
21552 }
21553
21554 // Create an environment
21555 v8::Local<Context> context1 = Context::New(isolate);
21556 context1->Enter();
21557 v8::Handle<v8::Object> global1 = context1->Global();
21558 global1->Set(v8_str("object"), obj_template->NewInstance());
21559 {
21560 v8::TryCatch try_catch(isolate);
21561 value = CompileRun("'use strong'; object.x");
21562 CHECK(try_catch.HasCaught());
21563 CHECK(access_was_called);
21564 }
21565 access_was_called = false;
21566 {
21567 v8::TryCatch try_catch(isolate);
21568 value = CompileRun("'use strong'; object.foo");
21569 CHECK(try_catch.HasCaught());
21570 CHECK(access_was_called);
21571 }
21572 access_was_called = false;
21573 {
21574 v8::TryCatch try_catch(isolate);
21575 value = CompileRun("'use strong'; object[10]");
21576 CHECK(try_catch.HasCaught());
21577 CHECK(access_was_called);
21578 }
21579
21580 context1->Exit();
21581 context0->Exit();
21582 }
21583
21584
21585 TEST(StrongModeArityCallFromApi) { 21427 TEST(StrongModeArityCallFromApi) {
21586 i::FLAG_strong_mode = true; 21428 i::FLAG_strong_mode = true;
21587 LocalContext env; 21429 LocalContext env;
21588 v8::Isolate* isolate = env->GetIsolate(); 21430 v8::Isolate* isolate = env->GetIsolate();
21589 v8::HandleScope scope(isolate); 21431 v8::HandleScope scope(isolate);
21590 Local<Function> fun; 21432 Local<Function> fun;
21591 { 21433 {
21592 v8::TryCatch try_catch(isolate); 21434 v8::TryCatch try_catch(isolate);
21593 fun = Local<Function>::Cast(CompileRun( 21435 fun = Local<Function>::Cast(CompileRun(
21594 "function f(x) { 'use strong'; }" 21436 "function f(x) { 'use strong'; }"
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
21813 CHECK(set->Has(env.local(), set).FromJust()); 21655 CHECK(set->Has(env.local(), set).FromJust());
21814 21656
21815 CHECK(set->Delete(env.local(), set).FromJust()); 21657 CHECK(set->Delete(env.local(), set).FromJust());
21816 CHECK_EQ(2U, set->Size()); 21658 CHECK_EQ(2U, set->Size());
21817 CHECK(!set->Has(env.local(), set).FromJust()); 21659 CHECK(!set->Has(env.local(), set).FromJust());
21818 CHECK(!set->Delete(env.local(), set).FromJust()); 21660 CHECK(!set->Delete(env.local(), set).FromJust());
21819 21661
21820 set->Clear(); 21662 set->Clear();
21821 CHECK_EQ(0U, set->Size()); 21663 CHECK_EQ(0U, set->Size());
21822 } 21664 }
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