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 15207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15218 " 'isConstructor'];\n" | 15218 " 'isConstructor'];\n" |
15219 "for (var i = 0; i < setters.length; i++) {\n" | 15219 "for (var i = 0; i < setters.length; i++) {\n" |
15220 " var prop = setters[i];\n" | 15220 " var prop = setters[i];\n" |
15221 " Object.prototype.__defineSetter__(prop, function() { throw prop; });\n" | 15221 " Object.prototype.__defineSetter__(prop, function() { throw prop; });\n" |
15222 "}\n"); | 15222 "}\n"); |
15223 CompileRun("throw 'exception';"); | 15223 CompileRun("throw 'exception';"); |
15224 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); | 15224 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); |
15225 } | 15225 } |
15226 | 15226 |
15227 | 15227 |
| 15228 static void StackTraceDisplayNameListener( |
| 15229 v8::Handle<v8::Message> message, |
| 15230 v8::Handle<Value>) { |
| 15231 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); |
| 15232 CHECK_EQ(4, stack_trace->GetFrameCount()); |
| 15233 checkStackFrame("origin", "foo:0", 4, 7, false, false, |
| 15234 stack_trace->GetFrame(0)); |
| 15235 checkStackFrame("origin", "foo:1", 5, 27, false, false, |
| 15236 stack_trace->GetFrame(1)); |
| 15237 checkStackFrame("origin", "foo:2", 5, 27, false, false, |
| 15238 stack_trace->GetFrame(2)); |
| 15239 checkStackFrame("origin", "", 1, 14, false, false, |
| 15240 stack_trace->GetFrame(3)); |
| 15241 } |
| 15242 |
| 15243 |
| 15244 TEST(GetStackTraceContainsFunctionsWithDisplayName) { |
| 15245 LocalContext env; |
| 15246 v8::HandleScope scope(env->GetIsolate()); |
| 15247 |
| 15248 CompileRunWithOrigin( |
| 15249 "function gen(name, counter) {\n" |
| 15250 " var f = function() {\n" |
| 15251 " if (counter === 0)\n" |
| 15252 " throw 1;\n" |
| 15253 " gen(name, counter - 1)();\n" |
| 15254 " };\n" |
| 15255 " f.displayName = name + ':' + counter;\n" |
| 15256 " return f;\n" |
| 15257 "};", |
| 15258 "origin"); |
| 15259 |
| 15260 v8::V8::AddMessageListener(StackTraceDisplayNameListener); |
| 15261 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); |
| 15262 CompileRunWithOrigin("gen('foo', 2)();", "origin"); |
| 15263 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); |
| 15264 v8::V8::RemoveMessageListeners(StackTraceDisplayNameListener); |
| 15265 } |
| 15266 |
| 15267 |
15228 static void RethrowStackTraceHandler(v8::Handle<v8::Message> message, | 15268 static void RethrowStackTraceHandler(v8::Handle<v8::Message> message, |
15229 v8::Handle<v8::Value> data) { | 15269 v8::Handle<v8::Value> data) { |
15230 // Use the frame where JavaScript is called from. | 15270 // Use the frame where JavaScript is called from. |
15231 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); | 15271 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); |
15232 CHECK(!stack_trace.IsEmpty()); | 15272 CHECK(!stack_trace.IsEmpty()); |
15233 int frame_count = stack_trace->GetFrameCount(); | 15273 int frame_count = stack_trace->GetFrameCount(); |
15234 CHECK_EQ(3, frame_count); | 15274 CHECK_EQ(3, frame_count); |
15235 int line_number[] = {1, 2, 5}; | 15275 int line_number[] = {1, 2, 5}; |
15236 for (int i = 0; i < frame_count; i++) { | 15276 for (int i = 0; i < frame_count; i++) { |
15237 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber()); | 15277 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber()); |
(...skipping 6703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21941 } | 21981 } |
21942 { | 21982 { |
21943 v8::TryCatch try_catch; | 21983 v8::TryCatch try_catch; |
21944 uint16_t* data = reinterpret_cast<uint16_t*>(buffer); | 21984 uint16_t* data = reinterpret_cast<uint16_t*>(buffer); |
21945 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString, | 21985 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString, |
21946 length).IsEmpty()); | 21986 length).IsEmpty()); |
21947 CHECK(try_catch.HasCaught()); | 21987 CHECK(try_catch.HasCaught()); |
21948 } | 21988 } |
21949 free(buffer); | 21989 free(buffer); |
21950 } | 21990 } |
OLD | NEW |