JSErrorHandler.cpp [plain text]
#include "config.h"
#include "JSErrorHandler.h"
#include "Document.h"
#include "ErrorEvent.h"
#include "Event.h"
#include "EventNames.h"
#include "JSEvent.h"
#include "JSMainThreadExecState.h"
#include "JSMainThreadExecStateInstrumentation.h"
#include <runtime/JSLock.h>
#include <runtime/VMEntryScope.h>
#include <wtf/Ref.h>
using namespace JSC;
namespace WebCore {
JSErrorHandler::JSErrorHandler(JSObject* function, JSObject* wrapper, bool isAttribute, DOMWrapperWorld& world)
: JSEventListener(function, wrapper, isAttribute, world)
{
}
JSErrorHandler::~JSErrorHandler()
{
}
void JSErrorHandler::handleEvent(ScriptExecutionContext* scriptExecutionContext, Event* event)
{
if (!is<ErrorEvent>(*event))
return JSEventListener::handleEvent(scriptExecutionContext, event);
ASSERT(scriptExecutionContext);
if (!scriptExecutionContext)
return;
ErrorEvent& errorEvent = downcast<ErrorEvent>(*event);
JSLockHolder lock(scriptExecutionContext->vm());
JSObject* jsFunction = this->jsFunction(scriptExecutionContext);
if (!jsFunction)
return;
JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(scriptExecutionContext, isolatedWorld());
if (!globalObject)
return;
ExecState* exec = globalObject->globalExec();
CallData callData;
CallType callType = jsFunction->methodTable()->getCallData(jsFunction, callData);
if (callType != CallType::None) {
Ref<JSErrorHandler> protectedThis(*this);
Event* savedEvent = globalObject->currentEvent();
globalObject->setCurrentEvent(event);
MarkedArgumentBuffer args;
args.append(jsStringWithCache(exec, errorEvent.message()));
args.append(jsStringWithCache(exec, errorEvent.filename()));
args.append(jsNumber(errorEvent.lineno()));
args.append(jsNumber(errorEvent.colno()));
args.append(errorEvent.sanitizedErrorValue(*exec, *globalObject));
VM& vm = globalObject->vm();
VMEntryScope entryScope(vm, vm.entryScope ? vm.entryScope->globalObject() : globalObject);
InspectorInstrumentationCookie cookie = JSMainThreadExecState::instrumentFunctionCall(scriptExecutionContext, callType, callData);
NakedPtr<Exception> exception;
JSValue returnValue = scriptExecutionContext->isDocument()
? JSMainThreadExecState::profiledCall(exec, JSC::ProfilingReason::Other, jsFunction, callType, callData, globalObject, args, exception)
: JSC::profiledCall(exec, JSC::ProfilingReason::Other, jsFunction, callType, callData, globalObject, args, exception);
InspectorInstrumentation::didCallFunction(cookie, scriptExecutionContext);
globalObject->setCurrentEvent(savedEvent);
if (exception)
reportException(exec, exception);
else {
if (returnValue.isTrue())
event->preventDefault();
}
}
}
}