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 11 matching lines...) Expand all Loading... |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #ifdef ENABLE_DEBUGGER_SUPPORT | 28 #ifdef ENABLE_DEBUGGER_SUPPORT |
29 | 29 |
30 #include <stdlib.h> | 30 #include <stdlib.h> |
31 | 31 |
| 32 // TODO(dcarney): remove |
| 33 #define V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW |
| 34 #define V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT |
| 35 |
32 #include "v8.h" | 36 #include "v8.h" |
33 | 37 |
34 #include "api.h" | 38 #include "api.h" |
35 #include "cctest.h" | 39 #include "cctest.h" |
36 #include "compilation-cache.h" | 40 #include "compilation-cache.h" |
37 #include "debug.h" | 41 #include "debug.h" |
38 #include "deoptimizer.h" | 42 #include "deoptimizer.h" |
39 #include "platform.h" | 43 #include "platform.h" |
40 #include "stub-cache.h" | 44 #include "stub-cache.h" |
41 #include "utils.h" | 45 #include "utils.h" |
(...skipping 5104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5146 "\n" | 5150 "\n" |
5147 "foo();\n"; | 5151 "foo();\n"; |
5148 | 5152 |
5149 v8::V8::Initialize(); | 5153 v8::V8::Initialize(); |
5150 DebugLocalContext env; | 5154 DebugLocalContext env; |
5151 v8::HandleScope scope(env->GetIsolate()); | 5155 v8::HandleScope scope(env->GetIsolate()); |
5152 v8::Debug::SetMessageHandler2(&ThreadedMessageHandler); | 5156 v8::Debug::SetMessageHandler2(&ThreadedMessageHandler); |
5153 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 5157 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
5154 global_template->Set(v8::String::New("ThreadedAtBarrier1"), | 5158 global_template->Set(v8::String::New("ThreadedAtBarrier1"), |
5155 v8::FunctionTemplate::New(ThreadedAtBarrier1)); | 5159 v8::FunctionTemplate::New(ThreadedAtBarrier1)); |
5156 v8::Handle<v8::Context> context = v8::Context::New(NULL, global_template); | 5160 v8::Handle<v8::Context> context = v8::Context::New(v8::Isolate::GetCurrent(), |
| 5161 NULL, |
| 5162 global_template); |
5157 v8::Context::Scope context_scope(context); | 5163 v8::Context::Scope context_scope(context); |
5158 | 5164 |
5159 CompileRun(source); | 5165 CompileRun(source); |
5160 } | 5166 } |
5161 | 5167 |
5162 void DebuggerThread::Run() { | 5168 void DebuggerThread::Run() { |
5163 const int kBufSize = 1000; | 5169 const int kBufSize = 1000; |
5164 uint16_t buffer[kBufSize]; | 5170 uint16_t buffer[kBufSize]; |
5165 | 5171 |
5166 const char* command_1 = "{\"seq\":102," | 5172 const char* command_1 = "{\"seq\":102," |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5522 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 5528 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
5523 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 5529 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
5524 global_template->Set(v8::String::New("CheckFrameCount"), | 5530 global_template->Set(v8::String::New("CheckFrameCount"), |
5525 v8::FunctionTemplate::New(CheckFrameCount)); | 5531 v8::FunctionTemplate::New(CheckFrameCount)); |
5526 global_template->Set(v8::String::New("CheckSourceLine"), | 5532 global_template->Set(v8::String::New("CheckSourceLine"), |
5527 v8::FunctionTemplate::New(CheckSourceLine)); | 5533 v8::FunctionTemplate::New(CheckSourceLine)); |
5528 global_template->Set(v8::String::New("CheckDataParameter"), | 5534 global_template->Set(v8::String::New("CheckDataParameter"), |
5529 v8::FunctionTemplate::New(CheckDataParameter)); | 5535 v8::FunctionTemplate::New(CheckDataParameter)); |
5530 global_template->Set(v8::String::New("CheckClosure"), | 5536 global_template->Set(v8::String::New("CheckClosure"), |
5531 v8::FunctionTemplate::New(CheckClosure)); | 5537 v8::FunctionTemplate::New(CheckClosure)); |
5532 v8::Handle<v8::Context> context = v8::Context::New(NULL, global_template); | 5538 v8::Handle<v8::Context> context = v8::Context::New(v8::Isolate::GetCurrent(), |
| 5539 NULL, |
| 5540 global_template); |
5533 v8::Context::Scope context_scope(context); | 5541 v8::Context::Scope context_scope(context); |
5534 | 5542 |
5535 // Compile a function for checking the number of JavaScript frames. | 5543 // Compile a function for checking the number of JavaScript frames. |
5536 v8::Script::Compile(v8::String::New(frame_count_source))->Run(); | 5544 v8::Script::Compile(v8::String::New(frame_count_source))->Run(); |
5537 frame_count = v8::Local<v8::Function>::Cast( | 5545 frame_count = v8::Local<v8::Function>::Cast( |
5538 context->Global()->Get(v8::String::New("frame_count"))); | 5546 context->Global()->Get(v8::String::New("frame_count"))); |
5539 | 5547 |
5540 // Compile a function for returning the source line for the top frame. | 5548 // Compile a function for returning the source line for the top frame. |
5541 v8::Script::Compile(v8::String::New(frame_source_line_source))->Run(); | 5549 v8::Script::Compile(v8::String::New(frame_source_line_source))->Run(); |
5542 frame_source_line = v8::Local<v8::Function>::Cast( | 5550 frame_source_line = v8::Local<v8::Function>::Cast( |
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6246 if (IsBreakEventMessage(print_buffer)) { | 6254 if (IsBreakEventMessage(print_buffer)) { |
6247 SendContinueCommand(); | 6255 SendContinueCommand(); |
6248 } | 6256 } |
6249 } | 6257 } |
6250 | 6258 |
6251 | 6259 |
6252 // Test which creates two contexts and sets different embedder data on each. | 6260 // Test which creates two contexts and sets different embedder data on each. |
6253 // Checks that this data is set correctly and that when the debug message | 6261 // Checks that this data is set correctly and that when the debug message |
6254 // handler is called the expected context is the one active. | 6262 // handler is called the expected context is the one active. |
6255 TEST(ContextData) { | 6263 TEST(ContextData) { |
6256 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 6264 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 6265 v8::HandleScope scope(isolate); |
6257 | 6266 |
6258 v8::Debug::SetMessageHandler2(ContextCheckMessageHandler); | 6267 v8::Debug::SetMessageHandler2(ContextCheckMessageHandler); |
6259 | 6268 |
6260 // Create two contexts. | 6269 // Create two contexts. |
6261 v8::Persistent<v8::Context> context_1; | 6270 v8::Handle<v8::Context> context_1; |
6262 v8::Persistent<v8::Context> context_2; | 6271 v8::Handle<v8::Context> context_2; |
6263 v8::Handle<v8::ObjectTemplate> global_template = | 6272 v8::Handle<v8::ObjectTemplate> global_template = |
6264 v8::Handle<v8::ObjectTemplate>(); | 6273 v8::Handle<v8::ObjectTemplate>(); |
6265 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>(); | 6274 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>(); |
6266 context_1 = v8::Context::New(NULL, global_template, global_object); | 6275 context_1 = v8::Context::New(isolate, NULL, global_template, global_object); |
6267 context_2 = v8::Context::New(NULL, global_template, global_object); | 6276 context_2 = v8::Context::New(isolate, NULL, global_template, global_object); |
6268 | 6277 |
6269 // Default data value is undefined. | 6278 // Default data value is undefined. |
6270 CHECK(context_1->GetEmbedderData(0)->IsUndefined()); | 6279 CHECK(context_1->GetEmbedderData(0)->IsUndefined()); |
6271 CHECK(context_2->GetEmbedderData(0)->IsUndefined()); | 6280 CHECK(context_2->GetEmbedderData(0)->IsUndefined()); |
6272 | 6281 |
6273 // Set and check different data values. | 6282 // Set and check different data values. |
6274 v8::Handle<v8::String> data_1 = v8::String::New("1"); | 6283 v8::Handle<v8::String> data_1 = v8::String::New("1"); |
6275 v8::Handle<v8::String> data_2 = v8::String::New("2"); | 6284 v8::Handle<v8::String> data_2 = v8::String::New("2"); |
6276 context_1->SetEmbedderData(0, data_1); | 6285 context_1->SetEmbedderData(0, data_1); |
6277 context_2->SetEmbedderData(0, data_2); | 6286 context_2->SetEmbedderData(0, data_2); |
6278 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1)); | 6287 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1)); |
6279 CHECK(context_2->GetEmbedderData(0)->StrictEquals(data_2)); | 6288 CHECK(context_2->GetEmbedderData(0)->StrictEquals(data_2)); |
6280 | 6289 |
6281 // Simple test function which causes a break. | 6290 // Simple test function which causes a break. |
6282 const char* source = "function f() { debugger; }"; | 6291 const char* source = "function f() { debugger; }"; |
6283 | 6292 |
6284 // Enter and run function in the first context. | 6293 // Enter and run function in the first context. |
6285 { | 6294 { |
6286 v8::Context::Scope context_scope(context_1); | 6295 v8::Context::Scope context_scope(context_1); |
6287 expected_context = context_1; | 6296 expected_context = v8::Persistent<v8::Context>(*context_1); |
6288 expected_context_data = data_1; | 6297 expected_context_data = data_1; |
6289 v8::Local<v8::Function> f = CompileFunction(source, "f"); | 6298 v8::Local<v8::Function> f = CompileFunction(source, "f"); |
6290 f->Call(context_1->Global(), 0, NULL); | 6299 f->Call(context_1->Global(), 0, NULL); |
6291 } | 6300 } |
6292 | 6301 |
6293 | 6302 |
6294 // Enter and run function in the second context. | 6303 // Enter and run function in the second context. |
6295 { | 6304 { |
6296 v8::Context::Scope context_scope(context_2); | 6305 v8::Context::Scope context_scope(context_2); |
6297 expected_context = context_2; | 6306 expected_context = v8::Persistent<v8::Context>(*context_2); |
6298 expected_context_data = data_2; | 6307 expected_context_data = data_2; |
6299 v8::Local<v8::Function> f = CompileFunction(source, "f"); | 6308 v8::Local<v8::Function> f = CompileFunction(source, "f"); |
6300 f->Call(context_2->Global(), 0, NULL); | 6309 f->Call(context_2->Global(), 0, NULL); |
6301 } | 6310 } |
6302 | 6311 |
6303 // Two times compile event and two times break event. | 6312 // Two times compile event and two times break event. |
6304 CHECK_GT(message_handler_hit_count, 4); | 6313 CHECK_GT(message_handler_hit_count, 4); |
6305 | 6314 |
6306 v8::Debug::SetMessageHandler2(NULL); | 6315 v8::Debug::SetMessageHandler2(NULL); |
6307 CheckDebuggerUnloaded(); | 6316 CheckDebuggerUnloaded(); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6418 // cause Break events. | 6427 // cause Break events. |
6419 CHECK_EQ(1, break_point_hit_count); | 6428 CHECK_EQ(1, break_point_hit_count); |
6420 CHECK_EQ("f", last_function_hit); | 6429 CHECK_EQ("f", last_function_hit); |
6421 } | 6430 } |
6422 #endif // V8_INTERPRETED_REGEXP | 6431 #endif // V8_INTERPRETED_REGEXP |
6423 | 6432 |
6424 | 6433 |
6425 // Common part of EvalContextData and NestedBreakEventContextData tests. | 6434 // Common part of EvalContextData and NestedBreakEventContextData tests. |
6426 static void ExecuteScriptForContextCheck() { | 6435 static void ExecuteScriptForContextCheck() { |
6427 // Create a context. | 6436 // Create a context. |
6428 v8::Persistent<v8::Context> context_1; | 6437 v8::Handle<v8::Context> context_1; |
6429 v8::Handle<v8::ObjectTemplate> global_template = | 6438 v8::Handle<v8::ObjectTemplate> global_template = |
6430 v8::Handle<v8::ObjectTemplate>(); | 6439 v8::Handle<v8::ObjectTemplate>(); |
6431 context_1 = v8::Context::New(NULL, global_template); | 6440 context_1 = |
| 6441 v8::Context::New(v8::Isolate::GetCurrent(), NULL, global_template); |
6432 | 6442 |
6433 // Default data value is undefined. | 6443 // Default data value is undefined. |
6434 CHECK(context_1->GetEmbedderData(0)->IsUndefined()); | 6444 CHECK(context_1->GetEmbedderData(0)->IsUndefined()); |
6435 | 6445 |
6436 // Set and check a data value. | 6446 // Set and check a data value. |
6437 v8::Handle<v8::String> data_1 = v8::String::New("1"); | 6447 v8::Handle<v8::String> data_1 = v8::String::New("1"); |
6438 context_1->SetEmbedderData(0, data_1); | 6448 context_1->SetEmbedderData(0, data_1); |
6439 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1)); | 6449 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1)); |
6440 | 6450 |
6441 // Simple test function with eval that causes a break. | 6451 // Simple test function with eval that causes a break. |
6442 const char* source = "function f() { eval('debugger;'); }"; | 6452 const char* source = "function f() { eval('debugger;'); }"; |
6443 | 6453 |
6444 // Enter and run function in the context. | 6454 // Enter and run function in the context. |
6445 { | 6455 { |
6446 v8::Context::Scope context_scope(context_1); | 6456 v8::Context::Scope context_scope(context_1); |
6447 expected_context = context_1; | 6457 expected_context = v8::Persistent<v8::Context>(*context_1); |
6448 expected_context_data = data_1; | 6458 expected_context_data = data_1; |
6449 v8::Local<v8::Function> f = CompileFunction(source, "f"); | 6459 v8::Local<v8::Function> f = CompileFunction(source, "f"); |
6450 f->Call(context_1->Global(), 0, NULL); | 6460 f->Call(context_1->Global(), 0, NULL); |
6451 } | 6461 } |
6452 } | 6462 } |
6453 | 6463 |
6454 | 6464 |
6455 // 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 |
6456 // 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 |
6457 // 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 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7077 CHECK_EQ(expected_callback_data, details.GetCallbackData()); | 7087 CHECK_EQ(expected_callback_data, details.GetCallbackData()); |
7078 } | 7088 } |
7079 | 7089 |
7080 // Check that event details contain context where debug event occured. | 7090 // Check that event details contain context where debug event occured. |
7081 TEST(DebugEventContext) { | 7091 TEST(DebugEventContext) { |
7082 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 7092 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
7083 expected_callback_data = v8::Int32::New(2010); | 7093 expected_callback_data = v8::Int32::New(2010); |
7084 v8::Debug::SetDebugEventListener2(DebugEventContextChecker, | 7094 v8::Debug::SetDebugEventListener2(DebugEventContextChecker, |
7085 expected_callback_data); | 7095 expected_callback_data); |
7086 expected_context = v8::Context::New(); | 7096 expected_context = v8::Context::New(); |
7087 v8::Context::Scope context_scope(expected_context); | 7097 v8::Context::Scope context_scope( |
| 7098 v8::Isolate::GetCurrent(), expected_context); |
7088 v8::Script::Compile(v8::String::New("(function(){debugger;})();"))->Run(); | 7099 v8::Script::Compile(v8::String::New("(function(){debugger;})();"))->Run(); |
7089 expected_context.Dispose(expected_context->GetIsolate()); | 7100 expected_context.Dispose(expected_context->GetIsolate()); |
7090 expected_context.Clear(); | 7101 expected_context.Clear(); |
7091 v8::Debug::SetDebugEventListener(NULL); | 7102 v8::Debug::SetDebugEventListener(NULL); |
7092 expected_context_data = v8::Handle<v8::Value>(); | 7103 expected_context_data = v8::Handle<v8::Value>(); |
7093 CheckDebuggerUnloaded(); | 7104 CheckDebuggerUnloaded(); |
7094 } | 7105 } |
7095 | 7106 |
7096 | 7107 |
7097 static void* expected_break_data; | 7108 static void* expected_break_data; |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7540 TEST(LiveEditDisabled) { | 7551 TEST(LiveEditDisabled) { |
7541 v8::internal::FLAG_allow_natives_syntax = true; | 7552 v8::internal::FLAG_allow_natives_syntax = true; |
7542 LocalContext env; | 7553 LocalContext env; |
7543 v8::HandleScope scope(env->GetIsolate()); | 7554 v8::HandleScope scope(env->GetIsolate()); |
7544 v8::Debug::SetLiveEditEnabled(false); | 7555 v8::Debug::SetLiveEditEnabled(false); |
7545 CompileRun("%LiveEditCompareStrings('', '')"); | 7556 CompileRun("%LiveEditCompareStrings('', '')"); |
7546 } | 7557 } |
7547 | 7558 |
7548 | 7559 |
7549 #endif // ENABLE_DEBUGGER_SUPPORT | 7560 #endif // ENABLE_DEBUGGER_SUPPORT |
OLD | NEW |