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 14893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14904 " 'isConstructor'];\n" | 14904 " 'isConstructor'];\n" |
14905 "for (var i = 0; i < setters.length; i++) {\n" | 14905 "for (var i = 0; i < setters.length; i++) {\n" |
14906 " var prop = setters[i];\n" | 14906 " var prop = setters[i];\n" |
14907 " Object.prototype.__defineSetter__(prop, function() { throw prop; });\n" | 14907 " Object.prototype.__defineSetter__(prop, function() { throw prop; });\n" |
14908 "}\n"); | 14908 "}\n"); |
14909 CompileRun("throw 'exception';"); | 14909 CompileRun("throw 'exception';"); |
14910 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); | 14910 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); |
14911 } | 14911 } |
14912 | 14912 |
14913 | 14913 |
14914 static void StackTraceDisplayNameListener(v8::Handle<v8::Message> message, | |
14915 v8::Handle<Value>) { | |
14916 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); | |
14917 CHECK_EQ(4, stack_trace->GetFrameCount()); | |
14918 checkStackFrame("origin", "foo:0", 4, 7, false, false, | |
14919 stack_trace->GetFrame(0)); | |
14920 checkStackFrame("origin", "foo:1", 5, 27, false, false, | |
14921 stack_trace->GetFrame(1)); | |
14922 checkStackFrame("origin", "foo", 5, 27, false, false, | |
14923 stack_trace->GetFrame(2)); | |
14924 checkStackFrame("origin", "", 1, 14, false, false, stack_trace->GetFrame(3)); | |
14925 } | |
14926 | |
14927 | |
14928 TEST(GetStackTraceContainsFunctionsWithDisplayName) { | |
yurys
2015/03/05 14:12:56
...WithFunctionName
kozy
2015/03/05 15:01:09
Done.
| |
14929 LocalContext env; | |
14930 v8::HandleScope scope(env->GetIsolate()); | |
14931 | |
14932 CompileRunWithOrigin( | |
14933 "function gen(name, counter) {\n" | |
14934 " var f = function foo() {\n" | |
14935 " if (counter === 0)\n" | |
14936 " throw 1;\n" | |
14937 " gen(name, counter - 1)();\n" | |
14938 " };\n" | |
14939 " Object.defineProperty(f, 'name', {writable:true});\n" | |
14940 " if (counter == 2)\n" | |
14941 " f.name = 42;\n" | |
14942 " else\n" | |
14943 " f.name = name + ':' + counter;\n" | |
14944 " return f;\n" | |
14945 "};", | |
14946 "origin"); | |
14947 | |
14948 v8::V8::AddMessageListener(StackTraceDisplayNameListener); | |
yurys
2015/03/05 14:12:56
...DisplayName... -> ...FunctionName... here and b
kozy
2015/03/05 15:01:09
Done.
| |
14949 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); | |
14950 CompileRunWithOrigin("gen('foo', 2)();", "origin"); | |
14951 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); | |
14952 v8::V8::RemoveMessageListeners(StackTraceDisplayNameListener); | |
14953 } | |
14954 | |
14955 | |
14914 static void RethrowStackTraceHandler(v8::Handle<v8::Message> message, | 14956 static void RethrowStackTraceHandler(v8::Handle<v8::Message> message, |
14915 v8::Handle<v8::Value> data) { | 14957 v8::Handle<v8::Value> data) { |
14916 // Use the frame where JavaScript is called from. | 14958 // Use the frame where JavaScript is called from. |
14917 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); | 14959 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); |
14918 CHECK(!stack_trace.IsEmpty()); | 14960 CHECK(!stack_trace.IsEmpty()); |
14919 int frame_count = stack_trace->GetFrameCount(); | 14961 int frame_count = stack_trace->GetFrameCount(); |
14920 CHECK_EQ(3, frame_count); | 14962 CHECK_EQ(3, frame_count); |
14921 int line_number[] = {1, 2, 5}; | 14963 int line_number[] = {1, 2, 5}; |
14922 for (int i = 0; i < frame_count; i++) { | 14964 for (int i = 0; i < frame_count; i++) { |
14923 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber()); | 14965 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber()); |
(...skipping 6667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
21591 } | 21633 } |
21592 { | 21634 { |
21593 v8::TryCatch try_catch; | 21635 v8::TryCatch try_catch; |
21594 uint16_t* data = reinterpret_cast<uint16_t*>(buffer); | 21636 uint16_t* data = reinterpret_cast<uint16_t*>(buffer); |
21595 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString, | 21637 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString, |
21596 length).IsEmpty()); | 21638 length).IsEmpty()); |
21597 CHECK(try_catch.HasCaught()); | 21639 CHECK(try_catch.HasCaught()); |
21598 } | 21640 } |
21599 free(buffer); | 21641 free(buffer); |
21600 } | 21642 } |
OLD | NEW |