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