OLD | NEW |
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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 129 |
130 | 130 |
131 // Helper class for creating a V8 enviromnent for running tests | 131 // Helper class for creating a V8 enviromnent for running tests |
132 class DebugLocalContext { | 132 class DebugLocalContext { |
133 public: | 133 public: |
134 inline DebugLocalContext( | 134 inline DebugLocalContext( |
135 v8::ExtensionConfiguration* extensions = 0, | 135 v8::ExtensionConfiguration* extensions = 0, |
136 v8::Handle<v8::ObjectTemplate> global_template = | 136 v8::Handle<v8::ObjectTemplate> global_template = |
137 v8::Handle<v8::ObjectTemplate>(), | 137 v8::Handle<v8::ObjectTemplate>(), |
138 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>()) | 138 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>()) |
139 : scope_(v8::Isolate::GetCurrent()), | 139 : context_(v8::Context::New(extensions, global_template, global_object)) { |
140 context_( | |
141 v8::Context::New(v8::Isolate::GetCurrent(), | |
142 extensions, | |
143 global_template, | |
144 global_object)) { | |
145 context_->Enter(); | 140 context_->Enter(); |
146 } | 141 } |
147 inline ~DebugLocalContext() { | 142 inline ~DebugLocalContext() { |
148 context_->Exit(); | 143 context_->Exit(); |
| 144 context_.Dispose(context_->GetIsolate()); |
149 } | 145 } |
150 inline v8::Context* operator->() { return *context_; } | 146 inline v8::Context* operator->() { return *context_; } |
151 inline v8::Context* operator*() { return *context_; } | 147 inline v8::Context* operator*() { return *context_; } |
152 inline bool IsReady() { return !context_.IsEmpty(); } | 148 inline bool IsReady() { return !context_.IsEmpty(); } |
153 void ExposeDebug() { | 149 void ExposeDebug() { |
154 v8::internal::Isolate* isolate = | 150 v8::internal::Isolate* isolate = |
155 reinterpret_cast<v8::internal::Isolate*>(context_->GetIsolate()); | 151 reinterpret_cast<v8::internal::Isolate*>(context_->GetIsolate()); |
156 v8::internal::Debug* debug = isolate->debug(); | 152 v8::internal::Debug* debug = isolate->debug(); |
157 // Expose the debug context global object in the global object for testing. | 153 // Expose the debug context global object in the global object for testing. |
158 debug->Load(); | 154 debug->Load(); |
159 debug->debug_context()->set_security_token( | 155 debug->debug_context()->set_security_token( |
160 v8::Utils::OpenHandle(*context_)->security_token()); | 156 v8::Utils::OpenHandle(*context_)->security_token()); |
161 | 157 |
162 Handle<JSGlobalProxy> global(Handle<JSGlobalProxy>::cast( | 158 Handle<JSGlobalProxy> global(Handle<JSGlobalProxy>::cast( |
163 v8::Utils::OpenHandle(*context_->Global()))); | 159 v8::Utils::OpenHandle(*context_->Global()))); |
164 Handle<v8::internal::String> debug_string = | 160 Handle<v8::internal::String> debug_string = |
165 FACTORY->InternalizeOneByteString(STATIC_ASCII_VECTOR("debug")); | 161 FACTORY->InternalizeOneByteString(STATIC_ASCII_VECTOR("debug")); |
166 SetProperty(isolate, global, debug_string, | 162 SetProperty(isolate, global, debug_string, |
167 Handle<Object>(debug->debug_context()->global_proxy(), isolate), | 163 Handle<Object>(debug->debug_context()->global_proxy(), isolate), |
168 DONT_ENUM, | 164 DONT_ENUM, |
169 ::v8::internal::kNonStrictMode); | 165 ::v8::internal::kNonStrictMode); |
170 } | 166 } |
171 | 167 |
172 private: | 168 private: |
173 v8::HandleScope scope_; | 169 v8::Persistent<v8::Context> context_; |
174 v8::Local<v8::Context> context_; | |
175 }; | 170 }; |
176 | 171 |
177 | 172 |
178 // --- H e l p e r F u n c t i o n s | 173 // --- H e l p e r F u n c t i o n s |
179 | 174 |
180 | 175 |
181 // Compile and run the supplied source and return the fequested function. | 176 // Compile and run the supplied source and return the fequested function. |
182 static v8::Local<v8::Function> CompileFunction(DebugLocalContext* env, | 177 static v8::Local<v8::Function> CompileFunction(DebugLocalContext* env, |
183 const char* source, | 178 const char* source, |
184 const char* function_name) { | 179 const char* function_name) { |
(...skipping 4047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4232 } | 4227 } |
4233 | 4228 |
4234 static const char* kSimpleExtensionSource = | 4229 static const char* kSimpleExtensionSource = |
4235 "(function Foo() {" | 4230 "(function Foo() {" |
4236 " return 4;" | 4231 " return 4;" |
4237 "})() "; | 4232 "})() "; |
4238 | 4233 |
4239 // http://crbug.com/28933 | 4234 // http://crbug.com/28933 |
4240 // Test that debug break is disabled when bootstrapper is active. | 4235 // Test that debug break is disabled when bootstrapper is active. |
4241 TEST(NoBreakWhenBootstrapping) { | 4236 TEST(NoBreakWhenBootstrapping) { |
4242 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 4237 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
4243 v8::HandleScope scope(isolate); | |
4244 | 4238 |
4245 // Register a debug event listener which sets the break flag and counts. | 4239 // Register a debug event listener which sets the break flag and counts. |
4246 v8::Debug::SetDebugEventListener(DebugEventCounter); | 4240 v8::Debug::SetDebugEventListener(DebugEventCounter); |
4247 | 4241 |
4248 // Set the debug break flag. | 4242 // Set the debug break flag. |
4249 v8::Debug::DebugBreak(); | 4243 v8::Debug::DebugBreak(); |
4250 break_point_hit_count = 0; | 4244 break_point_hit_count = 0; |
4251 { | 4245 { |
4252 // Create a context with an extension to make sure that some JavaScript | 4246 // Create a context with an extension to make sure that some JavaScript |
4253 // code is executed during bootstrapping. | 4247 // code is executed during bootstrapping. |
4254 v8::RegisterExtension(new v8::Extension("simpletest", | 4248 v8::RegisterExtension(new v8::Extension("simpletest", |
4255 kSimpleExtensionSource)); | 4249 kSimpleExtensionSource)); |
4256 const char* extension_names[] = { "simpletest" }; | 4250 const char* extension_names[] = { "simpletest" }; |
4257 v8::ExtensionConfiguration extensions(1, extension_names); | 4251 v8::ExtensionConfiguration extensions(1, extension_names); |
4258 v8::HandleScope handle_scope(isolate); | 4252 v8::Persistent<v8::Context> context = v8::Context::New(&extensions); |
4259 v8::Context::New(isolate, &extensions); | 4253 context.Dispose(context->GetIsolate()); |
4260 } | 4254 } |
4261 // Check that no DebugBreak events occured during the context creation. | 4255 // Check that no DebugBreak events occured during the context creation. |
4262 CHECK_EQ(0, break_point_hit_count); | 4256 CHECK_EQ(0, break_point_hit_count); |
4263 | 4257 |
4264 // Get rid of the debug event listener. | 4258 // Get rid of the debug event listener. |
4265 v8::Debug::SetDebugEventListener(NULL); | 4259 v8::Debug::SetDebugEventListener(NULL); |
4266 CheckDebuggerUnloaded(); | 4260 CheckDebuggerUnloaded(); |
4267 } | 4261 } |
4268 | 4262 |
4269 static v8::Handle<v8::Array> NamedEnum(const v8::AccessorInfo&) { | 4263 static v8::Handle<v8::Array> NamedEnum(const v8::AccessorInfo&) { |
(...skipping 1964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6234 v8::String::New("in compile")); | 6228 v8::String::New("in compile")); |
6235 CHECK_EQ("in compile", last_script_data_hit); | 6229 CHECK_EQ("in compile", last_script_data_hit); |
6236 script3->Run(); | 6230 script3->Run(); |
6237 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); | 6231 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); |
6238 f->Call(env->Global(), 0, NULL); | 6232 f->Call(env->Global(), 0, NULL); |
6239 CHECK_EQ(4, break_point_hit_count); | 6233 CHECK_EQ(4, break_point_hit_count); |
6240 CHECK_EQ("in compile", last_script_data_hit); | 6234 CHECK_EQ("in compile", last_script_data_hit); |
6241 } | 6235 } |
6242 | 6236 |
6243 | 6237 |
6244 static v8::Handle<v8::Context> expected_context; | 6238 static v8::Persistent<v8::Context> expected_context; |
6245 static v8::Handle<v8::Value> expected_context_data; | 6239 static v8::Handle<v8::Value> expected_context_data; |
6246 | 6240 |
6247 | 6241 |
6248 // Check that the expected context is the one generating the debug event. | 6242 // Check that the expected context is the one generating the debug event. |
6249 static void ContextCheckMessageHandler(const v8::Debug::Message& message) { | 6243 static void ContextCheckMessageHandler(const v8::Debug::Message& message) { |
6250 CHECK(message.GetEventContext() == expected_context); | 6244 CHECK(message.GetEventContext() == expected_context); |
6251 CHECK(message.GetEventContext()->GetEmbedderData(0)->StrictEquals( | 6245 CHECK(message.GetEventContext()->GetEmbedderData(0)->StrictEquals( |
6252 expected_context_data)); | 6246 expected_context_data)); |
6253 message_handler_hit_count++; | 6247 message_handler_hit_count++; |
6254 | 6248 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6292 context_2->SetEmbedderData(0, data_2); | 6286 context_2->SetEmbedderData(0, data_2); |
6293 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1)); | 6287 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1)); |
6294 CHECK(context_2->GetEmbedderData(0)->StrictEquals(data_2)); | 6288 CHECK(context_2->GetEmbedderData(0)->StrictEquals(data_2)); |
6295 | 6289 |
6296 // Simple test function which causes a break. | 6290 // Simple test function which causes a break. |
6297 const char* source = "function f() { debugger; }"; | 6291 const char* source = "function f() { debugger; }"; |
6298 | 6292 |
6299 // Enter and run function in the first context. | 6293 // Enter and run function in the first context. |
6300 { | 6294 { |
6301 v8::Context::Scope context_scope(context_1); | 6295 v8::Context::Scope context_scope(context_1); |
6302 expected_context = context_1; | 6296 expected_context = v8::Persistent<v8::Context>(*context_1); |
6303 expected_context_data = data_1; | 6297 expected_context_data = data_1; |
6304 v8::Local<v8::Function> f = CompileFunction(source, "f"); | 6298 v8::Local<v8::Function> f = CompileFunction(source, "f"); |
6305 f->Call(context_1->Global(), 0, NULL); | 6299 f->Call(context_1->Global(), 0, NULL); |
6306 } | 6300 } |
6307 | 6301 |
6308 | 6302 |
6309 // Enter and run function in the second context. | 6303 // Enter and run function in the second context. |
6310 { | 6304 { |
6311 v8::Context::Scope context_scope(context_2); | 6305 v8::Context::Scope context_scope(context_2); |
6312 expected_context = context_2; | 6306 expected_context = v8::Persistent<v8::Context>(*context_2); |
6313 expected_context_data = data_2; | 6307 expected_context_data = data_2; |
6314 v8::Local<v8::Function> f = CompileFunction(source, "f"); | 6308 v8::Local<v8::Function> f = CompileFunction(source, "f"); |
6315 f->Call(context_2->Global(), 0, NULL); | 6309 f->Call(context_2->Global(), 0, NULL); |
6316 } | 6310 } |
6317 | 6311 |
6318 // Two times compile event and two times break event. | 6312 // Two times compile event and two times break event. |
6319 CHECK_GT(message_handler_hit_count, 4); | 6313 CHECK_GT(message_handler_hit_count, 4); |
6320 | 6314 |
6321 v8::Debug::SetMessageHandler2(NULL); | 6315 v8::Debug::SetMessageHandler2(NULL); |
6322 CheckDebuggerUnloaded(); | 6316 CheckDebuggerUnloaded(); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6453 v8::Handle<v8::String> data_1 = v8::String::New("1"); | 6447 v8::Handle<v8::String> data_1 = v8::String::New("1"); |
6454 context_1->SetEmbedderData(0, data_1); | 6448 context_1->SetEmbedderData(0, data_1); |
6455 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1)); | 6449 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1)); |
6456 | 6450 |
6457 // Simple test function with eval that causes a break. | 6451 // Simple test function with eval that causes a break. |
6458 const char* source = "function f() { eval('debugger;'); }"; | 6452 const char* source = "function f() { eval('debugger;'); }"; |
6459 | 6453 |
6460 // Enter and run function in the context. | 6454 // Enter and run function in the context. |
6461 { | 6455 { |
6462 v8::Context::Scope context_scope(context_1); | 6456 v8::Context::Scope context_scope(context_1); |
6463 expected_context = v8::Local<v8::Context>(*context_1); | 6457 expected_context = v8::Persistent<v8::Context>(*context_1); |
6464 expected_context_data = data_1; | 6458 expected_context_data = data_1; |
6465 v8::Local<v8::Function> f = CompileFunction(source, "f"); | 6459 v8::Local<v8::Function> f = CompileFunction(source, "f"); |
6466 f->Call(context_1->Global(), 0, NULL); | 6460 f->Call(context_1->Global(), 0, NULL); |
6467 } | 6461 } |
6468 } | 6462 } |
6469 | 6463 |
6470 | 6464 |
6471 // Test which creates a context and sets embedder data on it. Checks that this | 6465 // Test which creates a context and sets embedder data on it. Checks that this |
6472 // data is set correctly and that when the debug message handler is called for | 6466 // data is set correctly and that when the debug message handler is called for |
6473 // break event in an eval statement the expected context is the one returned by | 6467 // break event in an eval statement the expected context is the one returned by |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6612 } | 6606 } |
6613 | 6607 |
6614 | 6608 |
6615 // Test that GetEventContext doesn't fail and return empty handle for | 6609 // Test that GetEventContext doesn't fail and return empty handle for |
6616 // ScriptCollected events. | 6610 // ScriptCollected events. |
6617 TEST(ScriptCollectedEventContext) { | 6611 TEST(ScriptCollectedEventContext) { |
6618 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 6612 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
6619 v8::internal::Debug* debug = | 6613 v8::internal::Debug* debug = |
6620 reinterpret_cast<v8::internal::Isolate*>(isolate)->debug(); | 6614 reinterpret_cast<v8::internal::Isolate*>(isolate)->debug(); |
6621 script_collected_message_count = 0; | 6615 script_collected_message_count = 0; |
| 6616 v8::HandleScope scope(isolate); |
6622 | 6617 |
6623 { // Scope for the DebugLocalContext. | 6618 { // Scope for the DebugLocalContext. |
6624 DebugLocalContext env; | 6619 DebugLocalContext env; |
6625 | 6620 |
6626 // Request the loaded scripts to initialize the debugger script cache. | 6621 // Request the loaded scripts to initialize the debugger script cache. |
6627 debug->GetLoadedScripts(); | 6622 debug->GetLoadedScripts(); |
6628 | 6623 |
6629 // Do garbage collection to ensure that only the script in this test will be | 6624 // Do garbage collection to ensure that only the script in this test will be |
6630 // collected afterwards. | 6625 // collected afterwards. |
6631 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 6626 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
6632 | 6627 |
6633 v8::Debug::SetMessageHandler2(ScriptCollectedMessageHandler); | 6628 v8::Debug::SetMessageHandler2(ScriptCollectedMessageHandler); |
6634 v8::Script::Compile(v8::String::New("eval('a=1')"))->Run(); | 6629 { |
6635 v8::Script::Compile(v8::String::New("eval('a=2')"))->Run(); | 6630 v8::Script::Compile(v8::String::New("eval('a=1')"))->Run(); |
| 6631 v8::Script::Compile(v8::String::New("eval('a=2')"))->Run(); |
| 6632 } |
6636 } | 6633 } |
6637 | 6634 |
6638 // Do garbage collection to collect the script above which is no longer | 6635 // Do garbage collection to collect the script above which is no longer |
6639 // referenced. | 6636 // referenced. |
6640 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 6637 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
6641 | 6638 |
6642 CHECK_EQ(4, script_collected_message_count); | 6639 CHECK_EQ(2, script_collected_message_count); |
6643 | 6640 |
6644 v8::Debug::SetMessageHandler2(NULL); | 6641 v8::Debug::SetMessageHandler2(NULL); |
6645 } | 6642 } |
6646 | 6643 |
6647 | 6644 |
6648 // Debug event listener which counts the after compile events. | 6645 // Debug event listener which counts the after compile events. |
6649 int after_compile_message_count = 0; | 6646 int after_compile_message_count = 0; |
6650 static void AfterCompileMessageHandler(const v8::Debug::Message& message) { | 6647 static void AfterCompileMessageHandler(const v8::Debug::Message& message) { |
6651 // Count the number of scripts collected. | 6648 // Count the number of scripts collected. |
6652 if (message.IsEvent()) { | 6649 if (message.IsEvent()) { |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7085 | 7082 |
7086 | 7083 |
7087 static v8::Handle<v8::Value> expected_callback_data; | 7084 static v8::Handle<v8::Value> expected_callback_data; |
7088 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) { | 7085 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) { |
7089 CHECK(details.GetEventContext() == expected_context); | 7086 CHECK(details.GetEventContext() == expected_context); |
7090 CHECK_EQ(expected_callback_data, details.GetCallbackData()); | 7087 CHECK_EQ(expected_callback_data, details.GetCallbackData()); |
7091 } | 7088 } |
7092 | 7089 |
7093 // Check that event details contain context where debug event occured. | 7090 // Check that event details contain context where debug event occured. |
7094 TEST(DebugEventContext) { | 7091 TEST(DebugEventContext) { |
7095 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 7092 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
7096 v8::HandleScope scope(isolate); | |
7097 expected_callback_data = v8::Int32::New(2010); | 7093 expected_callback_data = v8::Int32::New(2010); |
7098 v8::Debug::SetDebugEventListener2(DebugEventContextChecker, | 7094 v8::Debug::SetDebugEventListener2(DebugEventContextChecker, |
7099 expected_callback_data); | 7095 expected_callback_data); |
7100 expected_context = v8::Context::New(isolate); | 7096 expected_context = v8::Context::New(); |
7101 v8::Context::Scope context_scope(expected_context); | 7097 v8::Context::Scope context_scope( |
| 7098 v8::Isolate::GetCurrent(), expected_context); |
7102 v8::Script::Compile(v8::String::New("(function(){debugger;})();"))->Run(); | 7099 v8::Script::Compile(v8::String::New("(function(){debugger;})();"))->Run(); |
| 7100 expected_context.Dispose(expected_context->GetIsolate()); |
7103 expected_context.Clear(); | 7101 expected_context.Clear(); |
7104 v8::Debug::SetDebugEventListener(NULL); | 7102 v8::Debug::SetDebugEventListener(NULL); |
7105 expected_context_data = v8::Handle<v8::Value>(); | 7103 expected_context_data = v8::Handle<v8::Value>(); |
7106 CheckDebuggerUnloaded(); | 7104 CheckDebuggerUnloaded(); |
7107 } | 7105 } |
7108 | 7106 |
7109 | 7107 |
7110 static void* expected_break_data; | 7108 static void* expected_break_data; |
7111 static bool was_debug_break_called; | 7109 static bool was_debug_break_called; |
7112 static bool was_debug_event_called; | 7110 static bool was_debug_event_called; |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7553 TEST(LiveEditDisabled) { | 7551 TEST(LiveEditDisabled) { |
7554 v8::internal::FLAG_allow_natives_syntax = true; | 7552 v8::internal::FLAG_allow_natives_syntax = true; |
7555 LocalContext env; | 7553 LocalContext env; |
7556 v8::HandleScope scope(env->GetIsolate()); | 7554 v8::HandleScope scope(env->GetIsolate()); |
7557 v8::Debug::SetLiveEditEnabled(false); | 7555 v8::Debug::SetLiveEditEnabled(false); |
7558 CompileRun("%LiveEditCompareStrings('', '')"); | 7556 CompileRun("%LiveEditCompareStrings('', '')"); |
7559 } | 7557 } |
7560 | 7558 |
7561 | 7559 |
7562 #endif // ENABLE_DEBUGGER_SUPPORT | 7560 #endif // ENABLE_DEBUGGER_SUPPORT |
OLD | NEW |