diff options
Diffstat (limited to 'src/javascript/jsc/bindings/JSDOMExceptionHandling.cpp')
-rw-r--r-- | src/javascript/jsc/bindings/JSDOMExceptionHandling.cpp | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/src/javascript/jsc/bindings/JSDOMExceptionHandling.cpp b/src/javascript/jsc/bindings/JSDOMExceptionHandling.cpp index 70f3c4d87..494bf9e3a 100644 --- a/src/javascript/jsc/bindings/JSDOMExceptionHandling.cpp +++ b/src/javascript/jsc/bindings/JSDOMExceptionHandling.cpp @@ -30,10 +30,71 @@ #include "JavaScriptCore/ExceptionHelpers.h" #include "JavaScriptCore/ScriptCallStack.h" #include "JavaScriptCore/ScriptCallStackFactory.h" +#include "headers.h" + +#include "CachedScript.h" namespace WebCore { using namespace JSC; +void reportException(JSGlobalObject* lexicalGlobalObject, JSC::Exception* exception, CachedScript* cachedScript, bool fromModule, ExceptionDetails* exceptionDetails) +{ + VM& vm = lexicalGlobalObject->vm(); + RELEASE_ASSERT(vm.currentThreadIsHoldingAPILock()); + if (vm.isTerminationException(exception)) + return; + + // We can declare a CatchScope here because we will clear the exception below if it's + // not a TerminationException. If it's a TerminationException, it'll remain sticky in + // the VM, but we have the check above to ensure that we do not re-enter this scope. + auto scope = DECLARE_CATCH_SCOPE(vm); + + ErrorHandlingScope errorScope(lexicalGlobalObject->vm()); + + // auto callStack = Inspector::createScriptCallStackFromException(lexicalGlobalObject, exception); + scope.clearException(); + vm.clearLastException(); + + auto* globalObject = jsCast<JSDOMGlobalObject*>(lexicalGlobalObject); + // if (auto* window = jsDynamicCast<JSDOMWindow*>(vm, globalObject)) { + // if (!window->wrapped().isCurrentlyDisplayedInFrame()) + // return; + // } + + int lineNumber = 0; + int columnNumber = 0; + String exceptionSourceURL; + // if (auto* callFrame = callStack->firstNonNativeCallFrame()) { + // lineNumber = callFrame->lineNumber(); + // columnNumber = callFrame->columnNumber(); + // exceptionSourceURL = callFrame->sourceURL(); + // } + + auto errorMessage = retrieveErrorMessage(*lexicalGlobalObject, vm, exception->value(), scope); + Zig__GlobalObject__reportUncaughtException(globalObject, exception); + + if (exceptionDetails) { + exceptionDetails->message = errorMessage; + exceptionDetails->lineNumber = lineNumber; + exceptionDetails->columnNumber = columnNumber; + exceptionDetails->sourceURL = exceptionSourceURL; + } +} + +void reportException(JSGlobalObject* lexicalGlobalObject, JSValue exceptionValue, CachedScript* cachedScript, bool fromModule) +{ + VM& vm = lexicalGlobalObject->vm(); + RELEASE_ASSERT(vm.currentThreadIsHoldingAPILock()); + auto* exception = jsDynamicCast<JSC::Exception*>(vm, exceptionValue); + if (!exception) { + exception = vm.lastException(); + if (!exception) + exception = JSC::Exception::create(lexicalGlobalObject->vm(), exceptionValue, JSC::Exception::DoNotCaptureStack); + } + + reportException(lexicalGlobalObject, exception, cachedScript, fromModule); +} + String retrieveErrorMessageWithoutName(JSGlobalObject& lexicalGlobalObject, VM& vm, JSValue exception, CatchScope& catchScope) { // FIXME: <http://webkit.org/b/115087> Web Inspector: WebCore::reportException should not evaluate JavaScript handling exceptions @@ -76,7 +137,7 @@ void reportCurrentException(JSGlobalObject* lexicalGlobalObject) auto scope = DECLARE_CATCH_SCOPE(vm); auto* exception = scope.exception(); scope.clearException(); - // reportException(lexicalGlobalObject, exception); + reportException(lexicalGlobalObject, exception); } JSValue createDOMException(JSGlobalObject* lexicalGlobalObject, ExceptionCode ec, const String& message) |