| 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 2436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2447 expected_step_sequence = "bcc"; | 2447 expected_step_sequence = "bcc"; |
| 2448 b->Call(env->Global(), 0, NULL); | 2448 b->Call(env->Global(), 0, NULL); |
| 2449 CHECK_EQ(strlen(expected_step_sequence), break_point_hit_count); | 2449 CHECK_EQ(strlen(expected_step_sequence), break_point_hit_count); |
| 2450 | 2450 |
| 2451 // Step through invocation of d + e. | 2451 // Step through invocation of d + e. |
| 2452 v8::Local<v8::Function> d = CompileFunction(&env, src, "d"); | 2452 v8::Local<v8::Function> d = CompileFunction(&env, src, "d"); |
| 2453 SetBreakPoint(d, 0); | 2453 SetBreakPoint(d, 0); |
| 2454 ChangeBreakOnException(false, true); | 2454 ChangeBreakOnException(false, true); |
| 2455 step_action = StepIn; | 2455 step_action = StepIn; |
| 2456 break_point_hit_count = 0; | 2456 break_point_hit_count = 0; |
| 2457 expected_step_sequence = "ddedd"; | 2457 expected_step_sequence = "dded"; |
| 2458 d->Call(env->Global(), 0, NULL); | 2458 d->Call(env->Global(), 0, NULL); |
| 2459 CHECK_EQ(strlen(expected_step_sequence), break_point_hit_count); | 2459 CHECK_EQ(strlen(expected_step_sequence), break_point_hit_count); |
| 2460 | 2460 |
| 2461 // Step through invocation of d + e now with break on caught exceptions. | 2461 // Step through invocation of d + e now with break on caught exceptions. |
| 2462 ChangeBreakOnException(true, true); | 2462 ChangeBreakOnException(true, true); |
| 2463 step_action = StepIn; | 2463 step_action = StepIn; |
| 2464 break_point_hit_count = 0; | 2464 break_point_hit_count = 0; |
| 2465 expected_step_sequence = "ddeedd"; | 2465 expected_step_sequence = "ddeed"; |
| 2466 d->Call(env->Global(), 0, NULL); | 2466 d->Call(env->Global(), 0, NULL); |
| 2467 CHECK_EQ(strlen(expected_step_sequence), break_point_hit_count); | 2467 CHECK_EQ(strlen(expected_step_sequence), break_point_hit_count); |
| 2468 | 2468 |
| 2469 // Step through invocation of f + g + h. | 2469 // Step through invocation of f + g + h. |
| 2470 v8::Local<v8::Function> f = CompileFunction(&env, src, "f"); | 2470 v8::Local<v8::Function> f = CompileFunction(&env, src, "f"); |
| 2471 SetBreakPoint(f, 0); | 2471 SetBreakPoint(f, 0); |
| 2472 ChangeBreakOnException(false, true); | 2472 ChangeBreakOnException(false, true); |
| 2473 step_action = StepIn; | 2473 step_action = StepIn; |
| 2474 break_point_hit_count = 0; | 2474 break_point_hit_count = 0; |
| 2475 expected_step_sequence = "ffghff"; | 2475 expected_step_sequence = "ffghf"; |
| 2476 f->Call(env->Global(), 0, NULL); | 2476 f->Call(env->Global(), 0, NULL); |
| 2477 CHECK_EQ(strlen(expected_step_sequence), break_point_hit_count); | 2477 CHECK_EQ(strlen(expected_step_sequence), break_point_hit_count); |
| 2478 | 2478 |
| 2479 // Step through invocation of f + g + h now with break on caught exceptions. | 2479 // Step through invocation of f + g + h now with break on caught exceptions. |
| 2480 ChangeBreakOnException(true, true); | 2480 ChangeBreakOnException(true, true); |
| 2481 step_action = StepIn; | 2481 step_action = StepIn; |
| 2482 break_point_hit_count = 0; | 2482 break_point_hit_count = 0; |
| 2483 expected_step_sequence = "ffghhff"; | 2483 expected_step_sequence = "ffghhf"; |
| 2484 f->Call(env->Global(), 0, NULL); | 2484 f->Call(env->Global(), 0, NULL); |
| 2485 CHECK_EQ(strlen(expected_step_sequence), break_point_hit_count); | 2485 CHECK_EQ(strlen(expected_step_sequence), break_point_hit_count); |
| 2486 | 2486 |
| 2487 // Get rid of the debug event listener. | 2487 // Get rid of the debug event listener. |
| 2488 v8::Debug::RemoveDebugEventListener(DebugEventStepSequence); | 2488 v8::Debug::RemoveDebugEventListener(DebugEventStepSequence); |
| 2489 } | 2489 } |
| 2490 | 2490 |
| 2491 | 2491 |
| 2492 TEST(DebugBreak) { | 2492 TEST(DebugBreak) { |
| 2493 v8::HandleScope scope; | 2493 v8::HandleScope scope; |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2739 CHECK(CompileRun(source)->BooleanValue()); | 2739 CHECK(CompileRun(source)->BooleanValue()); |
| 2740 | 2740 |
| 2741 source = "both_values[2].name() == 'c'"; | 2741 source = "both_values[2].name() == 'c'"; |
| 2742 CHECK(CompileRun(source)->BooleanValue()); | 2742 CHECK(CompileRun(source)->BooleanValue()); |
| 2743 | 2743 |
| 2744 source = "both_values[3].name() == 1"; | 2744 source = "both_values[3].name() == 1"; |
| 2745 CHECK(CompileRun(source)->BooleanValue()); | 2745 CHECK(CompileRun(source)->BooleanValue()); |
| 2746 | 2746 |
| 2747 source = "both_values[4].name() == 10"; | 2747 source = "both_values[4].name() == 10"; |
| 2748 CHECK(CompileRun(source)->BooleanValue()); | 2748 CHECK(CompileRun(source)->BooleanValue()); |
| 2749 | |
| 2750 // Check the property values. | |
| 2751 source = "both_values[0].value().value() == 'AA'"; | |
| 2752 CHECK(CompileRun(source)->BooleanValue()); | |
| 2753 | |
| 2754 source = "both_values[1].value().value() == 'BB'"; | |
| 2755 CHECK(CompileRun(source)->BooleanValue()); | |
| 2756 | |
| 2757 source = "both_values[2].value().value() == 'CC'"; | |
| 2758 CHECK(CompileRun(source)->BooleanValue()); | |
| 2759 | |
| 2760 source = "both_values[3].value().value() == 2"; | |
| 2761 CHECK(CompileRun(source)->BooleanValue()); | |
| 2762 | |
| 2763 source = "both_values[4].value().value() == 11"; | |
| 2764 CHECK(CompileRun(source)->BooleanValue()); | |
| 2765 } | 2749 } |
| 2766 | 2750 |
| 2767 | 2751 |
| 2752 TEST(HiddenPrototypePropertyMirror) { |
| 2753 // Create a V8 environment with debug access. |
| 2754 v8::HandleScope scope; |
| 2755 DebugLocalContext env; |
| 2756 env.ExposeDebug(); |
| 2757 |
| 2758 v8::Handle<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(); |
| 2759 t0->InstanceTemplate()->Set(v8::String::New("x"), v8::Number::New(0)); |
| 2760 v8::Handle<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); |
| 2761 t1->SetHiddenPrototype(true); |
| 2762 t1->InstanceTemplate()->Set(v8::String::New("y"), v8::Number::New(1)); |
| 2763 v8::Handle<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(); |
| 2764 t2->SetHiddenPrototype(true); |
| 2765 t2->InstanceTemplate()->Set(v8::String::New("z"), v8::Number::New(2)); |
| 2766 v8::Handle<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(); |
| 2767 t3->InstanceTemplate()->Set(v8::String::New("u"), v8::Number::New(3)); |
| 2768 |
| 2769 // Create object and set them on the global object. |
| 2770 v8::Handle<v8::Object> o0 = t0->GetFunction()->NewInstance(); |
| 2771 env->Global()->Set(v8::String::New("o0"), o0); |
| 2772 v8::Handle<v8::Object> o1 = t1->GetFunction()->NewInstance(); |
| 2773 env->Global()->Set(v8::String::New("o1"), o1); |
| 2774 v8::Handle<v8::Object> o2 = t2->GetFunction()->NewInstance(); |
| 2775 env->Global()->Set(v8::String::New("o2"), o2); |
| 2776 v8::Handle<v8::Object> o3 = t3->GetFunction()->NewInstance(); |
| 2777 env->Global()->Set(v8::String::New("o3"), o3); |
| 2778 |
| 2779 // Get mirrors for the four objects. |
| 2780 CompileRun( |
| 2781 "o0_mirror = debug.MakeMirror(o0);" |
| 2782 "o1_mirror = debug.MakeMirror(o1);" |
| 2783 "o2_mirror = debug.MakeMirror(o2);" |
| 2784 "o3_mirror = debug.MakeMirror(o3)"); |
| 2785 CHECK(CompileRun("o0_mirror instanceof debug.ObjectMirror")->BooleanValue()); |
| 2786 CHECK(CompileRun("o1_mirror instanceof debug.ObjectMirror")->BooleanValue()); |
| 2787 CHECK(CompileRun("o2_mirror instanceof debug.ObjectMirror")->BooleanValue()); |
| 2788 CHECK(CompileRun("o3_mirror instanceof debug.ObjectMirror")->BooleanValue()); |
| 2789 |
| 2790 // Check that each object has one property. |
| 2791 CHECK_EQ(1, CompileRun( |
| 2792 "o0_mirror.propertyNames().length")->Int32Value()); |
| 2793 CHECK_EQ(1, CompileRun( |
| 2794 "o1_mirror.propertyNames().length")->Int32Value()); |
| 2795 CHECK_EQ(1, CompileRun( |
| 2796 "o2_mirror.propertyNames().length")->Int32Value()); |
| 2797 CHECK_EQ(1, CompileRun( |
| 2798 "o3_mirror.propertyNames().length")->Int32Value()); |
| 2799 |
| 2800 // Set o1 as prototype for o0. o1 has the hidden prototype flag so all |
| 2801 // properties on o1 should be seen on o0. |
| 2802 o0->Set(v8::String::New("__proto__"), o1); |
| 2803 CHECK_EQ(2, CompileRun( |
| 2804 "o0_mirror.propertyNames().length")->Int32Value()); |
| 2805 CHECK_EQ(0, CompileRun( |
| 2806 "o0_mirror.property('x').value().value()")->Int32Value()); |
| 2807 CHECK_EQ(1, CompileRun( |
| 2808 "o0_mirror.property('y').value().value()")->Int32Value()); |
| 2809 |
| 2810 // Set o2 as prototype for o0 (it will end up after o1 as o1 has the hidden |
| 2811 // prototype flag. o2 also has the hidden prototype flag so all properties |
| 2812 // on o2 should be seen on o0 as well as properties on o1. |
| 2813 o0->Set(v8::String::New("__proto__"), o2); |
| 2814 CHECK_EQ(3, CompileRun( |
| 2815 "o0_mirror.propertyNames().length")->Int32Value()); |
| 2816 CHECK_EQ(0, CompileRun( |
| 2817 "o0_mirror.property('x').value().value()")->Int32Value()); |
| 2818 CHECK_EQ(1, CompileRun( |
| 2819 "o0_mirror.property('y').value().value()")->Int32Value()); |
| 2820 CHECK_EQ(2, CompileRun( |
| 2821 "o0_mirror.property('z').value().value()")->Int32Value()); |
| 2822 |
| 2823 // Set o3 as prototype for o0 (it will end up after o1 and o2 as both o1 and |
| 2824 // o2 has the hidden prototype flag. o3 does not have the hidden prototype |
| 2825 // flag so properties on o3 should not be seen on o0 whereas the properties |
| 2826 // from o1 and o2 should still be seen on o0. |
| 2827 // Final prototype chain: o0 -> o1 -> o2 -> o3 |
| 2828 // Hidden prototypes: ^^ ^^ |
| 2829 o0->Set(v8::String::New("__proto__"), o3); |
| 2830 CHECK_EQ(3, CompileRun( |
| 2831 "o0_mirror.propertyNames().length")->Int32Value()); |
| 2832 CHECK_EQ(1, CompileRun( |
| 2833 "o3_mirror.propertyNames().length")->Int32Value()); |
| 2834 CHECK_EQ(0, CompileRun( |
| 2835 "o0_mirror.property('x').value().value()")->Int32Value()); |
| 2836 CHECK_EQ(1, CompileRun( |
| 2837 "o0_mirror.property('y').value().value()")->Int32Value()); |
| 2838 CHECK_EQ(2, CompileRun( |
| 2839 "o0_mirror.property('z').value().value()")->Int32Value()); |
| 2840 CHECK(CompileRun("o0_mirror.property('u').isUndefined()")->BooleanValue()); |
| 2841 |
| 2842 // The prototype (__proto__) for o0 should be o3 as o1 and o2 are hidden. |
| 2843 CHECK(CompileRun("o0_mirror.protoObject() == o3_mirror")->BooleanValue()); |
| 2844 } |
| 2845 |
| 2846 |
| 2768 // Multithreaded tests of JSON debugger protocol | 2847 // Multithreaded tests of JSON debugger protocol |
| 2769 | 2848 |
| 2770 // Support classes | 2849 // Support classes |
| 2771 | 2850 |
| 2772 // Copies a C string to a 16-bit string. Does not check for buffer overflow. | 2851 // Copies a C string to a 16-bit string. Does not check for buffer overflow. |
| 2773 // Does not use the V8 engine to convert strings, so it can be used | 2852 // Does not use the V8 engine to convert strings, so it can be used |
| 2774 // in any thread. Returns the length of the string. | 2853 // in any thread. Returns the length of the string. |
| 2775 int AsciiToUtf16(const char* input_buffer, uint16_t* output_buffer) { | 2854 int AsciiToUtf16(const char* input_buffer, uint16_t* output_buffer) { |
| 2776 int i; | 2855 int i; |
| 2777 for (i = 0; input_buffer[i] != '\0'; ++i) { | 2856 for (i = 0; input_buffer[i] != '\0'; ++i) { |
| (...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3420 " CheckSourceLine(2)\n" | 3499 " CheckSourceLine(2)\n" |
| 3421 " CheckSourceLine(3)\n" | 3500 " CheckSourceLine(3)\n" |
| 3422 "}; f()"))->Run(); | 3501 "}; f()"))->Run(); |
| 3423 | 3502 |
| 3424 // Test that a parameter can be passed to a function called in the debugger. | 3503 // Test that a parameter can be passed to a function called in the debugger. |
| 3425 v8::Script::Compile(v8::String::New("CheckDataParameter()"))->Run(); | 3504 v8::Script::Compile(v8::String::New("CheckDataParameter()"))->Run(); |
| 3426 | 3505 |
| 3427 // Test that a function with closure can be run in the debugger. | 3506 // Test that a function with closure can be run in the debugger. |
| 3428 v8::Script::Compile(v8::String::New("CheckClosure()"))->Run(); | 3507 v8::Script::Compile(v8::String::New("CheckClosure()"))->Run(); |
| 3429 } | 3508 } |
| OLD | NEW |