OLD | NEW |
1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 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 2511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2522 " if (v != 0) throw 'Wrong value ' + v + ' at iteration ' + i;" | 2522 " if (v != 0) throw 'Wrong value ' + v + ' at iteration ' + i;" |
2523 " }" | 2523 " }" |
2524 " 'PASSED'" | 2524 " 'PASSED'" |
2525 "} catch(e) {" | 2525 "} catch(e) {" |
2526 " e" | 2526 " e" |
2527 "}"; | 2527 "}"; |
2528 ExpectString(code, "PASSED"); | 2528 ExpectString(code, "PASSED"); |
2529 } | 2529 } |
2530 | 2530 |
2531 | 2531 |
| 2532 THREADED_TEST(IndexedInterceptorWithAccessorCheck) { |
| 2533 v8::HandleScope scope; |
| 2534 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 2535 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
| 2536 |
| 2537 LocalContext context; |
| 2538 Local<v8::Object> obj = templ->NewInstance(); |
| 2539 obj->TurnOnAccessCheck(); |
| 2540 context->Global()->Set(v8_str("obj"), obj); |
| 2541 |
| 2542 const char* code = |
| 2543 "try {" |
| 2544 " for (var i = 0; i < 100; i++) {" |
| 2545 " var v = obj[0];" |
| 2546 " if (v != undefined) throw 'Wrong value ' + v + ' at iteration ' + i;" |
| 2547 " }" |
| 2548 " 'PASSED'" |
| 2549 "} catch(e) {" |
| 2550 " e" |
| 2551 "}"; |
| 2552 ExpectString(code, "PASSED"); |
| 2553 } |
| 2554 |
| 2555 |
| 2556 THREADED_TEST(IndexedInterceptorWithAccessorCheckSwitchedOn) { |
| 2557 i::FLAG_allow_natives_syntax = true; |
| 2558 v8::HandleScope scope; |
| 2559 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 2560 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
| 2561 |
| 2562 LocalContext context; |
| 2563 Local<v8::Object> obj = templ->NewInstance(); |
| 2564 context->Global()->Set(v8_str("obj"), obj); |
| 2565 |
| 2566 const char* code = |
| 2567 "try {" |
| 2568 " for (var i = 0; i < 100; i++) {" |
| 2569 " var expected = i;" |
| 2570 " if (i == 5) {" |
| 2571 " %EnableAccessChecks(obj);" |
| 2572 " expected = undefined;" |
| 2573 " }" |
| 2574 " var v = obj[i];" |
| 2575 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" |
| 2576 " if (i == 5) %DisableAccessChecks(obj);" |
| 2577 " }" |
| 2578 " 'PASSED'" |
| 2579 "} catch(e) {" |
| 2580 " e" |
| 2581 "}"; |
| 2582 ExpectString(code, "PASSED"); |
| 2583 } |
| 2584 |
| 2585 |
| 2586 THREADED_TEST(IndexedInterceptorWithDifferentIndices) { |
| 2587 v8::HandleScope scope; |
| 2588 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 2589 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
| 2590 |
| 2591 LocalContext context; |
| 2592 Local<v8::Object> obj = templ->NewInstance(); |
| 2593 context->Global()->Set(v8_str("obj"), obj); |
| 2594 |
| 2595 const char* code = |
| 2596 "try {" |
| 2597 " for (var i = 0; i < 100; i++) {" |
| 2598 " var v = obj[i];" |
| 2599 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;" |
| 2600 " }" |
| 2601 " 'PASSED'" |
| 2602 "} catch(e) {" |
| 2603 " e" |
| 2604 "}"; |
| 2605 ExpectString(code, "PASSED"); |
| 2606 } |
| 2607 |
| 2608 |
| 2609 THREADED_TEST(IndexedInterceptorWithNotSmiLookup) { |
| 2610 v8::HandleScope scope; |
| 2611 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 2612 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
| 2613 |
| 2614 LocalContext context; |
| 2615 Local<v8::Object> obj = templ->NewInstance(); |
| 2616 context->Global()->Set(v8_str("obj"), obj); |
| 2617 |
| 2618 const char* code = |
| 2619 "try {" |
| 2620 " for (var i = 0; i < 100; i++) {" |
| 2621 " var expected = i;" |
| 2622 " if (i == 50) {" |
| 2623 " i = 'foobar';" |
| 2624 " expected = undefined;" |
| 2625 " }" |
| 2626 " var v = obj[i];" |
| 2627 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" |
| 2628 " }" |
| 2629 " 'PASSED'" |
| 2630 "} catch(e) {" |
| 2631 " e" |
| 2632 "}"; |
| 2633 ExpectString(code, "PASSED"); |
| 2634 } |
| 2635 |
| 2636 |
| 2637 THREADED_TEST(IndexedInterceptorGoingMegamorphic) { |
| 2638 v8::HandleScope scope; |
| 2639 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 2640 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
| 2641 |
| 2642 LocalContext context; |
| 2643 Local<v8::Object> obj = templ->NewInstance(); |
| 2644 context->Global()->Set(v8_str("obj"), obj); |
| 2645 |
| 2646 const char* code = |
| 2647 "var original = obj;" |
| 2648 "try {" |
| 2649 " for (var i = 0; i < 100; i++) {" |
| 2650 " var expected = i;" |
| 2651 " if (i == 50) {" |
| 2652 " obj = {50: 'foobar'};" |
| 2653 " expected = 'foobar';" |
| 2654 " }" |
| 2655 " var v = obj[i];" |
| 2656 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" |
| 2657 " if (i == 50) obj = original;" |
| 2658 " }" |
| 2659 " 'PASSED'" |
| 2660 "} catch(e) {" |
| 2661 " e" |
| 2662 "}"; |
| 2663 ExpectString(code, "PASSED"); |
| 2664 } |
| 2665 |
| 2666 |
| 2667 THREADED_TEST(IndexedInterceptorReceiverTurningSmi) { |
| 2668 v8::HandleScope scope; |
| 2669 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 2670 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
| 2671 |
| 2672 LocalContext context; |
| 2673 Local<v8::Object> obj = templ->NewInstance(); |
| 2674 context->Global()->Set(v8_str("obj"), obj); |
| 2675 |
| 2676 const char* code = |
| 2677 "var original = obj;" |
| 2678 "try {" |
| 2679 " for (var i = 0; i < 100; i++) {" |
| 2680 " var expected = i;" |
| 2681 " if (i == 5) {" |
| 2682 " obj = 239;" |
| 2683 " expected = undefined;" |
| 2684 " }" |
| 2685 " var v = obj[i];" |
| 2686 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" |
| 2687 " if (i == 5) obj = original;" |
| 2688 " }" |
| 2689 " 'PASSED'" |
| 2690 "} catch(e) {" |
| 2691 " e" |
| 2692 "}"; |
| 2693 ExpectString(code, "PASSED"); |
| 2694 } |
| 2695 |
| 2696 |
| 2697 THREADED_TEST(IndexedInterceptorOnProto) { |
| 2698 v8::HandleScope scope; |
| 2699 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 2700 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
| 2701 |
| 2702 LocalContext context; |
| 2703 Local<v8::Object> obj = templ->NewInstance(); |
| 2704 context->Global()->Set(v8_str("obj"), obj); |
| 2705 |
| 2706 const char* code = |
| 2707 "var o = {__proto__: obj};" |
| 2708 "try {" |
| 2709 " for (var i = 0; i < 100; i++) {" |
| 2710 " var v = o[i];" |
| 2711 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;" |
| 2712 " }" |
| 2713 " 'PASSED'" |
| 2714 "} catch(e) {" |
| 2715 " e" |
| 2716 "}"; |
| 2717 ExpectString(code, "PASSED"); |
| 2718 } |
| 2719 |
| 2720 |
2532 THREADED_TEST(MultiContexts) { | 2721 THREADED_TEST(MultiContexts) { |
2533 v8::HandleScope scope; | 2722 v8::HandleScope scope; |
2534 v8::Handle<ObjectTemplate> templ = ObjectTemplate::New(); | 2723 v8::Handle<ObjectTemplate> templ = ObjectTemplate::New(); |
2535 templ->Set(v8_str("dummy"), v8::FunctionTemplate::New(DummyCallHandler)); | 2724 templ->Set(v8_str("dummy"), v8::FunctionTemplate::New(DummyCallHandler)); |
2536 | 2725 |
2537 Local<String> password = v8_str("Password"); | 2726 Local<String> password = v8_str("Password"); |
2538 | 2727 |
2539 // Create an environment | 2728 // Create an environment |
2540 LocalContext context0(0, templ); | 2729 LocalContext context0(0, templ); |
2541 context0->SetSecurityToken(password); | 2730 context0->SetSecurityToken(password); |
(...skipping 6743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9285 CompileRun(source_exception); | 9474 CompileRun(source_exception); |
9286 other_context->Exit(); | 9475 other_context->Exit(); |
9287 v8::internal::Heap::CollectAllGarbage(false); | 9476 v8::internal::Heap::CollectAllGarbage(false); |
9288 if (GetGlobalObjectsCount() == 1) break; | 9477 if (GetGlobalObjectsCount() == 1) break; |
9289 } | 9478 } |
9290 CHECK_GE(2, gc_count); | 9479 CHECK_GE(2, gc_count); |
9291 CHECK_EQ(1, GetGlobalObjectsCount()); | 9480 CHECK_EQ(1, GetGlobalObjectsCount()); |
9292 | 9481 |
9293 other_context.Dispose(); | 9482 other_context.Dispose(); |
9294 } | 9483 } |
OLD | NEW |