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

Unified Diff: chrome/renderer/module_system.cc

Issue 10105013: ModuleSystem should not crash when JS has a syntax error. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: blah Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/module_system.cc
diff --git a/chrome/renderer/module_system.cc b/chrome/renderer/module_system.cc
index acca8ae9e24b45d8f7b7400b9bc95661cc8adb16..0389c3f1add6087dbf87e1a5c3067e1ac7f4dcf3 100644
--- a/chrome/renderer/module_system.cc
+++ b/chrome/renderer/module_system.cc
@@ -13,6 +13,14 @@ const char* kModuleSystem = "module_system";
const char* kModuleName = "module_name";
const char* kModuleField = "module_field";
+void DumpException(v8::Handle<v8::Message> message) {
+ LOG(ERROR) << "["
+ << *v8::String::Utf8Value(
+ message->GetScriptResourceName()->ToString())
+ << "(" << message->GetLineNumber() << ")] "
+ << *v8::String::Utf8Value(message->Get());
+}
+
} // namespace
ModuleSystem::ModuleSystem(SourceMap* source_map)
@@ -61,6 +69,7 @@ v8::Handle<v8::Value> ModuleSystem::RequireForJsInner(
v8::Handle<v8::Value> exports(modules->Get(module_name));
if (!exports->IsUndefined())
return handle_scope.Close(exports);
+
v8::Handle<v8::Value> source(GetSource(module_name));
if (source->IsUndefined())
return handle_scope.Close(v8::Undefined());
@@ -68,6 +77,9 @@ 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>());
+
exports = v8::Object::New();
v8::Handle<v8::Object> natives(NewInstance());
v8::Handle<v8::Value> args[] = {
@@ -112,6 +124,8 @@ v8::Handle<v8::Value> ModuleSystem::LazyFieldGetter(
module = module_system->RequireForJsInner(
parameters->Get(v8::String::New(kModuleName))->ToString())->ToObject();
}
+ if (module.IsEmpty())
+ return handle_scope.Close(v8::Handle<v8::Value>());
v8::Handle<v8::String> field =
parameters->Get(v8::String::New(kModuleField))->ToString();
@@ -141,7 +155,20 @@ v8::Handle<v8::Value> ModuleSystem::RunString(v8::Handle<v8::String> code,
v8::Handle<v8::String> name) {
v8::HandleScope handle_scope;
WebKit::WebScopedMicrotaskSuppression suppression;
- return handle_scope.Close(v8::Script::New(code, name)->Run());
+ 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());
+ return handle_scope.Close(result);
+ }
+
+ result = script->Run();
+ if (try_catch.HasCaught())
+ DumpException(try_catch.Message());
+
+ return handle_scope.Close(result);
}
v8::Handle<v8::Value> ModuleSystem::GetSource(
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698