Lines Matching refs:v8
1 // Copyright 2010 the V8 project authors. All rights reserved.
32 #include "v8.h"
44 using ::v8::internal::EmbeddedVector;
45 using ::v8::internal::Object;
46 using ::v8::internal::OS;
47 using ::v8::internal::Handle;
48 using ::v8::internal::Heap;
49 using ::v8::internal::JSGlobalProxy;
50 using ::v8::internal::Code;
51 using ::v8::internal::Debug;
52 using ::v8::internal::Debugger;
53 using ::v8::internal::CommandMessage;
54 using ::v8::internal::CommandMessageQueue;
55 using ::v8::internal::StepAction;
56 using ::v8::internal::StepIn; // From StepAction enum
57 using ::v8::internal::StepNext; // From StepAction enum
58 using ::v8::internal::StepOut; // From StepAction enum
59 using ::v8::internal::Vector;
60 using ::v8::internal::StrLength;
72 ::v8::internal::Address expected,
74 ::v8::internal::Address value) {
87 ::v8::internal::Address unexpected,
89 ::v8::internal::Address value) {
127 // Helper class for creating a V8 enviromnent for running tests
131 v8::ExtensionConfiguration* extensions = 0,
132 v8::Handle<v8::ObjectTemplate> global_template =
133 v8::Handle<v8::ObjectTemplate>(),
134 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>())
135 : context_(v8::Context::New(extensions, global_template, global_object)) {
142 inline v8::Context* operator->() { return *context_; }
143 inline v8::Context* operator*() { return *context_; }
146 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
150 v8::Utils::OpenHandle(*context_)->security_token());
153 v8::Utils::OpenHandle(*context_->Global())));
154 Handle<v8::internal::String> debug_string =
158 ::v8::internal::kNonStrictMode);
161 v8::Persistent<v8::Context> context_;
169 static v8::Local<v8::Function> CompileFunction(DebugLocalContext* env,
172 v8::Script::Compile(v8::String::New(source))->Run();
173 return v8::Local<v8::Function>::Cast(
174 (*env)->Global()->Get(v8::String::New(function_name)));
179 static v8::Local<v8::Function> CompileFunction(const char* source,
181 v8::Script::Compile(v8::String::New(source))->Run();
182 return v8::Local<v8::Function>::Cast(
183 v8::Context::GetCurrent()->Global()->Get(v8::String::New(function_name)));
188 static bool HasDebugInfo(v8::Handle<v8::Function> fun) {
189 Handle<v8::internal::JSFunction> f = v8::Utils::OpenHandle(*fun);
190 Handle<v8::internal::SharedFunctionInfo> shared(f->shared());
197 static int SetBreakPoint(Handle<v8::internal::JSFunction> fun, int position) {
199 Handle<v8::internal::SharedFunctionInfo> shared(fun->shared());
200 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
203 Handle<Object>(v8::internal::Smi::FromInt(++break_point)),
211 static int SetBreakPoint(v8::Handle<v8::Function> fun, int position) {
212 return SetBreakPoint(v8::Utils::OpenHandle(*fun), position);
225 v8::Handle<v8::String> str = v8::String::New(buffer.start());
226 return v8::Script::Compile(str)->Run()->Int32Value();
246 v8::TryCatch try_catch;
247 v8::Handle<v8::String> str = v8::String::New(buffer.start());
248 v8::Handle<v8::Value> value = v8::Script::Compile(str)->Run();
273 v8::TryCatch try_catch;
274 v8::Handle<v8::String> str = v8::String::New(buffer.start());
275 v8::Handle<v8::Value> value = v8::Script::Compile(str)->Run();
284 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
286 Handle<Object>(v8::internal::Smi::FromInt(break_point)));
297 v8::Script::Compile(v8::String::New(buffer.start()))->Run();
307 v8::Script::Compile(v8::String::New(buffer.start()))->Run();
317 v8::Script::Compile(v8::String::New(buffer.start()))->Run();
328 v8::Script::Compile(v8::String::New(buffer.start()))->Run();
339 v8::Script::Compile(v8::String::New(buffer.start()))->Run();
345 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
346 debug->ChangeBreakOnException(v8::internal::BreakException, caught);
347 debug->ChangeBreakOnException(v8::internal::BreakUncaughtException, uncaught);
354 v8::Script::Compile(
355 v8::String::New("debug.Debug.setBreakOnException()"))->Run();
357 v8::Script::Compile(
358 v8::String::New("debug.Debug.clearBreakOnException()"))->Run();
361 v8::Script::Compile(
362 v8::String::New("debug.Debug.setBreakOnUncaughtException()"))->Run();
364 v8::Script::Compile(
365 v8::String::New("debug.Debug.clearBreakOnUncaughtException()"))->Run();
372 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
377 // This function is in namespace v8::internal to be friend with class
378 // v8::internal::Debug.
379 namespace v8 {
386 v8::internal::DebugInfoListNode* node = debug->debug_info_list_;
412 v8::internal::Isolate::Current(),
413 v8::internal::Isolate::Current()->stub_cache()->ComputeCallDebugBreak(
461 } } // namespace v8::internal
467 v8::Debug::ProcessDebugMessages();
469 v8::internal::CheckDebuggerUnloaded(check_functions);
475 class TestBreakLocationIterator: public v8::internal::BreakLocationIterator {
477 explicit TestBreakLocationIterator(Handle<v8::internal::DebugInfo> debug_info)
478 : BreakLocationIterator(debug_info, v8::internal::SOURCE_BREAK_LOCATIONS) {}
479 v8::internal::RelocIterator* it() { return reloc_iterator_; }
480 v8::internal::RelocIterator* it_original() {
490 int position, v8::internal::RelocInfo::Mode mode,
492 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
495 Handle<v8::internal::JSFunction> fun = v8::Utils::OpenHandle(
500 Handle<v8::internal::SharedFunctionInfo> shared(fun->shared());
505 if (mode != v8::internal::RelocInfo::JS_RETURN) {
520 if (mode == v8::internal::RelocInfo::JS_RETURN) {
538 v8::Local<v8::Function> frame_function_name;
547 v8::Local<v8::Function> frame_argument_name;
556 v8::Local<v8::Function> frame_argument_value;
565 v8::Local<v8::Function> frame_local_name;
574 v8::Local<v8::Function> frame_local_value;
583 v8::Local<v8::Function> frame_source_line;
592 v8::Local<v8::Function> frame_source_column;
601 v8::Local<v8::Function> frame_script_name;
610 v8::Local<v8::Function> frame_script_data;
619 v8::Local<v8::Function> compiled_script_data;
627 v8::Handle<v8::Function> frame_count;
644 static void DebugEventBreakPointHitCount(v8::DebugEvent event,
645 v8::Handle<v8::Object> exec_state,
646 v8::Handle<v8::Object> event_data,
647 v8::Handle<v8::Value> data) {
648 Debug* debug = v8::internal::Isolate::Current()->debug();
653 if (event == v8::Break) {
658 v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(0) };
659 v8::Handle<v8::Value> result = frame_function_name->Call(exec_state,
665 v8::Handle<v8::String> function_name(result->ToString());
673 v8::Handle<v8::Value> argv[argc] = { exec_state };
674 v8::Handle<v8::Value> result = frame_source_line->Call(exec_state,
683 v8::Handle<v8::Value> argv[argc] = { exec_state };
684 v8::Handle<v8::Value> result = frame_source_column->Call(exec_state,
693 v8::Handle<v8::Value> argv[argc] = { exec_state };
694 v8::Handle<v8::Value> result = frame_script_name->Call(exec_state,
700 v8::Handle<v8::String> script_name(result->ToString());
708 v8::Handle<v8::Value> argv[argc] = { exec_state };
709 v8::Handle<v8::Value> result = frame_script_data->Call(exec_state,
716 v8::Handle<v8::String> script_data(result->ToString());
720 } else if (event == v8::AfterCompile && !compiled_script_data.IsEmpty()) {
722 v8::Handle<v8::Value> argv[argc] = { event_data };
723 v8::Handle<v8::Value> result = compiled_script_data->Call(exec_state,
730 v8::Handle<v8::String> script_data(result->ToString());
749 static void DebugEventCounter(v8::DebugEvent event,
750 v8::Handle<v8::Object> exec_state,
751 v8::Handle<v8::Object> event_data,
752 v8::Handle<v8::Value> data) {
753 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
759 if (event == v8::Break) {
761 } else if (event == v8::Exception) {
765 v8::Local<v8::String> fun_name = v8::String::New("uncaught");
766 v8::Local<v8::Function> fun =
767 v8::Function::Cast(*event_data->Get(fun_name));
768 v8::Local<v8::Value> result = *fun->Call(event_data, 0, NULL);
778 v8::Handle<v8::Value> argv[kArgc] = { exec_state };
780 v8::Handle<v8::Value> result = frame_count->Call(exec_state, kArgc, argv);
796 v8::Handle<v8::Value> expected; // The expected result.
806 v8::Local<v8::Function> evaluate_check_function;
809 static void DebugEventEvaluate(v8::DebugEvent event,
810 v8::Handle<v8::Object> exec_state,
811 v8::Handle<v8::Object> event_data,
812 v8::Handle<v8::Value> data) {
813 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
817 if (event == v8::Break) {
820 v8::Handle<v8::Value> argv[argc] = { exec_state,
821 v8::String::New(checks[i].expr),
823 v8::Handle<v8::Value> result =
826 v8::String::AsciiValue ascii(checks[i].expected->ToString());
836 static void DebugEventRemoveBreakPoint(v8::DebugEvent event,
837 v8::Handle<v8::Object> exec_state,
838 v8::Handle<v8::Object> event_data,
839 v8::Handle<v8::Value> data) {
840 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
844 if (event == v8::Break) {
846 v8::Handle<v8::Function> fun = v8::Handle<v8::Function>::Cast(data);
855 static void DebugEventStep(v8::DebugEvent event,
856 v8::Handle<v8::Object> exec_state,
857 v8::Handle<v8::Object> event_data,
858 v8::Handle<v8::Value> data) {
859 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
863 if (event == v8::Break) {
882 static void DebugEventStepSequence(v8::DebugEvent event,
883 v8::Handle<v8
884 v8::Handle<v8::Object> event_data,
885 v8::Handle<v8::Value> data) {
886 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
890 if (event == v8::Break || event == v8::Exception) {
895 v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(0) };
896 v8::Handle<v8::Value> result = frame_function_name->Call(exec_state,
899 v8::String::AsciiValue function_name(result->ToString());
913 v8::DebugEvent event,
914 v8::Handle<v8::Object> exec_state,
915 v8::Handle<v8::Object> event_data,
916 v8::Handle<v8::Value> data) {
917 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
924 if (event == v8::Break) {
928 HEAP->CollectGarbage(v8::internal::NEW_SPACE);
939 static void DebugEventBreak(v8::DebugEvent event,
940 v8::Handle<v8::Object> exec_state,
941 v8::Handle<v8::Object> event_data,
942 v8::Handle<v8::Value> data) {
943 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
947 if (event == v8::Break) {
953 HEAP->CollectGarbage(v8::internal::NEW_SPACE);
956 v8::Debug::DebugBreak();
965 static void DebugEventBreakMax(v8::DebugEvent event,
966 v8::Handle<v8::Object> exec_state,
967 v8::Handle<v8::Object> event_data,
968 v8::Handle<v8::Value> data) {
969 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
973 if (event == v8::Break) {
979 v8::Debug::DebugBreak();
982 v8::V8::TerminateExecution();
998 static void MessageCallbackCount(v8::Handle<v8::Message> message,
999 v8::Handle<v8::Value> data) {
1010 using ::v8::internal::Builtins;
1011 using ::v8::internal::Isolate;
1012 v8::HandleScope scope;
1018 v8::internal::RelocInfo::JS_RETURN,
1023 v8::internal::RelocInfo::CODE_TARGET_CONTEXT,
1029 v8::internal::RelocInfo::CODE_TARGET_CONTEXT,
1043 v8::internal::RelocInfo::CODE_TARGET,
1051 v8::internal::RelocInfo::CODE_TARGET,
1058 Handle<Code> debug_break_0 = v8::internal::ComputeCallDebugBreak(0);
1059 Handle<Code> debug_break_1 = v8::internal::ComputeCallDebugBreak(1);
1060 Handle<Code> debug_break_4 = v8::internal::ComputeCallDebugBreak(4);
1065 v8::internal::RelocInfo::CODE_TARGET_CONTEXT,
1071 v8::internal::RelocInfo::CODE_TARGET_CONTEXT,
1077 v8::internal::RelocInfo::CODE_TARGET_CONTEXT,
1085 v8::HandleScope scope;
1088 v8::Local<v8::Function> foo =
1090 v8::Local<v8::Function> bar =
1093 CHECK_EQ(0, v8::internal::GetDebuggedFunctions()->length());
1098 CHECK_EQ(1, v8::internal::GetDebuggedFunctions()->length());
1103 CHECK_EQ(2, v8::internal::GetDebuggedFunctions()->length());
1108 CHECK_EQ(1, v8::internal::GetDebuggedFunctions()->length());
1113 CHECK_EQ(0, v8::internal::GetDebuggedFunctions()->length());
1122 v8::HandleScope scope;
1125 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
1126 v8::Undefined());
1127 v8::Script::Compile(v8::String::New("function foo(){bar=0;}"))->Run();
1128 v8::Local<v8::Function> foo =
1129 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
1147 v8::Debug::SetDebugEventListener(NULL);
1155 v8::HandleScope scope;
1157 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
1158 v8::Undefined());
1159 v8::Script::Compile(v8::String::New("bar=1"))->Run();
1160 v8::Script::Compile(v8::String::New("function foo(){var x=bar;}"))->Run();
1161 v8::Local<v8::Function> foo =
1162 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
1180 v8::Debug::SetDebugEventListener(NULL);
1188 v8::HandleScope scope;
1190 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
1191 v8::Undefined());
1192 v8::Script::Compile(v8::String::New("function bar(){}"))->Run();
1193 v8::Script::Compile(v8::String::New("function foo(){bar();}"))->Run();
1194 v8::Local<v8::Function> foo =
1195 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
1213 v8::Debug::SetDebugEventListener(NULL);
1221 v8::HandleScope scope;
1223 v8::Debug::SetDebugEventListener(DebugEventBreakPointCollectGarbage,
1224 v8::Undefined());
1225 v8::Script::Compile(v8::String::New("function bar(){return 1;}"))->Run();
1226 v8::Script::Compile(v8::String::New("function foo(){return bar();}"))->Run();
1227 v8::Local<v8::Function> foo =
1228 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
1246 v8::Debug::SetDebugEventListener(NULL);
1254 v8::HandleScope scope;
1256 v8::Debug::SetDebugEventListener(DebugEventBreakPointCollectGarbage,
1257 v8::Undefined());
1258 v8::Script::Compile(v8::String::New("function bar(){ this.x = 1;}"))->Run();
1259 v8::Script::Compile(v8::String::New(
1261 v8::Local<v8::Function> foo =
1262 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
1280 v8::Debug::SetDebugEventListener(NULL);
1288 v8::HandleScope scope;
1301 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
1302 v8::Undefined());
1303 v8::Script::Compile(v8::String::New("function foo(){}"))->Run();
1304 v8::Local<v8::Function> foo =
1305 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
1327 v8::Debug::SetDebugEventListener(NULL);
1332 static void CallWithBreakPoints(v8::Local<v8::Object> recv,
1333 v8::Local<v8::Function> f,
1346 v8::HandleScope scope;
1349 v8::Debug::SetDebugEventListener(DebugEventBreakPointCollectGarbage,
1350 v8::Undefined());
1351 v8::Local<v8::Function> foo;
1378 v8::Debug::SetDebugEventListener(NULL);
1385 static void CallAndGC(v8::Local<v8::Object> recv,
1386 v8::Local<v8::Function> f,
1396 HEAP->CollectGarbage(v8::internal::NEW_SPACE);
1410 v8::HandleScope scope;
1413 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
1414 v8::Undefined());
1415 v8::Local<v8::Function> foo;
1419 v8::Local<v8::Function> bar =
1428 v8::Local<v8::Function> bar =
1437 v8::Local<v8::Function> bar =
1448 v8::Local<v8::Function> bar =
1457 v8::Local<v8::Function> bar =
1465 v8::Debug::SetDebugEventListener(NULL);
1480 v8::HandleScope scope;
1484 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
1485 v8::Undefined());
1486 v8::Script::Compile(v8::String::New("function bar(){}"))->Run();
1487 v8::Script::Compile(v8::String::New("function foo(){bar();bar();}"))->Run();
1491 v8::Local<v8::Script> foo = v8::Script::Compile(v8::String::New("foo()"));
1523 v8::Debug::SetDebugEventListener(NULL);
1536 v8::HandleScope scope;
1540 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
1541 v8::Undefined());
1543 v8::Local<v8::String> script = v8::String::New(
1563 v8::ScriptOrigin origin =
1564 v8::ScriptOrigin(v8::String::New("test"));
1565 v8::Script::Compile(script, &origin)->Run();
1566 v8::Local<v8::Function> f =
1567 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
1568 v8::Local<v8::Function> g =
1569 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g")));
1625 v8::Debug::SetDebugEventListener(NULL);
1640 v8::HandleScope scope;
1644 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
1645 v8::Undefined());
1647 v8::Local<v8::String> source = v8::String::New(
1667 v8::ScriptOrigin origin =
1668 v8::ScriptOrigin(v8::String::New("test"));
1669 v8::Local<v8::Script> script = v8::Script::Compile(source, &origin);
1671 v8::Local<v8::Function> f =
1672 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
1673 v8::Local<v8::Function> g =
1674 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g")));
1733 v8::Debug::SetDebugEventListener(NULL);
1749 v8::HandleScope scope;
1753 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
1754 v8::Undefined());
1756 v8::Local<v8::String> script = v8::String::New(
1762 v8::ScriptOrigin origin =
1763 v8::ScriptOrigin(v8::String::New("test"));
1764 v8::Script::Compile(script, &origin)->Run();
1765 v8::Local<v8::Function> f =
1766 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
1789 v8::Script::Compile(script, &origin)->Run();
1790 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
1798 v8::Debug::SetDebugEventListener(NULL);
1806 v8::HandleScope scope;
1810 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
1811 v8::Undefined());
1813 v8::Local<v8::String> script = v8::String::New(
1823 v8::ScriptOrigin origin =
1824 v8::ScriptOrigin(v8::String::New("test"));
1825 v8::Script::Compile(script, &origin)->Run();
1826 v8::Local<v8::Function> f =
1827 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
1851 v8::Script::Compile(script, &origin)->Run();
1852 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
1860 v8::Debug::SetDebugEventListener(NULL);
1868 v8::HandleScope scope;
1872 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
1873 v8::Undefined());
1875 v8::Local<v8::String> script = v8::String::New(
1881 v8::ScriptOrigin origin =
1882 v8::ScriptOrigin(v8::String::New("test"));
1883 v8
1884 v8::Local<v8::Function> f =
1885 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
1906 v8::Script::Compile(script, &origin)->Run();
1907 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
1915 v8::Debug::SetDebugEventListener(NULL);
1923 v8::HandleScope scope;
1927 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
1928 v8::Undefined());
1930 v8::Local<v8::Function> f;
1931 v8::Local<v8::String> script = v8::String::New(
1940 v8::ScriptOrigin origin_1 = v8::ScriptOrigin(v8::String::New("1"));
1941 v8::ScriptOrigin origin_2 = v8::ScriptOrigin(v8::String::New("2"));
1947 v8::Script::Compile(script, &origin_1)->Run();
1948 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
1957 v8::Script::Compile(script, &origin_2)->Run();
1958 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
1966 v8::Script::Compile(script, &origin_1)->Run();
1967 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
1974 v8::Debug::SetDebugEventListener(NULL);
1982 v8::HandleScope scope;
1986 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
1987 v8::Undefined());
1989 v8::Local<v8::Function> f;
1990 v8::Local<v8::String> script_f = v8::String::New(
1995 v8::Local<v8::Function> g;
1996 v8::Local<v8::String> script_g = v8::String::New(
2001 v8::ScriptOrigin origin =
2002 v8::ScriptOrigin(v8::String::New("test"));
2008 v8::Script::Compile(script_f, &origin)->Run();
2009 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
2010 v8::Script::Compile(script_g, &origin)->Run();
2011 g = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g")));
2040 v8::Debug::SetDebugEventListener(NULL);
2048 v8::HandleScope scope;
2052 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
2053 v8::Undefined());
2055 v8::Local<v8::Function> f;
2056 v8::Local<v8::String> script = v8::String::New(
2063 v8::ScriptOrigin origin(v8::String::New("test.html"),
2064 v8::Integer::New(7));
2071 v8::Script::Compile(script, &origin)->Run();
2072 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
2096 v8::Debug::SetDebugEventListener(NULL);
2103 v8::HandleScope scope;
2112 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
2113 v8::Undefined());
2115 v8::Local<v8::Function> f;
2116 v8::Local<v8::Function> g;
2117 v8::Local<v8::String> script = v8::String::New(
2139 v8::ScriptOrigin origin(v8::String::New("test.html"), v8::Integer::New(0));
2140 v8::Script::Compile(script, &origin)->Run();
2141 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
2142 g = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g")));
2180 v8::Script::Compile(script, &origin)->Run();
2189 v8::Script::Compile(script, &origin)->Run();
2199 v8::Script::Compile(script, &origin)->Run();
2202 v8::Debug::SetDebugEventListener(NULL);
2209 v8::HandleScope scope;
2213 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
2214 v8::Undefined());
2216 v8::Local<v8::String> script = v8::String::New(
2221 v8::Local<v8::Function> f;
2223 v8::HandleScope scope;
2224 v8::Script::Compile(script, v8::String::New("test.html"))->Run();
2226 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
2239 v8::Script::Compile(script, v8::String::New("test.html"))->Run();
2244 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
2247 v8::Debug::SetDebugEventListener(NULL);
2255 v8::HandleScope scope;
2259 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
2260 v8::Undefined());
2262 v8::Local<v8::String> script_source = v8::String::New(
2270 v8::HandleScope scope;
2272 v8::Script::Compile(script_source, v8::String::New("test.html"))->Run();
2280 v8::Debug::SetDebugEventListener(NULL);
2288 v8::HandleScope scope;
2291 v8::Local<v8::Function> foo =
2296 v8::Debug::SetDebugEventListener(DebugEventRemoveBreakPoint, foo);
2306 v8::Debug::SetDebugEventListener(NULL);
2314 v8::HandleScope scope;
2316 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
2317 v8::Undefined());
2318 v8::Script::Compile(v8::String::New("function bar(){debugger}"))->Run();
2319 v8::Script::Compile(v8::String::New(
2321 v8::Local<v8::Function> foo =
2322 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
2323 v8::Local<v8::Function> bar =
2324 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("bar")));
2334 v8::Debug::SetDebugEventListener(NULL);
2342 v8::HandleScope scope;
2344 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
2345 v8::Undefined());
2346 v8::Script::Compile(v8::String::New("function foo(){debugger;}"))->Run();
2347 v8::Local<v8::Function> foo =
2348 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
2361 v8::Debug::SetDebugEventListener(NULL);
2369 v8::HandleScope scope;
2378 v8::Debug::SetDebugEventListener(DebugEventEvaluate);
2383 {"x", v8::Undefined()},
2384 {"a", v8::Undefined()},
2385 {NULL, v8::Handle<v8::Value>()}
2388 {"x", v8::String::New("Hello, world!")},
2389 {"a", v8::Undefined()},
2390 {NULL, v8::Handle<v8::Value>()}
2393 {"x", v8::String::New("Hello, world!")},
2394 {"a", v8::String::New("Hello, world!")},
2395 {NULL, v8::Handle<v8::Value>()}
2402 v8::Local<v8::Function> foo = CompileFunction(&env,
2414 v8::Handle<v8::Value> argv_foo[1] = { v8::String::New("Hello, world!") };
2435 v8::Local<v8::Function> bar = CompileFunction(&env,
2454 v8::Handle<v8::Value> argv_bar_1[2] = {
2455 v8::Undefined(),
2456 v8::Number::New(barbar_break_position)
2463 v8::Handle<v8::Value> argv_bar_2[2] = {
2464 v8::String::New("Hello, world!"),
2465 v8::Number::New(barbar_break_position)
2472 v8::Handle<v8::Value> argv_bar_3[2] = {
2473 v8::String::New("Hello, world!"),
2474 v8::Number::New(barbar_break_position + 1)
2478 v8::Debug::SetDebugEventListener(NULL);
2483 // Does not use the V8 engine to convert strings, so it can be used
2566 v8::Debug::ClientData* client_data) {
2585 v8::Debug::SetMessageHandler(DebugProcessDebugMessagesHandler);
2587 v8::HandleScope scope;
2593 v8::Script::Compile(v8::String::New(source))->Run();
2595 v8::Debug::ProcessDebugMessages();
2608 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_111, buffer));
2618 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_112, buffer));
2628 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_113, buffer));
2630 v8::Debug::ProcessDebugMessages();
2639 v8::Debug::SetMessageHandler(NULL);
2640 v8::Debug::SetDebugEventListener(NULL);
2647 v8::HandleScope scope;
2651 v8::Local<v8::Function> foo = CompileFunction(&env,
2661 v8::Debug::SetDebugEventListener(DebugEventStep);
2670 v8::Debug::SetDebugEventListener(NULL);
2674 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
2683 v8::Debug::SetDebugEventListener(NULL);
2690 v8::HandleScope scope;
2694 v8::Debug::SetDebugEventListener(DebugEventStep);
2698 v8::Local<v8::Function> foo = CompileFunction(
2712 v8::Local<v8::Array> a = v8::Array::New(10);
2714 a->Set(v8::Number::New(i), v8::Number::New(i));
2719 v8::Handle<v8::Value> args[kArgc] = { a };
2731 v8::Debug::SetDebugEventListener(NULL);
2738 v8::HandleScope scope;
2742 v8::Debug::SetDebugEventListener(DebugEventStep);
2746 v8::Local<v8::Function> foo = CompileFunction(
2759 v8::Local<v8::Array> a = v8::Array::New(10);
2761 a->Set(v8::Number::New(i), v8::Number::New(i));
2766 v8::Handle<v8::Value> args[kArgc] = { a };
2778 v8::Debug::SetDebugEventListener(NULL);
2785 v8::HandleScope scope;
2789 v8::Debug::SetDebugEventListener(DebugEventStep);
2792 v8::Local<v8::Function> foo = CompileFunction(
2822 v8::Debug::SetDebugEventListener(NULL);
2828 v8::HandleScope scope;
2832 v8::Debug::SetDebugEventListener(DebugEventStep);
2835 v8::Local<v8::Function> foo = CompileFunction(
2857 v8::Debug::SetDebugEventListener(NULL);
2870 v8::HandleScope scope;
2874 v8::Debug::SetDebugEventListener(DebugEventStep);
2877 v8::Local<v8::Function> foo = CompileFunction(&env,
2897 v8::Debug::SetDebugEventListener(NULL);
2901 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
2910 v8::Debug::SetDebugEventListener(NULL);
2916 v8::HandleScope scope;
2920 v8::Debug::SetDebugEventListener(DebugEventStep);
2932 v8::Local<v8
2943 v8::Debug::SetDebugEventListener(NULL);
2949 v8::HandleScope scope;
2953 v8::Debug::SetDebugEventListener(DebugEventStep);
2965 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
2976 v8::Debug::SetDebugEventListener(NULL);
2982 v8::HandleScope scope;
2986 v8::Debug::SetDebugEventListener(DebugEventStep);
3001 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
3007 v8::Handle<v8::Value> argv_true[argc] = { v8::True() };
3014 v8::Handle<v8::Value> argv_false[argc] = { v8::False() };
3019 v8::Debug::SetDebugEventListener(NULL);
3025 v8::HandleScope scope;
3029 v8::Debug::SetDebugEventListener(DebugEventStep);
3050 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
3056 v8::Handle<v8::Value> argv_1[argc] = { v8::Number::New(1) };
3063 v8::Handle<v8::Value> argv_2[argc] = { v8::Number::New(2) };
3070 v8::Handle<v8::Value> argv_3[argc] = { v8::Number::New(3) };
3075 v8::Debug::SetDebugEventListener(NULL);
3081 v8::HandleScope scope;
3085 v8::Debug::SetDebugEventListener(DebugEventStep);
3097 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
3103 v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(10) };
3110 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) };
3115 v8::Debug::SetDebugEventListener(NULL);
3121 v8::HandleScope scope;
3125 v8::Debug::SetDebugEventListener(DebugEventStep);
3137 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
3143 v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(10) };
3150 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) };
3155 v8::Debug::SetDebugEventListener(NULL);
3161 v8::HandleScope scope;
3165 v8::Debug::SetDebugEventListener(DebugEventStep);
3177 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
3184 v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(10) };
3191 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) };
3196 v8::Debug::SetDebugEventListener(NULL);
3202 v8::HandleScope scope;
3206 v8::Debug::SetDebugEventListener(DebugEventStep);
3224 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
3225 v8::Handle<v8::Value> result;
3233 v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(10) };
3241 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) };
3247 v8::Debug::SetDebugEventListener(NULL);
3253 v8::HandleScope scope;
3257 v8::Debug::SetDebugEventListener(DebugEventStep);
3275 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
3276 v8::Handle<v8::Value> result;
3285 v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(10) };
3293 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) };
3299 v8::Debug::SetDebugEventListener(NULL);
3305 v8::HandleScope scope;
3309 v8::Debug::SetDebugEventListener(DebugEventStep);
3313 v8::Local<v8::Function> foo;
3347 v8::Debug::SetDebugEventListener(NULL);
3353 v8::HandleScope scope;
3357 v8::Debug::SetDebugEventListener(DebugEventStep);
3367 env->Global()->Set(v8::String::New("b"), v8::Object::New());
3368 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
3369 v8::Handle<v8::Value> result;
3378 v8::Debug::SetDebugEventListener(NULL);
3384 v8::HandleScope scope;
3388 v8::Debug::SetDebugEventListener(DebugEventStep);
3398 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
3409 v8::Handle<v8::Value> argv_true[argc] = { v8::True() };
3414 v8::Debug::SetDebugEventListener(NULL);
3420 v8::HandleScope scope;
3429 v8::Debug::SetDebugEventListener(DebugEventStepSequence);
3437 v8::Local<v8::Function> a = CompileFunction(&env, src, "a");
3465 v8::Debug::SetDebugEventListener(NULL);
3471 v8
3480 v8::Debug::SetDebugEventListener(DebugEventStepSequence);
3489 v8::Local<v8::Function> a = CompileFunction(&env, src, "a");
3517 v8::Debug::SetDebugEventListener(NULL);
3523 v8::HandleScope scope;
3532 v8::Debug::SetDebugEventListener(DebugEventStepSequence);
3540 v8::Local<v8::Function> a = CompileFunction(&env, src, "a");
3552 v8::Debug::SetDebugEventListener(NULL);
3559 v8::HandleScope scope;
3563 v8::Local<v8::Function> foo = CompileFunction(
3569 v8::Debug::SetDebugEventListener(DebugEventStep);
3578 v8::Debug::SetDebugEventListener(NULL);
3582 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
3590 v8::Debug::SetDebugEventListener(NULL);
3597 v8::HandleScope scope;
3601 v8::Local<v8::Function> foo = CompileFunction(
3608 v8::Debug::SetDebugEventListener(DebugEventStep);
3617 v8::Debug::SetDebugEventListener(NULL);
3621 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
3629 v8::Debug::SetDebugEventListener(NULL);
3636 v8::HandleScope scope;
3640 v8::Local<v8::Function> foo = CompileFunction(
3653 v8::Debug::SetDebugEventListener(DebugEventStep);
3664 v8::Handle<v8::Value> argv[argc] = { v8::True() };
3668 v8::Debug::SetDebugEventListener(NULL);
3672 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
3680 v8::Debug::SetDebugEventListener(NULL);
3687 v8::HandleScope scope;
3692 v8::Debug::SetDebugEventListener(DebugEventCounter);
3702 v8::ScriptOrigin origin(v8::String::New(script_name), v8::Integer::New(0));
3703 v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::New(src),
3705 v8::Local<v8::Value> r = script->Run();
3711 v8::Debug::SetDebugEventListener(NULL);
3723 v8::HandleScope scope;
3727 v8::internal::Isolate::Current()->TraceException(false);
3730 v8::Local<v8::Function> throws =
3732 v8::Local<v8::Function> caught =
3736 v8::Local<v8::Function> notCaught =
3739 v8::V8::AddMessageListener(MessageCallbackCount);
3740 v8::Debug::SetDebugEventListener(DebugEventCounter);
3858 v8::Debug::SetDebugEventListener(NULL);
3860 v8::V8::RemoveMessageListeners(MessageCallbackCount);
3865 // v8::Script::Compile there is no JavaScript stack whereas when compiling using
3868 v8::HandleScope scope;
3874 v8::internal::Isolate::Current()->TraceException(false);
3879 v8::V8::AddMessageListener(MessageCallbackCount);
3880 v8::Debug::SetDebugEventListener(DebugEventCounter);
3892 v8::Script::Compile(v8::String::New("+++"));
3899 v8::Script::Compile(v8::String::New("x x"));
3906 v8::Script::Compile(v8::String::New("eval('+++')"))->Run();
3913 v8::Script::Compile(v8::String::New("eval('x x')"))->Run();
3922 v8::HandleScope scope;
3934 v8::Debug::SetDebugEventListener(DebugEventStepSequence);
3947 v8::Local<v8::Function> a = CompileFunction(&env, src, "a");
3957 v8::Local<v8
3966 v8::Local<v8::Function> d = CompileFunction(&env, src, "d");
3986 v8::Local<v8::Function> f = CompileFunction(&env, src, "f");
4006 v8::Debug::SetDebugEventListener(NULL);
4012 v8::HandleScope scope;
4018 CHECK(v8::internal::FLAG_verify_heap);
4022 v8::Debug::SetDebugEventListener(DebugEventBreak);
4029 v8::Local<v8::Function> f0 = CompileFunction(&env, src, "f0");
4030 v8::Local<v8::Function> f1 = CompileFunction(&env, src, "f1");
4031 v8::Local<v8::Function> f2 = CompileFunction(&env, src, "f2");
4032 v8::Local<v8::Function> f3 = CompileFunction(&env, src, "f3");
4035 v8::Handle<v8::Value> argv[] = { v8::Number::New(1),
4036 v8::Number::New(1),
4037 v8::Number::New(1),
4038 v8::Number::New(1) };
4047 v8::Debug::DebugBreak();
4062 v8::Debug::SetDebugEventListener(NULL);
4070 v8::HandleScope scope;
4074 v8::Debug::SetDebugEventListener(DebugEventCounter);
4078 v8::Local<v8::Function> f = CompileFunction(&env, src, "f");
4081 v8::Debug::DebugBreak();
4089 v8::Debug::DebugBreak();
4090 v8::internal::DisableBreak disable_break(true);
4099 v8::Debug::SetDebugEventListener(NULL);
4111 v8::HandleScope scope;
4114 v8::Debug::SetDebugEventListener(DebugEventCounter);
4117 v8::Debug::DebugBreak();
4122 v8::RegisterExtension(new v8::Extension("simpletest",
4125 v8::ExtensionConfiguration extensions(1, extension_names);
4126 v8::Persistent<v8::Context> context = v8::Context::New(&extensions);
4133 v8::Debug::SetDebugEventListener(NULL);
4137 static v8::Handle<v8::Array> NamedEnum(const v8::AccessorInfo&) {
4138 v8::Handle<v8::Array> result = v8::Array::New(3);
4139 result->Set(v8::Integer::New(0), v8::String::New("a"));
4140 result->Set(v8::Integer::New(1), v8::String::New("b"));
4141 result->Set(v8::Integer::New(2), v8::String::New("c"));
4146 static v8::Handle<v8::Array> IndexedEnum(const v8::AccessorInfo&) {
4147 v8::Handle<v8::Array> result = v8::Array::New(2);
4148 result->Set(v8::Integer::New(0), v8::Number::New(1));
4149 result->Set(v8::Integer::New(1), v8::Number::New(10));
4154 static v8::Handle<v8::Value> NamedGetter(v8::Local<v8::String> name,
4155 const v8::AccessorInfo& info) {
4156 v8::String::AsciiValue n(name);
4158 return v8::String::New("AA");
4160 return v8::String::New("BB");
4162 return v8::String::New("CC");
4164 return v8::Undefined();
4171 static v8::Handle<v8::Value> IndexedGetter(uint32_t index,
4172 const v8::AccessorInfo& info) {
4173 return v8::Number::New(index + 1);
4178 // Create a V8 environment with debug access.
4179 v8::HandleScope scope;
4184 v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New();
4186 env->Global()->Set(v8::String::New("intercepted_named"),
4190 v8::Handle<v8::ObjectTemplate> indexed = v8::ObjectTemplate::New();
4196 env->Global()->Set(v8::String::New("intercepted_indexed"),
4200 v8::Handle<v8::ObjectTemplate> both = v8::ObjectTemplate::New();
4203 env->Global()->Set(v8::String::New("intercepted_both"), both->NewInstance());
4309 // Create a V8 environment with debug access.
4310 v8::HandleScope scope;
4314 v8::Handle<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New();
4315 t0->InstanceTemplate()->Set(v8::String::New("x"), v8::Number::New(0));
4316 v8::Handle<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New();
4318 t1->InstanceTemplate()->Set(v8::String::New("y"), v8::Number::New(1));
4319 v8::Handle<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New();
4321 t2->InstanceTemplate()->Set(v8::String::New("z"), v8::Number::New(2));
4322 v8::Handle<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New();
4323 t3->InstanceTemplate()->Set(v8::String::New("u"), v8::Number::New(3));
4326 v8::Handle<v8::Object> o0 = t0->GetFunction()->NewInstance();
4327 env->Global()->Set(v8::String::New("o0"), o0);
4328 v8::Handle<v8::Object> o1 = t1->GetFunction()->NewInstance();
4329 env->Global()->Set(v8::String::New("o1"), o1);
4330 v8::Handle<v8::Object> o2 = t2->GetFunction()->NewInstance();
4331 env->Global()->Set(v8::String::New("o2"), o2);
4332 v8::Handle<v8::Object> o3 = t3->GetFunction()->NewInstance();
4333 env->Global()->Set(v8::String::New("o3"), o3);
4358 o0->Set(v8::String::New("__proto__"), o1);
4369 o0->Set(v8::String::New("__proto__"), o2);
4385 o0->Set(v8::String::New("__proto__"), o3);
4403 static v8::Handle<v8::Value> ProtperyXNativeGetter(
4404 v8::Local<v8::String> property, const v8::AccessorInfo& info) {
4405 return v8::Integer::New(10);
4410 // Create a V8 environment with debug access.
4411 v8::HandleScope scope;
4415 v8::Handle<v8::String> name = v8::String::New("x");
4417 v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New();
4419 v8::Handle<v8::Value>(), v8::DEFAULT, v8::None);
4422 env->Global()->Set(v8::String::New("instance"), named->NewInstance());
4440 static v8::Handle<v8::Value> ProtperyXNativeGetterThrowingError(
4441 v8::Local<v8::String> property, const v8::AccessorInfo& info) {
4447 // Create a V8 environment with debug access.
4448 v8::HandleScope scope;
4452 v8::Handle<v8::String> name = v8::String::New("x");
4454 v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New();
4456 v8::Handle<v8::Value>(), v8::DEFAULT, v8::None);
4459 env->Global()->Set(v8::String::New("instance"), named->NewInstance());
4482 // Create a V8 environment with debug access.
4483 v8::HandleScope scope;
4489 v8::Script::Compile(v8::String::New(source))->Run();
4490 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(
4491 env->Global()->Get(v8::String::New("obj")));
4493 obj->SetHiddenValue(v8::String::New("v8::test-debug::a"),
4494 v8::Int32::New(11));
4510 v8::Handle<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New();
4511 t0->InstanceTemplate()->Set(v8::String::New("b"), v8::Number::New(2));
4513 v8::Handle<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New();
4514 t1->InstanceTemplate()->Set(v8::String::New("c"), v8::Number::New(3));
4518 v8::Handle<v8::Object> protoObj = t0->GetFunction()->NewInstance();
4519 protoObj->SetHiddenValue(v8::String::New("v8::test-debug::b"),
4520 v8::Int32::New(12));
4521 env->Global()->Set(v8::String::New("protoObj"), protoObj);
4522 v8::Handle<v8::Object> grandProtoObj = t1->GetFunction()->NewInstance();
4523 grandProtoObj->SetHiddenValue(v8::String::New("v8::test-debug::c"),
4524 v8::Int32::New(13));
4525 env->Global()->Set(v8::String::New("grandProtoObj"), grandProtoObj);
4528 protoObj->Set(v8::String::New("__proto__"), grandProtoObj);
4529 obj->Set(v8::String::New("__proto__"), protoObj);
4564 v8::internal::Mutex* lock_;
4565 v8::internal::Semaphore* sem_;
4613 v8::internal::Semaphore* semaphore_1;
4614 v8::internal::Semaphore* semaphore_2;
4719 // This is the debugger thread, that executes no v8 calls except
4721 class MessageQueueDebuggerThread : public v8::internal::Thread {
4723 explicit MessageQueueDebuggerThread(v8::internal::Isolate* isolate)
4729 v8::Debug::ClientData* client_data) {
4781 v8::Debug::SendCommand(buffer_1, AsciiToUtf16(command_1, buffer_1));
4782 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_2, buffer_2));
4783 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2));
4784 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2));
4785 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2));
4805 v8::Debug::SendCommand(buffer_1, AsciiToUtf16(command_1, buffer_1));
4806 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_2, buffer_2));
4807 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2));
4808 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_single_step, buffer_2));
4815 v8::Debug::SendCommand(buffer_1, AsciiToUtf16(command_2, buffer_1));
4816 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_continue, buffer_2));
4825 // This thread runs the v8 engine.
4830 // Create a V8 environment
4831 v8::HandleScope scope;
4834 v8::Debug::SetMessageHandler(MessageHandler);
4854 class TestClientData : public v8::Debug::ClientData {
4913 const v8::Debug::Message& message) {
4922 // Create a V8 environment
4923 v8::HandleScope scope;
4927 v8::Debug::SetMessageHandler2(MessageHandlerCountingClientData);
4946 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer),
4948 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer), NULL);
4949 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer),
4951 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer),
4955 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer));
4966 * occupying the v8 thread by a break command from the
4973 class V8Thread : public v8::internal::Thread {
4975 explicit V8Thread(v8::internal::Isolate* isolate)
4980 class DebuggerThread : public v8::internal::Thread {
4982 explicit DebuggerThread(v8::internal::Isolate* isolate)
4988 static v8::Handle<v8::Value> ThreadedAtBarrier1(const v8::Arguments& args) {
4990 return v8::Undefined();
4994 static void ThreadedMessageHandler(const v8::Debug::Message& message) {
4996 v8::String::Value json(message.GetJSON());
5027 v8::HandleScope scope;
5029 v8::Debug::SetMessageHandler2(&ThreadedMessageHandler);
5030 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
5031 global_template->Set(v8::String::New("ThreadedAtBarrier1"),
5032 v8::FunctionTemplate::New(ThreadedAtBarrier1));
5033 v8::Handle<v8::Context> context = v8::Context::New(NULL, global_template);
5034 v8::Context::Scope context_scope(context);
5052 v8::Debug::DebugBreak();
5054 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer));
5055 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer));
5063 // Create a V8 environment
5080 class BreakpointsV8Thread : public v8::internal::Thread {
5082 explicit BreakpointsV8Thread(v8::internal::Isolate* isolate)
5087 class BreakpointsDebuggerThread : public v8::internal::Thread {
5089 explicit BreakpointsDebuggerThread(v8::internal::Isolate* isolate,
5104 static void BreakpointsMessageHandler(const v8::Debug::Message& message) {
5106 v8::String::Value json(message.GetJSON());
5141 v8::HandleScope scope;
5143 v8::Debug::SetMessageHandler2(&BreakpointsMessageHandler);
5214 // v8 thread initializes, runs source_1
5217 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer));
5219 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer));
5221 // V8 thread starts compiling source_2.
5225 // v8 thread runs source_2 to breakpoint in cat().
5231 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_3, buffer));
5232 // V8 thread hits breakpoint in dog().
5237 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_4, buffer));
5243 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_5, buffer));
5250 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_6, buffer));
5256 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_7, buffer));
5262 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_8, buffer));
5272 // Create a V8 environment
5293 static void DummyDebugEventListener(v8::DebugEvent event,
5294 v8::Handle<v8::Object> exec_state,
5295 v8::Handle<v8::Object> event_data,
5296 v8::Handle<v8::Value> data) {
5301 v8::Debug::SetDebugEventListener(DummyDebugEventListener);
5305 static void DummyMessageHandler(const v8::Debug::Message& message) {
5310 v8::Debug::SetMessageHandler2(DummyMessageHandler);
5315 v8::Debug::DebugBreak();
5323 v8::Debug::SendCommand(dummy_buffer, dummy_length);
5335 v8::Handle<v8::Function> debugger_call_with_data;
5348 v8::Handle<v8::Function> debugger_call_with_closure;
5352 static v8::Handle<v8::Value> CheckFrameCount(const v8::Arguments& args) {
5353 CHECK(v8::Debug::Call(frame_count)->IsNumber());
5355 v8::Debug::Call(frame_count)->Int32Value());
5356 return v8::Undefined();
5362 static v8::Handle<v8::Value> CheckSourceLine(const v8::Arguments& args) {
5363 CHECK(v8::Debug::Call(frame_source_line)->IsNumber());
5365 v8::Debug::Call(frame_source_line)->Int32Value());
5366 return v8::Undefined();
5373 static v8::Handle<v8::Value> CheckDataParameter(const v8::Arguments& args) {
5374 v8::Handle<v8::String> data = v8::String::New("Test");
5375 CHECK(v8::Debug::Call(debugger_call_with_data, data)->IsString());
5377 CHECK(v8::Debug::Call(debugger_call_with_data).IsEmpty());
5378 CHECK(v8::Debug::Call(debugger_call_with_data).IsEmpty());
5380 v8::TryCatch catcher;
5381 v8::Debug::Call(debugger_call_with_data);
5385 return v8::Undefined();
5390 static v8::Handle<v8::Value> CheckClosure(const v8::Arguments& args) {
5391 CHECK(v8::Debug::Call(debugger_call_with_closure)->IsNumber());
5392 CHECK_EQ(3, v8::Debug::Call(debugger_call_with_closure)->Int32Value());
5393 return v8::Undefined();
5401 v8::HandleScope scope;
5402 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
5403 global_template->Set(v8::String::New("CheckFrameCount"),
5404 v8::FunctionTemplate::New(CheckFrameCount));
5405 global_template->Set(v8::String::New("CheckSourceLine"),
5406 v8::FunctionTemplate::New(CheckSourceLine));
5407 global_template->Set(v8::String::New("CheckDataParameter"),
5408 v8::FunctionTemplate::New(CheckDataParameter));
5409 global_template->Set(v8::String::New("CheckClosure"),
5410 v8::FunctionTemplate::New(CheckClosure));
5411 v8::Handle<v8::Context> context = v8::Context::New(NULL, global_template);
5412 v8::Context::Scope context_scope(context);
5415 v8::Script::Compile(v8::String::New(frame_count_source))->Run();
5416 frame_count = v8::Local<v8::Function>::Cast(
5417 context->Global()->Get(v8::String::New("frame_count")));
5420 v8::Script::Compile(v8::String::New(frame_source_line_source))->Run();
5421 frame_source_line = v8::Local<v8::Function>::Cast(
5422 context->Global()->Get(v8::String::New("frame_source_line")));
5425 v8::Script::Compile(v8::String::New(debugger_call_with_data_source))->Run();
5426 debugger_call_with_data = v8::Local<v8::Function>::Cast(
5427 context->Global()->Get(v8::String::New("debugger_call_with_data")));
5430 debugger_call_with_closure = v8::Local<v8::Function>::Cast(
5431 v8::Script::Compile(
5432 v8::String::New(debugger_call_with_closure_source))->Run());
5436 CHECK_EQ(v8::Integer::New(0), v8::Debug::Call(frame_count));
5439 v8::Script::Compile(v8::String::New("CheckFrameCount(1)"))->Run();
5440 v8::Script::Compile(v8::String::New("function f() {"
5445 v8::Script::Compile(v8::String::New("CheckSourceLine(0)"))->Run();
5446 v8::Script::Compile(v8::String::New("function f() {\n"
5453 v8::Script::Compile(v8::String::New("CheckDataParameter()"))->Run();
5456 v8::Script::Compile(v8::String::New("CheckClosure()"))->Run();
5460 v8::ScriptOrigin origin(v8::String::New("test"),
5461 v8::Integer::New(7));
5462 v8::Script::Compile(v8::String::New("CheckSourceLine(7)"), &origin)->Run();
5463 v8::Script::Compile(v8::String::New("function f() {\n"
5474 const v8::Debug::Message& message) {
5475 if (message.IsEvent() && message.GetEvent() == v8::Break) {
5494 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
5495 v8::Undefined());
5497 v8::HandleScope scope;
5499 v8::Local<v8::Function> foo =
5501 v8::Local<v8::Function> bar =
5520 v8::Debug::SetDebugEventListener(NULL);
5525 v8::Debug::SetMessageHandler2(MessageHandlerBreakPointHitCount);
5527 v8::HandleScope scope;
5530 v8::Local<v8::Function> foo =
5531 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
5532 v8::Local<v8::Function> bar =
5533 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
5547 v8::Debug::SetMessageHandler2(NULL);
5561 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer));
5567 static void MessageHandlerHitCount(const v8::Debug::Message& message) {
5571 v8::String::Value json(message.GetJSON());
5582 v8::HandleScope scope;
5589 v8::Debug::SetMessageHandler2(MessageHandlerHitCount);
5600 v8::Debug::SetMessageHandler(NULL);
5615 const v8::Debug::Message& message) {
5619 v8::Debug::SetMessageHandler(NULL);
5625 v8::HandleScope scope;
5632 v8::Debug::SetMessageHandler2(MessageHandlerClearingMessageHandler);
5650 class HostDispatchV8Thread : public v8::internal::Thread {
5652 explicit HostDispatchV8Thread(v8::internal::Isolate* isolate)
5657 class HostDispatchDebuggerThread : public v8::internal::Thread {
5659 explicit HostDispatchDebuggerThread(v8::internal::Isolate* isolate)
5666 static void HostDispatchMessageHandler(const v8::Debug::Message& message) {
5668 v8::String::Value json(message.GetJSON());
5690 v8::HandleScope scope;
5694 v8::Debug::SetMessageHandler2(HostDispatchMessageHandler);
5695 v8::Debug::SetHostDispatchHandler(HostDispatchDispatchHandler, 10 /* ms */);
5716 // v8 thread initializes, runs source_1
5719 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer));
5722 // v8 thread starts compiling source_2.
5727 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer));
5737 // Create a V8 environment
5751 /* In this test, the V8 thread waits for a message from the debug thread.
5753 * which signals the V8 thread to wake up.
5756 class DebugMessageDispatchV8Thread : public v8::internal::Thread {
5758 explicit DebugMessageDispatchV8Thread(v8::internal::Isolate* isolate)
5763 class DebugMessageDispatchDebuggerThread : public v8::internal::Thread {
5765 explicit DebugMessageDispatchDebuggerThread(v8::internal::Isolate* isolate)
5779 v8::HandleScope scope;
5783 v8::Debug::SetDebugMessageDispatchHandler(DebugMessageHandler);
5807 // Create a V8 environment
5822 v8::V8::Initialize();
5988 // Test for issue http://code.google.com/p/v8/issues/detail?id=289.
5991 class EmptyExternalStringResource : public v8::String::ExternalStringResource {
5998 ::v8::internal::EmbeddedVector<uint16_t, 1> empty_;
6003 v8::HandleScope scope;
6008 v8::Local<v8::String> source = v8::String::NewExternal(&source_ext_str);
6009 v8::Handle<v8::Script> evil_script = v8::Script::Compile(source);
6011 i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source)));
6028 CHECK_GT((*env)->Global()->Get(v8::String::New("count"))->Int32Value(), 8);
6034 v8::HandleScope scope;
6050 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
6051 v8::Undefined());
6054 v8::Local<v8::String> script = v8::String::New(
6059 v8::ScriptOrigin origin1 = v8::ScriptOrigin(v8::String::New("name"));
6060 v8::Handle<v8::Script> script1 = v8::Script::Compile(script, &origin1);
6061 script1->SetData(v8::String::New("data"));
6063 v8::Local<v8::Function> f;
6064 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
6073 v8::Script::Compile(script, &origin1)->Run();
6074 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
6080 v8::Local<v8::String> data_obj_source = v8::String::New(
6085 v8::Local<v8::Value> data_obj = v8::Script::Compile(data_obj_source)->Run();
6086 v8::ScriptOrigin origin2 = v8::ScriptOrigin(v8::String::New("new name"));
6087 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2);
6090 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
6096 v8::Handle<v8::Script> script3 =
6097 v8::Script::Compile(script, &origin2, NULL,
6098 v8::String::New("in compile"));
6101 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
6108 static v8::Persistent<v8::Context> expected_context;
6109 static v8::Handle<v8::Value> expected_context_data;
6113 static void ContextCheckMessageHandler(const v8::Debug::Message& message) {
6120 v8::String::Value json(message.GetJSON());
6134 v8::HandleScope scope;
6136 v8::Debug::SetMessageHandler2(ContextCheckMessageHandler);
6139 v8::Persistent<v8::Context> context_1;
6140 v8::Persistent<v8::Context> context_2;
6141 v8::Handle<v8::ObjectTemplate> global_template =
6142 v8::Handle<v8::ObjectTemplate>();
6143 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>();
6144 context_1 = v8::Context::New(NULL, global_template, global_object);
6145 context_2 = v8::Context::New(NULL, global_template, global_object);
6152 v8::Handle<v8::String> data_1 = v8::String::New("1");
6153 v8::Handle<v8::String> data_2 = v8::String::New("2");
6164 v8::Context::Scope context_scope(context_1);
6167 v8::Local<v8::Function> f = CompileFunction(source, "f");
6174 v8::Context::Scope context_scope(context_2);
6177 v8::Local<v8::Function> f = CompileFunction(source, "f");
6184 v8::Debug::SetMessageHandler2(NULL);
6191 static void DebugBreakMessageHandler(const v8::Debug::Message& message) {
6193 if (message.IsEvent() && message.GetEvent() == v8::Break) {
6196 v8::Debug::DebugBreak();
6210 v8::HandleScope scope;
6213 v8::Debug::SetMessageHandler2(DebugBreakMessageHandler);
6218 v8::Local<v8::Function> f =
6219 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
6220 v8::Local<v8::Function> g =
6221 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g")));
6237 v8::DebugEvent event,
6238 v8::Handle<v8::Object> exec_state,
6239 v8::Handle<v8::Object> event_data,
6240 v8::Handle<v8::Value> data) {
6242 if (event == v8::Break) {
6249 v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(0) };
6250 v8::Handle<v8::Value> result = frame_function_name->Call(exec_state,
6256 v8::Handle<v8::String> function_name(result->ToString());
6263 v8::Debug::DebugBreak();
6271 v8::HandleScope scope;
6285 v8::Local<v8::Function> f = CompileFunction(script, "f");
6287 v8::Handle<v8::Value> argv[argc] = { v8::String::New(" /* xxx */ a=0;") };
6288 v8::Local<v8::Value> result = f->Call(env->Global(), argc, argv);
6291 v8::Debug::SetDebugEventListener(DebugEventDebugBreak);
6292 v8::Debug::DebugBreak();
6306 v8::Persistent<v8::Context> context_1;
6307 v8::Handle<v8::ObjectTemplate> global_template =
6308 v8::Handle<v8::ObjectTemplate>();
6309 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>();
6310 context_1 = v8::Context::New(NULL, global_template, global_object);
6316 v8::Handle<v8::String> data_1 = v8::String::New("1");
6325 v8::Context::Scope context_scope(context_1);
6328 v8::Local<v8
6339 v8::HandleScope scope;
6340 v8::Debug::SetMessageHandler2(ContextCheckMessageHandler);
6346 v8::Debug::SetMessageHandler2(NULL);
6357 const v8::Debug::Message& message) {
6364 v8::String::Value json(message.GetJSON());
6382 v8::Debug::SendCommand(buffer, AsciiToUtf16(eval_command, buffer));
6402 v8::HandleScope scope;
6405 v8::Debug::SetMessageHandler2(DebugEvalContextCheckMessageHandler);
6414 v8::Debug::SetMessageHandler2(NULL);
6421 static void DebugEventScriptCollectedEvent(v8::DebugEvent event,
6422 v8::Handle<v8::Object> exec_state,
6423 v8::Handle<v8::Object> event_data,
6424 v8::Handle<v8::Value> data) {
6426 if (event == v8::ScriptCollected) {
6434 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
6437 v8::HandleScope scope;
6448 v8::Debug::SetDebugEventListener(DebugEventScriptCollectedEvent,
6449 v8::Undefined());
6451 v8::Script::Compile(v8::String::New("eval('a=1')"))->Run();
6452 v8::Script::Compile(v8::String::New("eval('a=2')"))->Run();
6461 v8::Debug::SetDebugEventListener(NULL);
6468 static void ScriptCollectedMessageHandler(const v8::Debug::Message& message) {
6470 if (message.IsEvent() && message.GetEvent() == v8::ScriptCollected) {
6472 v8::Handle<v8::Context> context = message.GetEventContext();
6481 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
6483 v8::HandleScope scope;
6495 v8::Debug::SetMessageHandler2(ScriptCollectedMessageHandler);
6497 v8::Script::Compile(v8::String::New("eval('a=1')"))->Run();
6498 v8::Script::Compile(v8::String::New("eval('a=2')"))->Run();
6508 v8::Debug::SetMessageHandler2(NULL);
6514 static void AfterCompileMessageHandler(const v8::Debug::Message& message) {
6517 if (message.GetEvent() == v8::AfterCompile) {
6519 } else if (message.GetEvent() == v8::Break) {
6529 v8::HandleScope scope;
6534 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
6535 v8::Script::Compile(v8::String::New(script))->Run();
6536 v8::Debug::SetMessageHandler2(NULL);
6538 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
6539 v8::Debug::DebugBreak();
6540 v8::Script::Compile(v8::String::New(script))->Run();
6543 v8::Debug::SetMessageHandler2(NULL);
6553 v8::HandleScope scope;
6558 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
6559 v8::Script::Compile(v8::String::New(script))->Run();
6560 v8::Debug::SetMessageHandler2(NULL);
6562 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
6563 v8::Debug::DebugBreak();
6564 v8::Local<v8::Function> f =
6565 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
6569 v8::Debug::SetMessageHandler2(NULL);
6578 static void ExceptionMessageHandler(const v8::Debug::Message& message) {
6579 if (message.IsEvent() && message.GetEvent() == v8::Exception) {
6588 v8::HandleScope scope;
6597 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
6598 v8::Script::Compile(v8::String::New(script))->Run();
6599 v8::Debug::SetMessageHandler2(NULL);
6601 v8::Debug::SetMessageHandler2(ExceptionMessageHandler);
6602 v8::Local<v8::Function> f =
6603 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
6607 v8::Debug::SetMessageHandler2(NULL);
6617 v8::HandleScope scope;
6630 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
6632 v8::ScriptOrigin origin(
6633 v8::String::New(resource_name),
6634 v8::Integer::New(10),
6635 v8::Integer::New(1));
6638 v8::Script::Compile(v8::String::New(script), &origin)->Run();
6647 v8::Debug::SetMessageHandler2(NULL);
6651 static void BreakMessageHandler(const v8::Debug::Message& message) {
6653 if (message.IsEvent() && message.GetEvent() == v8::Break) {
6657 v8::HandleScope scope;
6658 v8::Handle<v8::String> json = message.GetJSON();
6661 } else if (message.IsEvent() && message.GetEvent() == v8::AfterCompile) {
6662 v8::HandleScope scope;
6669 v8::Handle<v8::String> json = message.GetJSON();
6684 v8::HandleScope scope;
6688 v8::Debug::SetMessageHandler2(BreakMessageHandler);
6691 v8::Debug::DebugBreak();
6695 v8::Local<v8::Function> f = CompileFunction(&env, src, "f");
6701 v8::Debug::DebugBreak();
6707 v8::Debug::SetMessageHandler2(NULL);
6714 static void CountingMessageHandler(const v8::Debug::Message& message) {
6720 v8::HandleScope scope;
6725 v8::Debug::SetMessageHandler2(CountingMessageHandler);
6735 v8::Debug::SendCommand(buffer, AsciiToUtf16(scripts_command, buffer));
6738 v8::Debug::ProcessDebugMessages();
6744 v8::Debug::SendCommand(buffer, AsciiToUtf16(scripts_command, buffer));
6745 v8::Debug::SendCommand(buffer, AsciiToUtf16(scripts_command, buffer));
6747 v8::Debug::ProcessDebugMessages();
6752 v8::Debug::SetMessageHandler2(NULL);
6759 static void MessageHandler(const v8::Debug::Message& message) {
6761 v8::String::Value json(message.GetJSON());
6776 v8::HandleScope scope;
6779 v8::Debug::SetMessageHandler2(BacktraceData::MessageHandler);
6790 v8::Debug::SendCommand(buffer, AsciiToUtf16(scripts_command, buffer));
6791 v8::Debug::ProcessDebugMessages();
6794 v8::Handle<v8::String> void0 = v8::String::New("void(0)");
6795 v8::Handle<v8::Script> script = v8::Script::Compile(void0, void0);
6799 v8::Debug::SendCommand(buffer, AsciiToUtf16(scripts_command, buffer));
6804 v8::Debug::SetMessageHandler2(NULL);
6810 v8::HandleScope scope;
6812 v8::Handle<v8::Value> obj = v8::Debug::GetMirror(v8::String::New("hodja"));
6813 v8::Handle<v8::Function> run_test = v8::Handle<v8::Function>::Cast(
6814 v8::Script::New(
6815 v8::String::New(
6821 v8::Handle<v8::Value> result = run_test->Call(env->Global(), 1, &obj);
6828 v8::HandleScope scope;
6832 v8::Local<v8::Function> foo = CompileFunction(
6840 v8::Debug::SetDebugEventListener(DebugEventBreakMax);
6843 v8::Debug::DebugBreak();
6854 v8::Debug::SetDebugEventListener(NULL);
6859 v8::Handle<v8::Context> debugee_context;
6860 v8::Handle<v8::Context> debugger_context;
6865 static v8::Handle<v8::Value> NamedGetterWithCallingContextCheck(
6866 v8::Local<v8::String> name,
6867 const v8::AccessorInfo& info) {
6868 CHECK_EQ(0, strcmp(*v8::String::AsciiValue(name), "a"));
6869 v8::Handle<v8::Context> current = v8::Context::GetCurrent();
6872 v8::Handle<v8::Context> calling = v8::Context::GetCalling();
6875 return v8::Int32::New(1);
6883 v8::DebugEvent event,
6884 v8::Handle<v8::Object> exec_state,
6885 v8::Handle<v8::Object> event_data,
6886 v8::Handle<v8::Value> data) {
6887 if (event == v8::Break) {
6889 CHECK(debugger_context == v8::Context::GetCurrent());
6890 v8::Handle<v8::Function> func(v8::Function::Cast(*CompileRun(
6896 v8::Handle<v8::Value> argv[argc] = { exec_state };
6897 v8::Handle<v8::Value> result = func->Call(exec_state, argc, argv);
6904 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
6906 v8::HandleScope scope;
6912 debugee_context = v8::Local<v8::Context>(*env);
6913 debugger_context = v8::Utils::ToLocal(debug->debug_context());
6916 v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New();
6917 named->SetAccessor(v8::String::New("a"),
6919 env->Global()->Set(v8::String::New("obj"),
6923 v8::Debug::SetDebugEventListener(DebugEventGetAtgumentPropertyValue);
6926 v8::Local<v8::Function> foo = CompileFunction(
6936 v8::Debug::SetDebugEventListener(NULL);
6937 debugee_context = v8::Handle<v8::Context>();
6938 debugger_context = v8::Handle<v8::Context>();
6944 v8::HandleScope scope;
6945 v8::Local<v8::Context> context1 = v8::Debug::GetDebugContext();
6946 v8::Local<v8::Context> context2 = v8::Debug::GetDebugContext();
6951 static v8::Handle<v8::Value> expected_callback_data;
6952 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) {
6959 v8::HandleScope scope;
6960 expected_callback_data = v8::Int32::New(2010);
6961 v8::Debug::SetDebugEventListener2(DebugEventContextChecker,
6963 expected_context = v8::Context::New();
6964 v8::Context::Scope context_scope(expected_context);
6965 v8::Script::Compile(v8::String::New("(function(){debugger;})();"))->Run();
6968 v8::Debug::SetDebugEventListener(NULL);
6969 expected_context_data = v8::Handle<v8::Value>();
6977 static void DebugEventBreakDataChecker(const v8::Debug::EventDetails& details) {
6978 if (details.GetEvent() == v8::BreakForCommand) {
6981 } else if (details.GetEvent() == v8::Break) {
6989 v8::HandleScope scope;
6991 v8::Debug::SetDebugEventListener2(DebugEventBreakDataChecker);
6999 v8::Debug::DebugBreakForCommand();
7000 v8::Script::Compile(v8::String::New("(function(x){return x;})(1);"))->Run();
7008 v8::Debug::DebugBreakForCommand(data1);
7009 v8::Script::Compile(v8::String::New("(function(x){return x+1;})(1);"))->Run();
7016 v8::Debug::DebugBreak();
7017 v8::Script::Compile(v8::String::New("(function(x){return x+2;})(1);"))->Run();
7025 v8::Debug::DebugBreak();
7026 v8::Debug::DebugBreakForCommand(data2);
7027 v8::Script::Compile(v8::String::New("(function(x){return x+3;})(1);"))->Run();
7035 v8::Debug::SetDebugEventListener(NULL);
7041 static void DebugEventBreakDeoptimize(v8::DebugEvent event,
7042 v8::Handle<v8::Object> exec_state,
7043 v8::Handle<v8::Object> event_data,
7044 v8::Handle<v8::Value> data) {
7045 if (event == v8::Break) {
7049 v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(0) };
7050 v8::Handle<v8::Value> result =
7055 v8::Handle<v8::String> function_name(result->ToString());
7064 v8::Debug::DebugBreak();
7072 v8::HandleScope scope;
7087 v8::Debug::SetDebugEventListener(DebugEventBreakDeoptimize,
7088 v8::Undefined());
7091 v8::Script::Compile(v8::String::New("function bar(){}; bar()"))->Run();
7094 v8::Debug::DebugBreak();
7095 v8::Script::Compile(v8::String::New("bar()"))->Run();
7099 v8::Debug::SetDebugEventListener(NULL);
7103 static void DebugEventBreakWithOptimizedStack(v8::DebugEvent event,
7104 v8::Handle<v8::Object> exec_state,
7105 v8::Handle<v8::Object> event_data,
7106 v8::Handle<v8::Value> data) {
7107 if (event == v8::Break) {
7111 v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(i) };
7113 v8::Handle<v8::Value> result =
7116 v8::Handle<v8::String> function_name(result->ToString());
7117 CHECK(function_name->Equals(v8::String::New("loop")));
7121 v8::Handle<v8::String> argument_name(result->ToString());
7122 CHECK(argument_name->Equals(v8::String::New("count")));
7134 v8::Handle<v8::String> local_name(result->ToString());
7135 CHECK(local_name->Equals(v8::String::New("local")));
7150 static v8::Handle<v8::Value> ScheduleBreak(const v8::Arguments& args) {
7151 v8::Debug::SetDebugEventListener(DebugEventBreakWithOptimizedStack,
7152 v8::Undefined());
7153 v8::Debug::DebugBreak();
7154 return v8::Undefined();
7159 v8::HandleScope scope;
7174 v8::Handle<v8::FunctionTemplate> schedule_break_template =
7175 v8::FunctionTemplate::New(ScheduleBreak);
7176 v8::Handle<v8::Function> schedule_break =
7186 v8::Script::Compile(v8::String::New(src))->Run();
7211 v8::Debug::DebugBreak();
7217 CHECK(!v8::V8::IsExecutionTerminating());
7223 v8::HandleScope scope;
7227 v8::Debug::SetDebugEventListener(DebugEventBreakMax);
7258 v8::Debug::SetDebugEventListener(NULL);