| OLD | NEW |
| 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 5430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5441 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5441 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 5442 templ->SetAccessCheckCallbacks(NamedSetAccessBlocker, | 5442 templ->SetAccessCheckCallbacks(NamedSetAccessBlocker, |
| 5443 IndexedSetAccessBlocker); | 5443 IndexedSetAccessBlocker); |
| 5444 templ->Set(v8_str("x"), v8::True()); | 5444 templ->Set(v8_str("x"), v8::True()); |
| 5445 Local<v8::Object> instance = templ->NewInstance(); | 5445 Local<v8::Object> instance = templ->NewInstance(); |
| 5446 context->Global()->Set(v8_str("obj"), instance); | 5446 context->Global()->Set(v8_str("obj"), instance); |
| 5447 Local<Value> value = CompileRun("obj.x"); | 5447 Local<Value> value = CompileRun("obj.x"); |
| 5448 CHECK(value->BooleanValue()); | 5448 CHECK(value->BooleanValue()); |
| 5449 } | 5449 } |
| 5450 | 5450 |
| 5451 static bool NamedGetAccessBlocker(Local<v8::Object> obj, |
| 5452 Local<Value> name, |
| 5453 v8::AccessType type, |
| 5454 Local<Value> data) { |
| 5455 return false; |
| 5456 } |
| 5457 |
| 5458 |
| 5459 static bool IndexedGetAccessBlocker(Local<v8::Object> obj, |
| 5460 uint32_t key, |
| 5461 v8::AccessType type, |
| 5462 Local<Value> data) { |
| 5463 return false; |
| 5464 } |
| 5465 |
| 5466 |
| 5467 |
| 5468 THREADED_TEST(AccessChecksReenabledCorrectly) { |
| 5469 v8::HandleScope scope; |
| 5470 LocalContext context; |
| 5471 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 5472 templ->SetAccessCheckCallbacks(NamedGetAccessBlocker, |
| 5473 IndexedGetAccessBlocker); |
| 5474 templ->Set(v8_str("a"), v8_str("a")); |
| 5475 // Add more than 8 (see kMaxFastProperties) properties |
| 5476 // so that the constructor will force copying map. |
| 5477 // Cannot sprintf, gcc complains unsafety. |
| 5478 char buf[5]; |
| 5479 for (char i = '0'; i <= '9' ; i++) { |
| 5480 buf[1] = i; |
| 5481 for (char j = '0'; j <= '9'; j++) { |
| 5482 buf[2] = j; |
| 5483 for (char k = '0'; k <= '9'; k++) { |
| 5484 buf[3] = k; |
| 5485 buf[4] = 0; |
| 5486 templ->Set(v8_str(buf), v8::Number::New(k)); |
| 5487 } |
| 5488 } |
| 5489 } |
| 5490 |
| 5491 Local<v8::Object> instance_1 = templ->NewInstance(); |
| 5492 context->Global()->Set(v8_str("obj_1"), instance_1); |
| 5493 |
| 5494 Local<Value> value_1 = CompileRun("obj_1.a"); |
| 5495 CHECK(value_1->IsUndefined()); |
| 5496 |
| 5497 Local<v8::Object> instance_2 = templ->NewInstance(); |
| 5498 context->Global()->Set(v8_str("obj_2"), instance_2); |
| 5499 |
| 5500 Local<Value> value_2 = CompileRun("obj_2.a"); |
| 5501 CHECK(value_2->IsUndefined()); |
| 5502 } |
| 5451 | 5503 |
| 5452 // This tests that access check information remains on the global | 5504 // This tests that access check information remains on the global |
| 5453 // object template when creating contexts. | 5505 // object template when creating contexts. |
| 5454 THREADED_TEST(AccessControlRepeatedContextCreation) { | 5506 THREADED_TEST(AccessControlRepeatedContextCreation) { |
| 5455 v8::HandleScope handle_scope; | 5507 v8::HandleScope handle_scope; |
| 5456 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 5508 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
| 5457 global_template->SetAccessCheckCallbacks(NamedSetAccessBlocker, | 5509 global_template->SetAccessCheckCallbacks(NamedSetAccessBlocker, |
| 5458 IndexedSetAccessBlocker); | 5510 IndexedSetAccessBlocker); |
| 5459 i::Handle<i::ObjectTemplateInfo> internal_template = | 5511 i::Handle<i::ObjectTemplateInfo> internal_template = |
| 5460 v8::Utils::OpenHandle(*global_template); | 5512 v8::Utils::OpenHandle(*global_template); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5548 CompileRun("for (var j = 0; j < 10; j++) new RegExp('');"); | 5600 CompileRun("for (var j = 0; j < 10; j++) new RegExp('');"); |
| 5549 } | 5601 } |
| 5550 // Test CallIC. | 5602 // Test CallIC. |
| 5551 for (int i = 0; i < 2; i++) { | 5603 for (int i = 0; i < 2; i++) { |
| 5552 LocalContext context; | 5604 LocalContext context; |
| 5553 context->Global()->Set(v8_str("tmp"), v8::True()); | 5605 context->Global()->Set(v8_str("tmp"), v8::True()); |
| 5554 context->Global()->Delete(v8_str("tmp")); | 5606 context->Global()->Delete(v8_str("tmp")); |
| 5555 CompileRun("for (var j = 0; j < 10; j++) RegExp('')"); | 5607 CompileRun("for (var j = 0; j < 10; j++) RegExp('')"); |
| 5556 } | 5608 } |
| 5557 } | 5609 } |
| 5610 |
| 5611 |
| 5612 // Test that cross-context new calls use the context of the callee to |
| 5613 // create the new JavaScript object. |
| 5614 THREADED_TEST(CrossContextNew) { |
| 5615 v8::HandleScope scope; |
| 5616 v8::Persistent<Context> context0 = Context::New(); |
| 5617 v8::Persistent<Context> context1 = Context::New(); |
| 5618 |
| 5619 // Allow cross-domain access. |
| 5620 Local<String> token = v8_str("<security token>"); |
| 5621 context0->SetSecurityToken(token); |
| 5622 context1->SetSecurityToken(token); |
| 5623 |
| 5624 // Set an 'x' property on the Object prototype and define a |
| 5625 // constructor function in context0. |
| 5626 context0->Enter(); |
| 5627 CompileRun("Object.prototype.x = 42; function C() {};"); |
| 5628 context0->Exit(); |
| 5629 |
| 5630 // Call the constructor function from context0 and check that the |
| 5631 // result has the 'x' property. |
| 5632 context1->Enter(); |
| 5633 context1->Global()->Set(v8_str("other"), context0->Global()); |
| 5634 Local<Value> value = CompileRun("var instance = new other.C(); instance.x"); |
| 5635 CHECK(value->IsInt32()); |
| 5636 CHECK_EQ(42, value->Int32Value()); |
| 5637 context1->Exit(); |
| 5638 |
| 5639 // Dispose the contexts to allow them to be garbage collected. |
| 5640 context0.Dispose(); |
| 5641 context1.Dispose(); |
| 5642 } |
| OLD | NEW |