Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(391)

Side by Side Diff: test/cctest/test-api.cc

Issue 917743002: [V8] Use Function.name for stack frames in v8::StackTrace (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Added Function.name getter check Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/isolate.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 StackTraceFunctionNameListener(v8::Handle<v8::Message> message,
14915 v8::Handle<Value>) {
14916 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace();
14917 CHECK_EQ(5, 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", "foo", 5, 27, false, false,
14925 stack_trace->GetFrame(3));
14926 checkStackFrame("origin", "", 1, 14, false, false, stack_trace->GetFrame(4));
14927 }
14928
14929
14930 TEST(GetStackTraceContainsFunctionsWithFunctionName) {
14931 LocalContext env;
14932 v8::HandleScope scope(env->GetIsolate());
14933
14934 CompileRunWithOrigin(
14935 "function gen(name, counter) {\n"
14936 " var f = function foo() {\n"
14937 " if (counter === 0)\n"
14938 " throw 1;\n"
14939 " gen(name, counter - 1)();\n"
14940 " };\n"
14941 " if (counter == 3) {\n"
14942 " Object.defineProperty(f, 'name', {get: function(){ throw 239; }});\n"
14943 " } else {\n"
14944 " Object.defineProperty(f, 'name', {writable:true});\n"
14945 " if (counter == 2)\n"
14946 " f.name = 42;\n"
14947 " else\n"
14948 " f.name = name + ':' + counter;\n"
14949 " }\n"
14950 " return f;\n"
14951 "};",
14952 "origin");
14953
14954 v8::V8::AddMessageListener(StackTraceFunctionNameListener);
14955 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
14956 CompileRunWithOrigin("gen('foo', 3)();", "origin");
14957 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
14958 v8::V8::RemoveMessageListeners(StackTraceFunctionNameListener);
14959 }
14960
14961
14914 static void RethrowStackTraceHandler(v8::Handle<v8::Message> message, 14962 static void RethrowStackTraceHandler(v8::Handle<v8::Message> message,
14915 v8::Handle<v8::Value> data) { 14963 v8::Handle<v8::Value> data) {
14916 // Use the frame where JavaScript is called from. 14964 // Use the frame where JavaScript is called from.
14917 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); 14965 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace();
14918 CHECK(!stack_trace.IsEmpty()); 14966 CHECK(!stack_trace.IsEmpty());
14919 int frame_count = stack_trace->GetFrameCount(); 14967 int frame_count = stack_trace->GetFrameCount();
14920 CHECK_EQ(3, frame_count); 14968 CHECK_EQ(3, frame_count);
14921 int line_number[] = {1, 2, 5}; 14969 int line_number[] = {1, 2, 5};
14922 for (int i = 0; i < frame_count; i++) { 14970 for (int i = 0; i < frame_count; i++) {
14923 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber()); 14971 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber());
(...skipping 6667 matching lines...) Expand 10 before | Expand all | Expand 10 after
21591 } 21639 }
21592 { 21640 {
21593 v8::TryCatch try_catch; 21641 v8::TryCatch try_catch;
21594 uint16_t* data = reinterpret_cast<uint16_t*>(buffer); 21642 uint16_t* data = reinterpret_cast<uint16_t*>(buffer);
21595 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString, 21643 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString,
21596 length).IsEmpty()); 21644 length).IsEmpty());
21597 CHECK(try_catch.HasCaught()); 21645 CHECK(try_catch.HasCaught());
21598 } 21646 }
21599 free(buffer); 21647 free(buffer);
21600 } 21648 }
OLDNEW
« no previous file with comments | « src/isolate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698