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 3620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3631 v8::Persistent<Context> context1 = Context::New(); | 3631 v8::Persistent<Context> context1 = Context::New(); |
3632 context1->Enter(); | 3632 context1->Enter(); |
3633 | 3633 |
3634 // Make easy access to the object from the other environment. | 3634 // Make easy access to the object from the other environment. |
3635 v8::Handle<v8::Object> global1 = context1->Global(); | 3635 v8::Handle<v8::Object> global1 = context1->Global(); |
3636 global1->Set(v8_str("obj"), object); | 3636 global1->Set(v8_str("obj"), object); |
3637 | 3637 |
3638 v8::Handle<Value> value; | 3638 v8::Handle<Value> value; |
3639 | 3639 |
3640 // Check that the named access-control function is called every time. | 3640 // Check that the named access-control function is called every time. |
3641 value = v8_compile("for (var i = 0; i < 10; i++) obj.prop = 1;")->Run(); | 3641 CompileRun("function testProp(obj) {" |
3642 value = v8_compile("for (var i = 0; i < 10; i++) obj.prop;" | 3642 " for (var i = 0; i < 10; i++) obj.prop = 1;" |
3643 "obj.prop")->Run(); | 3643 " for (var j = 0; j < 10; j++) obj.prop;" |
| 3644 " return obj.prop" |
| 3645 "}"); |
| 3646 value = CompileRun("testProp(obj)"); |
3644 CHECK(value->IsNumber()); | 3647 CHECK(value->IsNumber()); |
3645 CHECK_EQ(1, value->Int32Value()); | 3648 CHECK_EQ(1, value->Int32Value()); |
3646 CHECK_EQ(21, named_access_count); | 3649 CHECK_EQ(21, named_access_count); |
3647 | 3650 |
3648 // Check that the named access-control function is called every time. | 3651 // Check that the named access-control function is called every time. |
3649 value = v8_compile("var p = 'prop';")->Run(); | 3652 CompileRun("var p = 'prop';" |
3650 value = v8_compile("for (var i = 0; i < 10; i++) obj[p] = 1;")->Run(); | 3653 "function testKeyed(obj) {" |
3651 value = v8_compile("for (var i = 0; i < 10; i++) obj[p];" | 3654 " for (var i = 0; i < 10; i++) obj[p] = 1;" |
3652 "obj[p]")->Run(); | 3655 " for (var j = 0; j < 10; j++) obj[p];" |
| 3656 " return obj[p];" |
| 3657 "}"); |
| 3658 // Use obj which requires access checks. No inline caching is used |
| 3659 // in that case. |
| 3660 value = CompileRun("testKeyed(obj)"); |
3653 CHECK(value->IsNumber()); | 3661 CHECK(value->IsNumber()); |
3654 CHECK_EQ(1, value->Int32Value()); | 3662 CHECK_EQ(1, value->Int32Value()); |
3655 CHECK_EQ(42, named_access_count); | 3663 CHECK_EQ(42, named_access_count); |
| 3664 // Force the inline caches into generic state and try again. |
| 3665 CompileRun("testKeyed({ a: 0 })"); |
| 3666 CompileRun("testKeyed({ b: 0 })"); |
| 3667 value = CompileRun("testKeyed(obj)"); |
| 3668 CHECK(value->IsNumber()); |
| 3669 CHECK_EQ(1, value->Int32Value()); |
| 3670 CHECK_EQ(63, named_access_count); |
3656 | 3671 |
3657 // Check that the indexed access-control function is called every time. | 3672 // Check that the indexed access-control function is called every time. |
3658 value = v8_compile("for (var i = 0; i < 10; i++) obj[0] = 1;")->Run(); | 3673 CompileRun("function testIndexed(obj) {" |
3659 value = v8_compile("for (var i = 0; i < 10; i++) obj[0];" | 3674 " for (var i = 0; i < 10; i++) obj[0] = 1;" |
3660 "obj[0]")->Run(); | 3675 " for (var j = 0; j < 10; j++) obj[0];" |
| 3676 " return obj[0]" |
| 3677 "}"); |
| 3678 value = CompileRun("testIndexed(obj)"); |
3661 CHECK(value->IsNumber()); | 3679 CHECK(value->IsNumber()); |
3662 CHECK_EQ(1, value->Int32Value()); | 3680 CHECK_EQ(1, value->Int32Value()); |
3663 CHECK_EQ(21, indexed_access_count); | 3681 CHECK_EQ(21, indexed_access_count); |
| 3682 // Force the inline caches into generic state. |
| 3683 CompileRun("testIndexed(new Array(1))"); |
| 3684 // Test that the indexed access check is called. |
| 3685 value = CompileRun("testIndexed(obj)"); |
| 3686 CHECK(value->IsNumber()); |
| 3687 CHECK_EQ(1, value->Int32Value()); |
| 3688 CHECK_EQ(42, indexed_access_count); |
| 3689 |
| 3690 // Check that the named access check is called when invoking |
| 3691 // functions on an object that requires access checks. |
| 3692 CompileRun("obj.f = function() {}"); |
| 3693 CompileRun("function testCallNormal(obj) {" |
| 3694 " for (var i = 0; i < 10; i++) obj.f();" |
| 3695 "}"); |
| 3696 CompileRun("testCallNormal(obj)"); |
| 3697 CHECK_EQ(74, named_access_count); |
| 3698 |
| 3699 // Force obj into slow case. |
| 3700 value = CompileRun("delete obj.prop"); |
| 3701 CHECK(value->BooleanValue()); |
| 3702 // Force inline caches into dictionary probing mode. |
| 3703 CompileRun("var o = { x: 0 }; delete o.x; testProp(o);"); |
| 3704 // Test that the named access check is called. |
| 3705 value = CompileRun("testProp(obj);"); |
| 3706 CHECK(value->IsNumber()); |
| 3707 CHECK_EQ(1, value->Int32Value()); |
| 3708 CHECK_EQ(96, named_access_count); |
| 3709 |
| 3710 // Force the call inline cache into dictionary probing mode. |
| 3711 CompileRun("o.f = function() {}; testCallNormal(o)"); |
| 3712 // Test that the named access check is still called for each |
| 3713 // invocation of the function. |
| 3714 value = CompileRun("testCallNormal(obj)"); |
| 3715 CHECK_EQ(106, named_access_count); |
3664 | 3716 |
3665 context1->Exit(); | 3717 context1->Exit(); |
3666 context0->Exit(); | 3718 context0->Exit(); |
3667 context1.Dispose(); | 3719 context1.Dispose(); |
3668 context0.Dispose(); | 3720 context0.Dispose(); |
3669 } | 3721 } |
3670 | 3722 |
3671 | 3723 |
3672 static bool NamedAccessFlatten(Local<v8::Object> global, | 3724 static bool NamedAccessFlatten(Local<v8::Object> global, |
3673 Local<Value> name, | 3725 Local<Value> name, |
(...skipping 1759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5433 CompileRun("for (var j = 0; j < 10; j++) new RegExp('');"); | 5485 CompileRun("for (var j = 0; j < 10; j++) new RegExp('');"); |
5434 } | 5486 } |
5435 // Test CallIC. | 5487 // Test CallIC. |
5436 for (int i = 0; i < 2; i++) { | 5488 for (int i = 0; i < 2; i++) { |
5437 LocalContext context; | 5489 LocalContext context; |
5438 context->Global()->Set(v8_str("tmp"), v8::True()); | 5490 context->Global()->Set(v8_str("tmp"), v8::True()); |
5439 context->Global()->Delete(v8_str("tmp")); | 5491 context->Global()->Delete(v8_str("tmp")); |
5440 CompileRun("for (var j = 0; j < 10; j++) RegExp('')"); | 5492 CompileRun("for (var j = 0; j < 10; j++) RegExp('')"); |
5441 } | 5493 } |
5442 } | 5494 } |
OLD | NEW |