Commit efbb06bc authored by haraken@chromium.org's avatar haraken@chromium.org

JS errors thrown in private scripts should be reported to stderr in Debug builds

In order to debug private scripts, JS errors thrown in the private scripts
(e.g., ReferenceError thrown when we make a typo in private scripts)
need to be reported to stderr. This CL makes the change.

The fprintf(stderr, ...) is enabled only in Debug builds.

This CL also renames throwDOMExceptionInPrivateScriptIfNeeded to rethrowExceptionInPrivateScript.

BUG=341031

Review URL: https://codereview.chromium.org/460573002

git-svn-id: svn://svn.chromium.org/blink/trunk@180033 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 6f506392
...@@ -205,8 +205,19 @@ v8::Handle<v8::Value> PrivateScriptRunner::runDOMMethod(ScriptState* scriptState ...@@ -205,8 +205,19 @@ v8::Handle<v8::Value> PrivateScriptRunner::runDOMMethod(ScriptState* scriptState
return V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(method), scriptState->executionContext(), holder, argc, argv, scriptState->isolate()); return V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(method), scriptState->executionContext(), holder, argc, argv, scriptState->isolate());
} }
bool PrivateScriptRunner::throwDOMExceptionInPrivateScriptIfNeeded(v8::Isolate* isolate, ExceptionState& exceptionState, v8::Handle<v8::Value> exception) static void dumpJSError(String exceptionName, String message)
{ {
// FIXME: Set a ScriptOrigin of the private script and print a more informative message.
#ifndef NDEBUG
fprintf(stderr, "Private script throws an exception: %s\n", exceptionName.utf8().data());
if (!message.isEmpty())
fprintf(stderr, "%s\n", message.utf8().data());
#endif
}
bool PrivateScriptRunner::rethrowExceptionInPrivateScript(v8::Isolate* isolate, ExceptionState& exceptionState, v8::TryCatch& block)
{
v8::Handle<v8::Value> exception = block.Exception();
if (exception.IsEmpty() || !exception->IsObject()) if (exception.IsEmpty() || !exception->IsObject())
return false; return false;
...@@ -216,47 +227,57 @@ bool PrivateScriptRunner::throwDOMExceptionInPrivateScriptIfNeeded(v8::Isolate* ...@@ -216,47 +227,57 @@ bool PrivateScriptRunner::throwDOMExceptionInPrivateScriptIfNeeded(v8::Isolate*
return false; return false;
String exceptionName = toCoreString(v8::Handle<v8::String>::Cast(name)); String exceptionName = toCoreString(v8::Handle<v8::String>::Cast(name));
if (exceptionName == "DOMExceptionInPrivateScript") { if (exceptionName == "DOMExceptionInPrivateScript") {
v8::Handle<v8::Value> message = exceptionObject->Get(v8String(isolate, "message")); v8::Handle<v8::Value> v8Message = exceptionObject->Get(v8String(isolate, "message"));
RELEASE_ASSERT(!message.IsEmpty() && message->IsString()); RELEASE_ASSERT(!v8Message.IsEmpty() && v8Message->IsString());
v8::Handle<v8::Value> code = exceptionObject->Get(v8String(isolate, "code")); v8::Handle<v8::Value> code = exceptionObject->Get(v8String(isolate, "code"));
RELEASE_ASSERT(!code.IsEmpty() && code->IsInt32()); RELEASE_ASSERT(!code.IsEmpty() && code->IsInt32());
exceptionState.throwDOMException(toInt32(code), toCoreString(v8::Handle<v8::String>::Cast(message))); exceptionState.throwDOMException(toInt32(code), toCoreString(v8::Handle<v8::String>::Cast(v8Message)));
exceptionState.throwIfNeeded(); exceptionState.throwIfNeeded();
return true; return true;
} }
if (exceptionName == "Error") { if (exceptionName == "Error") {
v8::Handle<v8::Value> message = exceptionObject->Get(v8String(isolate, "message")); v8::Handle<v8::Value> v8Message = exceptionObject->Get(v8String(isolate, "message"));
RELEASE_ASSERT(!message.IsEmpty() && message->IsString()); RELEASE_ASSERT(!v8Message.IsEmpty() && v8Message->IsString());
exceptionState.throwDOMException(V8GeneralError, toCoreString(v8::Handle<v8::String>::Cast(message))); String message = toCoreString(v8::Handle<v8::String>::Cast(v8Message));
exceptionState.throwDOMException(V8GeneralError, message);
exceptionState.throwIfNeeded(); exceptionState.throwIfNeeded();
dumpJSError(exceptionName, message);
return true; return true;
} }
if (exceptionName == "TypeError") { if (exceptionName == "TypeError") {
v8::Handle<v8::Value> message = exceptionObject->Get(v8String(isolate, "message")); v8::Handle<v8::Value> v8Message = exceptionObject->Get(v8String(isolate, "message"));
RELEASE_ASSERT(!message.IsEmpty() && message->IsString()); RELEASE_ASSERT(!v8Message.IsEmpty() && v8Message->IsString());
exceptionState.throwDOMException(V8TypeError, toCoreString(v8::Handle<v8::String>::Cast(message))); String message = toCoreString(v8::Handle<v8::String>::Cast(v8Message));
exceptionState.throwDOMException(V8TypeError, message);
exceptionState.throwIfNeeded(); exceptionState.throwIfNeeded();
dumpJSError(exceptionName, message);
return true; return true;
} }
if (exceptionName == "RangeError") { if (exceptionName == "RangeError") {
v8::Handle<v8::Value> message = exceptionObject->Get(v8String(isolate, "message")); v8::Handle<v8::Value> v8Message = exceptionObject->Get(v8String(isolate, "message"));
RELEASE_ASSERT(!message.IsEmpty() && message->IsString()); RELEASE_ASSERT(!v8Message.IsEmpty() && v8Message->IsString());
exceptionState.throwDOMException(V8RangeError, toCoreString(v8::Handle<v8::String>::Cast(message))); String message = toCoreString(v8::Handle<v8::String>::Cast(v8Message));
exceptionState.throwDOMException(V8RangeError, message);
exceptionState.throwIfNeeded(); exceptionState.throwIfNeeded();
dumpJSError(exceptionName, message);
return true; return true;
} }
if (exceptionName == "SyntaxError") { if (exceptionName == "SyntaxError") {
v8::Handle<v8::Value> message = exceptionObject->Get(v8String(isolate, "message")); v8::Handle<v8::Value> v8Message = exceptionObject->Get(v8String(isolate, "message"));
RELEASE_ASSERT(!message.IsEmpty() && message->IsString()); RELEASE_ASSERT(!v8Message.IsEmpty() && v8Message->IsString());
exceptionState.throwDOMException(V8SyntaxError, toCoreString(v8::Handle<v8::String>::Cast(message))); String message = toCoreString(v8::Handle<v8::String>::Cast(v8Message));
exceptionState.throwDOMException(V8SyntaxError, message);
exceptionState.throwIfNeeded(); exceptionState.throwIfNeeded();
dumpJSError(exceptionName, message);
return true; return true;
} }
if (exceptionName == "ReferenceError") { if (exceptionName == "ReferenceError") {
v8::Handle<v8::Value> message = exceptionObject->Get(v8String(isolate, "message")); v8::Handle<v8::Value> v8Message = exceptionObject->Get(v8String(isolate, "message"));
RELEASE_ASSERT(!message.IsEmpty() && message->IsString()); RELEASE_ASSERT(!v8Message.IsEmpty() && v8Message->IsString());
exceptionState.throwDOMException(V8ReferenceError, toCoreString(v8::Handle<v8::String>::Cast(message))); String message = toCoreString(v8::Handle<v8::String>::Cast(v8Message));
exceptionState.throwDOMException(V8ReferenceError, message);
exceptionState.throwIfNeeded(); exceptionState.throwIfNeeded();
dumpJSError(exceptionName, message);
return true; return true;
} }
return false; return false;
......
...@@ -21,7 +21,7 @@ public: ...@@ -21,7 +21,7 @@ public:
static void runDOMAttributeSetter(ScriptState*, String className, String attributeName, v8::Handle<v8::Value> holder, v8::Handle<v8::Value> v8Value); static void runDOMAttributeSetter(ScriptState*, String className, String attributeName, v8::Handle<v8::Value> holder, v8::Handle<v8::Value> v8Value);
static v8::Handle<v8::Value> runDOMMethod(ScriptState*, String className, String methodName, v8::Handle<v8::Value> holder, int argc, v8::Handle<v8::Value> argv[]); static v8::Handle<v8::Value> runDOMMethod(ScriptState*, String className, String methodName, v8::Handle<v8::Value> holder, int argc, v8::Handle<v8::Value> argv[]);
static bool throwDOMExceptionInPrivateScriptIfNeeded(v8::Isolate*, ExceptionState&, v8::Handle<v8::Value>); static bool rethrowExceptionInPrivateScript(v8::Isolate*, ExceptionState&, v8::TryCatch&);
}; };
} // namespace blink } // namespace blink
......
...@@ -361,7 +361,7 @@ bool {{v8_class}}::PrivateScript::{{attribute.name}}AttributeGetter(LocalFrame* ...@@ -361,7 +361,7 @@ bool {{v8_class}}::PrivateScript::{{attribute.name}}AttributeGetter(LocalFrame*
v8::TryCatch block; v8::TryCatch block;
v8::Handle<v8::Value> v8Value = PrivateScriptRunner::runDOMAttributeGetter(scriptState, "{{cpp_class}}", "{{attribute.name}}", holder); v8::Handle<v8::Value> v8Value = PrivateScriptRunner::runDOMAttributeGetter(scriptState, "{{cpp_class}}", "{{attribute.name}}", holder);
if (block.HasCaught()) { if (block.HasCaught()) {
if (!PrivateScriptRunner::throwDOMExceptionInPrivateScriptIfNeeded(scriptState->isolate(), exceptionState, block.Exception())) { if (!PrivateScriptRunner::rethrowExceptionInPrivateScript(scriptState->isolate(), exceptionState, block)) {
// FIXME: We should support more exceptions. // FIXME: We should support more exceptions.
RELEASE_ASSERT_NOT_REACHED(); RELEASE_ASSERT_NOT_REACHED();
} }
...@@ -397,7 +397,7 @@ bool {{v8_class}}::PrivateScript::{{attribute.name}}AttributeSetter(LocalFrame* ...@@ -397,7 +397,7 @@ bool {{v8_class}}::PrivateScript::{{attribute.name}}AttributeSetter(LocalFrame*
v8::TryCatch block; v8::TryCatch block;
PrivateScriptRunner::runDOMAttributeSetter(scriptState, "{{cpp_class}}", "{{attribute.name}}", holder, {{attribute.private_script_cpp_value_to_v8_value}}); PrivateScriptRunner::runDOMAttributeSetter(scriptState, "{{cpp_class}}", "{{attribute.name}}", holder, {{attribute.private_script_cpp_value_to_v8_value}});
if (block.HasCaught()) { if (block.HasCaught()) {
if (!PrivateScriptRunner::throwDOMExceptionInPrivateScriptIfNeeded(scriptState->isolate(), exceptionState, block.Exception())) { if (!PrivateScriptRunner::rethrowExceptionInPrivateScript(scriptState->isolate(), exceptionState, block)) {
// FIXME: We should support more exceptions. // FIXME: We should support more exceptions.
RELEASE_ASSERT_NOT_REACHED(); RELEASE_ASSERT_NOT_REACHED();
} }
......
...@@ -564,7 +564,7 @@ bool {{v8_class}}::PrivateScript::{{method.name}}Method({{method.argument_declar ...@@ -564,7 +564,7 @@ bool {{v8_class}}::PrivateScript::{{method.name}}Method({{method.argument_declar
{% if method.idl_type == 'void' %} {% if method.idl_type == 'void' %}
PrivateScriptRunner::runDOMMethod(scriptState, "{{cpp_class}}", "{{method.name}}", holder, {{method.arguments | length}}, argv); PrivateScriptRunner::runDOMMethod(scriptState, "{{cpp_class}}", "{{method.name}}", holder, {{method.arguments | length}}, argv);
if (block.HasCaught()) { if (block.HasCaught()) {
if (!PrivateScriptRunner::throwDOMExceptionInPrivateScriptIfNeeded(scriptState->isolate(), exceptionState, block.Exception())) { if (!PrivateScriptRunner::rethrowExceptionInPrivateScript(scriptState->isolate(), exceptionState, block)) {
// FIXME: We should support more exceptions. // FIXME: We should support more exceptions.
RELEASE_ASSERT_NOT_REACHED(); RELEASE_ASSERT_NOT_REACHED();
} }
...@@ -574,7 +574,7 @@ bool {{v8_class}}::PrivateScript::{{method.name}}Method({{method.argument_declar ...@@ -574,7 +574,7 @@ bool {{v8_class}}::PrivateScript::{{method.name}}Method({{method.argument_declar
{% else %} {% else %}
v8::Handle<v8::Value> v8Value = PrivateScriptRunner::runDOMMethod(scriptState, "{{cpp_class}}", "{{method.name}}", holder, {{method.arguments | length}}, argv); v8::Handle<v8::Value> v8Value = PrivateScriptRunner::runDOMMethod(scriptState, "{{cpp_class}}", "{{method.name}}", holder, {{method.arguments | length}}, argv);
if (block.HasCaught()) { if (block.HasCaught()) {
if (!PrivateScriptRunner::throwDOMExceptionInPrivateScriptIfNeeded(scriptState->isolate(), exceptionState, block.Exception())) { if (!PrivateScriptRunner::rethrowExceptionInPrivateScript(scriptState->isolate(), exceptionState, block)) {
// FIXME: We should support more exceptions. // FIXME: We should support more exceptions.
RELEASE_ASSERT_NOT_REACHED(); RELEASE_ASSERT_NOT_REACHED();
} }
......
...@@ -1877,7 +1877,7 @@ bool V8TestInterface::PrivateScript::shortMethodWithShortArgumentImplementedInPr ...@@ -1877,7 +1877,7 @@ bool V8TestInterface::PrivateScript::shortMethodWithShortArgumentImplementedInPr
v8::TryCatch block; v8::TryCatch block;
v8::Handle<v8::Value> v8Value = PrivateScriptRunner::runDOMMethod(scriptState, "TestInterfaceImplementation", "shortMethodWithShortArgumentImplementedInPrivateScript", holder, 1, argv); v8::Handle<v8::Value> v8Value = PrivateScriptRunner::runDOMMethod(scriptState, "TestInterfaceImplementation", "shortMethodWithShortArgumentImplementedInPrivateScript", holder, 1, argv);
if (block.HasCaught()) { if (block.HasCaught()) {
if (!PrivateScriptRunner::throwDOMExceptionInPrivateScriptIfNeeded(scriptState->isolate(), exceptionState, block.Exception())) { if (!PrivateScriptRunner::rethrowExceptionInPrivateScript(scriptState->isolate(), exceptionState, block)) {
// FIXME: We should support more exceptions. // FIXME: We should support more exceptions.
RELEASE_ASSERT_NOT_REACHED(); RELEASE_ASSERT_NOT_REACHED();
} }
...@@ -1910,7 +1910,7 @@ bool V8TestInterface::PrivateScript::stringAttributeAttributeGetter(LocalFrame* ...@@ -1910,7 +1910,7 @@ bool V8TestInterface::PrivateScript::stringAttributeAttributeGetter(LocalFrame*
v8::TryCatch block; v8::TryCatch block;
v8::Handle<v8::Value> v8Value = PrivateScriptRunner::runDOMAttributeGetter(scriptState, "TestInterfaceImplementation", "stringAttribute", holder); v8::Handle<v8::Value> v8Value = PrivateScriptRunner::runDOMAttributeGetter(scriptState, "TestInterfaceImplementation", "stringAttribute", holder);
if (block.HasCaught()) { if (block.HasCaught()) {
if (!PrivateScriptRunner::throwDOMExceptionInPrivateScriptIfNeeded(scriptState->isolate(), exceptionState, block.Exception())) { if (!PrivateScriptRunner::rethrowExceptionInPrivateScript(scriptState->isolate(), exceptionState, block)) {
// FIXME: We should support more exceptions. // FIXME: We should support more exceptions.
RELEASE_ASSERT_NOT_REACHED(); RELEASE_ASSERT_NOT_REACHED();
} }
...@@ -1943,7 +1943,7 @@ bool V8TestInterface::PrivateScript::stringAttributeAttributeSetter(LocalFrame* ...@@ -1943,7 +1943,7 @@ bool V8TestInterface::PrivateScript::stringAttributeAttributeSetter(LocalFrame*
v8::TryCatch block; v8::TryCatch block;
PrivateScriptRunner::runDOMAttributeSetter(scriptState, "TestInterfaceImplementation", "stringAttribute", holder, v8String(scriptState->isolate(), cppValue)); PrivateScriptRunner::runDOMAttributeSetter(scriptState, "TestInterfaceImplementation", "stringAttribute", holder, v8String(scriptState->isolate(), cppValue));
if (block.HasCaught()) { if (block.HasCaught()) {
if (!PrivateScriptRunner::throwDOMExceptionInPrivateScriptIfNeeded(scriptState->isolate(), exceptionState, block.Exception())) { if (!PrivateScriptRunner::rethrowExceptionInPrivateScript(scriptState->isolate(), exceptionState, block)) {
// FIXME: We should support more exceptions. // FIXME: We should support more exceptions.
RELEASE_ASSERT_NOT_REACHED(); RELEASE_ASSERT_NOT_REACHED();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment