Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: test/cctest/test-debug.cc

Issue 146213004: A64: Synchronize with r16849. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-date.cc ('k') | test/cctest/test-declarative-accessors.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 135
136 136
137 // Helper class for creating a V8 enviromnent for running tests 137 // Helper class for creating a V8 enviromnent for running tests
138 class DebugLocalContext { 138 class DebugLocalContext {
139 public: 139 public:
140 inline DebugLocalContext( 140 inline DebugLocalContext(
141 v8::ExtensionConfiguration* extensions = 0, 141 v8::ExtensionConfiguration* extensions = 0,
142 v8::Handle<v8::ObjectTemplate> global_template = 142 v8::Handle<v8::ObjectTemplate> global_template =
143 v8::Handle<v8::ObjectTemplate>(), 143 v8::Handle<v8::ObjectTemplate>(),
144 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>()) 144 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>())
145 : scope_(v8::Isolate::GetCurrent()), 145 : scope_(CcTest::isolate()),
146 context_( 146 context_(
147 v8::Context::New(v8::Isolate::GetCurrent(), 147 v8::Context::New(CcTest::isolate(),
148 extensions, 148 extensions,
149 global_template, 149 global_template,
150 global_object)) { 150 global_object)) {
151 context_->Enter(); 151 context_->Enter();
152 } 152 }
153 inline ~DebugLocalContext() { 153 inline ~DebugLocalContext() {
154 context_->Exit(); 154 context_->Exit();
155 } 155 }
156 inline v8::Local<v8::Context> context() { return context_; } 156 inline v8::Local<v8::Context> context() { return context_; }
157 inline v8::Context* operator->() { return *context_; } 157 inline v8::Context* operator->() { return *context_; }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 v8::Handle<v8::String> str = v8::String::New(buffer.start()); 295 v8::Handle<v8::String> str = v8::String::New(buffer.start());
296 v8::Handle<v8::Value> value = v8::Script::Compile(str)->Run(); 296 v8::Handle<v8::Value> value = v8::Script::Compile(str)->Run();
297 CHECK(!try_catch.HasCaught()); 297 CHECK(!try_catch.HasCaught());
298 return value->Int32Value(); 298 return value->Int32Value();
299 } 299 }
300 } 300 }
301 301
302 302
303 // Clear a break point. 303 // Clear a break point.
304 static void ClearBreakPoint(int break_point) { 304 static void ClearBreakPoint(int break_point) {
305 v8::internal::Isolate* isolate = v8::internal::Isolate::Current(); 305 v8::internal::Isolate* isolate = CcTest::i_isolate();
306 v8::internal::Debug* debug = isolate->debug(); 306 v8::internal::Debug* debug = isolate->debug();
307 debug->ClearBreakPoint( 307 debug->ClearBreakPoint(
308 Handle<Object>(v8::internal::Smi::FromInt(break_point), isolate)); 308 Handle<Object>(v8::internal::Smi::FromInt(break_point), isolate));
309 } 309 }
310 310
311 311
312 // Clear a break point using the global Debug object. 312 // Clear a break point using the global Debug object.
313 static void ClearBreakPointFromJS(int break_point_number) { 313 static void ClearBreakPointFromJS(int break_point_number) {
314 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer; 314 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer;
315 OS::SNPrintF(buffer, 315 OS::SNPrintF(buffer,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 OS::SNPrintF(buffer, 357 OS::SNPrintF(buffer,
358 "debug.Debug.changeScriptBreakPointIgnoreCount(%d, %d)", 358 "debug.Debug.changeScriptBreakPointIgnoreCount(%d, %d)",
359 break_point_number, ignoreCount); 359 break_point_number, ignoreCount);
360 buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0'; 360 buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0';
361 v8::Script::Compile(v8::String::New(buffer.start()))->Run(); 361 v8::Script::Compile(v8::String::New(buffer.start()))->Run();
362 } 362 }
363 363
364 364
365 // Change break on exception. 365 // Change break on exception.
366 static void ChangeBreakOnException(bool caught, bool uncaught) { 366 static void ChangeBreakOnException(bool caught, bool uncaught) {
367 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); 367 v8::internal::Debug* debug = CcTest::i_isolate()->debug();
368 debug->ChangeBreakOnException(v8::internal::BreakException, caught); 368 debug->ChangeBreakOnException(v8::internal::BreakException, caught);
369 debug->ChangeBreakOnException(v8::internal::BreakUncaughtException, uncaught); 369 debug->ChangeBreakOnException(v8::internal::BreakUncaughtException, uncaught);
370 } 370 }
371 371
372 372
373 // Change break on exception using the global Debug object. 373 // Change break on exception using the global Debug object.
374 static void ChangeBreakOnExceptionFromJS(bool caught, bool uncaught) { 374 static void ChangeBreakOnExceptionFromJS(bool caught, bool uncaught) {
375 if (caught) { 375 if (caught) {
376 v8::Script::Compile( 376 v8::Script::Compile(
377 v8::String::New("debug.Debug.setBreakOnException()"))->Run(); 377 v8::String::New("debug.Debug.setBreakOnException()"))->Run();
378 } else { 378 } else {
379 v8::Script::Compile( 379 v8::Script::Compile(
380 v8::String::New("debug.Debug.clearBreakOnException()"))->Run(); 380 v8::String::New("debug.Debug.clearBreakOnException()"))->Run();
381 } 381 }
382 if (uncaught) { 382 if (uncaught) {
383 v8::Script::Compile( 383 v8::Script::Compile(
384 v8::String::New("debug.Debug.setBreakOnUncaughtException()"))->Run(); 384 v8::String::New("debug.Debug.setBreakOnUncaughtException()"))->Run();
385 } else { 385 } else {
386 v8::Script::Compile( 386 v8::Script::Compile(
387 v8::String::New("debug.Debug.clearBreakOnUncaughtException()"))->Run(); 387 v8::String::New("debug.Debug.clearBreakOnUncaughtException()"))->Run();
388 } 388 }
389 } 389 }
390 390
391 391
392 // Prepare to step to next break location. 392 // Prepare to step to next break location.
393 static void PrepareStep(StepAction step_action) { 393 static void PrepareStep(StepAction step_action) {
394 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); 394 v8::internal::Debug* debug = CcTest::i_isolate()->debug();
395 debug->PrepareStep(step_action, 1, StackFrame::NO_ID); 395 debug->PrepareStep(step_action, 1, StackFrame::NO_ID);
396 } 396 }
397 397
398 398
399 // This function is in namespace v8::internal to be friend with class 399 // This function is in namespace v8::internal to be friend with class
400 // v8::internal::Debug. 400 // v8::internal::Debug.
401 namespace v8 { 401 namespace v8 {
402 namespace internal { 402 namespace internal {
403 403
404 // Collect the currently debugged functions. 404 // Collect the currently debugged functions.
405 Handle<FixedArray> GetDebuggedFunctions() { 405 Handle<FixedArray> GetDebuggedFunctions() {
406 Debug* debug = Isolate::Current()->debug(); 406 Debug* debug = CcTest::i_isolate()->debug();
407 407
408 v8::internal::DebugInfoListNode* node = debug->debug_info_list_; 408 v8::internal::DebugInfoListNode* node = debug->debug_info_list_;
409 409
410 // Find the number of debugged functions. 410 // Find the number of debugged functions.
411 int count = 0; 411 int count = 0;
412 while (node) { 412 while (node) {
413 count++; 413 count++;
414 node = node->next(); 414 node = node->next();
415 } 415 }
416 416
417 // Allocate array for the debugged functions 417 // Allocate array for the debugged functions
418 Handle<FixedArray> debugged_functions = 418 Handle<FixedArray> debugged_functions =
419 Isolate::Current()->factory()->NewFixedArray(count); 419 CcTest::i_isolate()->factory()->NewFixedArray(count);
420 420
421 // Run through the debug info objects and collect all functions. 421 // Run through the debug info objects and collect all functions.
422 count = 0; 422 count = 0;
423 while (node) { 423 while (node) {
424 debugged_functions->set(count++, *node->debug_info()); 424 debugged_functions->set(count++, *node->debug_info());
425 node = node->next(); 425 node = node->next();
426 } 426 }
427 427
428 return debugged_functions; 428 return debugged_functions;
429 } 429 }
430 430
431 431
432 static Handle<Code> ComputeCallDebugBreak(int argc) { 432 static Handle<Code> ComputeCallDebugBreak(int argc) {
433 return Isolate::Current()->stub_cache()->ComputeCallDebugBreak(argc, 433 return CcTest::i_isolate()->stub_cache()->ComputeCallDebugBreak(argc,
434 Code::CALL_IC); 434 Code::CALL_IC);
435 } 435 }
436 436
437 437
438 // Check that the debugger has been fully unloaded. 438 // Check that the debugger has been fully unloaded.
439 void CheckDebuggerUnloaded(bool check_functions) { 439 void CheckDebuggerUnloaded(bool check_functions) {
440 // Check that the debugger context is cleared and that there is no debug 440 // Check that the debugger context is cleared and that there is no debug
441 // information stored for the debugger. 441 // information stored for the debugger.
442 CHECK(Isolate::Current()->debug()->debug_context().is_null()); 442 CHECK(CcTest::i_isolate()->debug()->debug_context().is_null());
443 CHECK_EQ(NULL, Isolate::Current()->debug()->debug_info_list_); 443 CHECK_EQ(NULL, CcTest::i_isolate()->debug()->debug_info_list_);
444 444
445 // Collect garbage to ensure weak handles are cleared. 445 // Collect garbage to ensure weak handles are cleared.
446 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 446 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
447 HEAP->CollectAllGarbage(Heap::kMakeHeapIterableMask); 447 CcTest::heap()->CollectAllGarbage(Heap::kMakeHeapIterableMask);
448 448
449 // Iterate the head and check that there are no debugger related objects left. 449 // Iterate the head and check that there are no debugger related objects left.
450 HeapIterator iterator(HEAP); 450 HeapIterator iterator(CcTest::heap());
451 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { 451 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) {
452 CHECK(!obj->IsDebugInfo()); 452 CHECK(!obj->IsDebugInfo());
453 CHECK(!obj->IsBreakPointInfo()); 453 CHECK(!obj->IsBreakPointInfo());
454 454
455 // If deep check of functions is requested check that no debug break code 455 // If deep check of functions is requested check that no debug break code
456 // is left in all functions. 456 // is left in all functions.
457 if (check_functions) { 457 if (check_functions) {
458 if (obj->IsJSFunction()) { 458 if (obj->IsJSFunction()) {
459 JSFunction* fun = JSFunction::cast(obj); 459 JSFunction* fun = JSFunction::cast(obj);
460 for (RelocIterator it(fun->shared()->code()); !it.done(); it.next()) { 460 for (RelocIterator it(fun->shared()->code()); !it.done(); it.next()) {
461 RelocInfo::Mode rmode = it.rinfo()->rmode(); 461 RelocInfo::Mode rmode = it.rinfo()->rmode();
462 if (RelocInfo::IsCodeTarget(rmode)) { 462 if (RelocInfo::IsCodeTarget(rmode)) {
463 CHECK(!Debug::IsDebugBreak(it.rinfo()->target_address())); 463 CHECK(!Debug::IsDebugBreak(it.rinfo()->target_address()));
464 } else if (RelocInfo::IsJSReturn(rmode)) { 464 } else if (RelocInfo::IsJSReturn(rmode)) {
465 CHECK(!Debug::IsDebugBreakAtReturn(it.rinfo())); 465 CHECK(!Debug::IsDebugBreakAtReturn(it.rinfo()));
466 } 466 }
467 } 467 }
468 } 468 }
469 } 469 }
470 } 470 }
471 } 471 }
472 472
473 473
474 void ForceUnloadDebugger() { 474 void ForceUnloadDebugger() {
475 Isolate::Current()->debugger()->never_unload_debugger_ = false; 475 CcTest::i_isolate()->debugger()->never_unload_debugger_ = false;
476 Isolate::Current()->debugger()->UnloadDebugger(); 476 CcTest::i_isolate()->debugger()->UnloadDebugger();
477 } 477 }
478 478
479 479
480 } } // namespace v8::internal 480 } } // namespace v8::internal
481 481
482 482
483 // Check that the debugger has been fully unloaded. 483 // Check that the debugger has been fully unloaded.
484 static void CheckDebuggerUnloaded(bool check_functions = false) { 484 static void CheckDebuggerUnloaded(bool check_functions = false) {
485 // Let debugger to unload itself synchronously 485 // Let debugger to unload itself synchronously
486 v8::Debug::ProcessDebugMessages(); 486 v8::Debug::ProcessDebugMessages();
(...skipping 14 matching lines...) Expand all
501 } 501 }
502 }; 502 };
503 503
504 504
505 // Compile a function, set a break point and check that the call at the break 505 // Compile a function, set a break point and check that the call at the break
506 // location in the code is the expected debug_break function. 506 // location in the code is the expected debug_break function.
507 void CheckDebugBreakFunction(DebugLocalContext* env, 507 void CheckDebugBreakFunction(DebugLocalContext* env,
508 const char* source, const char* name, 508 const char* source, const char* name,
509 int position, v8::internal::RelocInfo::Mode mode, 509 int position, v8::internal::RelocInfo::Mode mode,
510 Code* debug_break) { 510 Code* debug_break) {
511 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); 511 v8::internal::Debug* debug = CcTest::i_isolate()->debug();
512 512
513 // Create function and set the break point. 513 // Create function and set the break point.
514 Handle<v8::internal::JSFunction> fun = v8::Utils::OpenHandle( 514 Handle<v8::internal::JSFunction> fun = v8::Utils::OpenHandle(
515 *CompileFunction(env, source, name)); 515 *CompileFunction(env, source, name));
516 int bp = SetBreakPoint(fun, position); 516 int bp = SetBreakPoint(fun, position);
517 517
518 // Check that the debug break function is as expected. 518 // Check that the debug break function is as expected.
519 Handle<v8::internal::SharedFunctionInfo> shared(fun->shared()); 519 Handle<v8::internal::SharedFunctionInfo> shared(fun->shared());
520 CHECK(Debug::HasDebugInfo(shared)); 520 CHECK(Debug::HasDebugInfo(shared));
521 TestBreakLocationIterator it1(Debug::GetDebugInfo(shared)); 521 TestBreakLocationIterator it1(Debug::GetDebugInfo(shared));
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 int last_source_column = -1; 667 int last_source_column = -1;
668 668
669 // Debug event handler which counts the break points which have been hit. 669 // Debug event handler which counts the break points which have been hit.
670 int break_point_hit_count = 0; 670 int break_point_hit_count = 0;
671 int break_point_hit_count_deoptimize = 0; 671 int break_point_hit_count_deoptimize = 0;
672 static void DebugEventBreakPointHitCount( 672 static void DebugEventBreakPointHitCount(
673 const v8::Debug::EventDetails& event_details) { 673 const v8::Debug::EventDetails& event_details) {
674 v8::DebugEvent event = event_details.GetEvent(); 674 v8::DebugEvent event = event_details.GetEvent();
675 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState(); 675 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState();
676 v8::Handle<v8::Object> event_data = event_details.GetEventData(); 676 v8::Handle<v8::Object> event_data = event_details.GetEventData();
677 v8::internal::Isolate* isolate = v8::internal::Isolate::Current(); 677 v8::internal::Isolate* isolate = CcTest::i_isolate();
678 Debug* debug = isolate->debug(); 678 Debug* debug = isolate->debug();
679 // When hitting a debug event listener there must be a break set. 679 // When hitting a debug event listener there must be a break set.
680 CHECK_NE(debug->break_id(), 0); 680 CHECK_NE(debug->break_id(), 0);
681 681
682 // Count the number of breaks. 682 // Count the number of breaks.
683 if (event == v8::Break) { 683 if (event == v8::Break) {
684 break_point_hit_count++; 684 break_point_hit_count++;
685 if (!frame_function_name.IsEmpty()) { 685 if (!frame_function_name.IsEmpty()) {
686 // Get the name of the function. 686 // Get the name of the function.
687 const int argc = 2; 687 const int argc = 2;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 break_point_hit_count = 0; 780 break_point_hit_count = 0;
781 exception_hit_count = 0; 781 exception_hit_count = 0;
782 uncaught_exception_hit_count = 0; 782 uncaught_exception_hit_count = 0;
783 } 783 }
784 784
785 static void DebugEventCounter( 785 static void DebugEventCounter(
786 const v8::Debug::EventDetails& event_details) { 786 const v8::Debug::EventDetails& event_details) {
787 v8::DebugEvent event = event_details.GetEvent(); 787 v8::DebugEvent event = event_details.GetEvent();
788 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState(); 788 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState();
789 v8::Handle<v8::Object> event_data = event_details.GetEventData(); 789 v8::Handle<v8::Object> event_data = event_details.GetEventData();
790 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); 790 v8::internal::Debug* debug = CcTest::i_isolate()->debug();
791 791
792 // When hitting a debug event listener there must be a break set. 792 // When hitting a debug event listener there must be a break set.
793 CHECK_NE(debug->break_id(), 0); 793 CHECK_NE(debug->break_id(), 0);
794 794
795 // Count the number of breaks. 795 // Count the number of breaks.
796 if (event == v8::Break) { 796 if (event == v8::Break) {
797 break_point_hit_count++; 797 break_point_hit_count++;
798 } else if (event == v8::Exception) { 798 } else if (event == v8::Exception) {
799 exception_hit_count++; 799 exception_hit_count++;
800 800
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 "function evaluate_check(exec_state, expr, expected) {" 842 "function evaluate_check(exec_state, expr, expected) {"
843 " return exec_state.frame(0).evaluate(expr).value() === expected;" 843 " return exec_state.frame(0).evaluate(expr).value() === expected;"
844 "}"; 844 "}";
845 v8::Local<v8::Function> evaluate_check_function; 845 v8::Local<v8::Function> evaluate_check_function;
846 846
847 // The actual debug event described by the longer comment above. 847 // The actual debug event described by the longer comment above.
848 static void DebugEventEvaluate( 848 static void DebugEventEvaluate(
849 const v8::Debug::EventDetails& event_details) { 849 const v8::Debug::EventDetails& event_details) {
850 v8::DebugEvent event = event_details.GetEvent(); 850 v8::DebugEvent event = event_details.GetEvent();
851 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState(); 851 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState();
852 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); 852 v8::internal::Debug* debug = CcTest::i_isolate()->debug();
853 // When hitting a debug event listener there must be a break set. 853 // When hitting a debug event listener there must be a break set.
854 CHECK_NE(debug->break_id(), 0); 854 CHECK_NE(debug->break_id(), 0);
855 855
856 if (event == v8::Break) { 856 if (event == v8::Break) {
857 for (int i = 0; checks[i].expr != NULL; i++) { 857 for (int i = 0; checks[i].expr != NULL; i++) {
858 const int argc = 3; 858 const int argc = 3;
859 v8::Handle<v8::Value> argv[argc] = { exec_state, 859 v8::Handle<v8::Value> argv[argc] = { exec_state,
860 v8::String::New(checks[i].expr), 860 v8::String::New(checks[i].expr),
861 checks[i].expected }; 861 checks[i].expected };
862 v8::Handle<v8::Value> result = 862 v8::Handle<v8::Value> result =
863 evaluate_check_function->Call(exec_state, argc, argv); 863 evaluate_check_function->Call(exec_state, argc, argv);
864 if (!result->IsTrue()) { 864 if (!result->IsTrue()) {
865 v8::String::Utf8Value utf8(checks[i].expected->ToString()); 865 v8::String::Utf8Value utf8(checks[i].expected->ToString());
866 V8_Fatal(__FILE__, __LINE__, "%s != %s", checks[i].expr, *utf8); 866 V8_Fatal(__FILE__, __LINE__, "%s != %s", checks[i].expr, *utf8);
867 } 867 }
868 } 868 }
869 } 869 }
870 } 870 }
871 871
872 872
873 // This debug event listener removes a breakpoint in a function 873 // This debug event listener removes a breakpoint in a function
874 int debug_event_remove_break_point = 0; 874 int debug_event_remove_break_point = 0;
875 static void DebugEventRemoveBreakPoint( 875 static void DebugEventRemoveBreakPoint(
876 const v8::Debug::EventDetails& event_details) { 876 const v8::Debug::EventDetails& event_details) {
877 v8::DebugEvent event = event_details.GetEvent(); 877 v8::DebugEvent event = event_details.GetEvent();
878 v8::Handle<v8::Value> data = event_details.GetCallbackData(); 878 v8::Handle<v8::Value> data = event_details.GetCallbackData();
879 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); 879 v8::internal::Debug* debug = CcTest::i_isolate()->debug();
880 // When hitting a debug event listener there must be a break set. 880 // When hitting a debug event listener there must be a break set.
881 CHECK_NE(debug->break_id(), 0); 881 CHECK_NE(debug->break_id(), 0);
882 882
883 if (event == v8::Break) { 883 if (event == v8::Break) {
884 break_point_hit_count++; 884 break_point_hit_count++;
885 CHECK(data->IsFunction()); 885 CHECK(data->IsFunction());
886 ClearBreakPoint(debug_event_remove_break_point); 886 ClearBreakPoint(debug_event_remove_break_point);
887 } 887 }
888 } 888 }
889 889
890 890
891 // Debug event handler which counts break points hit and performs a step 891 // Debug event handler which counts break points hit and performs a step
892 // afterwards. 892 // afterwards.
893 StepAction step_action = StepIn; // Step action to perform when stepping. 893 StepAction step_action = StepIn; // Step action to perform when stepping.
894 static void DebugEventStep( 894 static void DebugEventStep(
895 const v8::Debug::EventDetails& event_details) { 895 const v8::Debug::EventDetails& event_details) {
896 v8::DebugEvent event = event_details.GetEvent(); 896 v8::DebugEvent event = event_details.GetEvent();
897 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); 897 v8::internal::Debug* debug = CcTest::i_isolate()->debug();
898 // When hitting a debug event listener there must be a break set. 898 // When hitting a debug event listener there must be a break set.
899 CHECK_NE(debug->break_id(), 0); 899 CHECK_NE(debug->break_id(), 0);
900 900
901 if (event == v8::Break) { 901 if (event == v8::Break) {
902 break_point_hit_count++; 902 break_point_hit_count++;
903 PrepareStep(step_action); 903 PrepareStep(step_action);
904 } 904 }
905 } 905 }
906 906
907 907
908 // Debug event handler which counts break points hit and performs a step 908 // Debug event handler which counts break points hit and performs a step
909 // afterwards. For each call the expected function is checked. 909 // afterwards. For each call the expected function is checked.
910 // For this debug event handler to work the following two global varaibles 910 // For this debug event handler to work the following two global varaibles
911 // must be initialized. 911 // must be initialized.
912 // expected_step_sequence: An array of the expected function call sequence. 912 // expected_step_sequence: An array of the expected function call sequence.
913 // frame_function_name: A JavaScript function (see below). 913 // frame_function_name: A JavaScript function (see below).
914 914
915 // String containing the expected function call sequence. Note: this only works 915 // String containing the expected function call sequence. Note: this only works
916 // if functions have name length of one. 916 // if functions have name length of one.
917 const char* expected_step_sequence = NULL; 917 const char* expected_step_sequence = NULL;
918 918
919 // The actual debug event described by the longer comment above. 919 // The actual debug event described by the longer comment above.
920 static void DebugEventStepSequence( 920 static void DebugEventStepSequence(
921 const v8::Debug::EventDetails& event_details) { 921 const v8::Debug::EventDetails& event_details) {
922 v8::DebugEvent event = event_details.GetEvent(); 922 v8::DebugEvent event = event_details.GetEvent();
923 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState(); 923 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState();
924 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); 924 v8::internal::Debug* debug = CcTest::i_isolate()->debug();
925 // When hitting a debug event listener there must be a break set. 925 // When hitting a debug event listener there must be a break set.
926 CHECK_NE(debug->break_id(), 0); 926 CHECK_NE(debug->break_id(), 0);
927 927
928 if (event == v8::Break || event == v8::Exception) { 928 if (event == v8::Break || event == v8::Exception) {
929 // Check that the current function is the expected. 929 // Check that the current function is the expected.
930 CHECK(break_point_hit_count < 930 CHECK(break_point_hit_count <
931 StrLength(expected_step_sequence)); 931 StrLength(expected_step_sequence));
932 const int argc = 2; 932 const int argc = 2;
933 v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(0) }; 933 v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(0) };
934 v8::Handle<v8::Value> result = frame_function_name->Call(exec_state, 934 v8::Handle<v8::Value> result = frame_function_name->Call(exec_state,
935 argc, argv); 935 argc, argv);
936 CHECK(result->IsString()); 936 CHECK(result->IsString());
937 v8::String::Utf8Value function_name(result->ToString()); 937 v8::String::Utf8Value function_name(result->ToString());
938 CHECK_EQ(1, StrLength(*function_name)); 938 CHECK_EQ(1, StrLength(*function_name));
939 CHECK_EQ((*function_name)[0], 939 CHECK_EQ((*function_name)[0],
940 expected_step_sequence[break_point_hit_count]); 940 expected_step_sequence[break_point_hit_count]);
941 941
942 // Perform step. 942 // Perform step.
943 break_point_hit_count++; 943 break_point_hit_count++;
944 PrepareStep(step_action); 944 PrepareStep(step_action);
945 } 945 }
946 } 946 }
947 947
948 948
949 // Debug event handler which performs a garbage collection. 949 // Debug event handler which performs a garbage collection.
950 static void DebugEventBreakPointCollectGarbage( 950 static void DebugEventBreakPointCollectGarbage(
951 const v8::Debug::EventDetails& event_details) { 951 const v8::Debug::EventDetails& event_details) {
952 v8::DebugEvent event = event_details.GetEvent(); 952 v8::DebugEvent event = event_details.GetEvent();
953 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); 953 v8::internal::Debug* debug = CcTest::i_isolate()->debug();
954 // When hitting a debug event listener there must be a break set. 954 // When hitting a debug event listener there must be a break set.
955 CHECK_NE(debug->break_id(), 0); 955 CHECK_NE(debug->break_id(), 0);
956 956
957 // Perform a garbage collection when break point is hit and continue. Based 957 // Perform a garbage collection when break point is hit and continue. Based
958 // on the number of break points hit either scavenge or mark compact 958 // on the number of break points hit either scavenge or mark compact
959 // collector is used. 959 // collector is used.
960 if (event == v8::Break) { 960 if (event == v8::Break) {
961 break_point_hit_count++; 961 break_point_hit_count++;
962 if (break_point_hit_count % 2 == 0) { 962 if (break_point_hit_count % 2 == 0) {
963 // Scavenge. 963 // Scavenge.
964 HEAP->CollectGarbage(v8::internal::NEW_SPACE); 964 CcTest::heap()->CollectGarbage(v8::internal::NEW_SPACE);
965 } else { 965 } else {
966 // Mark sweep compact. 966 // Mark sweep compact.
967 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 967 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
968 } 968 }
969 } 969 }
970 } 970 }
971 971
972 972
973 // Debug event handler which re-issues a debug break and calls the garbage 973 // Debug event handler which re-issues a debug break and calls the garbage
974 // collector to have the heap verified. 974 // collector to have the heap verified.
975 static void DebugEventBreak( 975 static void DebugEventBreak(
976 const v8::Debug::EventDetails& event_details) { 976 const v8::Debug::EventDetails& event_details) {
977 v8::DebugEvent event = event_details.GetEvent(); 977 v8::DebugEvent event = event_details.GetEvent();
978 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); 978 v8::internal::Debug* debug = CcTest::i_isolate()->debug();
979 // When hitting a debug event listener there must be a break set. 979 // When hitting a debug event listener there must be a break set.
980 CHECK_NE(debug->break_id(), 0); 980 CHECK_NE(debug->break_id(), 0);
981 981
982 if (event == v8::Break) { 982 if (event == v8::Break) {
983 // Count the number of breaks. 983 // Count the number of breaks.
984 break_point_hit_count++; 984 break_point_hit_count++;
985 985
986 // Run the garbage collector to enforce heap verification if option 986 // Run the garbage collector to enforce heap verification if option
987 // --verify-heap is set. 987 // --verify-heap is set.
988 HEAP->CollectGarbage(v8::internal::NEW_SPACE); 988 CcTest::heap()->CollectGarbage(v8::internal::NEW_SPACE);
989 989
990 // Set the break flag again to come back here as soon as possible. 990 // Set the break flag again to come back here as soon as possible.
991 v8::Debug::DebugBreak(); 991 v8::Debug::DebugBreak(CcTest::isolate());
992 } 992 }
993 } 993 }
994 994
995 995
996 // Debug event handler which re-issues a debug break until a limit has been 996 // Debug event handler which re-issues a debug break until a limit has been
997 // reached. 997 // reached.
998 int max_break_point_hit_count = 0; 998 int max_break_point_hit_count = 0;
999 bool terminate_after_max_break_point_hit = false; 999 bool terminate_after_max_break_point_hit = false;
1000 static void DebugEventBreakMax( 1000 static void DebugEventBreakMax(
1001 const v8::Debug::EventDetails& event_details) { 1001 const v8::Debug::EventDetails& event_details) {
1002 v8::DebugEvent event = event_details.GetEvent(); 1002 v8::DebugEvent event = event_details.GetEvent();
1003 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState(); 1003 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState();
1004 v8::internal::Isolate* isolate = v8::internal::Isolate::Current(); 1004 v8::Isolate* v8_isolate = CcTest::isolate();
1005 v8::internal::Isolate* isolate = CcTest::i_isolate();
1005 v8::internal::Debug* debug = isolate->debug(); 1006 v8::internal::Debug* debug = isolate->debug();
1006 // When hitting a debug event listener there must be a break set. 1007 // When hitting a debug event listener there must be a break set.
1007 CHECK_NE(debug->break_id(), 0); 1008 CHECK_NE(debug->break_id(), 0);
1008 1009
1009 if (event == v8::Break) { 1010 if (event == v8::Break) {
1010 if (break_point_hit_count < max_break_point_hit_count) { 1011 if (break_point_hit_count < max_break_point_hit_count) {
1011 // Count the number of breaks. 1012 // Count the number of breaks.
1012 break_point_hit_count++; 1013 break_point_hit_count++;
1013 1014
1014 // Collect the JavsScript stack height if the function frame_count is 1015 // Collect the JavsScript stack height if the function frame_count is
1015 // compiled. 1016 // compiled.
1016 if (!frame_count.IsEmpty()) { 1017 if (!frame_count.IsEmpty()) {
1017 static const int kArgc = 1; 1018 static const int kArgc = 1;
1018 v8::Handle<v8::Value> argv[kArgc] = { exec_state }; 1019 v8::Handle<v8::Value> argv[kArgc] = { exec_state };
1019 // Using exec_state as receiver is just to have a receiver. 1020 // Using exec_state as receiver is just to have a receiver.
1020 v8::Handle<v8::Value> result = 1021 v8::Handle<v8::Value> result =
1021 frame_count->Call(exec_state, kArgc, argv); 1022 frame_count->Call(exec_state, kArgc, argv);
1022 last_js_stack_height = result->Int32Value(); 1023 last_js_stack_height = result->Int32Value();
1023 } 1024 }
1024 1025
1025 // Set the break flag again to come back here as soon as possible. 1026 // Set the break flag again to come back here as soon as possible.
1026 v8::Debug::DebugBreak(); 1027 v8::Debug::DebugBreak(v8_isolate);
1027 1028
1028 } else if (terminate_after_max_break_point_hit) { 1029 } else if (terminate_after_max_break_point_hit) {
1029 // Terminate execution after the last break if requested. 1030 // Terminate execution after the last break if requested.
1030 v8::V8::TerminateExecution(); 1031 v8::V8::TerminateExecution(v8_isolate);
1031 } 1032 }
1032 1033
1033 // Perform a full deoptimization when the specified number of 1034 // Perform a full deoptimization when the specified number of
1034 // breaks have been hit. 1035 // breaks have been hit.
1035 if (break_point_hit_count == break_point_hit_count_deoptimize) { 1036 if (break_point_hit_count == break_point_hit_count_deoptimize) {
1036 i::Deoptimizer::DeoptimizeAll(isolate); 1037 i::Deoptimizer::DeoptimizeAll(isolate);
1037 } 1038 }
1038 } 1039 }
1039 } 1040 }
1040 1041
(...skipping 27 matching lines...) Expand all
1068 1069
1069 CheckDebugBreakFunction(&env, 1070 CheckDebugBreakFunction(&env,
1070 "function f1(){}", "f1", 1071 "function f1(){}", "f1",
1071 0, 1072 0,
1072 v8::internal::RelocInfo::JS_RETURN, 1073 v8::internal::RelocInfo::JS_RETURN,
1073 NULL); 1074 NULL);
1074 CheckDebugBreakFunction(&env, 1075 CheckDebugBreakFunction(&env,
1075 "function f2(){x=1;}", "f2", 1076 "function f2(){x=1;}", "f2",
1076 0, 1077 0,
1077 v8::internal::RelocInfo::CODE_TARGET_CONTEXT, 1078 v8::internal::RelocInfo::CODE_TARGET_CONTEXT,
1078 Isolate::Current()->builtins()->builtin( 1079 CcTest::i_isolate()->builtins()->builtin(
1079 Builtins::kStoreIC_DebugBreak)); 1080 Builtins::kStoreIC_DebugBreak));
1080 CheckDebugBreakFunction(&env, 1081 CheckDebugBreakFunction(&env,
1081 "function f3(){var a=x;}", "f3", 1082 "function f3(){var a=x;}", "f3",
1082 0, 1083 0,
1083 v8::internal::RelocInfo::CODE_TARGET_CONTEXT, 1084 v8::internal::RelocInfo::CODE_TARGET_CONTEXT,
1084 Isolate::Current()->builtins()->builtin( 1085 CcTest::i_isolate()->builtins()->builtin(
1085 Builtins::kLoadIC_DebugBreak)); 1086 Builtins::kLoadIC_DebugBreak));
1086 1087
1087 // TODO(1240753): Make the test architecture independent or split 1088 // TODO(1240753): Make the test architecture independent or split
1088 // parts of the debugger into architecture dependent files. This 1089 // parts of the debugger into architecture dependent files. This
1089 // part currently disabled as it is not portable between IA32/ARM. 1090 // part currently disabled as it is not portable between IA32/ARM.
1090 // Currently on ICs for keyed store/load on ARM. 1091 // Currently on ICs for keyed store/load on ARM.
1091 #if !defined (__arm__) && !defined(__thumb__) 1092 #if !defined (__arm__) && !defined(__thumb__)
1092 CheckDebugBreakFunction( 1093 CheckDebugBreakFunction(
1093 &env, 1094 &env,
1094 "function f4(){var index='propertyName'; var a={}; a[index] = 'x';}", 1095 "function f4(){var index='propertyName'; var a={}; a[index] = 'x';}",
1095 "f4", 1096 "f4",
1096 0, 1097 0,
1097 v8::internal::RelocInfo::CODE_TARGET, 1098 v8::internal::RelocInfo::CODE_TARGET,
1098 Isolate::Current()->builtins()->builtin( 1099 CcTest::i_isolate()->builtins()->builtin(
1099 Builtins::kKeyedStoreIC_DebugBreak)); 1100 Builtins::kKeyedStoreIC_DebugBreak));
1100 CheckDebugBreakFunction( 1101 CheckDebugBreakFunction(
1101 &env, 1102 &env,
1102 "function f5(){var index='propertyName'; var a={}; return a[index];}", 1103 "function f5(){var index='propertyName'; var a={}; return a[index];}",
1103 "f5", 1104 "f5",
1104 0, 1105 0,
1105 v8::internal::RelocInfo::CODE_TARGET, 1106 v8::internal::RelocInfo::CODE_TARGET,
1106 Isolate::Current()->builtins()->builtin( 1107 CcTest::i_isolate()->builtins()->builtin(
1107 Builtins::kKeyedLoadIC_DebugBreak)); 1108 Builtins::kKeyedLoadIC_DebugBreak));
1108 #endif 1109 #endif
1109 1110
1110 CheckDebugBreakFunction( 1111 CheckDebugBreakFunction(
1111 &env, 1112 &env,
1112 "function f6(a){return a==null;}", 1113 "function f6(a){return a==null;}",
1113 "f6", 1114 "f6",
1114 0, 1115 0,
1115 v8::internal::RelocInfo::CODE_TARGET, 1116 v8::internal::RelocInfo::CODE_TARGET,
1116 Isolate::Current()->builtins()->builtin( 1117 CcTest::i_isolate()->builtins()->builtin(
1117 Builtins::kCompareNilIC_DebugBreak)); 1118 Builtins::kCompareNilIC_DebugBreak));
1118 1119
1119 // Check the debug break code stubs for call ICs with different number of 1120 // Check the debug break code stubs for call ICs with different number of
1120 // parameters. 1121 // parameters.
1121 Handle<Code> debug_break_0 = v8::internal::ComputeCallDebugBreak(0); 1122 Handle<Code> debug_break_0 = v8::internal::ComputeCallDebugBreak(0);
1122 Handle<Code> debug_break_1 = v8::internal::ComputeCallDebugBreak(1); 1123 Handle<Code> debug_break_1 = v8::internal::ComputeCallDebugBreak(1);
1123 Handle<Code> debug_break_4 = v8::internal::ComputeCallDebugBreak(4); 1124 Handle<Code> debug_break_4 = v8::internal::ComputeCallDebugBreak(4);
1124 1125
1125 CheckDebugBreakFunction(&env, 1126 CheckDebugBreakFunction(&env,
1126 "function f4_0(){x();}", "f4_0", 1127 "function f4_0(){x();}", "f4_0",
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 static void CallAndGC(v8::Local<v8::Object> recv, 1443 static void CallAndGC(v8::Local<v8::Object> recv,
1443 v8::Local<v8::Function> f) { 1444 v8::Local<v8::Function> f) {
1444 break_point_hit_count = 0; 1445 break_point_hit_count = 0;
1445 1446
1446 for (int i = 0; i < 3; i++) { 1447 for (int i = 0; i < 3; i++) {
1447 // Call function. 1448 // Call function.
1448 f->Call(recv, 0, NULL); 1449 f->Call(recv, 0, NULL);
1449 CHECK_EQ(1 + i * 3, break_point_hit_count); 1450 CHECK_EQ(1 + i * 3, break_point_hit_count);
1450 1451
1451 // Scavenge and call function. 1452 // Scavenge and call function.
1452 HEAP->CollectGarbage(v8::internal::NEW_SPACE); 1453 CcTest::heap()->CollectGarbage(v8::internal::NEW_SPACE);
1453 f->Call(recv, 0, NULL); 1454 f->Call(recv, 0, NULL);
1454 CHECK_EQ(2 + i * 3, break_point_hit_count); 1455 CHECK_EQ(2 + i * 3, break_point_hit_count);
1455 1456
1456 // Mark sweep (and perhaps compact) and call function. 1457 // Mark sweep (and perhaps compact) and call function.
1457 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 1458 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
1458 f->Call(recv, 0, NULL); 1459 f->Call(recv, 0, NULL);
1459 CHECK_EQ(3 + i * 3, break_point_hit_count); 1460 CHECK_EQ(3 + i * 3, break_point_hit_count);
1460 } 1461 }
1461 } 1462 }
1462 1463
1463 1464
1464 // Test that a break point can be set at a return store location. 1465 // Test that a break point can be set at a return store location.
1465 TEST(BreakPointSurviveGC) { 1466 TEST(BreakPointSurviveGC) {
1466 break_point_hit_count = 0; 1467 break_point_hit_count = 0;
1467 DebugLocalContext env; 1468 DebugLocalContext env;
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
2251 " a = 1; // line 1\n" 2252 " a = 1; // line 1\n"
2252 "}\n" 2253 "}\n"
2253 "a = 2; // line 3\n"); 2254 "a = 2; // line 3\n");
2254 v8::Local<v8::Function> f; 2255 v8::Local<v8::Function> f;
2255 { 2256 {
2256 v8::HandleScope scope(env->GetIsolate()); 2257 v8::HandleScope scope(env->GetIsolate());
2257 v8::Script::Compile(script, v8::String::New("test.html"))->Run(); 2258 v8::Script::Compile(script, v8::String::New("test.html"))->Run();
2258 } 2259 }
2259 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); 2260 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
2260 2261
2261 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 2262 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
2262 2263
2263 SetScriptBreakPointByNameFromJS("test.html", 3, -1); 2264 SetScriptBreakPointByNameFromJS("test.html", 3, -1);
2264 2265
2265 // Call f and check that there was no break points. 2266 // Call f and check that there was no break points.
2266 break_point_hit_count = 0; 2267 break_point_hit_count = 0;
2267 f->Call(env->Global(), 0, NULL); 2268 f->Call(env->Global(), 0, NULL);
2268 CHECK_EQ(0, break_point_hit_count); 2269 CHECK_EQ(0, break_point_hit_count);
2269 2270
2270 // Recompile and run script and check that break point was hit. 2271 // Recompile and run script and check that break point was hit.
2271 break_point_hit_count = 0; 2272 break_point_hit_count = 0;
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
2544 CheckDebuggerUnloaded(); 2545 CheckDebuggerUnloaded();
2545 } 2546 }
2546 2547
2547 2548
2548 bool checkedDebugEvals = true; 2549 bool checkedDebugEvals = true;
2549 v8::Handle<v8::Function> checkGlobalEvalFunction; 2550 v8::Handle<v8::Function> checkGlobalEvalFunction;
2550 v8::Handle<v8::Function> checkFrameEvalFunction; 2551 v8::Handle<v8::Function> checkFrameEvalFunction;
2551 static void CheckDebugEval(const v8::Debug::EventDetails& eventDetails) { 2552 static void CheckDebugEval(const v8::Debug::EventDetails& eventDetails) {
2552 if (eventDetails.GetEvent() == v8::Break) { 2553 if (eventDetails.GetEvent() == v8::Break) {
2553 ++debugEventCount; 2554 ++debugEventCount;
2554 v8::HandleScope handleScope(v8::Isolate::GetCurrent()); 2555 v8::HandleScope handleScope(CcTest::isolate());
2555 2556
2556 v8::Handle<v8::Value> args[] = { eventDetails.GetExecutionState() }; 2557 v8::Handle<v8::Value> args[] = { eventDetails.GetExecutionState() };
2557 CHECK(checkGlobalEvalFunction->Call( 2558 CHECK(checkGlobalEvalFunction->Call(
2558 eventDetails.GetEventContext()->Global(), 1, args)->IsTrue()); 2559 eventDetails.GetEventContext()->Global(), 1, args)->IsTrue());
2559 CHECK(checkFrameEvalFunction->Call( 2560 CHECK(checkFrameEvalFunction->Call(
2560 eventDetails.GetEventContext()->Global(), 1, args)->IsTrue()); 2561 eventDetails.GetEventContext()->Global(), 1, args)->IsTrue());
2561 } 2562 }
2562 } 2563 }
2563 2564
2564 2565
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
2719 uint16_t buffer[kBufferSize]; 2720 uint16_t buffer[kBufferSize];
2720 2721
2721 const char* command_111 = "{\"seq\":111," 2722 const char* command_111 = "{\"seq\":111,"
2722 "\"type\":\"request\"," 2723 "\"type\":\"request\","
2723 "\"command\":\"evaluate\"," 2724 "\"command\":\"evaluate\","
2724 "\"arguments\":{" 2725 "\"arguments\":{"
2725 " \"global\":true," 2726 " \"global\":true,"
2726 " \"expression\":\"v1\",\"disable_break\":true" 2727 " \"expression\":\"v1\",\"disable_break\":true"
2727 "}}"; 2728 "}}";
2728 2729
2729 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_111, buffer)); 2730 v8::Isolate* isolate = CcTest::isolate();
2731 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_111, buffer));
2730 2732
2731 const char* command_112 = "{\"seq\":112," 2733 const char* command_112 = "{\"seq\":112,"
2732 "\"type\":\"request\"," 2734 "\"type\":\"request\","
2733 "\"command\":\"evaluate\"," 2735 "\"command\":\"evaluate\","
2734 "\"arguments\":{" 2736 "\"arguments\":{"
2735 " \"global\":true," 2737 " \"global\":true,"
2736 " \"expression\":\"getAnimal()\",\"disable_break\":true" 2738 " \"expression\":\"getAnimal()\",\"disable_break\":true"
2737 "}}"; 2739 "}}";
2738 2740
2739 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_112, buffer)); 2741 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_112, buffer));
2740 2742
2741 const char* command_113 = "{\"seq\":113," 2743 const char* command_113 = "{\"seq\":113,"
2742 "\"type\":\"request\"," 2744 "\"type\":\"request\","
2743 "\"command\":\"evaluate\"," 2745 "\"command\":\"evaluate\","
2744 "\"arguments\":{" 2746 "\"arguments\":{"
2745 " \"global\":true," 2747 " \"global\":true,"
2746 " \"expression\":\"239 + 566\",\"disable_break\":true" 2748 " \"expression\":\"239 + 566\",\"disable_break\":true"
2747 "}}"; 2749 "}}";
2748 2750
2749 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_113, buffer)); 2751 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_113, buffer));
2750 2752
2751 v8::Debug::ProcessDebugMessages(); 2753 v8::Debug::ProcessDebugMessages();
2752 2754
2753 CHECK_EQ(3, process_debug_messages_data.counter); 2755 CHECK_EQ(3, process_debug_messages_data.counter);
2754 2756
2755 CHECK_EQ(strcmp("Pinguin", process_debug_messages_data.results[0].buffer), 0); 2757 CHECK_EQ(strcmp("Pinguin", process_debug_messages_data.results[0].buffer), 0);
2756 CHECK_EQ(strcmp("Capybara", process_debug_messages_data.results[1].buffer), 2758 CHECK_EQ(strcmp("Capybara", process_debug_messages_data.results[1].buffer),
2757 0); 2759 0);
2758 CHECK_EQ(strcmp("805", process_debug_messages_data.results[2].buffer), 0); 2760 CHECK_EQ(strcmp("805", process_debug_messages_data.results[2].buffer), 0);
2759 2761
(...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after
3838 // of debug event exception callbacks and message callbacks are collected. The 3840 // of debug event exception callbacks and message callbacks are collected. The
3839 // number of debug event exception callbacks are used to check that the 3841 // number of debug event exception callbacks are used to check that the
3840 // debugger is called correctly and the number of message callbacks is used to 3842 // debugger is called correctly and the number of message callbacks is used to
3841 // check that uncaught exceptions are still returned even if there is a break 3843 // check that uncaught exceptions are still returned even if there is a break
3842 // for them. 3844 // for them.
3843 TEST(BreakOnException) { 3845 TEST(BreakOnException) {
3844 DebugLocalContext env; 3846 DebugLocalContext env;
3845 v8::HandleScope scope(env->GetIsolate()); 3847 v8::HandleScope scope(env->GetIsolate());
3846 env.ExposeDebug(); 3848 env.ExposeDebug();
3847 3849
3848 v8::internal::Isolate::Current()->TraceException(false); 3850 CcTest::i_isolate()->TraceException(false);
3849 3851
3850 // Create functions for testing break on exception. 3852 // Create functions for testing break on exception.
3851 CompileFunction(&env, "function throws(){throw 1;}", "throws"); 3853 CompileFunction(&env, "function throws(){throw 1;}", "throws");
3852 v8::Local<v8::Function> caught = 3854 v8::Local<v8::Function> caught =
3853 CompileFunction(&env, 3855 CompileFunction(&env,
3854 "function caught(){try {throws();} catch(e) {};}", 3856 "function caught(){try {throws();} catch(e) {};}",
3855 "caught"); 3857 "caught");
3856 v8::Local<v8::Function> notCaught = 3858 v8::Local<v8::Function> notCaught =
3857 CompileFunction(&env, "function notCaught(){throws();}", "notCaught"); 3859 CompileFunction(&env, "function notCaught(){throws();}", "notCaught");
3858 3860
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
3984 // Test break on exception from compiler errors. When compiling using 3986 // Test break on exception from compiler errors. When compiling using
3985 // v8::Script::Compile there is no JavaScript stack whereas when compiling using 3987 // v8::Script::Compile there is no JavaScript stack whereas when compiling using
3986 // eval there are JavaScript frames. 3988 // eval there are JavaScript frames.
3987 TEST(BreakOnCompileException) { 3989 TEST(BreakOnCompileException) {
3988 DebugLocalContext env; 3990 DebugLocalContext env;
3989 v8::HandleScope scope(env->GetIsolate()); 3991 v8::HandleScope scope(env->GetIsolate());
3990 3992
3991 // For this test, we want to break on uncaught exceptions: 3993 // For this test, we want to break on uncaught exceptions:
3992 ChangeBreakOnException(false, true); 3994 ChangeBreakOnException(false, true);
3993 3995
3994 v8::internal::Isolate::Current()->TraceException(false); 3996 CcTest::i_isolate()->TraceException(false);
3995 3997
3996 // Create a function for checking the function when hitting a break point. 3998 // Create a function for checking the function when hitting a break point.
3997 frame_count = CompileFunction(&env, frame_count_source, "frame_count"); 3999 frame_count = CompileFunction(&env, frame_count_source, "frame_count");
3998 4000
3999 v8::V8::AddMessageListener(MessageCallbackCount); 4001 v8::V8::AddMessageListener(MessageCallbackCount);
4000 v8::Debug::SetDebugEventListener2(DebugEventCounter); 4002 v8::Debug::SetDebugEventListener2(DebugEventCounter);
4001 4003
4002 DebugEventCounterClear(); 4004 DebugEventCounterClear();
4003 MessageCallbackCountClear(); 4005 MessageCallbackCountClear();
4004 4006
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
4155 v8::Number::New(1), 4157 v8::Number::New(1),
4156 v8::Number::New(1) }; 4158 v8::Number::New(1) };
4157 4159
4158 // Call all functions to make sure that they are compiled. 4160 // Call all functions to make sure that they are compiled.
4159 f0->Call(env->Global(), 0, NULL); 4161 f0->Call(env->Global(), 0, NULL);
4160 f1->Call(env->Global(), 0, NULL); 4162 f1->Call(env->Global(), 0, NULL);
4161 f2->Call(env->Global(), 0, NULL); 4163 f2->Call(env->Global(), 0, NULL);
4162 f3->Call(env->Global(), 0, NULL); 4164 f3->Call(env->Global(), 0, NULL);
4163 4165
4164 // Set the debug break flag. 4166 // Set the debug break flag.
4165 v8::Debug::DebugBreak(); 4167 v8::Debug::DebugBreak(env->GetIsolate());
4166 4168
4167 // Call all functions with different argument count. 4169 // Call all functions with different argument count.
4168 break_point_hit_count = 0; 4170 break_point_hit_count = 0;
4169 for (unsigned int i = 0; i < ARRAY_SIZE(argv); i++) { 4171 for (unsigned int i = 0; i < ARRAY_SIZE(argv); i++) {
4170 f0->Call(env->Global(), i, argv); 4172 f0->Call(env->Global(), i, argv);
4171 f1->Call(env->Global(), i, argv); 4173 f1->Call(env->Global(), i, argv);
4172 f2->Call(env->Global(), i, argv); 4174 f2->Call(env->Global(), i, argv);
4173 f3->Call(env->Global(), i, argv); 4175 f3->Call(env->Global(), i, argv);
4174 } 4176 }
4175 4177
(...skipping 13 matching lines...) Expand all
4189 v8::HandleScope scope(env->GetIsolate()); 4191 v8::HandleScope scope(env->GetIsolate());
4190 4192
4191 // Register a debug event listener which sets the break flag and counts. 4193 // Register a debug event listener which sets the break flag and counts.
4192 v8::Debug::SetDebugEventListener2(DebugEventCounter); 4194 v8::Debug::SetDebugEventListener2(DebugEventCounter);
4193 4195
4194 // Create a function for testing stepping. 4196 // Create a function for testing stepping.
4195 const char* src = "function f() {g()};function g(){i=0; while(i<10){i++}}"; 4197 const char* src = "function f() {g()};function g(){i=0; while(i<10){i++}}";
4196 v8::Local<v8::Function> f = CompileFunction(&env, src, "f"); 4198 v8::Local<v8::Function> f = CompileFunction(&env, src, "f");
4197 4199
4198 // Set the debug break flag. 4200 // Set the debug break flag.
4199 v8::Debug::DebugBreak(); 4201 v8::Debug::DebugBreak(env->GetIsolate());
4200 4202
4201 // Call all functions with different argument count. 4203 // Call all functions with different argument count.
4202 break_point_hit_count = 0; 4204 break_point_hit_count = 0;
4203 f->Call(env->Global(), 0, NULL); 4205 f->Call(env->Global(), 0, NULL);
4204 CHECK_EQ(1, break_point_hit_count); 4206 CHECK_EQ(1, break_point_hit_count);
4205 4207
4206 { 4208 {
4207 v8::Debug::DebugBreak(); 4209 v8::Debug::DebugBreak(env->GetIsolate());
4208 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(env->GetIsolate()); 4210 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(env->GetIsolate());
4209 v8::internal::DisableBreak disable_break(isolate, true); 4211 v8::internal::DisableBreak disable_break(isolate, true);
4210 f->Call(env->Global(), 0, NULL); 4212 f->Call(env->Global(), 0, NULL);
4211 CHECK_EQ(1, break_point_hit_count); 4213 CHECK_EQ(1, break_point_hit_count);
4212 } 4214 }
4213 4215
4214 f->Call(env->Global(), 0, NULL); 4216 f->Call(env->Global(), 0, NULL);
4215 CHECK_EQ(2, break_point_hit_count); 4217 CHECK_EQ(2, break_point_hit_count);
4216 4218
4217 // Get rid of the debug event listener. 4219 // Get rid of the debug event listener.
4218 v8::Debug::SetDebugEventListener2(NULL); 4220 v8::Debug::SetDebugEventListener2(NULL);
4219 CheckDebuggerUnloaded(); 4221 CheckDebuggerUnloaded();
4220 } 4222 }
4221 4223
4222 static const char* kSimpleExtensionSource = 4224 static const char* kSimpleExtensionSource =
4223 "(function Foo() {" 4225 "(function Foo() {"
4224 " return 4;" 4226 " return 4;"
4225 "})() "; 4227 "})() ";
4226 4228
4227 // http://crbug.com/28933 4229 // http://crbug.com/28933
4228 // Test that debug break is disabled when bootstrapper is active. 4230 // Test that debug break is disabled when bootstrapper is active.
4229 TEST(NoBreakWhenBootstrapping) { 4231 TEST(NoBreakWhenBootstrapping) {
4230 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 4232 v8::Isolate* isolate = CcTest::isolate();
4231 v8::HandleScope scope(isolate); 4233 v8::HandleScope scope(isolate);
4232 4234
4233 // Register a debug event listener which sets the break flag and counts. 4235 // Register a debug event listener which sets the break flag and counts.
4234 v8::Debug::SetDebugEventListener2(DebugEventCounter); 4236 v8::Debug::SetDebugEventListener2(DebugEventCounter);
4235 4237
4236 // Set the debug break flag. 4238 // Set the debug break flag.
4237 v8::Debug::DebugBreak(); 4239 v8::Debug::DebugBreak(isolate);
4238 break_point_hit_count = 0; 4240 break_point_hit_count = 0;
4239 { 4241 {
4240 // Create a context with an extension to make sure that some JavaScript 4242 // Create a context with an extension to make sure that some JavaScript
4241 // code is executed during bootstrapping. 4243 // code is executed during bootstrapping.
4242 v8::RegisterExtension(new v8::Extension("simpletest", 4244 v8::RegisterExtension(new v8::Extension("simpletest",
4243 kSimpleExtensionSource)); 4245 kSimpleExtensionSource));
4244 const char* extension_names[] = { "simpletest" }; 4246 const char* extension_names[] = { "simpletest" };
4245 v8::ExtensionConfiguration extensions(1, extension_names); 4247 v8::ExtensionConfiguration extensions(1, extension_names);
4246 v8::HandleScope handle_scope(isolate); 4248 v8::HandleScope handle_scope(isolate);
4247 v8::Context::New(isolate, &extensions); 4249 v8::Context::New(isolate, &extensions);
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
4882 4884
4883 /* Interleaved sequence of actions by the two threads:*/ 4885 /* Interleaved sequence of actions by the two threads:*/
4884 // Main thread compiles and runs source_1 4886 // Main thread compiles and runs source_1
4885 message_queue_barriers.semaphore_1.Signal(); 4887 message_queue_barriers.semaphore_1.Signal();
4886 message_queue_barriers.barrier_1.Wait(); 4888 message_queue_barriers.barrier_1.Wait();
4887 // Post 6 commands, filling the command queue and making it expand. 4889 // Post 6 commands, filling the command queue and making it expand.
4888 // These calls return immediately, but the commands stay on the queue 4890 // These calls return immediately, but the commands stay on the queue
4889 // until the execution of source_2. 4891 // until the execution of source_2.
4890 // Note: AsciiToUtf16 executes before SendCommand, so command is copied 4892 // Note: AsciiToUtf16 executes before SendCommand, so command is copied
4891 // to buffer before buffer is sent to SendCommand. 4893 // to buffer before buffer is sent to SendCommand.
4892 v8::Debug::SendCommand(buffer_1, AsciiToUtf16(command_1, buffer_1)); 4894 v8::Isolate* isolate = CcTest::isolate();
4893 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_2, buffer_2)); 4895 v8::Debug::SendCommand(isolate, buffer_1, AsciiToUtf16(command_1, buffer_1));
4894 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2)); 4896 v8::Debug::SendCommand(isolate, buffer_2, AsciiToUtf16(command_2, buffer_2));
4895 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2)); 4897 v8::Debug::SendCommand(isolate, buffer_2, AsciiToUtf16(command_3, buffer_2));
4896 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2)); 4898 v8::Debug::SendCommand(isolate, buffer_2, AsciiToUtf16(command_3, buffer_2));
4899 v8::Debug::SendCommand(isolate, buffer_2, AsciiToUtf16(command_3, buffer_2));
4897 message_queue_barriers.barrier_2.Wait(); 4900 message_queue_barriers.barrier_2.Wait();
4898 // Main thread compiles and runs source_2. 4901 // Main thread compiles and runs source_2.
4899 // Queued commands are executed at the start of compilation of source_2( 4902 // Queued commands are executed at the start of compilation of source_2(
4900 // beforeCompile event). 4903 // beforeCompile event).
4901 // Free the message handler to process all the messages from the queue. 7 4904 // Free the message handler to process all the messages from the queue. 7
4902 // messages are expected: 2 afterCompile events and 5 responses. 4905 // messages are expected: 2 afterCompile events and 5 responses.
4903 // All the commands added so far will fail to execute as long as call stack 4906 // All the commands added so far will fail to execute as long as call stack
4904 // is empty on beforeCompile event. 4907 // is empty on beforeCompile event.
4905 for (int i = 0; i < 6 ; ++i) { 4908 for (int i = 0; i < 6 ; ++i) {
4906 message_queue_barriers.semaphore_1.Signal(); 4909 message_queue_barriers.semaphore_1.Signal();
4907 } 4910 }
4908 message_queue_barriers.barrier_3.Wait(); 4911 message_queue_barriers.barrier_3.Wait();
4909 // Main thread compiles and runs source_3. 4912 // Main thread compiles and runs source_3.
4910 // Don't stop in the afterCompile handler. 4913 // Don't stop in the afterCompile handler.
4911 message_queue_barriers.semaphore_1.Signal(); 4914 message_queue_barriers.semaphore_1.Signal();
4912 // source_3 includes a debugger statement, which causes a break event. 4915 // source_3 includes a debugger statement, which causes a break event.
4913 // Wait on break event from hitting "debugger" statement 4916 // Wait on break event from hitting "debugger" statement
4914 message_queue_barriers.semaphore_2.Wait(); 4917 message_queue_barriers.semaphore_2.Wait();
4915 // These should execute after the "debugger" statement in source_2 4918 // These should execute after the "debugger" statement in source_2
4916 v8::Debug::SendCommand(buffer_1, AsciiToUtf16(command_1, buffer_1)); 4919 v8::Debug::SendCommand(isolate, buffer_1, AsciiToUtf16(command_1, buffer_1));
4917 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_2, buffer_2)); 4920 v8::Debug::SendCommand(isolate, buffer_2, AsciiToUtf16(command_2, buffer_2));
4918 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2)); 4921 v8::Debug::SendCommand(isolate, buffer_2, AsciiToUtf16(command_3, buffer_2));
4919 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_single_step, buffer_2)); 4922 v8::Debug::SendCommand(
4923 isolate, buffer_2, AsciiToUtf16(command_single_step, buffer_2));
4920 // Run after 2 break events, 4 responses. 4924 // Run after 2 break events, 4 responses.
4921 for (int i = 0; i < 6 ; ++i) { 4925 for (int i = 0; i < 6 ; ++i) {
4922 message_queue_barriers.semaphore_1.Signal(); 4926 message_queue_barriers.semaphore_1.Signal();
4923 } 4927 }
4924 // Wait on break event after a single step executes. 4928 // Wait on break event after a single step executes.
4925 message_queue_barriers.semaphore_2.Wait(); 4929 message_queue_barriers.semaphore_2.Wait();
4926 v8::Debug::SendCommand(buffer_1, AsciiToUtf16(command_2, buffer_1)); 4930 v8::Debug::SendCommand(isolate, buffer_1, AsciiToUtf16(command_2, buffer_1));
4927 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_continue, buffer_2)); 4931 v8::Debug::SendCommand(
4932 isolate, buffer_2, AsciiToUtf16(command_continue, buffer_2));
4928 // Run after 2 responses. 4933 // Run after 2 responses.
4929 for (int i = 0; i < 2 ; ++i) { 4934 for (int i = 0; i < 2 ; ++i) {
4930 message_queue_barriers.semaphore_1.Signal(); 4935 message_queue_barriers.semaphore_1.Signal();
4931 } 4936 }
4932 // Main thread continues running source_3 to end, waits for this thread. 4937 // Main thread continues running source_3 to end, waits for this thread.
4933 } 4938 }
4934 4939
4935 4940
4936 // This thread runs the v8 engine. 4941 // This thread runs the v8 engine.
4937 TEST(MessageQueues) { 4942 TEST(MessageQueues) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
5023 if (message.GetClientData() != NULL) { 5028 if (message.GetClientData() != NULL) {
5024 handled_client_data_instances_count++; 5029 handled_client_data_instances_count++;
5025 } 5030 }
5026 } 5031 }
5027 5032
5028 5033
5029 // Tests that all client data passed to the debugger are sent to the handler. 5034 // Tests that all client data passed to the debugger are sent to the handler.
5030 TEST(SendClientDataToHandler) { 5035 TEST(SendClientDataToHandler) {
5031 // Create a V8 environment 5036 // Create a V8 environment
5032 DebugLocalContext env; 5037 DebugLocalContext env;
5033 v8::HandleScope scope(env->GetIsolate()); 5038 v8::Isolate* isolate = env->GetIsolate();
5039 v8::HandleScope scope(isolate);
5034 TestClientData::ResetCounters(); 5040 TestClientData::ResetCounters();
5035 handled_client_data_instances_count = 0; 5041 handled_client_data_instances_count = 0;
5036 v8::Debug::SetMessageHandler2(MessageHandlerCountingClientData); 5042 v8::Debug::SetMessageHandler2(MessageHandlerCountingClientData);
5037 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;"; 5043 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;";
5038 const int kBufferSize = 1000; 5044 const int kBufferSize = 1000;
5039 uint16_t buffer[kBufferSize]; 5045 uint16_t buffer[kBufferSize];
5040 const char* command_1 = 5046 const char* command_1 =
5041 "{\"seq\":117," 5047 "{\"seq\":117,"
5042 "\"type\":\"request\"," 5048 "\"type\":\"request\","
5043 "\"command\":\"evaluate\"," 5049 "\"command\":\"evaluate\","
5044 "\"arguments\":{\"expression\":\"1+2\"}}"; 5050 "\"arguments\":{\"expression\":\"1+2\"}}";
5045 const char* command_2 = 5051 const char* command_2 =
5046 "{\"seq\":118," 5052 "{\"seq\":118,"
5047 "\"type\":\"request\"," 5053 "\"type\":\"request\","
5048 "\"command\":\"evaluate\"," 5054 "\"command\":\"evaluate\","
5049 "\"arguments\":{\"expression\":\"1+a\"}}"; 5055 "\"arguments\":{\"expression\":\"1+a\"}}";
5050 const char* command_continue = 5056 const char* command_continue =
5051 "{\"seq\":106," 5057 "{\"seq\":106,"
5052 "\"type\":\"request\"," 5058 "\"type\":\"request\","
5053 "\"command\":\"continue\"}"; 5059 "\"command\":\"continue\"}";
5054 5060
5055 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer), 5061 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_1, buffer),
5056 new TestClientData()); 5062 new TestClientData());
5057 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer), NULL); 5063 v8::Debug::SendCommand(
5058 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer), 5064 isolate, buffer, AsciiToUtf16(command_2, buffer), NULL);
5065 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_2, buffer),
5059 new TestClientData()); 5066 new TestClientData());
5060 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer), 5067 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_2, buffer),
5061 new TestClientData()); 5068 new TestClientData());
5062 // All the messages will be processed on beforeCompile event. 5069 // All the messages will be processed on beforeCompile event.
5063 CompileRun(source_1); 5070 CompileRun(source_1);
5064 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer)); 5071 v8::Debug::SendCommand(
5072 isolate, buffer, AsciiToUtf16(command_continue, buffer));
5065 CHECK_EQ(3, TestClientData::constructor_call_counter); 5073 CHECK_EQ(3, TestClientData::constructor_call_counter);
5066 CHECK_EQ(TestClientData::constructor_call_counter, 5074 CHECK_EQ(TestClientData::constructor_call_counter,
5067 handled_client_data_instances_count); 5075 handled_client_data_instances_count);
5068 CHECK_EQ(TestClientData::constructor_call_counter, 5076 CHECK_EQ(TestClientData::constructor_call_counter,
5069 TestClientData::destructor_call_counter); 5077 TestClientData::destructor_call_counter);
5070 } 5078 }
5071 5079
5072 5080
5073 /* Test ThreadedDebugging */ 5081 /* Test ThreadedDebugging */
5074 /* This test interrupts a running infinite loop that is 5082 /* This test interrupts a running infinite loop that is
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
5134 "\n" 5142 "\n"
5135 "foo();\n"; 5143 "foo();\n";
5136 5144
5137 v8::V8::Initialize(); 5145 v8::V8::Initialize();
5138 DebugLocalContext env; 5146 DebugLocalContext env;
5139 v8::HandleScope scope(env->GetIsolate()); 5147 v8::HandleScope scope(env->GetIsolate());
5140 v8::Debug::SetMessageHandler2(&ThreadedMessageHandler); 5148 v8::Debug::SetMessageHandler2(&ThreadedMessageHandler);
5141 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 5149 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
5142 global_template->Set(v8::String::New("ThreadedAtBarrier1"), 5150 global_template->Set(v8::String::New("ThreadedAtBarrier1"),
5143 v8::FunctionTemplate::New(ThreadedAtBarrier1)); 5151 v8::FunctionTemplate::New(ThreadedAtBarrier1));
5144 v8::Handle<v8::Context> context = v8::Context::New(v8::Isolate::GetCurrent(), 5152 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate(),
5145 NULL, 5153 NULL,
5146 global_template); 5154 global_template);
5147 v8::Context::Scope context_scope(context); 5155 v8::Context::Scope context_scope(context);
5148 5156
5149 CompileRun(source); 5157 CompileRun(source);
5150 } 5158 }
5151 5159
5152 5160
5153 void DebuggerThread::Run() { 5161 void DebuggerThread::Run() {
5154 const int kBufSize = 1000; 5162 const int kBufSize = 1000;
5155 uint16_t buffer[kBufSize]; 5163 uint16_t buffer[kBufSize];
5156 5164
5157 const char* command_1 = "{\"seq\":102," 5165 const char* command_1 = "{\"seq\":102,"
5158 "\"type\":\"request\"," 5166 "\"type\":\"request\","
5159 "\"command\":\"evaluate\"," 5167 "\"command\":\"evaluate\","
5160 "\"arguments\":{\"expression\":\"bar(false)\"}}"; 5168 "\"arguments\":{\"expression\":\"bar(false)\"}}";
5161 const char* command_2 = "{\"seq\":103," 5169 const char* command_2 = "{\"seq\":103,"
5162 "\"type\":\"request\"," 5170 "\"type\":\"request\","
5163 "\"command\":\"continue\"}"; 5171 "\"command\":\"continue\"}";
5164 5172
5173 v8::Isolate* isolate = CcTest::isolate();
5165 threaded_debugging_barriers.barrier_1.Wait(); 5174 threaded_debugging_barriers.barrier_1.Wait();
5166 v8::Debug::DebugBreak(); 5175 v8::Debug::DebugBreak(isolate);
5167 threaded_debugging_barriers.barrier_2.Wait(); 5176 threaded_debugging_barriers.barrier_2.Wait();
5168 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer)); 5177 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_1, buffer));
5169 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer)); 5178 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_2, buffer));
5170 } 5179 }
5171 5180
5172 5181
5173 TEST(ThreadedDebugging) { 5182 UNINITIALIZED_TEST(ThreadedDebugging) {
5174 DebuggerThread debugger_thread; 5183 DebuggerThread debugger_thread;
5175 V8Thread v8_thread; 5184 V8Thread v8_thread;
5176 5185
5177 // Create a V8 environment 5186 // Create a V8 environment
5178 v8_thread.Start(); 5187 v8_thread.Start();
5179 debugger_thread.Start(); 5188 debugger_thread.Start();
5180 5189
5181 v8_thread.Join(); 5190 v8_thread.Join();
5182 debugger_thread.Join(); 5191 debugger_thread.Join();
5183 } 5192 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
5316 command_7 = "{\"seq\":107," 5325 command_7 = "{\"seq\":107,"
5317 "\"type\":\"request\"," 5326 "\"type\":\"request\","
5318 "\"command\":\"evaluate\"," 5327 "\"command\":\"evaluate\","
5319 "\"arguments\":{\"expression\":\"dog()\",\"disable_break\":true}}"; 5328 "\"arguments\":{\"expression\":\"dog()\",\"disable_break\":true}}";
5320 } 5329 }
5321 const char* command_8 = "{\"seq\":108," 5330 const char* command_8 = "{\"seq\":108,"
5322 "\"type\":\"request\"," 5331 "\"type\":\"request\","
5323 "\"command\":\"continue\"}"; 5332 "\"command\":\"continue\"}";
5324 5333
5325 5334
5335 v8::Isolate* isolate = CcTest::isolate();
5326 // v8 thread initializes, runs source_1 5336 // v8 thread initializes, runs source_1
5327 breakpoints_barriers->barrier_1.Wait(); 5337 breakpoints_barriers->barrier_1.Wait();
5328 // 1:Set breakpoint in cat() (will get id 1). 5338 // 1:Set breakpoint in cat() (will get id 1).
5329 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer)); 5339 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_1, buffer));
5330 // 2:Set breakpoint in dog() (will get id 2). 5340 // 2:Set breakpoint in dog() (will get id 2).
5331 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer)); 5341 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_2, buffer));
5332 breakpoints_barriers->barrier_2.Wait(); 5342 breakpoints_barriers->barrier_2.Wait();
5333 // V8 thread starts compiling source_2. 5343 // V8 thread starts compiling source_2.
5334 // Automatic break happens, to run queued commands 5344 // Automatic break happens, to run queued commands
5335 // breakpoints_barriers->semaphore_1.Wait(); 5345 // breakpoints_barriers->semaphore_1.Wait();
5336 // Commands 1 through 3 run, thread continues. 5346 // Commands 1 through 3 run, thread continues.
5337 // v8 thread runs source_2 to breakpoint in cat(). 5347 // v8 thread runs source_2 to breakpoint in cat().
5338 // message callback receives break event. 5348 // message callback receives break event.
5339 breakpoints_barriers->semaphore_1.Wait(); 5349 breakpoints_barriers->semaphore_1.Wait();
5340 // Must have hit breakpoint #1. 5350 // Must have hit breakpoint #1.
5341 CHECK_EQ(1, break_event_breakpoint_id); 5351 CHECK_EQ(1, break_event_breakpoint_id);
5342 // 4:Evaluate dog() (which has a breakpoint). 5352 // 4:Evaluate dog() (which has a breakpoint).
5343 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_3, buffer)); 5353 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_3, buffer));
5344 // V8 thread hits breakpoint in dog(). 5354 // V8 thread hits breakpoint in dog().
5345 breakpoints_barriers->semaphore_1.Wait(); // wait for break event 5355 breakpoints_barriers->semaphore_1.Wait(); // wait for break event
5346 // Must have hit breakpoint #2. 5356 // Must have hit breakpoint #2.
5347 CHECK_EQ(2, break_event_breakpoint_id); 5357 CHECK_EQ(2, break_event_breakpoint_id);
5348 // 5:Evaluate (x + 1). 5358 // 5:Evaluate (x + 1).
5349 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_4, buffer)); 5359 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_4, buffer));
5350 // Evaluate (x + 1) finishes. 5360 // Evaluate (x + 1) finishes.
5351 breakpoints_barriers->semaphore_1.Wait(); 5361 breakpoints_barriers->semaphore_1.Wait();
5352 // Must have result 108. 5362 // Must have result 108.
5353 CHECK_EQ(108, evaluate_int_result); 5363 CHECK_EQ(108, evaluate_int_result);
5354 // 6:Continue evaluation of dog(). 5364 // 6:Continue evaluation of dog().
5355 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_5, buffer)); 5365 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_5, buffer));
5356 // Evaluate dog() finishes. 5366 // Evaluate dog() finishes.
5357 breakpoints_barriers->semaphore_1.Wait(); 5367 breakpoints_barriers->semaphore_1.Wait();
5358 // Must have result 107. 5368 // Must have result 107.
5359 CHECK_EQ(107, evaluate_int_result); 5369 CHECK_EQ(107, evaluate_int_result);
5360 // 7:Continue evaluation of source_2, finish cat(17), hit breakpoint 5370 // 7:Continue evaluation of source_2, finish cat(17), hit breakpoint
5361 // in cat(19). 5371 // in cat(19).
5362 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_6, buffer)); 5372 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_6, buffer));
5363 // Message callback gets break event. 5373 // Message callback gets break event.
5364 breakpoints_barriers->semaphore_1.Wait(); // wait for break event 5374 breakpoints_barriers->semaphore_1.Wait(); // wait for break event
5365 // Must have hit breakpoint #1. 5375 // Must have hit breakpoint #1.
5366 CHECK_EQ(1, break_event_breakpoint_id); 5376 CHECK_EQ(1, break_event_breakpoint_id);
5367 // 8: Evaluate dog() with breaks disabled. 5377 // 8: Evaluate dog() with breaks disabled.
5368 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_7, buffer)); 5378 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_7, buffer));
5369 // Evaluate dog() finishes. 5379 // Evaluate dog() finishes.
5370 breakpoints_barriers->semaphore_1.Wait(); 5380 breakpoints_barriers->semaphore_1.Wait();
5371 // Must have result 116. 5381 // Must have result 116.
5372 CHECK_EQ(116, evaluate_int_result); 5382 CHECK_EQ(116, evaluate_int_result);
5373 // 9: Continue evaluation of source2, reach end. 5383 // 9: Continue evaluation of source2, reach end.
5374 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_8, buffer)); 5384 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_8, buffer));
5375 } 5385 }
5376 5386
5377 5387
5378 void TestRecursiveBreakpointsGeneric(bool global_evaluate) { 5388 void TestRecursiveBreakpointsGeneric(bool global_evaluate) {
5379 i::FLAG_debugger_auto_break = true; 5389 i::FLAG_debugger_auto_break = true;
5380 5390
5381 BreakpointsDebuggerThread breakpoints_debugger_thread(global_evaluate); 5391 BreakpointsDebuggerThread breakpoints_debugger_thread(global_evaluate);
5382 BreakpointsV8Thread breakpoints_v8_thread; 5392 BreakpointsV8Thread breakpoints_v8_thread;
5383 5393
5384 // Create a V8 environment 5394 // Create a V8 environment
5385 Barriers stack_allocated_breakpoints_barriers; 5395 Barriers stack_allocated_breakpoints_barriers;
5386 breakpoints_barriers = &stack_allocated_breakpoints_barriers; 5396 breakpoints_barriers = &stack_allocated_breakpoints_barriers;
5387 5397
5388 breakpoints_v8_thread.Start(); 5398 breakpoints_v8_thread.Start();
5389 breakpoints_debugger_thread.Start(); 5399 breakpoints_debugger_thread.Start();
5390 5400
5391 breakpoints_v8_thread.Join(); 5401 breakpoints_v8_thread.Join();
5392 breakpoints_debugger_thread.Join(); 5402 breakpoints_debugger_thread.Join();
5393 } 5403 }
5394 5404
5395 5405
5396 TEST(RecursiveBreakpoints) { 5406 UNINITIALIZED_TEST(RecursiveBreakpoints) {
5397 TestRecursiveBreakpointsGeneric(false); 5407 TestRecursiveBreakpointsGeneric(false);
5398 } 5408 }
5399 5409
5400 5410
5401 TEST(RecursiveBreakpointsGlobal) { 5411 UNINITIALIZED_TEST(RecursiveBreakpointsGlobal) {
5402 TestRecursiveBreakpointsGeneric(true); 5412 TestRecursiveBreakpointsGeneric(true);
5403 } 5413 }
5404 5414
5405 5415
5406 static void DummyDebugEventListener( 5416 static void DummyDebugEventListener(
5407 const v8::Debug::EventDetails& event_details) { 5417 const v8::Debug::EventDetails& event_details) {
5408 } 5418 }
5409 5419
5410 5420
5411 TEST(SetDebugEventListenerOnUninitializedVM) { 5421 TEST(SetDebugEventListenerOnUninitializedVM) {
5412 v8::Debug::SetDebugEventListener2(DummyDebugEventListener); 5422 v8::Debug::SetDebugEventListener2(DummyDebugEventListener);
5413 } 5423 }
5414 5424
5415 5425
5416 static void DummyMessageHandler(const v8::Debug::Message& message) { 5426 static void DummyMessageHandler(const v8::Debug::Message& message) {
5417 } 5427 }
5418 5428
5419 5429
5420 TEST(SetMessageHandlerOnUninitializedVM) { 5430 TEST(SetMessageHandlerOnUninitializedVM) {
5421 v8::Debug::SetMessageHandler2(DummyMessageHandler); 5431 v8::Debug::SetMessageHandler2(DummyMessageHandler);
5422 } 5432 }
5423 5433
5424 5434
5425 TEST(DebugBreakOnUninitializedVM) {
5426 v8::Debug::DebugBreak();
5427 }
5428
5429
5430 TEST(SendCommandToUninitializedVM) {
5431 const char* dummy_command = "{}";
5432 uint16_t dummy_buffer[80];
5433 int dummy_length = AsciiToUtf16(dummy_command, dummy_buffer);
5434 v8::Debug::SendCommand(dummy_buffer, dummy_length);
5435 }
5436
5437
5438 // Source for a JavaScript function which returns the data parameter of a 5435 // Source for a JavaScript function which returns the data parameter of a
5439 // function called in the context of the debugger. If no data parameter is 5436 // function called in the context of the debugger. If no data parameter is
5440 // passed it throws an exception. 5437 // passed it throws an exception.
5441 static const char* debugger_call_with_data_source = 5438 static const char* debugger_call_with_data_source =
5442 "function debugger_call_with_data(exec_state, data) {" 5439 "function debugger_call_with_data(exec_state, data) {"
5443 " if (data) return data;" 5440 " if (data) return data;"
5444 " throw 'No data!'" 5441 " throw 'No data!'"
5445 "}"; 5442 "}";
5446 v8::Handle<v8::Function> debugger_call_with_data; 5443 v8::Handle<v8::Function> debugger_call_with_data;
5447 5444
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
5498 static void CheckClosure(const v8::FunctionCallbackInfo<v8::Value>& args) { 5495 static void CheckClosure(const v8::FunctionCallbackInfo<v8::Value>& args) {
5499 CHECK(v8::Debug::Call(debugger_call_with_closure)->IsNumber()); 5496 CHECK(v8::Debug::Call(debugger_call_with_closure)->IsNumber());
5500 CHECK_EQ(3, v8::Debug::Call(debugger_call_with_closure)->Int32Value()); 5497 CHECK_EQ(3, v8::Debug::Call(debugger_call_with_closure)->Int32Value());
5501 } 5498 }
5502 5499
5503 5500
5504 // Test functions called through the debugger. 5501 // Test functions called through the debugger.
5505 TEST(CallFunctionInDebugger) { 5502 TEST(CallFunctionInDebugger) {
5506 // Create and enter a context with the functions CheckFrameCount, 5503 // Create and enter a context with the functions CheckFrameCount,
5507 // CheckSourceLine and CheckDataParameter installed. 5504 // CheckSourceLine and CheckDataParameter installed.
5508 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5505 v8::HandleScope scope(CcTest::isolate());
5509 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 5506 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
5510 global_template->Set(v8::String::New("CheckFrameCount"), 5507 global_template->Set(v8::String::New("CheckFrameCount"),
5511 v8::FunctionTemplate::New(CheckFrameCount)); 5508 v8::FunctionTemplate::New(CheckFrameCount));
5512 global_template->Set(v8::String::New("CheckSourceLine"), 5509 global_template->Set(v8::String::New("CheckSourceLine"),
5513 v8::FunctionTemplate::New(CheckSourceLine)); 5510 v8::FunctionTemplate::New(CheckSourceLine));
5514 global_template->Set(v8::String::New("CheckDataParameter"), 5511 global_template->Set(v8::String::New("CheckDataParameter"),
5515 v8::FunctionTemplate::New(CheckDataParameter)); 5512 v8::FunctionTemplate::New(CheckDataParameter));
5516 global_template->Set(v8::String::New("CheckClosure"), 5513 global_template->Set(v8::String::New("CheckClosure"),
5517 v8::FunctionTemplate::New(CheckClosure)); 5514 v8::FunctionTemplate::New(CheckClosure));
5518 v8::Handle<v8::Context> context = v8::Context::New(v8::Isolate::GetCurrent(), 5515 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate(),
5519 NULL, 5516 NULL,
5520 global_template); 5517 global_template);
5521 v8::Context::Scope context_scope(context); 5518 v8::Context::Scope context_scope(context);
5522 5519
5523 // Compile a function for checking the number of JavaScript frames. 5520 // Compile a function for checking the number of JavaScript frames.
5524 v8::Script::Compile(v8::String::New(frame_count_source))->Run(); 5521 v8::Script::Compile(v8::String::New(frame_count_source))->Run();
5525 frame_count = v8::Local<v8::Function>::Cast( 5522 frame_count = v8::Local<v8::Function>::Cast(
5526 context->Global()->Get(v8::String::New("frame_count"))); 5523 context->Global()->Get(v8::String::New("frame_count")));
5527 5524
5528 // Compile a function for returning the source line for the top frame. 5525 // Compile a function for returning the source line for the top frame.
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
5657 5654
5658 // Sends continue command to the debugger. 5655 // Sends continue command to the debugger.
5659 static void SendContinueCommand() { 5656 static void SendContinueCommand() {
5660 const int kBufferSize = 1000; 5657 const int kBufferSize = 1000;
5661 uint16_t buffer[kBufferSize]; 5658 uint16_t buffer[kBufferSize];
5662 const char* command_continue = 5659 const char* command_continue =
5663 "{\"seq\":0," 5660 "{\"seq\":0,"
5664 "\"type\":\"request\"," 5661 "\"type\":\"request\","
5665 "\"command\":\"continue\"}"; 5662 "\"command\":\"continue\"}";
5666 5663
5667 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer)); 5664 v8::Debug::SendCommand(
5665 CcTest::isolate(), buffer, AsciiToUtf16(command_continue, buffer));
5668 } 5666 }
5669 5667
5670 5668
5671 // Debugger message handler which counts the number of times it is called. 5669 // Debugger message handler which counts the number of times it is called.
5672 static int message_handler_hit_count = 0; 5670 static int message_handler_hit_count = 0;
5673 static void MessageHandlerHitCount(const v8::Debug::Message& message) { 5671 static void MessageHandlerHitCount(const v8::Debug::Message& message) {
5674 message_handler_hit_count++; 5672 message_handler_hit_count++;
5675 5673
5676 static char print_buffer[1000]; 5674 static char print_buffer[1000];
5677 v8::String::Value json(message.GetJSON()); 5675 v8::String::Value json(message.GetJSON());
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
5811 uint16_t buffer[kBufSize]; 5809 uint16_t buffer[kBufSize];
5812 5810
5813 const char* command_1 = "{\"seq\":101," 5811 const char* command_1 = "{\"seq\":101,"
5814 "\"type\":\"request\"," 5812 "\"type\":\"request\","
5815 "\"command\":\"setbreakpoint\"," 5813 "\"command\":\"setbreakpoint\","
5816 "\"arguments\":{\"type\":\"function\",\"target\":\"cat\",\"line\":3}}"; 5814 "\"arguments\":{\"type\":\"function\",\"target\":\"cat\",\"line\":3}}";
5817 const char* command_2 = "{\"seq\":102," 5815 const char* command_2 = "{\"seq\":102,"
5818 "\"type\":\"request\"," 5816 "\"type\":\"request\","
5819 "\"command\":\"continue\"}"; 5817 "\"command\":\"continue\"}";
5820 5818
5819 v8::Isolate* isolate = CcTest::isolate();
5821 // v8 thread initializes, runs source_1 5820 // v8 thread initializes, runs source_1
5822 host_dispatch_barriers->barrier_1.Wait(); 5821 host_dispatch_barriers->barrier_1.Wait();
5823 // 1: Set breakpoint in cat(). 5822 // 1: Set breakpoint in cat().
5824 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer)); 5823 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_1, buffer));
5825 5824
5826 host_dispatch_barriers->barrier_2.Wait(); 5825 host_dispatch_barriers->barrier_2.Wait();
5827 // v8 thread starts compiling source_2. 5826 // v8 thread starts compiling source_2.
5828 // Break happens, to run queued commands and host dispatches. 5827 // Break happens, to run queued commands and host dispatches.
5829 // Wait for host dispatch to be processed. 5828 // Wait for host dispatch to be processed.
5830 host_dispatch_barriers->semaphore_1.Wait(); 5829 host_dispatch_barriers->semaphore_1.Wait();
5831 // 2: Continue evaluation 5830 // 2: Continue evaluation
5832 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer)); 5831 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_2, buffer));
5833 } 5832 }
5834 5833
5835 5834
5836 TEST(DebuggerHostDispatch) { 5835 UNINITIALIZED_TEST(DebuggerHostDispatch) {
5837 HostDispatchDebuggerThread host_dispatch_debugger_thread; 5836 HostDispatchDebuggerThread host_dispatch_debugger_thread;
5838 HostDispatchV8Thread host_dispatch_v8_thread; 5837 HostDispatchV8Thread host_dispatch_v8_thread;
5839 i::FLAG_debugger_auto_break = true; 5838 i::FLAG_debugger_auto_break = true;
5840 5839
5841 // Create a V8 environment 5840 // Create a V8 environment
5842 Barriers stack_allocated_host_dispatch_barriers; 5841 Barriers stack_allocated_host_dispatch_barriers;
5843 host_dispatch_barriers = &stack_allocated_host_dispatch_barriers; 5842 host_dispatch_barriers = &stack_allocated_host_dispatch_barriers;
5844 5843
5845 host_dispatch_v8_thread.Start(); 5844 host_dispatch_v8_thread.Start();
5846 host_dispatch_debugger_thread.Start(); 5845 host_dispatch_debugger_thread.Start();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
5892 } 5891 }
5893 5892
5894 5893
5895 void DebugMessageDispatchDebuggerThread::Run() { 5894 void DebugMessageDispatchDebuggerThread::Run() {
5896 debug_message_dispatch_barriers->barrier_1.Wait(); 5895 debug_message_dispatch_barriers->barrier_1.Wait();
5897 SendContinueCommand(); 5896 SendContinueCommand();
5898 debug_message_dispatch_barriers->barrier_2.Wait(); 5897 debug_message_dispatch_barriers->barrier_2.Wait();
5899 } 5898 }
5900 5899
5901 5900
5902 TEST(DebuggerDebugMessageDispatch) { 5901 UNINITIALIZED_TEST(DebuggerDebugMessageDispatch) {
5903 DebugMessageDispatchDebuggerThread debug_message_dispatch_debugger_thread; 5902 DebugMessageDispatchDebuggerThread debug_message_dispatch_debugger_thread;
5904 DebugMessageDispatchV8Thread debug_message_dispatch_v8_thread; 5903 DebugMessageDispatchV8Thread debug_message_dispatch_v8_thread;
5905 5904
5906 i::FLAG_debugger_auto_break = true; 5905 i::FLAG_debugger_auto_break = true;
5907 5906
5908 // Create a V8 environment 5907 // Create a V8 environment
5909 Barriers stack_allocated_debug_message_dispatch_barriers; 5908 Barriers stack_allocated_debug_message_dispatch_barriers;
5910 debug_message_dispatch_barriers = 5909 debug_message_dispatch_barriers =
5911 &stack_allocated_debug_message_dispatch_barriers; 5910 &stack_allocated_debug_message_dispatch_barriers;
5912 5911
5913 debug_message_dispatch_v8_thread.Start(); 5912 debug_message_dispatch_v8_thread.Start();
5914 debug_message_dispatch_debugger_thread.Start(); 5913 debug_message_dispatch_debugger_thread.Start();
5915 5914
5916 debug_message_dispatch_v8_thread.Join(); 5915 debug_message_dispatch_v8_thread.Join();
5917 debug_message_dispatch_debugger_thread.Join(); 5916 debug_message_dispatch_debugger_thread.Join();
5918 } 5917 }
5919 5918
5920 5919
5921 TEST(DebuggerAgent) { 5920 TEST(DebuggerAgent) {
5922 v8::V8::Initialize(); 5921 v8::V8::Initialize();
5923 i::Debugger* debugger = i::Isolate::Current()->debugger(); 5922 i::Debugger* debugger = CcTest::i_isolate()->debugger();
5924 // Make sure these ports is not used by other tests to allow tests to run in 5923 // Make sure these ports is not used by other tests to allow tests to run in
5925 // parallel. 5924 // parallel.
5926 const int kPort1 = 5858 + FlagDependentPortOffset(); 5925 const int kPort1 = 5858 + FlagDependentPortOffset();
5927 const int kPort2 = 5857 + FlagDependentPortOffset(); 5926 const int kPort2 = 5857 + FlagDependentPortOffset();
5928 const int kPort3 = 5856 + FlagDependentPortOffset(); 5927 const int kPort3 = 5856 + FlagDependentPortOffset();
5929 5928
5930 // Make a string with the port2 number. 5929 // Make a string with the port2 number.
5931 const int kPortBufferLen = 6; 5930 const int kPortBufferLen = 6;
5932 char port2_str[kPortBufferLen]; 5931 char port2_str[kPortBufferLen];
5933 OS::SNPrintF(i::Vector<char>(port2_str, kPortBufferLen), "%d", kPort2); 5932 OS::SNPrintF(i::Vector<char>(port2_str, kPortBufferLen), "%d", kPort2);
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
6228 if (IsBreakEventMessage(print_buffer)) { 6227 if (IsBreakEventMessage(print_buffer)) {
6229 SendContinueCommand(); 6228 SendContinueCommand();
6230 } 6229 }
6231 } 6230 }
6232 6231
6233 6232
6234 // Test which creates two contexts and sets different embedder data on each. 6233 // Test which creates two contexts and sets different embedder data on each.
6235 // Checks that this data is set correctly and that when the debug message 6234 // Checks that this data is set correctly and that when the debug message
6236 // handler is called the expected context is the one active. 6235 // handler is called the expected context is the one active.
6237 TEST(ContextData) { 6236 TEST(ContextData) {
6238 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 6237 v8::Isolate* isolate = CcTest::isolate();
6239 v8::HandleScope scope(isolate); 6238 v8::HandleScope scope(isolate);
6240 6239
6241 // Create two contexts. 6240 // Create two contexts.
6242 v8::Handle<v8::Context> context_1; 6241 v8::Handle<v8::Context> context_1;
6243 v8::Handle<v8::Context> context_2; 6242 v8::Handle<v8::Context> context_2;
6244 v8::Handle<v8::ObjectTemplate> global_template = 6243 v8::Handle<v8::ObjectTemplate> global_template =
6245 v8::Handle<v8::ObjectTemplate>(); 6244 v8::Handle<v8::ObjectTemplate>();
6246 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>(); 6245 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>();
6247 context_1 = v8::Context::New(isolate, NULL, global_template, global_object); 6246 context_1 = v8::Context::New(isolate, NULL, global_template, global_object);
6248 context_2 = v8::Context::New(isolate, NULL, global_template, global_object); 6247 context_2 = v8::Context::New(isolate, NULL, global_template, global_object);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
6291 } 6290 }
6292 6291
6293 6292
6294 // Debug message handler which issues a debug break when it hits a break event. 6293 // Debug message handler which issues a debug break when it hits a break event.
6295 static int message_handler_break_hit_count = 0; 6294 static int message_handler_break_hit_count = 0;
6296 static void DebugBreakMessageHandler(const v8::Debug::Message& message) { 6295 static void DebugBreakMessageHandler(const v8::Debug::Message& message) {
6297 // Schedule a debug break for break events. 6296 // Schedule a debug break for break events.
6298 if (message.IsEvent() && message.GetEvent() == v8::Break) { 6297 if (message.IsEvent() && message.GetEvent() == v8::Break) {
6299 message_handler_break_hit_count++; 6298 message_handler_break_hit_count++;
6300 if (message_handler_break_hit_count == 1) { 6299 if (message_handler_break_hit_count == 1) {
6301 v8::Debug::DebugBreak(); 6300 v8::Debug::DebugBreak(message.GetIsolate());
6302 } 6301 }
6303 } 6302 }
6304 6303
6305 // Issue a continue command if this event will not cause the VM to start 6304 // Issue a continue command if this event will not cause the VM to start
6306 // running. 6305 // running.
6307 if (!message.WillStartRunning()) { 6306 if (!message.WillStartRunning()) {
6308 SendContinueCommand(); 6307 SendContinueCommand();
6309 } 6308 }
6310 } 6309 }
6311 6310
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
6363 } 6362 }
6364 6363
6365 // Keep forcing breaks. 6364 // Keep forcing breaks.
6366 if (break_point_hit_count < 20) { 6365 if (break_point_hit_count < 20) {
6367 v8::Debug::DebugBreak(); 6366 v8::Debug::DebugBreak();
6368 } 6367 }
6369 } 6368 }
6370 } 6369 }
6371 6370
6372 6371
6373 TEST(RegExpDebugBreak) { 6372 UNINITIALIZED_TEST(RegExpDebugBreak) {
6374 // This test only applies to native regexps. 6373 // This test only applies to native regexps.
6375 DebugLocalContext env; 6374 DebugLocalContext env;
6376 v8::HandleScope scope(env->GetIsolate()); 6375 v8::HandleScope scope(env->GetIsolate());
6377 6376
6378 // Create a function for checking the function when hitting a break point. 6377 // Create a function for checking the function when hitting a break point.
6379 frame_function_name = CompileFunction(&env, 6378 frame_function_name = CompileFunction(&env,
6380 frame_function_name_source, 6379 frame_function_name_source,
6381 "frame_function_name"); 6380 "frame_function_name");
6382 6381
6383 // Test RegExp which matches white spaces and comments at the begining of a 6382 // Test RegExp which matches white spaces and comments at the begining of a
6384 // source line. 6383 // source line.
6385 const char* script = 6384 const char* script =
6386 "var sourceLineBeginningSkip = /^(?:[ \\v\\h]*(?:\\/\\*.*?\\*\\/)*)*/;\n" 6385 "var sourceLineBeginningSkip = /^(?:[ \\v\\h]*(?:\\/\\*.*?\\*\\/)*)*/;\n"
6387 "function f(s) { return s.match(sourceLineBeginningSkip)[0].length; }"; 6386 "function f(s) { return s.match(sourceLineBeginningSkip)[0].length; }";
6388 6387
6389 v8::Local<v8::Function> f = CompileFunction(script, "f"); 6388 v8::Local<v8::Function> f = CompileFunction(script, "f");
6390 const int argc = 1; 6389 const int argc = 1;
6391 v8::Handle<v8::Value> argv[argc] = { v8::String::New(" /* xxx */ a=0;") }; 6390 v8::Handle<v8::Value> argv[argc] = { v8::String::New(" /* xxx */ a=0;") };
6392 v8::Local<v8::Value> result = f->Call(env->Global(), argc, argv); 6391 v8::Local<v8::Value> result = f->Call(env->Global(), argc, argv);
6393 CHECK_EQ(12, result->Int32Value()); 6392 CHECK_EQ(12, result->Int32Value());
6394 6393
6395 v8::Debug::SetDebugEventListener2(DebugEventDebugBreak); 6394 v8::Debug::SetDebugEventListener2(DebugEventDebugBreak);
6396 v8::Debug::DebugBreak(); 6395 v8::Debug::DebugBreak(env->GetIsolate());
6397 result = f->Call(env->Global(), argc, argv); 6396 result = f->Call(env->Global(), argc, argv);
6398 6397
6399 // Check that there was only one break event. Matching RegExp should not 6398 // Check that there was only one break event. Matching RegExp should not
6400 // cause Break events. 6399 // cause Break events.
6401 CHECK_EQ(1, break_point_hit_count); 6400 CHECK_EQ(1, break_point_hit_count);
6402 CHECK_EQ("f", last_function_hit); 6401 CHECK_EQ("f", last_function_hit);
6403 } 6402 }
6404 #endif // V8_INTERPRETED_REGEXP 6403 #endif // V8_INTERPRETED_REGEXP
6405 6404
6406 6405
6407 // Common part of EvalContextData and NestedBreakEventContextData tests. 6406 // Common part of EvalContextData and NestedBreakEventContextData tests.
6408 static void ExecuteScriptForContextCheck( 6407 static void ExecuteScriptForContextCheck(
6409 v8::Debug::MessageHandler2 message_handler) { 6408 v8::Debug::MessageHandler2 message_handler) {
6410 // Create a context. 6409 // Create a context.
6411 v8::Handle<v8::Context> context_1; 6410 v8::Handle<v8::Context> context_1;
6412 v8::Handle<v8::ObjectTemplate> global_template = 6411 v8::Handle<v8::ObjectTemplate> global_template =
6413 v8::Handle<v8::ObjectTemplate>(); 6412 v8::Handle<v8::ObjectTemplate>();
6414 context_1 = 6413 context_1 =
6415 v8::Context::New(v8::Isolate::GetCurrent(), NULL, global_template); 6414 v8::Context::New(CcTest::isolate(), NULL, global_template);
6416 6415
6417 v8::Debug::SetMessageHandler2(message_handler); 6416 v8::Debug::SetMessageHandler2(message_handler);
6418 6417
6419 // Default data value is undefined. 6418 // Default data value is undefined.
6420 CHECK(context_1->GetEmbedderData(0)->IsUndefined()); 6419 CHECK(context_1->GetEmbedderData(0)->IsUndefined());
6421 6420
6422 // Set and check a data value. 6421 // Set and check a data value.
6423 v8::Handle<v8::String> data_1 = v8::String::New("1"); 6422 v8::Handle<v8::String> data_1 = v8::String::New("1");
6424 context_1->SetEmbedderData(0, data_1); 6423 context_1->SetEmbedderData(0, data_1);
6425 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1)); 6424 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1));
(...skipping 12 matching lines...) Expand all
6438 6437
6439 v8::Debug::SetMessageHandler2(NULL); 6438 v8::Debug::SetMessageHandler2(NULL);
6440 } 6439 }
6441 6440
6442 6441
6443 // Test which creates a context and sets embedder data on it. Checks that this 6442 // Test which creates a context and sets embedder data on it. Checks that this
6444 // data is set correctly and that when the debug message handler is called for 6443 // data is set correctly and that when the debug message handler is called for
6445 // break event in an eval statement the expected context is the one returned by 6444 // break event in an eval statement the expected context is the one returned by
6446 // Message.GetEventContext. 6445 // Message.GetEventContext.
6447 TEST(EvalContextData) { 6446 TEST(EvalContextData) {
6448 v8::HandleScope scope(v8::Isolate::GetCurrent()); 6447 v8::HandleScope scope(CcTest::isolate());
6449 6448
6450 ExecuteScriptForContextCheck(ContextCheckMessageHandler); 6449 ExecuteScriptForContextCheck(ContextCheckMessageHandler);
6451 6450
6452 // One time compile event and one time break event. 6451 // One time compile event and one time break event.
6453 CHECK_GT(message_handler_hit_count, 2); 6452 CHECK_GT(message_handler_hit_count, 2);
6454 CheckDebuggerUnloaded(); 6453 CheckDebuggerUnloaded();
6455 } 6454 }
6456 6455
6457 6456
6458 static bool sent_eval = false; 6457 static bool sent_eval = false;
6459 static int break_count = 0; 6458 static int break_count = 0;
6460 static int continue_command_send_count = 0; 6459 static int continue_command_send_count = 0;
6461 // Check that the expected context is the one generating the debug event 6460 // Check that the expected context is the one generating the debug event
6462 // including the case of nested break event. 6461 // including the case of nested break event.
6463 static void DebugEvalContextCheckMessageHandler( 6462 static void DebugEvalContextCheckMessageHandler(
6464 const v8::Debug::Message& message) { 6463 const v8::Debug::Message& message) {
6465 CHECK(message.GetEventContext() == expected_context); 6464 CHECK(message.GetEventContext() == expected_context);
6466 CHECK(message.GetEventContext()->GetEmbedderData(0)->StrictEquals( 6465 CHECK(message.GetEventContext()->GetEmbedderData(0)->StrictEquals(
6467 expected_context_data)); 6466 expected_context_data));
6468 message_handler_hit_count++; 6467 message_handler_hit_count++;
6469 6468
6470 static char print_buffer[1000]; 6469 static char print_buffer[1000];
6471 v8::String::Value json(message.GetJSON()); 6470 v8::String::Value json(message.GetJSON());
6472 Utf16ToAscii(*json, json.length(), print_buffer); 6471 Utf16ToAscii(*json, json.length(), print_buffer);
6473 6472
6473 v8::Isolate* isolate = message.GetIsolate();
6474 if (IsBreakEventMessage(print_buffer)) { 6474 if (IsBreakEventMessage(print_buffer)) {
6475 break_count++; 6475 break_count++;
6476 if (!sent_eval) { 6476 if (!sent_eval) {
6477 sent_eval = true; 6477 sent_eval = true;
6478 6478
6479 const int kBufferSize = 1000; 6479 const int kBufferSize = 1000;
6480 uint16_t buffer[kBufferSize]; 6480 uint16_t buffer[kBufferSize];
6481 const char* eval_command = 6481 const char* eval_command =
6482 "{\"seq\":0," 6482 "{\"seq\":0,"
6483 "\"type\":\"request\"," 6483 "\"type\":\"request\","
6484 "\"command\":\"evaluate\"," 6484 "\"command\":\"evaluate\","
6485 "\"arguments\":{\"expression\":\"debugger;\"," 6485 "\"arguments\":{\"expression\":\"debugger;\","
6486 "\"global\":true,\"disable_break\":false}}"; 6486 "\"global\":true,\"disable_break\":false}}";
6487 6487
6488 // Send evaluate command. 6488 // Send evaluate command.
6489 v8::Debug::SendCommand(buffer, AsciiToUtf16(eval_command, buffer)); 6489 v8::Debug::SendCommand(
6490 isolate, buffer, AsciiToUtf16(eval_command, buffer));
6490 return; 6491 return;
6491 } else { 6492 } else {
6492 // It's a break event caused by the evaluation request above. 6493 // It's a break event caused by the evaluation request above.
6493 SendContinueCommand(); 6494 SendContinueCommand();
6494 continue_command_send_count++; 6495 continue_command_send_count++;
6495 } 6496 }
6496 } else if (IsEvaluateResponseMessage(print_buffer) && 6497 } else if (IsEvaluateResponseMessage(print_buffer) &&
6497 continue_command_send_count < 2) { 6498 continue_command_send_count < 2) {
6498 // Response to the evaluation request. We're still on the breakpoint so 6499 // Response to the evaluation request. We're still on the breakpoint so
6499 // send continue. 6500 // send continue.
6500 SendContinueCommand(); 6501 SendContinueCommand();
6501 continue_command_send_count++; 6502 continue_command_send_count++;
6502 } 6503 }
6503 } 6504 }
6504 6505
6505 6506
6506 // Tests that context returned for break event is correct when the event occurs 6507 // Tests that context returned for break event is correct when the event occurs
6507 // in 'evaluate' debugger request. 6508 // in 'evaluate' debugger request.
6508 TEST(NestedBreakEventContextData) { 6509 TEST(NestedBreakEventContextData) {
6509 v8::HandleScope scope(v8::Isolate::GetCurrent()); 6510 v8::HandleScope scope(CcTest::isolate());
6510 break_count = 0; 6511 break_count = 0;
6511 message_handler_hit_count = 0; 6512 message_handler_hit_count = 0;
6512 6513
6513 ExecuteScriptForContextCheck(DebugEvalContextCheckMessageHandler); 6514 ExecuteScriptForContextCheck(DebugEvalContextCheckMessageHandler);
6514 6515
6515 // One time compile event and two times break event. 6516 // One time compile event and two times break event.
6516 CHECK_GT(message_handler_hit_count, 3); 6517 CHECK_GT(message_handler_hit_count, 3);
6517 6518
6518 // One break from the source and another from the evaluate request. 6519 // One break from the source and another from the evaluate request.
6519 CHECK_EQ(break_count, 2); 6520 CHECK_EQ(break_count, 2);
6520 CheckDebuggerUnloaded(); 6521 CheckDebuggerUnloaded();
6521 } 6522 }
6522 6523
6523 6524
6524 // Debug event listener which counts the script collected events. 6525 // Debug event listener which counts the script collected events.
6525 int script_collected_count = 0; 6526 int script_collected_count = 0;
6526 static void DebugEventScriptCollectedEvent( 6527 static void DebugEventScriptCollectedEvent(
6527 const v8::Debug::EventDetails& event_details) { 6528 const v8::Debug::EventDetails& event_details) {
6528 v8::DebugEvent event = event_details.GetEvent(); 6529 v8::DebugEvent event = event_details.GetEvent();
6529 // Count the number of breaks. 6530 // Count the number of breaks.
6530 if (event == v8::ScriptCollected) { 6531 if (event == v8::ScriptCollected) {
6531 script_collected_count++; 6532 script_collected_count++;
6532 } 6533 }
6533 } 6534 }
6534 6535
6535 6536
6536 // Test that scripts collected are reported through the debug event listener. 6537 // Test that scripts collected are reported through the debug event listener.
6537 TEST(ScriptCollectedEvent) { 6538 TEST(ScriptCollectedEvent) {
6538 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); 6539 v8::internal::Debug* debug = CcTest::i_isolate()->debug();
6539 break_point_hit_count = 0; 6540 break_point_hit_count = 0;
6540 script_collected_count = 0; 6541 script_collected_count = 0;
6541 DebugLocalContext env; 6542 DebugLocalContext env;
6542 v8::HandleScope scope(env->GetIsolate()); 6543 v8::HandleScope scope(env->GetIsolate());
6543 6544
6544 // Request the loaded scripts to initialize the debugger script cache. 6545 // Request the loaded scripts to initialize the debugger script cache.
6545 debug->GetLoadedScripts(); 6546 debug->GetLoadedScripts();
6546 6547
6547 // Do garbage collection to ensure that only the script in this test will be 6548 // Do garbage collection to ensure that only the script in this test will be
6548 // collected afterwards. 6549 // collected afterwards.
6549 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 6550 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
6550 6551
6551 script_collected_count = 0; 6552 script_collected_count = 0;
6552 v8::Debug::SetDebugEventListener2(DebugEventScriptCollectedEvent); 6553 v8::Debug::SetDebugEventListener2(DebugEventScriptCollectedEvent);
6553 { 6554 {
6554 v8::Script::Compile(v8::String::New("eval('a=1')"))->Run(); 6555 v8::Script::Compile(v8::String::New("eval('a=1')"))->Run();
6555 v8::Script::Compile(v8::String::New("eval('a=2')"))->Run(); 6556 v8::Script::Compile(v8::String::New("eval('a=2')"))->Run();
6556 } 6557 }
6557 6558
6558 // Do garbage collection to collect the script above which is no longer 6559 // Do garbage collection to collect the script above which is no longer
6559 // referenced. 6560 // referenced.
6560 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 6561 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
6561 6562
6562 CHECK_EQ(2, script_collected_count); 6563 CHECK_EQ(2, script_collected_count);
6563 6564
6564 v8::Debug::SetDebugEventListener2(NULL); 6565 v8::Debug::SetDebugEventListener2(NULL);
6565 CheckDebuggerUnloaded(); 6566 CheckDebuggerUnloaded();
6566 } 6567 }
6567 6568
6568 6569
6569 // Debug event listener which counts the script collected events. 6570 // Debug event listener which counts the script collected events.
6570 int script_collected_message_count = 0; 6571 int script_collected_message_count = 0;
6571 static void ScriptCollectedMessageHandler(const v8::Debug::Message& message) { 6572 static void ScriptCollectedMessageHandler(const v8::Debug::Message& message) {
6572 // Count the number of scripts collected. 6573 // Count the number of scripts collected.
6573 if (message.IsEvent() && message.GetEvent() == v8::ScriptCollected) { 6574 if (message.IsEvent() && message.GetEvent() == v8::ScriptCollected) {
6574 script_collected_message_count++; 6575 script_collected_message_count++;
6575 v8::Handle<v8::Context> context = message.GetEventContext(); 6576 v8::Handle<v8::Context> context = message.GetEventContext();
6576 CHECK(context.IsEmpty()); 6577 CHECK(context.IsEmpty());
6577 } 6578 }
6578 } 6579 }
6579 6580
6580 6581
6581 // Test that GetEventContext doesn't fail and return empty handle for 6582 // Test that GetEventContext doesn't fail and return empty handle for
6582 // ScriptCollected events. 6583 // ScriptCollected events.
6583 TEST(ScriptCollectedEventContext) { 6584 TEST(ScriptCollectedEventContext) {
6584 i::FLAG_stress_compaction = false; 6585 i::FLAG_stress_compaction = false;
6585 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 6586 v8::Isolate* isolate = CcTest::isolate();
6586 v8::internal::Debug* debug = 6587 v8::internal::Debug* debug =
6587 reinterpret_cast<v8::internal::Isolate*>(isolate)->debug(); 6588 reinterpret_cast<v8::internal::Isolate*>(isolate)->debug();
6588 script_collected_message_count = 0; 6589 script_collected_message_count = 0;
6589 v8::HandleScope scope(isolate); 6590 v8::HandleScope scope(isolate);
6590 6591
6591 v8::Persistent<v8::Context> context; 6592 v8::Persistent<v8::Context> context;
6592 { 6593 {
6593 v8::HandleScope scope(isolate); 6594 v8::HandleScope scope(isolate);
6594 context.Reset(isolate, v8::Context::New(isolate)); 6595 context.Reset(isolate, v8::Context::New(isolate));
6595 } 6596 }
6596 6597
6597 // Enter context. We can't have a handle to the context in the outer 6598 // Enter context. We can't have a handle to the context in the outer
6598 // scope, so we have to do it the hard way. 6599 // scope, so we have to do it the hard way.
6599 { 6600 {
6600 v8::HandleScope scope(isolate); 6601 v8::HandleScope scope(isolate);
6601 v8::Local<v8::Context> local_context = 6602 v8::Local<v8::Context> local_context =
6602 v8::Local<v8::Context>::New(isolate, context); 6603 v8::Local<v8::Context>::New(isolate, context);
6603 local_context->Enter(); 6604 local_context->Enter();
6604 } 6605 }
6605 6606
6606 // Request the loaded scripts to initialize the debugger script cache. 6607 // Request the loaded scripts to initialize the debugger script cache.
6607 debug->GetLoadedScripts(); 6608 debug->GetLoadedScripts();
6608 6609
6609 // Do garbage collection to ensure that only the script in this test will be 6610 // Do garbage collection to ensure that only the script in this test will be
6610 // collected afterwards. 6611 // collected afterwards.
6611 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 6612 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
6612 6613
6613 v8::Debug::SetMessageHandler2(ScriptCollectedMessageHandler); 6614 v8::Debug::SetMessageHandler2(ScriptCollectedMessageHandler);
6614 v8::Script::Compile(v8::String::New("eval('a=1')"))->Run(); 6615 v8::Script::Compile(v8::String::New("eval('a=1')"))->Run();
6615 v8::Script::Compile(v8::String::New("eval('a=2')"))->Run(); 6616 v8::Script::Compile(v8::String::New("eval('a=2')"))->Run();
6616 6617
6617 // Leave context 6618 // Leave context
6618 { 6619 {
6619 v8::HandleScope scope(isolate); 6620 v8::HandleScope scope(isolate);
6620 v8::Local<v8::Context> local_context = 6621 v8::Local<v8::Context> local_context =
6621 v8::Local<v8::Context>::New(isolate, context); 6622 v8::Local<v8::Context>::New(isolate, context);
6622 local_context->Exit(); 6623 local_context->Exit();
6623 } 6624 }
6624 context.Dispose(); 6625 context.Dispose();
6625 6626
6626 // Do garbage collection to collect the script above which is no longer 6627 // Do garbage collection to collect the script above which is no longer
6627 // referenced. 6628 // referenced.
6628 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 6629 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
6629 6630
6630 CHECK_EQ(2, script_collected_message_count); 6631 CHECK_EQ(2, script_collected_message_count);
6631 6632
6632 v8::Debug::SetMessageHandler2(NULL); 6633 v8::Debug::SetMessageHandler2(NULL);
6633 } 6634 }
6634 6635
6635 6636
6636 // Debug event listener which counts the after compile events. 6637 // Debug event listener which counts the after compile events.
6637 int after_compile_message_count = 0; 6638 int after_compile_message_count = 0;
6638 static void AfterCompileMessageHandler(const v8::Debug::Message& message) { 6639 static void AfterCompileMessageHandler(const v8::Debug::Message& message) {
(...skipping 14 matching lines...) Expand all
6653 DebugLocalContext env; 6654 DebugLocalContext env;
6654 v8::HandleScope scope(env->GetIsolate()); 6655 v8::HandleScope scope(env->GetIsolate());
6655 after_compile_message_count = 0; 6656 after_compile_message_count = 0;
6656 const char* script = "var a=1"; 6657 const char* script = "var a=1";
6657 6658
6658 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler); 6659 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
6659 v8::Script::Compile(v8::String::New(script))->Run(); 6660 v8::Script::Compile(v8::String::New(script))->Run();
6660 v8::Debug::SetMessageHandler2(NULL); 6661 v8::Debug::SetMessageHandler2(NULL);
6661 6662
6662 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler); 6663 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
6663 v8::Debug::DebugBreak(); 6664 v8::Debug::DebugBreak(env->GetIsolate());
6664 v8::Script::Compile(v8::String::New(script))->Run(); 6665 v8::Script::Compile(v8::String::New(script))->Run();
6665 6666
6666 // Setting listener to NULL should cause debugger unload. 6667 // Setting listener to NULL should cause debugger unload.
6667 v8::Debug::SetMessageHandler2(NULL); 6668 v8::Debug::SetMessageHandler2(NULL);
6668 CheckDebuggerUnloaded(); 6669 CheckDebuggerUnloaded();
6669 6670
6670 // Compilation cache should be disabled when debugger is active. 6671 // Compilation cache should be disabled when debugger is active.
6671 CHECK_EQ(2, after_compile_message_count); 6672 CHECK_EQ(2, after_compile_message_count);
6672 } 6673 }
6673 6674
6674 6675
6675 // Tests that break event is sent when message handler is reset. 6676 // Tests that break event is sent when message handler is reset.
6676 TEST(BreakMessageWhenMessageHandlerIsReset) { 6677 TEST(BreakMessageWhenMessageHandlerIsReset) {
6677 DebugLocalContext env; 6678 DebugLocalContext env;
6678 v8::HandleScope scope(env->GetIsolate()); 6679 v8::HandleScope scope(env->GetIsolate());
6679 after_compile_message_count = 0; 6680 after_compile_message_count = 0;
6680 const char* script = "function f() {};"; 6681 const char* script = "function f() {};";
6681 6682
6682 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler); 6683 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
6683 v8::Script::Compile(v8::String::New(script))->Run(); 6684 v8::Script::Compile(v8::String::New(script))->Run();
6684 v8::Debug::SetMessageHandler2(NULL); 6685 v8::Debug::SetMessageHandler2(NULL);
6685 6686
6686 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler); 6687 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
6687 v8::Debug::DebugBreak(); 6688 v8::Debug::DebugBreak(env->GetIsolate());
6688 v8::Local<v8::Function> f = 6689 v8::Local<v8::Function> f =
6689 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); 6690 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
6690 f->Call(env->Global(), 0, NULL); 6691 f->Call(env->Global(), 0, NULL);
6691 6692
6692 // Setting message handler to NULL should cause debugger unload. 6693 // Setting message handler to NULL should cause debugger unload.
6693 v8::Debug::SetMessageHandler2(NULL); 6694 v8::Debug::SetMessageHandler2(NULL);
6694 CheckDebuggerUnloaded(); 6695 CheckDebuggerUnloaded();
6695 6696
6696 // Compilation cache should be disabled when debugger is active. 6697 // Compilation cache should be disabled when debugger is active.
6697 CHECK_EQ(1, after_compile_message_count); 6698 CHECK_EQ(1, after_compile_message_count);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
6766 // sent. 6767 // sent.
6767 CHECK_EQ(1, after_compile_message_count); 6768 CHECK_EQ(1, after_compile_message_count);
6768 6769
6769 ClearBreakPointFromJS(sbp1); 6770 ClearBreakPointFromJS(sbp1);
6770 ClearBreakPointFromJS(sbp2); 6771 ClearBreakPointFromJS(sbp2);
6771 v8::Debug::SetMessageHandler2(NULL); 6772 v8::Debug::SetMessageHandler2(NULL);
6772 } 6773 }
6773 6774
6774 6775
6775 static void BreakMessageHandler(const v8::Debug::Message& message) { 6776 static void BreakMessageHandler(const v8::Debug::Message& message) {
6776 i::Isolate* isolate = i::Isolate::Current(); 6777 i::Isolate* isolate = CcTest::i_isolate();
6777 if (message.IsEvent() && message.GetEvent() == v8::Break) { 6778 if (message.IsEvent() && message.GetEvent() == v8::Break) {
6778 // Count the number of breaks. 6779 // Count the number of breaks.
6779 break_point_hit_count++; 6780 break_point_hit_count++;
6780 6781
6781 i::HandleScope scope(isolate); 6782 i::HandleScope scope(isolate);
6782 message.GetJSON(); 6783 message.GetJSON();
6783 6784
6784 SendContinueCommand(); 6785 SendContinueCommand();
6785 } else if (message.IsEvent() && message.GetEvent() == v8::AfterCompile) { 6786 } else if (message.IsEvent() && message.GetEvent() == v8::AfterCompile) {
6786 i::HandleScope scope(isolate); 6787 i::HandleScope scope(isolate);
(...skipping 10 matching lines...) Expand all
6797 isolate->stack_guard()->DebugBreak(); 6798 isolate->stack_guard()->DebugBreak();
6798 } else { 6799 } else {
6799 isolate->stack_guard()->Continue(i::DEBUGBREAK); 6800 isolate->stack_guard()->Continue(i::DEBUGBREAK);
6800 } 6801 }
6801 } 6802 }
6802 } 6803 }
6803 6804
6804 6805
6805 // Test that if DebugBreak is forced it is ignored when code from 6806 // Test that if DebugBreak is forced it is ignored when code from
6806 // debug-delay.js is executed. 6807 // debug-delay.js is executed.
6807 TEST(NoDebugBreakInAfterCompileMessageHandler) { 6808 UNINITIALIZED_TEST(NoDebugBreakInAfterCompileMessageHandler) {
6808 DebugLocalContext env; 6809 DebugLocalContext env;
6809 v8::HandleScope scope(env->GetIsolate()); 6810 v8::HandleScope scope(env->GetIsolate());
6810 6811
6811 // Register a debug event listener which sets the break flag and counts. 6812 // Register a debug event listener which sets the break flag and counts.
6812 v8::Debug::SetMessageHandler2(BreakMessageHandler); 6813 v8::Debug::SetMessageHandler2(BreakMessageHandler);
6813 6814
6814 // Set the debug break flag. 6815 // Set the debug break flag.
6815 v8::Debug::DebugBreak(); 6816 v8::Debug::DebugBreak();
6816 6817
6817 // Create a function for testing stepping. 6818 // Create a function for testing stepping.
6818 const char* src = "function f() { eval('var x = 10;'); } "; 6819 const char* src = "function f() { eval('var x = 10;'); } ";
6819 v8::Local<v8::Function> f = CompileFunction(&env, src, "f"); 6820 v8::Local<v8::Function> f = CompileFunction(&env, src, "f");
6820 6821
6821 // There should be only one break event. 6822 // There should be only one break event.
6822 CHECK_EQ(1, break_point_hit_count); 6823 CHECK_EQ(1, break_point_hit_count);
6823 6824
6824 // Set the debug break flag again. 6825 // Set the debug break flag again.
6825 v8::Debug::DebugBreak(); 6826 v8::Debug::DebugBreak(env->GetIsolate());
6826 f->Call(env->Global(), 0, NULL); 6827 f->Call(env->Global(), 0, NULL);
6827 // There should be one more break event when the script is evaluated in 'f'. 6828 // There should be one more break event when the script is evaluated in 'f'.
6828 CHECK_EQ(2, break_point_hit_count); 6829 CHECK_EQ(2, break_point_hit_count);
6829 6830
6830 // Get rid of the debug message handler. 6831 // Get rid of the debug message handler.
6831 v8::Debug::SetMessageHandler2(NULL); 6832 v8::Debug::SetMessageHandler2(NULL);
6832 CheckDebuggerUnloaded(); 6833 CheckDebuggerUnloaded();
6833 } 6834 }
6834 6835
6835 6836
6836 static int counting_message_handler_counter; 6837 static int counting_message_handler_counter;
6837 6838
6838 static void CountingMessageHandler(const v8::Debug::Message& message) { 6839 static void CountingMessageHandler(const v8::Debug::Message& message) {
6839 counting_message_handler_counter++; 6840 counting_message_handler_counter++;
6840 } 6841 }
6841 6842
6842 6843
6843 // Test that debug messages get processed when ProcessDebugMessages is called. 6844 // Test that debug messages get processed when ProcessDebugMessages is called.
6844 TEST(ProcessDebugMessages) { 6845 TEST(ProcessDebugMessages) {
6845 DebugLocalContext env; 6846 DebugLocalContext env;
6846 v8::HandleScope scope(env->GetIsolate()); 6847 v8::Isolate* isolate = env->GetIsolate();
6848 v8::HandleScope scope(isolate);
6847 6849
6848 counting_message_handler_counter = 0; 6850 counting_message_handler_counter = 0;
6849 6851
6850 v8::Debug::SetMessageHandler2(CountingMessageHandler); 6852 v8::Debug::SetMessageHandler2(CountingMessageHandler);
6851 6853
6852 const int kBufferSize = 1000; 6854 const int kBufferSize = 1000;
6853 uint16_t buffer[kBufferSize]; 6855 uint16_t buffer[kBufferSize];
6854 const char* scripts_command = 6856 const char* scripts_command =
6855 "{\"seq\":0," 6857 "{\"seq\":0,"
6856 "\"type\":\"request\"," 6858 "\"type\":\"request\","
6857 "\"command\":\"scripts\"}"; 6859 "\"command\":\"scripts\"}";
6858 6860
6859 // Send scripts command. 6861 // Send scripts command.
6860 v8::Debug::SendCommand(buffer, AsciiToUtf16(scripts_command, buffer)); 6862 v8::Debug::SendCommand(
6863 isolate, buffer, AsciiToUtf16(scripts_command, buffer));
6861 6864
6862 CHECK_EQ(0, counting_message_handler_counter); 6865 CHECK_EQ(0, counting_message_handler_counter);
6863 v8::Debug::ProcessDebugMessages(); 6866 v8::Debug::ProcessDebugMessages();
6864 // At least one message should come 6867 // At least one message should come
6865 CHECK_GE(counting_message_handler_counter, 1); 6868 CHECK_GE(counting_message_handler_counter, 1);
6866 6869
6867 counting_message_handler_counter = 0; 6870 counting_message_handler_counter = 0;
6868 6871
6869 v8::Debug::SendCommand(buffer, AsciiToUtf16(scripts_command, buffer)); 6872 v8::Debug::SendCommand(
6870 v8::Debug::SendCommand(buffer, AsciiToUtf16(scripts_command, buffer)); 6873 isolate, buffer, AsciiToUtf16(scripts_command, buffer));
6874 v8::Debug::SendCommand(
6875 isolate, buffer, AsciiToUtf16(scripts_command, buffer));
6871 CHECK_EQ(0, counting_message_handler_counter); 6876 CHECK_EQ(0, counting_message_handler_counter);
6872 v8::Debug::ProcessDebugMessages(); 6877 v8::Debug::ProcessDebugMessages();
6873 // At least two messages should come 6878 // At least two messages should come
6874 CHECK_GE(counting_message_handler_counter, 2); 6879 CHECK_GE(counting_message_handler_counter, 2);
6875 6880
6876 // Get rid of the debug message handler. 6881 // Get rid of the debug message handler.
6877 v8::Debug::SetMessageHandler2(NULL); 6882 v8::Debug::SetMessageHandler2(NULL);
6878 CheckDebuggerUnloaded(); 6883 CheckDebuggerUnloaded();
6879 } 6884 }
6880 6885
(...skipping 11 matching lines...) Expand all
6892 frame_counter = GetTotalFramesInt(print_buffer); 6897 frame_counter = GetTotalFramesInt(print_buffer);
6893 } 6898 }
6894 }; 6899 };
6895 6900
6896 int BacktraceData::frame_counter; 6901 int BacktraceData::frame_counter;
6897 6902
6898 6903
6899 // Test that debug messages get processed when ProcessDebugMessages is called. 6904 // Test that debug messages get processed when ProcessDebugMessages is called.
6900 TEST(Backtrace) { 6905 TEST(Backtrace) {
6901 DebugLocalContext env; 6906 DebugLocalContext env;
6902 v8::HandleScope scope(env->GetIsolate()); 6907 v8::Isolate* isolate = env->GetIsolate();
6908 v8::HandleScope scope(isolate);
6903 6909
6904 v8::Debug::SetMessageHandler2(BacktraceData::MessageHandler); 6910 v8::Debug::SetMessageHandler2(BacktraceData::MessageHandler);
6905 6911
6906 const int kBufferSize = 1000; 6912 const int kBufferSize = 1000;
6907 uint16_t buffer[kBufferSize]; 6913 uint16_t buffer[kBufferSize];
6908 const char* scripts_command = 6914 const char* scripts_command =
6909 "{\"seq\":0," 6915 "{\"seq\":0,"
6910 "\"type\":\"request\"," 6916 "\"type\":\"request\","
6911 "\"command\":\"backtrace\"}"; 6917 "\"command\":\"backtrace\"}";
6912 6918
6913 // Check backtrace from ProcessDebugMessages. 6919 // Check backtrace from ProcessDebugMessages.
6914 BacktraceData::frame_counter = -10; 6920 BacktraceData::frame_counter = -10;
6915 v8::Debug::SendCommand(buffer, AsciiToUtf16(scripts_command, buffer)); 6921 v8::Debug::SendCommand(
6922 isolate,
6923 buffer,
6924 AsciiToUtf16(scripts_command, buffer),
6925 NULL);
6916 v8::Debug::ProcessDebugMessages(); 6926 v8::Debug::ProcessDebugMessages();
6917 CHECK_EQ(BacktraceData::frame_counter, 0); 6927 CHECK_EQ(BacktraceData::frame_counter, 0);
6918 6928
6919 v8::Handle<v8::String> void0 = v8::String::New("void(0)"); 6929 v8::Handle<v8::String> void0 = v8::String::New("void(0)");
6920 v8::Handle<v8::Script> script = v8::Script::Compile(void0, void0); 6930 v8::Handle<v8::Script> script = v8::Script::Compile(void0, void0);
6921 6931
6922 // Check backtrace from "void(0)" script. 6932 // Check backtrace from "void(0)" script.
6923 BacktraceData::frame_counter = -10; 6933 BacktraceData::frame_counter = -10;
6924 v8::Debug::SendCommand(buffer, AsciiToUtf16(scripts_command, buffer)); 6934 v8::Debug::SendCommand(
6935 isolate,
6936 buffer,
6937 AsciiToUtf16(scripts_command, buffer),
6938 NULL);
6925 script->Run(); 6939 script->Run();
6926 CHECK_EQ(BacktraceData::frame_counter, 1); 6940 CHECK_EQ(BacktraceData::frame_counter, 1);
6927 6941
6928 // Get rid of the debug message handler. 6942 // Get rid of the debug message handler.
6929 v8::Debug::SetMessageHandler2(NULL); 6943 v8::Debug::SetMessageHandler2(NULL);
6930 CheckDebuggerUnloaded(); 6944 CheckDebuggerUnloaded();
6931 } 6945 }
6932 6946
6933 6947
6934 TEST(GetMirror) { 6948 TEST(GetMirror) {
(...skipping 23 matching lines...) Expand all
6958 &env, 6972 &env,
6959 "function baz(x) { }" 6973 "function baz(x) { }"
6960 "function bar(x) { baz(); }" 6974 "function bar(x) { baz(); }"
6961 "function foo(){ bar.apply(this, [1]); }", 6975 "function foo(){ bar.apply(this, [1]); }",
6962 "foo"); 6976 "foo");
6963 6977
6964 // Register a debug event listener which steps and counts. 6978 // Register a debug event listener which steps and counts.
6965 v8::Debug::SetDebugEventListener2(DebugEventBreakMax); 6979 v8::Debug::SetDebugEventListener2(DebugEventBreakMax);
6966 6980
6967 // Set the debug break flag before calling the code using function.apply. 6981 // Set the debug break flag before calling the code using function.apply.
6968 v8::Debug::DebugBreak(); 6982 v8::Debug::DebugBreak(env->GetIsolate());
6969 6983
6970 // Limit the number of debug breaks. This is a regression test for issue 493 6984 // Limit the number of debug breaks. This is a regression test for issue 493
6971 // where this test would enter an infinite loop. 6985 // where this test would enter an infinite loop.
6972 break_point_hit_count = 0; 6986 break_point_hit_count = 0;
6973 max_break_point_hit_count = 10000; // 10000 => infinite loop. 6987 max_break_point_hit_count = 10000; // 10000 => infinite loop.
6974 foo->Call(env->Global(), 0, NULL); 6988 foo->Call(env->Global(), 0, NULL);
6975 6989
6976 // When keeping the debug break several break will happen. 6990 // When keeping the debug break several break will happen.
6977 CHECK_GT(break_point_hit_count, 1); 6991 CHECK_GT(break_point_hit_count, 1);
6978 6992
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
7018 "})")); 7032 "})"));
7019 const int argc = 1; 7033 const int argc = 1;
7020 v8::Handle<v8::Value> argv[argc] = { exec_state }; 7034 v8::Handle<v8::Value> argv[argc] = { exec_state };
7021 v8::Handle<v8::Value> result = func->Call(exec_state, argc, argv); 7035 v8::Handle<v8::Value> result = func->Call(exec_state, argc, argv);
7022 CHECK(result->IsTrue()); 7036 CHECK(result->IsTrue());
7023 } 7037 }
7024 } 7038 }
7025 7039
7026 7040
7027 TEST(CallingContextIsNotDebugContext) { 7041 TEST(CallingContextIsNotDebugContext) {
7028 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); 7042 v8::internal::Debug* debug = CcTest::i_isolate()->debug();
7029 // Create and enter a debugee context. 7043 // Create and enter a debugee context.
7030 DebugLocalContext env; 7044 DebugLocalContext env;
7031 v8::HandleScope scope(env->GetIsolate()); 7045 v8::HandleScope scope(env->GetIsolate());
7032 env.ExposeDebug(); 7046 env.ExposeDebug();
7033 7047
7034 // Save handles to the debugger and debugee contexts to be used in 7048 // Save handles to the debugger and debugee contexts to be used in
7035 // NamedGetterWithCallingContextCheck. 7049 // NamedGetterWithCallingContextCheck.
7036 debugee_context = env.context(); 7050 debugee_context = env.context();
7037 debugger_context = v8::Utils::ToLocal(debug->debug_context()); 7051 debugger_context = v8::Utils::ToLocal(debug->debug_context());
7038 7052
(...skipping 19 matching lines...) Expand all
7058 CHECK_EQ(1, break_point_hit_count); 7072 CHECK_EQ(1, break_point_hit_count);
7059 7073
7060 v8::Debug::SetDebugEventListener2(NULL); 7074 v8::Debug::SetDebugEventListener2(NULL);
7061 debugee_context = v8::Handle<v8::Context>(); 7075 debugee_context = v8::Handle<v8::Context>();
7062 debugger_context = v8::Handle<v8::Context>(); 7076 debugger_context = v8::Handle<v8::Context>();
7063 CheckDebuggerUnloaded(); 7077 CheckDebuggerUnloaded();
7064 } 7078 }
7065 7079
7066 7080
7067 TEST(DebugContextIsPreservedBetweenAccesses) { 7081 TEST(DebugContextIsPreservedBetweenAccesses) {
7068 v8::HandleScope scope(v8::Isolate::GetCurrent()); 7082 v8::HandleScope scope(CcTest::isolate());
7069 v8::Local<v8::Context> context1 = v8::Debug::GetDebugContext(); 7083 v8::Local<v8::Context> context1 = v8::Debug::GetDebugContext();
7070 v8::Local<v8::Context> context2 = v8::Debug::GetDebugContext(); 7084 v8::Local<v8::Context> context2 = v8::Debug::GetDebugContext();
7071 CHECK_EQ(*context1, *context2); 7085 CHECK_EQ(*context1, *context2);
7072 } 7086 }
7073 7087
7074 7088
7075 static v8::Handle<v8::Value> expected_callback_data; 7089 static v8::Handle<v8::Value> expected_callback_data;
7076 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) { 7090 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) {
7077 CHECK(details.GetEventContext() == expected_context); 7091 CHECK(details.GetEventContext() == expected_context);
7078 CHECK_EQ(expected_callback_data, details.GetCallbackData()); 7092 CHECK_EQ(expected_callback_data, details.GetCallbackData());
7079 } 7093 }
7080 7094
7081 7095
7082 // Check that event details contain context where debug event occured. 7096 // Check that event details contain context where debug event occured.
7083 TEST(DebugEventContext) { 7097 TEST(DebugEventContext) {
7084 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 7098 v8::Isolate* isolate = CcTest::isolate();
7085 v8::HandleScope scope(isolate); 7099 v8::HandleScope scope(isolate);
7086 expected_callback_data = v8::Int32::New(2010); 7100 expected_callback_data = v8::Int32::New(2010);
7087 expected_context = v8::Context::New(isolate); 7101 expected_context = v8::Context::New(isolate);
7088 v8::Debug::SetDebugEventListener2(DebugEventContextChecker, 7102 v8::Debug::SetDebugEventListener2(DebugEventContextChecker,
7089 expected_callback_data); 7103 expected_callback_data);
7090 v8::Context::Scope context_scope(expected_context); 7104 v8::Context::Scope context_scope(expected_context);
7091 v8::Script::Compile(v8::String::New("(function(){debugger;})();"))->Run(); 7105 v8::Script::Compile(v8::String::New("(function(){debugger;})();"))->Run();
7092 expected_context.Clear(); 7106 expected_context.Clear();
7093 v8::Debug::SetDebugEventListener2(NULL); 7107 v8::Debug::SetDebugEventListener2(NULL);
7094 expected_context_data = v8::Handle<v8::Value>(); 7108 expected_context_data = v8::Handle<v8::Value>();
(...skipping 10 matching lines...) Expand all
7105 was_debug_event_called = true; 7119 was_debug_event_called = true;
7106 } else if (details.GetEvent() == v8::Break) { 7120 } else if (details.GetEvent() == v8::Break) {
7107 was_debug_break_called = true; 7121 was_debug_break_called = true;
7108 } 7122 }
7109 } 7123 }
7110 7124
7111 7125
7112 // Check that event details contain context where debug event occured. 7126 // Check that event details contain context where debug event occured.
7113 TEST(DebugEventBreakData) { 7127 TEST(DebugEventBreakData) {
7114 DebugLocalContext env; 7128 DebugLocalContext env;
7115 v8::HandleScope scope(env->GetIsolate()); 7129 v8::Isolate* isolate = env->GetIsolate();
7130 v8::HandleScope scope(isolate);
7116 v8::Debug::SetDebugEventListener2(DebugEventBreakDataChecker); 7131 v8::Debug::SetDebugEventListener2(DebugEventBreakDataChecker);
7117 7132
7118 TestClientData::constructor_call_counter = 0; 7133 TestClientData::constructor_call_counter = 0;
7119 TestClientData::destructor_call_counter = 0; 7134 TestClientData::destructor_call_counter = 0;
7120 7135
7121 expected_break_data = NULL; 7136 expected_break_data = NULL;
7122 was_debug_event_called = false; 7137 was_debug_event_called = false;
7123 was_debug_break_called = false; 7138 was_debug_break_called = false;
7124 v8::Debug::DebugBreakForCommand(); 7139 v8::Debug::DebugBreakForCommand(NULL, isolate);
7125 v8::Script::Compile(v8::String::New("(function(x){return x;})(1);"))->Run(); 7140 v8::Script::Compile(v8::String::New("(function(x){return x;})(1);"))->Run();
7126 CHECK(was_debug_event_called); 7141 CHECK(was_debug_event_called);
7127 CHECK(!was_debug_break_called); 7142 CHECK(!was_debug_break_called);
7128 7143
7129 TestClientData* data1 = new TestClientData(); 7144 TestClientData* data1 = new TestClientData();
7130 expected_break_data = data1; 7145 expected_break_data = data1;
7131 was_debug_event_called = false; 7146 was_debug_event_called = false;
7132 was_debug_break_called = false; 7147 was_debug_break_called = false;
7133 v8::Debug::DebugBreakForCommand(data1); 7148 v8::Debug::DebugBreakForCommand(data1, isolate);
7134 v8::Script::Compile(v8::String::New("(function(x){return x+1;})(1);"))->Run(); 7149 v8::Script::Compile(v8::String::New("(function(x){return x+1;})(1);"))->Run();
7135 CHECK(was_debug_event_called); 7150 CHECK(was_debug_event_called);
7136 CHECK(!was_debug_break_called); 7151 CHECK(!was_debug_break_called);
7137 7152
7138 expected_break_data = NULL; 7153 expected_break_data = NULL;
7139 was_debug_event_called = false; 7154 was_debug_event_called = false;
7140 was_debug_break_called = false; 7155 was_debug_break_called = false;
7141 v8::Debug::DebugBreak(); 7156 v8::Debug::DebugBreak(isolate);
7142 v8::Script::Compile(v8::String::New("(function(x){return x+2;})(1);"))->Run(); 7157 v8::Script::Compile(v8::String::New("(function(x){return x+2;})(1);"))->Run();
7143 CHECK(!was_debug_event_called); 7158 CHECK(!was_debug_event_called);
7144 CHECK(was_debug_break_called); 7159 CHECK(was_debug_break_called);
7145 7160
7146 TestClientData* data2 = new TestClientData(); 7161 TestClientData* data2 = new TestClientData();
7147 expected_break_data = data2; 7162 expected_break_data = data2;
7148 was_debug_event_called = false; 7163 was_debug_event_called = false;
7149 was_debug_break_called = false; 7164 was_debug_break_called = false;
7150 v8::Debug::DebugBreak(); 7165 v8::Debug::DebugBreak(isolate);
7151 v8::Debug::DebugBreakForCommand(data2); 7166 v8::Debug::DebugBreakForCommand(data2, isolate);
7152 v8::Script::Compile(v8::String::New("(function(x){return x+3;})(1);"))->Run(); 7167 v8::Script::Compile(v8::String::New("(function(x){return x+3;})(1);"))->Run();
7153 CHECK(was_debug_event_called); 7168 CHECK(was_debug_event_called);
7154 CHECK(was_debug_break_called); 7169 CHECK(was_debug_break_called);
7155 7170
7156 CHECK_EQ(2, TestClientData::constructor_call_counter); 7171 CHECK_EQ(2, TestClientData::constructor_call_counter);
7157 CHECK_EQ(TestClientData::constructor_call_counter, 7172 CHECK_EQ(TestClientData::constructor_call_counter,
7158 TestClientData::destructor_call_counter); 7173 TestClientData::destructor_call_counter);
7159 7174
7160 v8::Debug::SetDebugEventListener2(NULL); 7175 v8::Debug::SetDebugEventListener2(NULL);
7161 CheckDebuggerUnloaded(); 7176 CheckDebuggerUnloaded();
(...skipping 11 matching lines...) Expand all
7173 const int argc = 2; 7188 const int argc = 2;
7174 v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(0) }; 7189 v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(0) };
7175 v8::Handle<v8::Value> result = 7190 v8::Handle<v8::Value> result =
7176 frame_function_name->Call(exec_state, argc, argv); 7191 frame_function_name->Call(exec_state, argc, argv);
7177 if (!result->IsUndefined()) { 7192 if (!result->IsUndefined()) {
7178 char fn[80]; 7193 char fn[80];
7179 CHECK(result->IsString()); 7194 CHECK(result->IsString());
7180 v8::Handle<v8::String> function_name(result->ToString()); 7195 v8::Handle<v8::String> function_name(result->ToString());
7181 function_name->WriteUtf8(fn); 7196 function_name->WriteUtf8(fn);
7182 if (strcmp(fn, "bar") == 0) { 7197 if (strcmp(fn, "bar") == 0) {
7183 i::Deoptimizer::DeoptimizeAll(v8::internal::Isolate::Current()); 7198 i::Deoptimizer::DeoptimizeAll(CcTest::i_isolate());
7184 debug_event_break_deoptimize_done = true; 7199 debug_event_break_deoptimize_done = true;
7185 } 7200 }
7186 } 7201 }
7187 } 7202 }
7188 7203
7189 v8::Debug::DebugBreak(); 7204 v8::Debug::DebugBreak(CcTest::isolate());
7190 } 7205 }
7191 } 7206 }
7192 7207
7193 7208
7194 // Test deoptimization when execution is broken using the debug break stack 7209 // Test deoptimization when execution is broken using the debug break stack
7195 // check interrupt. 7210 // check interrupt.
7196 TEST(DeoptimizeDuringDebugBreak) { 7211 TEST(DeoptimizeDuringDebugBreak) {
7197 DebugLocalContext env; 7212 DebugLocalContext env;
7198 v8::HandleScope scope(env->GetIsolate()); 7213 v8::HandleScope scope(env->GetIsolate());
7199 env.ExposeDebug(); 7214 env.ExposeDebug();
7200 7215
7201 // Create a function for checking the function when hitting a break point. 7216 // Create a function for checking the function when hitting a break point.
7202 frame_function_name = CompileFunction(&env, 7217 frame_function_name = CompileFunction(&env,
7203 frame_function_name_source, 7218 frame_function_name_source,
7204 "frame_function_name"); 7219 "frame_function_name");
7205 7220
7206 7221
7207 // Set a debug event listener which will keep interrupting execution until 7222 // Set a debug event listener which will keep interrupting execution until
7208 // debug break. When inside function bar it will deoptimize all functions. 7223 // debug break. When inside function bar it will deoptimize all functions.
7209 // This tests lazy deoptimization bailout for the stack check, as the first 7224 // This tests lazy deoptimization bailout for the stack check, as the first
7210 // time in function bar when using debug break and no break points will be at 7225 // time in function bar when using debug break and no break points will be at
7211 // the initial stack check. 7226 // the initial stack check.
7212 v8::Debug::SetDebugEventListener2(DebugEventBreakDeoptimize); 7227 v8::Debug::SetDebugEventListener2(DebugEventBreakDeoptimize);
7213 7228
7214 // Compile and run function bar which will optimize it for some flag settings. 7229 // Compile and run function bar which will optimize it for some flag settings.
7215 v8::Script::Compile(v8::String::New("function bar(){}; bar()"))->Run(); 7230 v8::Script::Compile(v8::String::New("function bar(){}; bar()"))->Run();
7216 7231
7217 // Set debug break and call bar again. 7232 // Set debug break and call bar again.
7218 v8::Debug::DebugBreak(); 7233 v8::Debug::DebugBreak(env->GetIsolate());
7219 v8::Script::Compile(v8::String::New("bar()"))->Run(); 7234 v8::Script::Compile(v8::String::New("bar()"))->Run();
7220 7235
7221 CHECK(debug_event_break_deoptimize_done); 7236 CHECK(debug_event_break_deoptimize_done);
7222 7237
7223 v8::Debug::SetDebugEventListener2(NULL); 7238 v8::Debug::SetDebugEventListener2(NULL);
7224 } 7239 }
7225 7240
7226 7241
7227 static void DebugEventBreakWithOptimizedStack( 7242 static void DebugEventBreakWithOptimizedStack(
7228 const v8::Debug::EventDetails& event_details) { 7243 const v8::Debug::EventDetails& event_details) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
7266 result = frame_local_value->Call(exec_state, argc, argv); 7281 result = frame_local_value->Call(exec_state, argc, argv);
7267 CHECK(result->IsUndefined() || (result->Int32Value() == 42)); 7282 CHECK(result->IsUndefined() || (result->Int32Value() == 42));
7268 } 7283 }
7269 } 7284 }
7270 } 7285 }
7271 } 7286 }
7272 7287
7273 7288
7274 static void ScheduleBreak(const v8::FunctionCallbackInfo<v8::Value>& args) { 7289 static void ScheduleBreak(const v8::FunctionCallbackInfo<v8::Value>& args) {
7275 v8::Debug::SetDebugEventListener2(DebugEventBreakWithOptimizedStack); 7290 v8::Debug::SetDebugEventListener2(DebugEventBreakWithOptimizedStack);
7276 v8::Debug::DebugBreak(); 7291 v8::Debug::DebugBreak(args.GetIsolate());
7277 } 7292 }
7278 7293
7279 7294
7280 TEST(DebugBreakStackInspection) { 7295 TEST(DebugBreakStackInspection) {
7281 DebugLocalContext env; 7296 DebugLocalContext env;
7282 v8::HandleScope scope(env->GetIsolate()); 7297 v8::HandleScope scope(env->GetIsolate());
7283 7298
7284 frame_function_name = 7299 frame_function_name =
7285 CompileFunction(&env, frame_function_name_source, "frame_function_name"); 7300 CompileFunction(&env, frame_function_name_source, "frame_function_name");
7286 frame_argument_name = 7301 frame_argument_name =
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
7331 7346
7332 EmbeddedVector<char, 1024> buffer; 7347 EmbeddedVector<char, 1024> buffer;
7333 OS::SNPrintF(buffer, 7348 OS::SNPrintF(buffer,
7334 "function f() {%s%s%s}", 7349 "function f() {%s%s%s}",
7335 loop_head, loop_bodies[i], loop_tail); 7350 loop_head, loop_bodies[i], loop_tail);
7336 7351
7337 // Function with infinite loop. 7352 // Function with infinite loop.
7338 CompileRun(buffer.start()); 7353 CompileRun(buffer.start());
7339 7354
7340 // Set the debug break to enter the debugger as soon as possible. 7355 // Set the debug break to enter the debugger as soon as possible.
7341 v8::Debug::DebugBreak(); 7356 v8::Debug::DebugBreak(CcTest::isolate());
7342 7357
7343 // Call function with infinite loop. 7358 // Call function with infinite loop.
7344 CompileRun("f();"); 7359 CompileRun("f();");
7345 CHECK_EQ(kBreaksPerTest, break_point_hit_count); 7360 CHECK_EQ(kBreaksPerTest, break_point_hit_count);
7346 7361
7347 CHECK(!v8::V8::IsExecutionTerminating()); 7362 CHECK(!v8::V8::IsExecutionTerminating());
7348 } 7363 }
7349 } 7364 }
7350 } 7365 }
7351 7366
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
7401 v8::DebugEvent event = event_details.GetEvent(); 7416 v8::DebugEvent event = event_details.GetEvent();
7402 if (event != v8::Break) return; 7417 if (event != v8::Break) return;
7403 7418
7404 int expected_frame_count = 4; 7419 int expected_frame_count = 4;
7405 int expected_line_number[] = {1, 4, 7, 12}; 7420 int expected_line_number[] = {1, 4, 7, 12};
7406 7421
7407 i::Handle<i::Object> compiled_script = v8::Utils::OpenHandle(*inline_script); 7422 i::Handle<i::Object> compiled_script = v8::Utils::OpenHandle(*inline_script);
7408 i::Handle<i::Script> source_script = i::Handle<i::Script>(i::Script::cast( 7423 i::Handle<i::Script> source_script = i::Handle<i::Script>(i::Script::cast(
7409 i::JSFunction::cast(*compiled_script)->shared()->script())); 7424 i::JSFunction::cast(*compiled_script)->shared()->script()));
7410 7425
7411 int break_id = v8::internal::Isolate::Current()->debug()->break_id(); 7426 int break_id = CcTest::i_isolate()->debug()->break_id();
7412 char script[128]; 7427 char script[128];
7413 i::Vector<char> script_vector(script, sizeof(script)); 7428 i::Vector<char> script_vector(script, sizeof(script));
7414 OS::SNPrintF(script_vector, "%%GetFrameCount(%d)", break_id); 7429 OS::SNPrintF(script_vector, "%%GetFrameCount(%d)", break_id);
7415 v8::Local<v8::Value> result = CompileRun(script); 7430 v8::Local<v8::Value> result = CompileRun(script);
7416 7431
7417 int frame_count = result->Int32Value(); 7432 int frame_count = result->Int32Value();
7418 CHECK_EQ(expected_frame_count, frame_count); 7433 CHECK_EQ(expected_frame_count, frame_count);
7419 7434
7420 for (int i = 0; i < frame_count; i++) { 7435 for (int i = 0; i < frame_count; i++) {
7421 // The 5. element in the returned array of GetFrameDetails contains the 7436 // The 5. element in the returned array of GetFrameDetails contains the
7422 // source position of that frame. 7437 // source position of that frame.
7423 OS::SNPrintF(script_vector, "%%GetFrameDetails(%d, %d)[5]", break_id, i); 7438 OS::SNPrintF(script_vector, "%%GetFrameDetails(%d, %d)[5]", break_id, i);
7424 v8::Local<v8::Value> result = CompileRun(script); 7439 v8::Local<v8::Value> result = CompileRun(script);
7425 CHECK_EQ(expected_line_number[i], 7440 CHECK_EQ(expected_line_number[i],
7426 i::GetScriptLineNumber(source_script, result->Int32Value())); 7441 i::GetScriptLineNumber(source_script, result->Int32Value()));
7427 } 7442 }
7428 v8::Debug::SetDebugEventListener2(NULL); 7443 v8::Debug::SetDebugEventListener2(NULL);
7429 v8::V8::TerminateExecution(); 7444 v8::V8::TerminateExecution(CcTest::isolate());
7430 } 7445 }
7431 7446
7432 7447
7433 TEST(DebugBreakInline) { 7448 TEST(DebugBreakInline) {
7434 i::FLAG_allow_natives_syntax = true; 7449 i::FLAG_allow_natives_syntax = true;
7435 DebugLocalContext env; 7450 DebugLocalContext env;
7436 v8::HandleScope scope(env->GetIsolate()); 7451 v8::HandleScope scope(env->GetIsolate());
7437 const char* source = 7452 const char* source =
7438 "function debug(b) { \n" 7453 "function debug(b) { \n"
7439 " if (b) debugger; \n" 7454 " if (b) debugger; \n"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
7519 CHECK_EQ(2, CountNativeContexts()); 7534 CHECK_EQ(2, CountNativeContexts());
7520 7535
7521 v8::Debug::SetDebugEventListener2(NULL); 7536 v8::Debug::SetDebugEventListener2(NULL);
7522 } 7537 }
7523 7538
7524 7539
7525 TEST(LiveEditEnabled) { 7540 TEST(LiveEditEnabled) {
7526 v8::internal::FLAG_allow_natives_syntax = true; 7541 v8::internal::FLAG_allow_natives_syntax = true;
7527 LocalContext env; 7542 LocalContext env;
7528 v8::HandleScope scope(env->GetIsolate()); 7543 v8::HandleScope scope(env->GetIsolate());
7529 v8::Debug::SetLiveEditEnabled(true); 7544 v8::Debug::SetLiveEditEnabled(true, env->GetIsolate());
7530 CompileRun("%LiveEditCompareStrings('', '')"); 7545 CompileRun("%LiveEditCompareStrings('', '')");
7531 } 7546 }
7532 7547
7533 7548
7534 TEST(LiveEditDisabled) { 7549 TEST(LiveEditDisabled) {
7535 v8::internal::FLAG_allow_natives_syntax = true; 7550 v8::internal::FLAG_allow_natives_syntax = true;
7536 LocalContext env; 7551 LocalContext env;
7537 v8::HandleScope scope(env->GetIsolate()); 7552 v8::HandleScope scope(env->GetIsolate());
7538 v8::Debug::SetLiveEditEnabled(false); 7553 v8::Debug::SetLiveEditEnabled(false), env->GetIsolate();
7539 CompileRun("%LiveEditCompareStrings('', '')"); 7554 CompileRun("%LiveEditCompareStrings('', '')");
7540 } 7555 }
7541 7556
7542 7557
7543 #endif // ENABLE_DEBUGGER_SUPPORT 7558 #endif // ENABLE_DEBUGGER_SUPPORT
OLDNEW
« no previous file with comments | « test/cctest/test-date.cc ('k') | test/cctest/test-declarative-accessors.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698