| 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 1792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1803 int expected = args[2]->Int32Value(); | 1803 int expected = args[2]->Int32Value(); |
| 1804 if (equality) { | 1804 if (equality) { |
| 1805 CHECK_EQ(count, expected); | 1805 CHECK_EQ(count, expected); |
| 1806 } else { | 1806 } else { |
| 1807 CHECK_NE(count, expected); | 1807 CHECK_NE(count, expected); |
| 1808 } | 1808 } |
| 1809 return v8::Undefined(); | 1809 return v8::Undefined(); |
| 1810 } | 1810 } |
| 1811 | 1811 |
| 1812 | 1812 |
| 1813 THREADED_TEST(EvalInTryFinally) { |
| 1814 v8::HandleScope scope; |
| 1815 LocalContext context; |
| 1816 v8::TryCatch try_catch; |
| 1817 CompileRun("(function() {" |
| 1818 " try {" |
| 1819 " eval('asldkf (*&^&*^');" |
| 1820 " } finally {" |
| 1821 " return;" |
| 1822 " }" |
| 1823 "})()"); |
| 1824 CHECK(!try_catch.HasCaught()); |
| 1825 } |
| 1826 |
| 1827 |
| 1813 // This test works by making a stack of alternating JavaScript and C | 1828 // This test works by making a stack of alternating JavaScript and C |
| 1814 // activations. These activations set up exception handlers with regular | 1829 // activations. These activations set up exception handlers with regular |
| 1815 // intervals, one interval for C activations and another for JavaScript | 1830 // intervals, one interval for C activations and another for JavaScript |
| 1816 // activations. When enough activations have been created an exception is | 1831 // activations. When enough activations have been created an exception is |
| 1817 // thrown and we check that the right activation catches the exception and that | 1832 // thrown and we check that the right activation catches the exception and that |
| 1818 // no other activations do. The right activation is always the topmost one with | 1833 // no other activations do. The right activation is always the topmost one with |
| 1819 // a handler, regardless of whether it is in JavaScript or C. | 1834 // a handler, regardless of whether it is in JavaScript or C. |
| 1820 // | 1835 // |
| 1821 // The notation used to describe a test case looks like this: | 1836 // The notation used to describe a test case looks like this: |
| 1822 // | 1837 // |
| (...skipping 1836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3659 v8::Persistent<Context> context1 = Context::New(); | 3674 v8::Persistent<Context> context1 = Context::New(); |
| 3660 context1->Enter(); | 3675 context1->Enter(); |
| 3661 | 3676 |
| 3662 // Make easy access to the object from the other environment. | 3677 // Make easy access to the object from the other environment. |
| 3663 v8::Handle<v8::Object> global1 = context1->Global(); | 3678 v8::Handle<v8::Object> global1 = context1->Global(); |
| 3664 global1->Set(v8_str("obj"), object); | 3679 global1->Set(v8_str("obj"), object); |
| 3665 | 3680 |
| 3666 v8::Handle<Value> value; | 3681 v8::Handle<Value> value; |
| 3667 | 3682 |
| 3668 // Check that the named access-control function is called every time. | 3683 // Check that the named access-control function is called every time. |
| 3669 value = v8_compile("for (var i = 0; i < 10; i++) obj.prop = 1;")->Run(); | 3684 CompileRun("function testProp(obj) {" |
| 3670 value = v8_compile("for (var i = 0; i < 10; i++) obj.prop;" | 3685 " for (var i = 0; i < 10; i++) obj.prop = 1;" |
| 3671 "obj.prop")->Run(); | 3686 " for (var j = 0; j < 10; j++) obj.prop;" |
| 3687 " return obj.prop" |
| 3688 "}"); |
| 3689 value = CompileRun("testProp(obj)"); |
| 3672 CHECK(value->IsNumber()); | 3690 CHECK(value->IsNumber()); |
| 3673 CHECK_EQ(1, value->Int32Value()); | 3691 CHECK_EQ(1, value->Int32Value()); |
| 3674 CHECK_EQ(21, named_access_count); | 3692 CHECK_EQ(21, named_access_count); |
| 3675 | 3693 |
| 3676 // Check that the named access-control function is called every time. | 3694 // Check that the named access-control function is called every time. |
| 3677 value = v8_compile("var p = 'prop';")->Run(); | 3695 CompileRun("var p = 'prop';" |
| 3678 value = v8_compile("for (var i = 0; i < 10; i++) obj[p] = 1;")->Run(); | 3696 "function testKeyed(obj) {" |
| 3679 value = v8_compile("for (var i = 0; i < 10; i++) obj[p];" | 3697 " for (var i = 0; i < 10; i++) obj[p] = 1;" |
| 3680 "obj[p]")->Run(); | 3698 " for (var j = 0; j < 10; j++) obj[p];" |
| 3699 " return obj[p];" |
| 3700 "}"); |
| 3701 // Use obj which requires access checks. No inline caching is used |
| 3702 // in that case. |
| 3703 value = CompileRun("testKeyed(obj)"); |
| 3681 CHECK(value->IsNumber()); | 3704 CHECK(value->IsNumber()); |
| 3682 CHECK_EQ(1, value->Int32Value()); | 3705 CHECK_EQ(1, value->Int32Value()); |
| 3683 CHECK_EQ(42, named_access_count); | 3706 CHECK_EQ(42, named_access_count); |
| 3707 // Force the inline caches into generic state and try again. |
| 3708 CompileRun("testKeyed({ a: 0 })"); |
| 3709 CompileRun("testKeyed({ b: 0 })"); |
| 3710 value = CompileRun("testKeyed(obj)"); |
| 3711 CHECK(value->IsNumber()); |
| 3712 CHECK_EQ(1, value->Int32Value()); |
| 3713 CHECK_EQ(63, named_access_count); |
| 3684 | 3714 |
| 3685 // Check that the indexed access-control function is called every time. | 3715 // Check that the indexed access-control function is called every time. |
| 3686 value = v8_compile("for (var i = 0; i < 10; i++) obj[0] = 1;")->Run(); | 3716 CompileRun("function testIndexed(obj) {" |
| 3687 value = v8_compile("for (var i = 0; i < 10; i++) obj[0];" | 3717 " for (var i = 0; i < 10; i++) obj[0] = 1;" |
| 3688 "obj[0]")->Run(); | 3718 " for (var j = 0; j < 10; j++) obj[0];" |
| 3719 " return obj[0]" |
| 3720 "}"); |
| 3721 value = CompileRun("testIndexed(obj)"); |
| 3689 CHECK(value->IsNumber()); | 3722 CHECK(value->IsNumber()); |
| 3690 CHECK_EQ(1, value->Int32Value()); | 3723 CHECK_EQ(1, value->Int32Value()); |
| 3691 CHECK_EQ(21, indexed_access_count); | 3724 CHECK_EQ(21, indexed_access_count); |
| 3725 // Force the inline caches into generic state. |
| 3726 CompileRun("testIndexed(new Array(1))"); |
| 3727 // Test that the indexed access check is called. |
| 3728 value = CompileRun("testIndexed(obj)"); |
| 3729 CHECK(value->IsNumber()); |
| 3730 CHECK_EQ(1, value->Int32Value()); |
| 3731 CHECK_EQ(42, indexed_access_count); |
| 3732 |
| 3733 // Check that the named access check is called when invoking |
| 3734 // functions on an object that requires access checks. |
| 3735 CompileRun("obj.f = function() {}"); |
| 3736 CompileRun("function testCallNormal(obj) {" |
| 3737 " for (var i = 0; i < 10; i++) obj.f();" |
| 3738 "}"); |
| 3739 CompileRun("testCallNormal(obj)"); |
| 3740 CHECK_EQ(74, named_access_count); |
| 3741 |
| 3742 // Force obj into slow case. |
| 3743 value = CompileRun("delete obj.prop"); |
| 3744 CHECK(value->BooleanValue()); |
| 3745 // Force inline caches into dictionary probing mode. |
| 3746 CompileRun("var o = { x: 0 }; delete o.x; testProp(o);"); |
| 3747 // Test that the named access check is called. |
| 3748 value = CompileRun("testProp(obj);"); |
| 3749 CHECK(value->IsNumber()); |
| 3750 CHECK_EQ(1, value->Int32Value()); |
| 3751 CHECK_EQ(96, named_access_count); |
| 3752 |
| 3753 // Force the call inline cache into dictionary probing mode. |
| 3754 CompileRun("o.f = function() {}; testCallNormal(o)"); |
| 3755 // Test that the named access check is still called for each |
| 3756 // invocation of the function. |
| 3757 value = CompileRun("testCallNormal(obj)"); |
| 3758 CHECK_EQ(106, named_access_count); |
| 3692 | 3759 |
| 3693 context1->Exit(); | 3760 context1->Exit(); |
| 3694 context0->Exit(); | 3761 context0->Exit(); |
| 3695 context1.Dispose(); | 3762 context1.Dispose(); |
| 3696 context0.Dispose(); | 3763 context0.Dispose(); |
| 3697 } | 3764 } |
| 3698 | 3765 |
| 3699 | 3766 |
| 3700 static bool NamedAccessFlatten(Local<v8::Object> global, | 3767 static bool NamedAccessFlatten(Local<v8::Object> global, |
| 3701 Local<Value> name, | 3768 Local<Value> name, |
| (...skipping 1671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5373 templ->SetAccessCheckCallbacks(NamedSetAccessBlocker, | 5440 templ->SetAccessCheckCallbacks(NamedSetAccessBlocker, |
| 5374 IndexedSetAccessBlocker); | 5441 IndexedSetAccessBlocker); |
| 5375 templ->Set(v8_str("x"), v8::True()); | 5442 templ->Set(v8_str("x"), v8::True()); |
| 5376 Local<v8::Object> instance = templ->NewInstance(); | 5443 Local<v8::Object> instance = templ->NewInstance(); |
| 5377 context->Global()->Set(v8_str("obj"), instance); | 5444 context->Global()->Set(v8_str("obj"), instance); |
| 5378 Local<Value> value = CompileRun("obj.x"); | 5445 Local<Value> value = CompileRun("obj.x"); |
| 5379 CHECK(value->BooleanValue()); | 5446 CHECK(value->BooleanValue()); |
| 5380 } | 5447 } |
| 5381 | 5448 |
| 5382 | 5449 |
| 5450 // This tests that access check information remains on the global |
| 5451 // object template when creating contexts. |
| 5452 THREADED_TEST(AccessControlRepeatedContextCreation) { |
| 5453 v8::HandleScope handle_scope; |
| 5454 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
| 5455 global_template->SetAccessCheckCallbacks(NamedSetAccessBlocker, |
| 5456 IndexedSetAccessBlocker); |
| 5457 i::Handle<i::ObjectTemplateInfo> internal_template = |
| 5458 v8::Utils::OpenHandle(*global_template); |
| 5459 CHECK(!internal_template->constructor()->IsUndefined()); |
| 5460 i::Handle<i::FunctionTemplateInfo> constructor( |
| 5461 i::FunctionTemplateInfo::cast(internal_template->constructor())); |
| 5462 CHECK(!constructor->access_check_info()->IsUndefined()); |
| 5463 v8::Persistent<Context> context0 = Context::New(NULL, global_template); |
| 5464 CHECK(!constructor->access_check_info()->IsUndefined()); |
| 5465 } |
| 5466 |
| 5467 |
| 5383 static String::ExternalStringResource* SymbolCallback(const char* chars, | 5468 static String::ExternalStringResource* SymbolCallback(const char* chars, |
| 5384 size_t length) { | 5469 size_t length) { |
| 5385 uint16_t* buffer = i::NewArray<uint16_t>(length + 1); | 5470 uint16_t* buffer = i::NewArray<uint16_t>(length + 1); |
| 5386 for (size_t i = 0; i < length; i++) { | 5471 for (size_t i = 0; i < length; i++) { |
| 5387 buffer[i] = chars[i]; | 5472 buffer[i] = chars[i]; |
| 5388 } | 5473 } |
| 5389 buffer[length] = '\0'; | 5474 buffer[length] = '\0'; |
| 5390 return new TestResource(buffer); | 5475 return new TestResource(buffer); |
| 5391 } | 5476 } |
| 5392 | 5477 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5461 CompileRun("for (var j = 0; j < 10; j++) new RegExp('');"); | 5546 CompileRun("for (var j = 0; j < 10; j++) new RegExp('');"); |
| 5462 } | 5547 } |
| 5463 // Test CallIC. | 5548 // Test CallIC. |
| 5464 for (int i = 0; i < 2; i++) { | 5549 for (int i = 0; i < 2; i++) { |
| 5465 LocalContext context; | 5550 LocalContext context; |
| 5466 context->Global()->Set(v8_str("tmp"), v8::True()); | 5551 context->Global()->Set(v8_str("tmp"), v8::True()); |
| 5467 context->Global()->Delete(v8_str("tmp")); | 5552 context->Global()->Delete(v8_str("tmp")); |
| 5468 CompileRun("for (var j = 0; j < 10; j++) RegExp('')"); | 5553 CompileRun("for (var j = 0; j < 10; j++) RegExp('')"); |
| 5469 } | 5554 } |
| 5470 } | 5555 } |
| OLD | NEW |