JSCallbackData.cpp [plain text]
#include "config.h"
#include "JSCallbackData.h"
#include "Document.h"
#include "JSDOMBinding.h"
#include "JSExecState.h"
#include "JSExecStateInstrumentation.h"
#include <JavaScriptCore/Exception.h>
namespace WebCore {
using namespace JSC;
JSValue JSCallbackData::invokeCallback(JSDOMGlobalObject& globalObject, JSObject* callback, JSValue thisValue, MarkedArgumentBuffer& args, CallbackType method, PropertyName functionName, NakedPtr<JSC::Exception>& returnedException)
{
ASSERT(callback);
JSGlobalObject* lexicalGlobalObject = &globalObject;
VM& vm = lexicalGlobalObject->vm();
auto scope = DECLARE_CATCH_SCOPE(vm);
JSValue function;
CallData callData;
CallType callType = CallType::None;
if (method != CallbackType::Object) {
function = callback;
callType = callback->methodTable(vm)->getCallData(callback, callData);
}
if (callType == CallType::None) {
if (method == CallbackType::Function) {
returnedException = JSC::Exception::create(vm, createTypeError(lexicalGlobalObject));
return JSValue();
}
ASSERT(!functionName.isNull());
function = callback->get(lexicalGlobalObject, functionName);
if (UNLIKELY(scope.exception())) {
returnedException = scope.exception();
scope.clearException();
return JSValue();
}
callType = getCallData(vm, function, callData);
if (callType == CallType::None) {
returnedException = JSC::Exception::create(vm, createTypeError(lexicalGlobalObject));
return JSValue();
}
}
ASSERT(!function.isEmpty());
ASSERT(callType != CallType::None);
ScriptExecutionContext* context = globalObject.scriptExecutionContext();
if (!context)
return JSValue();
JSExecState::instrumentFunctionCall(context, callType, callData);
returnedException = nullptr;
JSValue result = JSExecState::profiledCall(lexicalGlobalObject, JSC::ProfilingReason::Other, function, callType, callData, thisValue, args, returnedException);
InspectorInstrumentation::didCallFunction(context);
return result;
}
void JSCallbackDataWeak::visitJSFunction(JSC::SlotVisitor& vistor)
{
vistor.append(m_callback);
}
bool JSCallbackDataWeak::WeakOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown>, void* context, SlotVisitor& visitor, const char** reason)
{
if (UNLIKELY(reason))
*reason = "Context is opaque root"; return visitor.containsOpaqueRoot(context);
}
}