Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 21411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 21422 v8::HandleScope handle_scope(isolate); | 21422 v8::HandleScope handle_scope(isolate); |
| 21423 | 21423 |
| 21424 // Should work | 21424 // Should work |
| 21425 v8::Local<v8::Object> obj = v8::Object::New(isolate); | 21425 v8::Local<v8::Object> obj = v8::Object::New(isolate); |
| 21426 | 21426 |
| 21427 USE(obj); | 21427 USE(obj); |
| 21428 } | 21428 } |
| 21429 } | 21429 } |
| 21430 | 21430 |
| 21431 | 21431 |
| 21432 static bool access_was_called = false; | |
| 21433 | |
| 21434 | |
| 21435 static bool AccessAlwaysAllowed(Local<v8::Object> global, Local<Value> name, | |
| 21436 v8::AccessType type, Local<Value> data) { | |
| 21437 access_was_called = true; | |
| 21438 return true; | |
| 21439 } | |
| 21440 | |
| 21441 | |
| 21442 TEST(StrongModeAccessChecks) { | |
|
rossberg
2015/06/30 12:38:03
Can we also have a test where the access check for
conradw
2015/06/30 15:12:56
Done.
| |
| 21443 i::FLAG_strong_mode = true; | |
| 21444 v8::Isolate* isolate = CcTest::isolate(); | |
| 21445 v8::HandleScope handle_scope(isolate); | |
| 21446 v8::Handle<Value> value; | |
| 21447 access_was_called = false; | |
| 21448 | |
| 21449 v8::Handle<v8::ObjectTemplate> obj_template = | |
| 21450 v8::ObjectTemplate::New(isolate); | |
| 21451 | |
| 21452 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42)); | |
| 21453 obj_template->SetAccessCheckCallbacks(AccessAlwaysAllowed, NULL); | |
| 21454 | |
| 21455 // Create an environment | |
| 21456 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template); | |
| 21457 context0->Enter(); | |
| 21458 v8::Handle<v8::Object> global0 = context0->Global(); | |
| 21459 global0->Set(v8_str("object"), obj_template->NewInstance()); | |
| 21460 { | |
| 21461 v8::TryCatch try_catch(isolate); | |
| 21462 value = CompileRun("'use strong'; object.x"); | |
| 21463 CHECK(!try_catch.HasCaught()); | |
| 21464 CHECK(!access_was_called); | |
| 21465 CHECK_EQ(42, value->Int32Value()); | |
| 21466 } | |
| 21467 { | |
| 21468 v8::TryCatch try_catch(isolate); | |
| 21469 value = CompileRun("'use strong'; object.foo"); | |
| 21470 CHECK(try_catch.HasCaught()); | |
| 21471 CHECK(!access_was_called); | |
| 21472 } | |
| 21473 { | |
| 21474 v8::TryCatch try_catch(isolate); | |
| 21475 value = CompileRun("'use strong'; object[10]"); | |
| 21476 CHECK(try_catch.HasCaught()); | |
| 21477 CHECK(!access_was_called); | |
| 21478 } | |
| 21479 | |
| 21480 // Create an environment | |
| 21481 v8::Local<Context> context1 = Context::New(isolate); | |
| 21482 context1->Enter(); | |
| 21483 v8::Handle<v8::Object> global1 = context1->Global(); | |
| 21484 global1->Set(v8_str("object"), obj_template->NewInstance()); | |
| 21485 { | |
| 21486 v8::TryCatch try_catch(isolate); | |
| 21487 value = CompileRun("'use strong'; object.x"); | |
| 21488 CHECK(!try_catch.HasCaught()); | |
| 21489 CHECK(access_was_called); | |
| 21490 CHECK_EQ(42, value->Int32Value()); | |
| 21491 } | |
| 21492 access_was_called = false; | |
| 21493 { | |
| 21494 v8::TryCatch try_catch(isolate); | |
| 21495 value = CompileRun("'use strong'; object.foo"); | |
| 21496 CHECK(try_catch.HasCaught()); | |
| 21497 CHECK(access_was_called); | |
| 21498 } | |
| 21499 access_was_called = false; | |
| 21500 { | |
| 21501 v8::TryCatch try_catch(isolate); | |
| 21502 value = CompileRun("'use strong'; object[10]"); | |
| 21503 CHECK(try_catch.HasCaught()); | |
| 21504 CHECK(access_was_called); | |
| 21505 } | |
| 21506 | |
| 21507 context1->Exit(); | |
| 21508 context0->Exit(); | |
| 21509 } | |
| 21510 | |
| 21511 | |
| 21432 TEST(StrongModeArityCallFromApi) { | 21512 TEST(StrongModeArityCallFromApi) { |
| 21433 i::FLAG_strong_mode = true; | 21513 i::FLAG_strong_mode = true; |
| 21434 LocalContext env; | 21514 LocalContext env; |
| 21435 v8::Isolate* isolate = env->GetIsolate(); | 21515 v8::Isolate* isolate = env->GetIsolate(); |
| 21436 v8::HandleScope scope(isolate); | 21516 v8::HandleScope scope(isolate); |
| 21437 Local<Function> fun; | 21517 Local<Function> fun; |
| 21438 { | 21518 { |
| 21439 v8::TryCatch try_catch(isolate); | 21519 v8::TryCatch try_catch(isolate); |
| 21440 fun = Local<Function>::Cast(CompileRun( | 21520 fun = Local<Function>::Cast(CompileRun( |
| 21441 "function f(x) { 'use strong'; }" | 21521 "function f(x) { 'use strong'; }" |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 21607 CHECK_EQ(2U, set->Size()); | 21687 CHECK_EQ(2U, set->Size()); |
| 21608 | 21688 |
| 21609 v8::Local<v8::Array> keys = set->AsArray(); | 21689 v8::Local<v8::Array> keys = set->AsArray(); |
| 21610 CHECK_EQ(2U, keys->Length()); | 21690 CHECK_EQ(2U, keys->Length()); |
| 21611 CHECK_EQ(1, keys->Get(0).As<v8::Int32>()->Value()); | 21691 CHECK_EQ(1, keys->Get(0).As<v8::Int32>()->Value()); |
| 21612 CHECK_EQ(2, keys->Get(1).As<v8::Int32>()->Value()); | 21692 CHECK_EQ(2, keys->Get(1).As<v8::Int32>()->Value()); |
| 21613 | 21693 |
| 21614 set = v8::Set::FromArray(env.local(), keys).ToLocalChecked(); | 21694 set = v8::Set::FromArray(env.local(), keys).ToLocalChecked(); |
| 21615 CHECK_EQ(2U, set->Size()); | 21695 CHECK_EQ(2U, set->Size()); |
| 21616 } | 21696 } |
| OLD | NEW |