Index: chrome/renderer/module_system.cc |
diff --git a/chrome/renderer/module_system.cc b/chrome/renderer/module_system.cc |
index 3205cd4917d3592d0cf8dbcb001cbc06be605532..27c234c2aff177b4a1c84edb2de10be3862f27df 100644 |
--- a/chrome/renderer/module_system.cc |
+++ b/chrome/renderer/module_system.cc |
@@ -60,12 +60,15 @@ bool ModuleSystem::IsPresentInCurrentContext() { |
} |
// static |
-void ModuleSystem::DumpException(v8::Handle<v8::Message> message) { |
+void ModuleSystem::DumpException(const v8::TryCatch& try_catch) { |
+ v8::Handle<v8::Message> message(try_catch.Message()); |
+ |
LOG(ERROR) << "[" |
<< *v8::String::Utf8Value( |
message->GetScriptResourceName()->ToString()) |
<< "(" << message->GetLineNumber() << ")] " |
- << *v8::String::Utf8Value(message->Get()); |
+ << *v8::String::Utf8Value(message->Get()) |
+ << "{" << *v8::String::Utf8Value(try_catch.StackTrace()) << "}"; |
} |
void ModuleSystem::Require(const std::string& module_name) { |
@@ -96,8 +99,10 @@ v8::Handle<v8::Value> ModuleSystem::RequireForJsInner( |
v8::Handle<v8::String>::Cast(source))); |
v8::Handle<v8::Function> func = |
v8::Handle<v8::Function>::Cast(RunString(wrapped_source, module_name)); |
- if (func.IsEmpty()) |
- return handle_scope.Close(v8::Handle<v8::Value>()); |
+ if (func.IsEmpty()) { |
+ return ThrowException(std::string(*v8::String::AsciiValue(module_name)) + |
+ ": Bad source"); |
+ } |
exports = v8::Object::New(); |
v8::Handle<v8::Object> natives(NewInstance()); |
@@ -108,7 +113,12 @@ v8::Handle<v8::Value> ModuleSystem::RequireForJsInner( |
}; |
{ |
WebKit::WebScopedMicrotaskSuppression suppression; |
+ v8::TryCatch try_catch; |
func->Call(global, 3, args); |
+ if (try_catch.HasCaught()) { |
+ DumpException(try_catch); |
+ return v8::Undefined(); |
+ } |
} |
modules->Set(module_name, exports); |
return handle_scope.Close(exports); |
@@ -184,16 +194,15 @@ v8::Handle<v8::Value> ModuleSystem::RunString(v8::Handle<v8::String> code, |
WebKit::WebScopedMicrotaskSuppression suppression; |
v8::Handle<v8::Value> result; |
v8::TryCatch try_catch; |
- try_catch.SetCaptureMessage(true); |
v8::Handle<v8::Script> script(v8::Script::New(code, name)); |
if (try_catch.HasCaught()) { |
- DumpException(try_catch.Message()); |
+ DumpException(try_catch); |
return handle_scope.Close(result); |
} |
result = script->Run(); |
if (try_catch.HasCaught()) |
- DumpException(try_catch.Message()); |
+ DumpException(try_catch); |
return handle_scope.Close(result); |
} |