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 5095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5137 "\n" | 5141 "\n" |
5138 "foo();\n"; | 5142 "foo();\n"; |
5139 | 5143 |
5140 v8::V8::Initialize(); | 5144 v8::V8::Initialize(); |
5141 DebugLocalContext env; | 5145 DebugLocalContext env; |
5142 v8::HandleScope scope(env->GetIsolate()); | 5146 v8::HandleScope scope(env->GetIsolate()); |
5143 v8::Debug::SetMessageHandler2(&ThreadedMessageHandler); | 5147 v8::Debug::SetMessageHandler2(&ThreadedMessageHandler); |
5144 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 5148 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
5145 global_template->Set(v8::String::New("ThreadedAtBarrier1"), | 5149 global_template->Set(v8::String::New("ThreadedAtBarrier1"), |
5146 v8::FunctionTemplate::New(ThreadedAtBarrier1)); | 5150 v8::FunctionTemplate::New(ThreadedAtBarrier1)); |
5147 v8::Handle<v8::Context> context = v8::Context::New(NULL, global_template); | 5151 v8::Handle<v8::Context> context = v8::Context::New(v8::Isolate::GetCurrent(), |
| 5152 NULL, |
| 5153 global_template); |
5148 v8::Context::Scope context_scope(context); | 5154 v8::Context::Scope context_scope(context); |
5149 | 5155 |
5150 CompileRun(source); | 5156 CompileRun(source); |
5151 } | 5157 } |
5152 | 5158 |
5153 void DebuggerThread::Run() { | 5159 void DebuggerThread::Run() { |
5154 const int kBufSize = 1000; | 5160 const int kBufSize = 1000; |
5155 uint16_t buffer[kBufSize]; | 5161 uint16_t buffer[kBufSize]; |
5156 | 5162 |
5157 const char* command_1 = "{\"seq\":102," | 5163 const char* command_1 = "{\"seq\":102," |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5513 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 5519 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
5514 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 5520 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
5515 global_template->Set(v8::String::New("CheckFrameCount"), | 5521 global_template->Set(v8::String::New("CheckFrameCount"), |
5516 v8::FunctionTemplate::New(CheckFrameCount)); | 5522 v8::FunctionTemplate::New(CheckFrameCount)); |
5517 global_template->Set(v8::String::New("CheckSourceLine"), | 5523 global_template->Set(v8::String::New("CheckSourceLine"), |
5518 v8::FunctionTemplate::New(CheckSourceLine)); | 5524 v8::FunctionTemplate::New(CheckSourceLine)); |
5519 global_template->Set(v8::String::New("CheckDataParameter"), | 5525 global_template->Set(v8::String::New("CheckDataParameter"), |
5520 v8::FunctionTemplate::New(CheckDataParameter)); | 5526 v8::FunctionTemplate::New(CheckDataParameter)); |
5521 global_template->Set(v8::String::New("CheckClosure"), | 5527 global_template->Set(v8::String::New("CheckClosure"), |
5522 v8::FunctionTemplate::New(CheckClosure)); | 5528 v8::FunctionTemplate::New(CheckClosure)); |
5523 v8::Handle<v8::Context> context = v8::Context::New(NULL, global_template); | 5529 v8::Handle<v8::Context> context = v8::Context::New(v8::Isolate::GetCurrent(), |
| 5530 NULL, |
| 5531 global_template); |
5524 v8::Context::Scope context_scope(context); | 5532 v8::Context::Scope context_scope(context); |
5525 | 5533 |
5526 // Compile a function for checking the number of JavaScript frames. | 5534 // Compile a function for checking the number of JavaScript frames. |
5527 v8::Script::Compile(v8::String::New(frame_count_source))->Run(); | 5535 v8::Script::Compile(v8::String::New(frame_count_source))->Run(); |
5528 frame_count = v8::Local<v8::Function>::Cast( | 5536 frame_count = v8::Local<v8::Function>::Cast( |
5529 context->Global()->Get(v8::String::New("frame_count"))); | 5537 context->Global()->Get(v8::String::New("frame_count"))); |
5530 | 5538 |
5531 // Compile a function for returning the source line for the top frame. | 5539 // Compile a function for returning the source line for the top frame. |
5532 v8::Script::Compile(v8::String::New(frame_source_line_source))->Run(); | 5540 v8::Script::Compile(v8::String::New(frame_source_line_source))->Run(); |
5533 frame_source_line = v8::Local<v8::Function>::Cast( | 5541 frame_source_line = v8::Local<v8::Function>::Cast( |
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6237 if (IsBreakEventMessage(print_buffer)) { | 6245 if (IsBreakEventMessage(print_buffer)) { |
6238 SendContinueCommand(); | 6246 SendContinueCommand(); |
6239 } | 6247 } |
6240 } | 6248 } |
6241 | 6249 |
6242 | 6250 |
6243 // Test which creates two contexts and sets different embedder data on each. | 6251 // Test which creates two contexts and sets different embedder data on each. |
6244 // Checks that this data is set correctly and that when the debug message | 6252 // Checks that this data is set correctly and that when the debug message |
6245 // handler is called the expected context is the one active. | 6253 // handler is called the expected context is the one active. |
6246 TEST(ContextData) { | 6254 TEST(ContextData) { |
6247 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 6255 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 6256 v8::HandleScope scope(isolate); |
6248 | 6257 |
6249 v8::Debug::SetMessageHandler2(ContextCheckMessageHandler); | 6258 v8::Debug::SetMessageHandler2(ContextCheckMessageHandler); |
6250 | 6259 |
6251 // Create two contexts. | 6260 // Create two contexts. |
6252 v8::Persistent<v8::Context> context_1; | 6261 v8::Handle<v8::Context> context_1; |
6253 v8::Persistent<v8::Context> context_2; | 6262 v8::Handle<v8::Context> context_2; |
6254 v8::Handle<v8::ObjectTemplate> global_template = | 6263 v8::Handle<v8::ObjectTemplate> global_template = |
6255 v8::Handle<v8::ObjectTemplate>(); | 6264 v8::Handle<v8::ObjectTemplate>(); |
6256 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>(); | 6265 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>(); |
6257 context_1 = v8::Context::New(NULL, global_template, global_object); | 6266 context_1 = v8::Context::New(isolate, NULL, global_template, global_object); |
6258 context_2 = v8::Context::New(NULL, global_template, global_object); | 6267 context_2 = v8::Context::New(isolate, NULL, global_template, global_object); |
6259 | 6268 |
6260 // Default data value is undefined. | 6269 // Default data value is undefined. |
6261 CHECK(context_1->GetEmbedderData(0)->IsUndefined()); | 6270 CHECK(context_1->GetEmbedderData(0)->IsUndefined()); |
6262 CHECK(context_2->GetEmbedderData(0)->IsUndefined()); | 6271 CHECK(context_2->GetEmbedderData(0)->IsUndefined()); |
6263 | 6272 |
6264 // Set and check different data values. | 6273 // Set and check different data values. |
6265 v8::Handle<v8::String> data_1 = v8::String::New("1"); | 6274 v8::Handle<v8::String> data_1 = v8::String::New("1"); |
6266 v8::Handle<v8::String> data_2 = v8::String::New("2"); | 6275 v8::Handle<v8::String> data_2 = v8::String::New("2"); |
6267 context_1->SetEmbedderData(0, data_1); | 6276 context_1->SetEmbedderData(0, data_1); |
6268 context_2->SetEmbedderData(0, data_2); | 6277 context_2->SetEmbedderData(0, data_2); |
6269 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1)); | 6278 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1)); |
6270 CHECK(context_2->GetEmbedderData(0)->StrictEquals(data_2)); | 6279 CHECK(context_2->GetEmbedderData(0)->StrictEquals(data_2)); |
6271 | 6280 |
6272 // Simple test function which causes a break. | 6281 // Simple test function which causes a break. |
6273 const char* source = "function f() { debugger; }"; | 6282 const char* source = "function f() { debugger; }"; |
6274 | 6283 |
6275 // Enter and run function in the first context. | 6284 // Enter and run function in the first context. |
6276 { | 6285 { |
6277 v8::Context::Scope context_scope(context_1); | 6286 v8::Context::Scope context_scope(context_1); |
6278 expected_context = context_1; | 6287 expected_context = v8::Persistent<v8::Context>(*context_1); |
6279 expected_context_data = data_1; | 6288 expected_context_data = data_1; |
6280 v8::Local<v8::Function> f = CompileFunction(source, "f"); | 6289 v8::Local<v8::Function> f = CompileFunction(source, "f"); |
6281 f->Call(context_1->Global(), 0, NULL); | 6290 f->Call(context_1->Global(), 0, NULL); |
6282 } | 6291 } |
6283 | 6292 |
6284 | 6293 |
6285 // Enter and run function in the second context. | 6294 // Enter and run function in the second context. |
6286 { | 6295 { |
6287 v8::Context::Scope context_scope(context_2); | 6296 v8::Context::Scope context_scope(context_2); |
6288 expected_context = context_2; | 6297 expected_context = v8::Persistent<v8::Context>(*context_2); |
6289 expected_context_data = data_2; | 6298 expected_context_data = data_2; |
6290 v8::Local<v8::Function> f = CompileFunction(source, "f"); | 6299 v8::Local<v8::Function> f = CompileFunction(source, "f"); |
6291 f->Call(context_2->Global(), 0, NULL); | 6300 f->Call(context_2->Global(), 0, NULL); |
6292 } | 6301 } |
6293 | 6302 |
6294 // Two times compile event and two times break event. | 6303 // Two times compile event and two times break event. |
6295 CHECK_GT(message_handler_hit_count, 4); | 6304 CHECK_GT(message_handler_hit_count, 4); |
6296 | 6305 |
6297 v8::Debug::SetMessageHandler2(NULL); | 6306 v8::Debug::SetMessageHandler2(NULL); |
6298 CheckDebuggerUnloaded(); | 6307 CheckDebuggerUnloaded(); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6409 // cause Break events. | 6418 // cause Break events. |
6410 CHECK_EQ(1, break_point_hit_count); | 6419 CHECK_EQ(1, break_point_hit_count); |
6411 CHECK_EQ("f", last_function_hit); | 6420 CHECK_EQ("f", last_function_hit); |
6412 } | 6421 } |
6413 #endif // V8_INTERPRETED_REGEXP | 6422 #endif // V8_INTERPRETED_REGEXP |
6414 | 6423 |
6415 | 6424 |
6416 // Common part of EvalContextData and NestedBreakEventContextData tests. | 6425 // Common part of EvalContextData and NestedBreakEventContextData tests. |
6417 static void ExecuteScriptForContextCheck() { | 6426 static void ExecuteScriptForContextCheck() { |
6418 // Create a context. | 6427 // Create a context. |
6419 v8::Persistent<v8::Context> context_1; | 6428 v8::Handle<v8::Context> context_1; |
6420 v8::Handle<v8::ObjectTemplate> global_template = | 6429 v8::Handle<v8::ObjectTemplate> global_template = |
6421 v8::Handle<v8::ObjectTemplate>(); | 6430 v8::Handle<v8::ObjectTemplate>(); |
6422 context_1 = v8::Context::New(NULL, global_template); | 6431 context_1 = |
| 6432 v8::Context::New(v8::Isolate::GetCurrent(), NULL, global_template); |
6423 | 6433 |
6424 // Default data value is undefined. | 6434 // Default data value is undefined. |
6425 CHECK(context_1->GetEmbedderData(0)->IsUndefined()); | 6435 CHECK(context_1->GetEmbedderData(0)->IsUndefined()); |
6426 | 6436 |
6427 // Set and check a data value. | 6437 // Set and check a data value. |
6428 v8::Handle<v8::String> data_1 = v8::String::New("1"); | 6438 v8::Handle<v8::String> data_1 = v8::String::New("1"); |
6429 context_1->SetEmbedderData(0, data_1); | 6439 context_1->SetEmbedderData(0, data_1); |
6430 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1)); | 6440 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1)); |
6431 | 6441 |
6432 // Simple test function with eval that causes a break. | 6442 // Simple test function with eval that causes a break. |
6433 const char* source = "function f() { eval('debugger;'); }"; | 6443 const char* source = "function f() { eval('debugger;'); }"; |
6434 | 6444 |
6435 // Enter and run function in the context. | 6445 // Enter and run function in the context. |
6436 { | 6446 { |
6437 v8::Context::Scope context_scope(context_1); | 6447 v8::Context::Scope context_scope(context_1); |
6438 expected_context = context_1; | 6448 expected_context = v8::Persistent<v8::Context>(*context_1); |
6439 expected_context_data = data_1; | 6449 expected_context_data = data_1; |
6440 v8::Local<v8::Function> f = CompileFunction(source, "f"); | 6450 v8::Local<v8::Function> f = CompileFunction(source, "f"); |
6441 f->Call(context_1->Global(), 0, NULL); | 6451 f->Call(context_1->Global(), 0, NULL); |
6442 } | 6452 } |
6443 } | 6453 } |
6444 | 6454 |
6445 | 6455 |
6446 // Test which creates a context and sets embedder data on it. Checks that this | 6456 // Test which creates a context and sets embedder data on it. Checks that this |
6447 // data is set correctly and that when the debug message handler is called for | 6457 // data is set correctly and that when the debug message handler is called for |
6448 // break event in an eval statement the expected context is the one returned by | 6458 // 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... |
7068 CHECK_EQ(expected_callback_data, details.GetCallbackData()); | 7078 CHECK_EQ(expected_callback_data, details.GetCallbackData()); |
7069 } | 7079 } |
7070 | 7080 |
7071 // Check that event details contain context where debug event occured. | 7081 // Check that event details contain context where debug event occured. |
7072 TEST(DebugEventContext) { | 7082 TEST(DebugEventContext) { |
7073 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 7083 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
7074 expected_callback_data = v8::Int32::New(2010); | 7084 expected_callback_data = v8::Int32::New(2010); |
7075 v8::Debug::SetDebugEventListener2(DebugEventContextChecker, | 7085 v8::Debug::SetDebugEventListener2(DebugEventContextChecker, |
7076 expected_callback_data); | 7086 expected_callback_data); |
7077 expected_context = v8::Context::New(); | 7087 expected_context = v8::Context::New(); |
7078 v8::Context::Scope context_scope(expected_context); | 7088 v8::Context::Scope context_scope( |
| 7089 v8::Isolate::GetCurrent(), expected_context); |
7079 v8::Script::Compile(v8::String::New("(function(){debugger;})();"))->Run(); | 7090 v8::Script::Compile(v8::String::New("(function(){debugger;})();"))->Run(); |
7080 expected_context.Dispose(expected_context->GetIsolate()); | 7091 expected_context.Dispose(expected_context->GetIsolate()); |
7081 expected_context.Clear(); | 7092 expected_context.Clear(); |
7082 v8::Debug::SetDebugEventListener(NULL); | 7093 v8::Debug::SetDebugEventListener(NULL); |
7083 expected_context_data = v8::Handle<v8::Value>(); | 7094 expected_context_data = v8::Handle<v8::Value>(); |
7084 CheckDebuggerUnloaded(); | 7095 CheckDebuggerUnloaded(); |
7085 } | 7096 } |
7086 | 7097 |
7087 | 7098 |
7088 static void* expected_break_data; | 7099 static void* expected_break_data; |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7531 TEST(LiveEditDisabled) { | 7542 TEST(LiveEditDisabled) { |
7532 v8::internal::FLAG_allow_natives_syntax = true; | 7543 v8::internal::FLAG_allow_natives_syntax = true; |
7533 LocalContext env; | 7544 LocalContext env; |
7534 v8::HandleScope scope(env->GetIsolate()); | 7545 v8::HandleScope scope(env->GetIsolate()); |
7535 v8::Debug::SetLiveEditEnabled(false); | 7546 v8::Debug::SetLiveEditEnabled(false); |
7536 CompileRun("%LiveEditCompareStrings('', '')"); | 7547 CompileRun("%LiveEditCompareStrings('', '')"); |
7537 } | 7548 } |
7538 | 7549 |
7539 | 7550 |
7540 #endif // ENABLE_DEBUGGER_SUPPORT | 7551 #endif // ENABLE_DEBUGGER_SUPPORT |
OLD | NEW |