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 14283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14294 // This is the source string inside the eval which has the call to baz. | 14294 // This is the source string inside the eval which has the call to baz. |
14295 checkStackFrame(NULL, "", 1, 1, is_eval, false, stackTrace->GetFrame(2)); | 14295 checkStackFrame(NULL, "", 1, 1, is_eval, false, stackTrace->GetFrame(2)); |
14296 // The last frame is an anonymous function which has the initial eval call. | 14296 // The last frame is an anonymous function which has the initial eval call. |
14297 checkStackFrame(origin, "", 10, 1, false, false, stackTrace->GetFrame(3)); | 14297 checkStackFrame(origin, "", 10, 1, false, false, stackTrace->GetFrame(3)); |
14298 | 14298 |
14299 CHECK(stackTrace->AsArray()->IsArray()); | 14299 CHECK(stackTrace->AsArray()->IsArray()); |
14300 } | 14300 } |
14301 } | 14301 } |
14302 | 14302 |
14303 | 14303 |
14304 void ChangeNewlines(int kind, char* dest, size_t dest_len, const char* source) { | |
14305 if (kind == 0) { | |
14306 for (size_t i = 0; i <= strlen(source); i++) { | |
14307 dest[i] = source[i]; | |
14308 } | |
14309 } else { | |
14310 for (size_t i = 0; i <= strlen(source); i++) { | |
14311 char c = source[i]; | |
14312 if (c == '\n') { | |
14313 if (kind == 1) { | |
14314 *dest++ = '\r'; | |
14315 *dest++ = '\n'; | |
14316 } else { | |
14317 // UTF-8 version of 0x2028 newline. | |
14318 *dest++ = '\xe2'; | |
14319 *dest++ = '\x80'; | |
14320 *dest++ = '\xa8'; | |
14321 } | |
14322 } else { | |
14323 *dest++ = c; | |
14324 } | |
14325 } | |
14326 } | |
14327 } | |
14328 | |
14329 | |
14330 // Tests the C++ StackTrace API. | 14304 // Tests the C++ StackTrace API. |
14331 // TODO(3074796): Reenable this as a THREADED_TEST once it passes. | 14305 // TODO(3074796): Reenable this as a THREADED_TEST once it passes. |
14332 // THREADED_TEST(CaptureStackTrace) { | 14306 // THREADED_TEST(CaptureStackTrace) { |
14333 TEST(CaptureStackTrace) { | 14307 TEST(CaptureStackTrace) { |
14334 v8::Isolate* isolate = CcTest::isolate(); | 14308 v8::Isolate* isolate = CcTest::isolate(); |
14335 v8::HandleScope scope(isolate); | 14309 v8::HandleScope scope(isolate); |
14336 v8::Handle<v8::String> origin = | 14310 v8::Handle<v8::String> origin = |
14337 v8::String::NewFromUtf8(isolate, "capture-stack-trace-test"); | 14311 v8::String::NewFromUtf8(isolate, "capture-stack-trace-test"); |
14338 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 14312 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
14339 templ->Set(v8_str("AnalyzeStackInNativeCode"), | 14313 templ->Set(v8_str("AnalyzeStackInNativeCode"), |
14340 v8::FunctionTemplate::New(isolate, AnalyzeStackInNativeCode)); | 14314 v8::FunctionTemplate::New(isolate, AnalyzeStackInNativeCode)); |
14341 LocalContext context(0, templ); | 14315 LocalContext context(0, templ); |
14342 | 14316 |
14343 for (int i = 0; i < 3; i++) { | 14317 // Test getting OVERVIEW information. Should ignore information that is not |
14344 // Test getting OVERVIEW information. Should ignore information that is not | 14318 // script name, function name, line number, and column offset. |
14345 // script name, function name, line number, and column offset. | 14319 const char *overview_source = |
14346 const char* overview_source = | 14320 "function bar() {\n" |
14347 "function bar() {\n" | 14321 " var y; AnalyzeStackInNativeCode(1);\n" |
14348 " var y; AnalyzeStackInNativeCode(1);\n" | 14322 "}\n" |
14349 "}\n" | 14323 "function foo() {\n" |
14350 "function foo() {\n" | 14324 "\n" |
14351 "\n" | 14325 " bar();\n" |
14352 " bar();\n" | 14326 "}\n" |
14353 "}\n" | 14327 "var x;eval('new foo();');"; |
14354 "var x;eval('new foo();');"; | 14328 v8::Handle<v8::String> overview_src = |
14355 size_t munged_length = strlen(overview_source) * 3 + 1; | 14329 v8::String::NewFromUtf8(isolate, overview_source); |
14356 char* overview_munged_source = new char[munged_length]; | 14330 v8::ScriptCompiler::Source script_source(overview_src, |
14357 ChangeNewlines(i, overview_munged_source, munged_length, overview_source); | 14331 v8::ScriptOrigin(origin)); |
| 14332 v8::Handle<Value> overview_result( |
| 14333 v8::ScriptCompiler::CompileUnbound(isolate, &script_source) |
| 14334 ->BindToCurrentContext() |
| 14335 ->Run()); |
| 14336 CHECK(!overview_result.IsEmpty()); |
| 14337 CHECK(overview_result->IsObject()); |
14358 | 14338 |
14359 v8::Handle<v8::String> overview_src = | 14339 // Test getting DETAILED information. |
14360 v8::String::NewFromUtf8(isolate, overview_munged_source); | 14340 const char *detailed_source = |
14361 delete[] overview_munged_source; | 14341 "function bat() {AnalyzeStackInNativeCode(2);\n" |
14362 v8::ScriptCompiler::Source script_source(overview_src, | 14342 "}\n" |
14363 v8::ScriptOrigin(origin)); | 14343 "\n" |
14364 v8::Handle<Value> overview_result( | 14344 "function baz() {\n" |
14365 v8::ScriptCompiler::CompileUnbound(isolate, &script_source) | 14345 " bat();\n" |
14366 ->BindToCurrentContext() | 14346 "}\n" |
14367 ->Run()); | 14347 "eval('new baz();');"; |
14368 CHECK(!overview_result.IsEmpty()); | 14348 v8::Handle<v8::String> detailed_src = |
14369 CHECK(overview_result->IsObject()); | 14349 v8::String::NewFromUtf8(isolate, detailed_source); |
14370 | 14350 // Make the script using a non-zero line and column offset. |
14371 // Test getting DETAILED information. | 14351 v8::Handle<v8::Integer> line_offset = v8::Integer::New(isolate, 3); |
14372 const char* detailed_source = | 14352 v8::Handle<v8::Integer> column_offset = v8::Integer::New(isolate, 5); |
14373 "function bat() {AnalyzeStackInNativeCode(2);\n" | 14353 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset); |
14374 "}\n" | 14354 v8::ScriptCompiler::Source script_source2(detailed_src, detailed_origin); |
14375 "\n" | 14355 v8::Handle<v8::UnboundScript> detailed_script( |
14376 "function baz() {\n" | 14356 v8::ScriptCompiler::CompileUnbound(isolate, &script_source2)); |
14377 " bat();\n" | 14357 v8::Handle<Value> detailed_result( |
14378 "}\n" | 14358 detailed_script->BindToCurrentContext()->Run()); |
14379 "eval('new baz();');"; | 14359 CHECK(!detailed_result.IsEmpty()); |
14380 munged_length = strlen(detailed_source) * 3 + 1; | 14360 CHECK(detailed_result->IsObject()); |
14381 char* detailed_munged_source = new char[munged_length]; | |
14382 ChangeNewlines(i, detailed_munged_source, munged_length, detailed_source); | |
14383 v8::Handle<v8::String> detailed_src = | |
14384 v8::String::NewFromUtf8(isolate, detailed_munged_source); | |
14385 delete[] detailed_munged_source; | |
14386 // Make the script using a non-zero line and column offset. | |
14387 v8::Handle<v8::Integer> line_offset = v8::Integer::New(isolate, 3); | |
14388 v8::Handle<v8::Integer> column_offset = v8::Integer::New(isolate, 5); | |
14389 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset); | |
14390 v8::ScriptCompiler::Source script_source2(detailed_src, detailed_origin); | |
14391 v8::Handle<v8::UnboundScript> detailed_script( | |
14392 v8::ScriptCompiler::CompileUnbound(isolate, &script_source2)); | |
14393 v8::Handle<Value> detailed_result( | |
14394 detailed_script->BindToCurrentContext()->Run()); | |
14395 CHECK(!detailed_result.IsEmpty()); | |
14396 CHECK(detailed_result->IsObject()); | |
14397 } | |
14398 } | 14361 } |
14399 | 14362 |
14400 | 14363 |
14401 static void StackTraceForUncaughtExceptionListener( | 14364 static void StackTraceForUncaughtExceptionListener( |
14402 v8::Handle<v8::Message> message, | 14365 v8::Handle<v8::Message> message, |
14403 v8::Handle<Value>) { | 14366 v8::Handle<Value>) { |
14404 report_count++; | 14367 report_count++; |
14405 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); | 14368 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); |
14406 CHECK_EQ(2, stack_trace->GetFrameCount()); | 14369 CHECK_EQ(2, stack_trace->GetFrameCount()); |
14407 checkStackFrame("origin", "foo", 2, 3, false, false, | 14370 checkStackFrame("origin", "foo", 2, 3, false, false, |
(...skipping 7046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21454 CHECK_EQ(2U, set->Size()); | 21417 CHECK_EQ(2U, set->Size()); |
21455 | 21418 |
21456 v8::Local<v8::Array> keys = set->AsArray(); | 21419 v8::Local<v8::Array> keys = set->AsArray(); |
21457 CHECK_EQ(2U, keys->Length()); | 21420 CHECK_EQ(2U, keys->Length()); |
21458 CHECK_EQ(1, keys->Get(0).As<v8::Int32>()->Value()); | 21421 CHECK_EQ(1, keys->Get(0).As<v8::Int32>()->Value()); |
21459 CHECK_EQ(2, keys->Get(1).As<v8::Int32>()->Value()); | 21422 CHECK_EQ(2, keys->Get(1).As<v8::Int32>()->Value()); |
21460 | 21423 |
21461 set = v8::Set::FromArray(env.local(), keys).ToLocalChecked(); | 21424 set = v8::Set::FromArray(env.local(), keys).ToLocalChecked(); |
21462 CHECK_EQ(2U, set->Size()); | 21425 CHECK_EQ(2U, set->Size()); |
21463 } | 21426 } |
OLD | NEW |