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 8234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8245 CHECK_EQ(2, type_switch->match(obj2)); | 8245 CHECK_EQ(2, type_switch->match(obj2)); |
8246 CHECK_EQ(3, type_switch->match(obj3)); | 8246 CHECK_EQ(3, type_switch->match(obj3)); |
8247 CHECK_EQ(3, type_switch->match(obj3)); | 8247 CHECK_EQ(3, type_switch->match(obj3)); |
8248 CHECK_EQ(2, type_switch->match(obj2)); | 8248 CHECK_EQ(2, type_switch->match(obj2)); |
8249 CHECK_EQ(1, type_switch->match(obj1)); | 8249 CHECK_EQ(1, type_switch->match(obj1)); |
8250 CHECK_EQ(0, type_switch->match(obj0)); | 8250 CHECK_EQ(0, type_switch->match(obj0)); |
8251 } | 8251 } |
8252 } | 8252 } |
8253 | 8253 |
8254 | 8254 |
8255 // For use within the TestSecurityHandler() test. | |
8256 static bool g_security_callback_result = false; | |
8257 static bool NamedSecurityTestCallback(Local<v8::Object> global, | |
8258 Local<Value> name, | |
8259 v8::AccessType type, | |
8260 Local<Value> data) { | |
8261 // Always allow read access. | |
8262 if (type == v8::ACCESS_GET) | |
8263 return true; | |
8264 | |
8265 // Sometimes allow other access. | |
8266 return g_security_callback_result; | |
8267 } | |
8268 | |
8269 | |
8270 static bool IndexedSecurityTestCallback(Local<v8::Object> global, | |
8271 uint32_t key, | |
8272 v8::AccessType type, | |
8273 Local<Value> data) { | |
8274 // Always allow read access. | |
8275 if (type == v8::ACCESS_GET) | |
8276 return true; | |
8277 | |
8278 // Sometimes allow other access. | |
8279 return g_security_callback_result; | |
8280 } | |
8281 | |
8282 | |
8283 static int trouble_nesting = 0; | 8255 static int trouble_nesting = 0; |
8284 static void TroubleCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { | 8256 static void TroubleCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { |
8285 ApiTestFuzzer::Fuzz(); | 8257 ApiTestFuzzer::Fuzz(); |
8286 trouble_nesting++; | 8258 trouble_nesting++; |
8287 | 8259 |
8288 // Call a JS function that throws an uncaught exception. | 8260 // Call a JS function that throws an uncaught exception. |
8289 Local<v8::Object> arg_this = | 8261 Local<v8::Object> arg_this = |
8290 args.GetIsolate()->GetCurrentContext()->Global(); | 8262 args.GetIsolate()->GetCurrentContext()->Global(); |
8291 Local<Value> trouble_callee = (trouble_nesting == 3) ? | 8263 Local<Value> trouble_callee = (trouble_nesting == 3) ? |
8292 arg_this->Get(v8_str("trouble_callee")) : | 8264 arg_this->Get(v8_str("trouble_callee")) : |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8399 "})()"); | 8371 "})()"); |
8400 CHECK(!try_catch.HasCaught()); | 8372 CHECK(!try_catch.HasCaught()); |
8401 CompileRun( | 8373 CompileRun( |
8402 "(function()" | 8374 "(function()" |
8403 " { try { throw ''; } finally { throw 0; }" | 8375 " { try { throw ''; } finally { throw 0; }" |
8404 "})()"); | 8376 "})()"); |
8405 CHECK(try_catch.HasCaught()); | 8377 CHECK(try_catch.HasCaught()); |
8406 } | 8378 } |
8407 | 8379 |
8408 | 8380 |
| 8381 // For use within the TestSecurityHandler() test. |
| 8382 static bool g_security_callback_result = false; |
| 8383 static bool NamedSecurityTestCallback(Local<v8::Object> global, |
| 8384 Local<Value> name, |
| 8385 v8::AccessType type, |
| 8386 Local<Value> data) { |
| 8387 printf("a\n"); |
| 8388 // Always allow read access. |
| 8389 if (type == v8::ACCESS_GET) |
| 8390 return true; |
| 8391 |
| 8392 // Sometimes allow other access. |
| 8393 return g_security_callback_result; |
| 8394 } |
| 8395 |
| 8396 |
| 8397 static bool IndexedSecurityTestCallback(Local<v8::Object> global, |
| 8398 uint32_t key, |
| 8399 v8::AccessType type, |
| 8400 Local<Value> data) { |
| 8401 printf("b\n"); |
| 8402 // Always allow read access. |
| 8403 if (type == v8::ACCESS_GET) |
| 8404 return true; |
| 8405 |
| 8406 // Sometimes allow other access. |
| 8407 return g_security_callback_result; |
| 8408 } |
| 8409 |
| 8410 |
8409 // SecurityHandler can't be run twice | 8411 // SecurityHandler can't be run twice |
8410 TEST(SecurityHandler) { | 8412 TEST(SecurityHandler) { |
8411 v8::Isolate* isolate = CcTest::isolate(); | 8413 v8::Isolate* isolate = CcTest::isolate(); |
8412 v8::HandleScope scope0(isolate); | 8414 v8::HandleScope scope0(isolate); |
8413 v8::Handle<v8::ObjectTemplate> global_template = | 8415 v8::Handle<v8::ObjectTemplate> global_template = |
8414 v8::ObjectTemplate::New(isolate); | 8416 v8::ObjectTemplate::New(isolate); |
8415 global_template->SetAccessCheckCallbacks(NamedSecurityTestCallback, | 8417 global_template->SetAccessCheckCallbacks(NamedSecurityTestCallback, |
8416 IndexedSecurityTestCallback); | 8418 IndexedSecurityTestCallback); |
8417 // Create an environment | 8419 // Create an environment |
8418 v8::Handle<Context> context0 = Context::New(isolate, NULL, global_template); | 8420 v8::Handle<Context> context0 = Context::New(isolate, NULL, global_template); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8570 Local<Script> access_f3 = v8_compile("f[99]"); | 8572 Local<Script> access_f3 = v8_compile("f[99]"); |
8571 for (int k = 0; k < 5; k++) { | 8573 for (int k = 0; k < 5; k++) { |
8572 CHECK(!access_f2->Run()->Equals(v8_num(100))); | 8574 CHECK(!access_f2->Run()->Equals(v8_num(100))); |
8573 CHECK(access_f2->Run()->IsUndefined()); | 8575 CHECK(access_f2->Run()->IsUndefined()); |
8574 CHECK(!access_f3->Run()->Equals(v8_num(101))); | 8576 CHECK(!access_f3->Run()->Equals(v8_num(101))); |
8575 CHECK(access_f3->Run()->IsUndefined()); | 8577 CHECK(access_f3->Run()->IsUndefined()); |
8576 } | 8578 } |
8577 } | 8579 } |
8578 | 8580 |
8579 | 8581 |
| 8582 static bool named_security_check_with_gc_called; |
| 8583 |
| 8584 static bool NamedSecurityCallbackWithGC(Local<v8::Object> global, |
| 8585 Local<Value> name, |
| 8586 v8::AccessType type, |
| 8587 Local<Value> data) { |
| 8588 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 8589 named_security_check_with_gc_called = true; |
| 8590 return true; |
| 8591 } |
| 8592 |
| 8593 |
| 8594 static bool indexed_security_check_with_gc_called; |
| 8595 |
| 8596 static bool IndexedSecurityTestCallbackWithGC(Local<v8::Object> global, |
| 8597 uint32_t key, |
| 8598 v8::AccessType type, |
| 8599 Local<Value> data) { |
| 8600 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 8601 indexed_security_check_with_gc_called = true; |
| 8602 return true; |
| 8603 } |
| 8604 |
| 8605 |
| 8606 TEST(SecurityTestGCAllowed) { |
| 8607 v8::Isolate* isolate = CcTest::isolate(); |
| 8608 v8::HandleScope handle_scope(isolate); |
| 8609 v8::Handle<v8::ObjectTemplate> object_template = |
| 8610 v8::ObjectTemplate::New(isolate); |
| 8611 object_template->SetAccessCheckCallbacks(NamedSecurityCallbackWithGC, |
| 8612 IndexedSecurityTestCallbackWithGC); |
| 8613 |
| 8614 v8::Handle<Context> context = Context::New(isolate); |
| 8615 v8::Context::Scope context_scope(context); |
| 8616 |
| 8617 context->Global()->Set(v8_str("obj"), object_template->NewInstance()); |
| 8618 |
| 8619 named_security_check_with_gc_called = false; |
| 8620 CompileRun("obj.foo = new String(1001);"); |
| 8621 CHECK(named_security_check_with_gc_called); |
| 8622 |
| 8623 indexed_security_check_with_gc_called = false; |
| 8624 CompileRun("obj[0] = new String(1002);"); |
| 8625 CHECK(indexed_security_check_with_gc_called); |
| 8626 |
| 8627 named_security_check_with_gc_called = false; |
| 8628 CHECK(CompileRun("obj.foo")->ToString()->Equals(v8_str("1001"))); |
| 8629 CHECK(named_security_check_with_gc_called); |
| 8630 |
| 8631 indexed_security_check_with_gc_called = false; |
| 8632 CHECK(CompileRun("obj[0]")->ToString()->Equals(v8_str("1002"))); |
| 8633 CHECK(indexed_security_check_with_gc_called); |
| 8634 } |
| 8635 |
| 8636 |
8580 THREADED_TEST(CrossDomainDelete) { | 8637 THREADED_TEST(CrossDomainDelete) { |
8581 LocalContext env1; | 8638 LocalContext env1; |
8582 v8::HandleScope handle_scope(env1->GetIsolate()); | 8639 v8::HandleScope handle_scope(env1->GetIsolate()); |
8583 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); | 8640 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); |
8584 | 8641 |
8585 Local<Value> foo = v8_str("foo"); | 8642 Local<Value> foo = v8_str("foo"); |
8586 Local<Value> bar = v8_str("bar"); | 8643 Local<Value> bar = v8_str("bar"); |
8587 | 8644 |
8588 // Set to the same domain. | 8645 // Set to the same domain. |
8589 env1->SetSecurityToken(foo); | 8646 env1->SetSecurityToken(foo); |
(...skipping 13805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22395 "f.call(friend);"); | 22452 "f.call(friend);"); |
22396 CHECK_EQ(2, named_access_count); | 22453 CHECK_EQ(2, named_access_count); |
22397 | 22454 |
22398 // Test access using Object.setPrototypeOf reflective method. | 22455 // Test access using Object.setPrototypeOf reflective method. |
22399 named_access_count = 0; | 22456 named_access_count = 0; |
22400 CompileRun("Object.setPrototypeOf(friend, {});"); | 22457 CompileRun("Object.setPrototypeOf(friend, {});"); |
22401 CHECK_EQ(1, named_access_count); | 22458 CHECK_EQ(1, named_access_count); |
22402 CompileRun("Object.getPrototypeOf(friend);"); | 22459 CompileRun("Object.getPrototypeOf(friend);"); |
22403 CHECK_EQ(2, named_access_count); | 22460 CHECK_EQ(2, named_access_count); |
22404 } | 22461 } |
OLD | NEW |