Revision: 3753
Author: [email protected]
Date: Mon Feb 1 02:34:57 2010
Log: Show user script source line that caused exception intead of a line in
a native script. When an error is reported as one happened in a native
script it's hard to track the original cause. See chromium issue:
http://crbug.com/25305
Review URL: http://codereview.chromium.org/555170
http://code.google.com/p/v8/source/detail?r=3753
Modified:
/branches/bleeding_edge/src/frames.cc
/branches/bleeding_edge/src/frames.h
/branches/bleeding_edge/test/cctest/test-api.cc
=======================================
--- /branches/bleeding_edge/src/frames.cc Tue Jan 12 07:16:23 2010
+++ /branches/bleeding_edge/src/frames.cc Mon Feb 1 02:34:57 2010
@@ -176,7 +176,7 @@
StackTraceFrameIterator::StackTraceFrameIterator() {
- if (!done() && !frame()->function()->IsJSFunction()) Advance();
+ if (!done() && !IsValidFrame()) Advance();
}
@@ -184,9 +184,17 @@
while (true) {
JavaScriptFrameIterator::Advance();
if (done()) return;
- if (frame()->function()->IsJSFunction()) return;
+ if (IsValidFrame()) return;
}
}
+
+bool StackTraceFrameIterator::IsValidFrame() {
+ if (!frame()->function()->IsJSFunction()) return false;
+ Object* script =
JSFunction::cast(frame()->function())->shared()->script();
+ // Don't show functions from native scripts to user.
+ return (script->IsScript() &&
+ Script::TYPE_NATIVE != Script::cast(script)->type()->value());
+}
//
-------------------------------------------------------------------------
=======================================
--- /branches/bleeding_edge/src/frames.h Thu Jan 21 08:42:41 2010
+++ /branches/bleeding_edge/src/frames.h Mon Feb 1 02:34:57 2010
@@ -589,6 +589,9 @@
public:
StackTraceFrameIterator();
void Advance();
+
+ private:
+ bool IsValidFrame();
};
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc Fri Jan 29 10:01:46 2010
+++ /branches/bleeding_edge/test/cctest/test-api.cc Mon Feb 1 02:34:57 2010
@@ -3601,6 +3601,37 @@
CHECK_EQ(1, report_count);
v8::V8::RemoveMessageListeners(ApiUncaughtExceptionTestListener);
}
+
+static const char* script_resource_name = "ExceptionInNativeScript.js";
+static void ExceptionInNativeScriptTestListener(v8::Handle<v8::Message>
message,
+ v8::Handle<Value>) {
+ v8::Handle<v8::Value> name_val = message->GetScriptResourceName();
+ CHECK(!name_val.IsEmpty() && name_val->IsString());
+ v8::String::AsciiValue name(message->GetScriptResourceName());
+ CHECK_EQ(script_resource_name, *name);
+ CHECK_EQ(3, message->GetLineNumber());
+ v8::String::AsciiValue source_line(message->GetSourceLine());
+ CHECK_EQ(" new o.foo();", *source_line);
+}
+
+TEST(ExceptionInNativeScript) {
+ v8::HandleScope scope;
+ LocalContext env;
+ v8::V8::AddMessageListener(ExceptionInNativeScriptTestListener);
+
+ Local<v8::FunctionTemplate> fun =
v8::FunctionTemplate::New(TroubleCallback);
+ v8::Local<v8::Object> global = env->Global();
+ global->Set(v8_str("trouble"), fun->GetFunction());
+
+ Script::Compile(v8_str("function trouble() {\n"
+ " var o = {};\n"
+ " new o.foo();\n"
+ "};"),
v8::String::New(script_resource_name))->Run();
+ Local<Value> trouble = global->Get(v8_str("trouble"));
+ CHECK(trouble->IsFunction());
+ Function::Cast(*trouble)->Call(global, 0, NULL);
+ v8::V8::RemoveMessageListeners(ExceptionInNativeScriptTestListener);
+}
TEST(CompilationErrorUsingTryCatchHandler) {
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev