ScriptFunctionCall.cpp [plain text]
#include "config.h"
#include "ScriptFunctionCall.h"
#include "JSCInlines.h"
#include "JSLock.h"
#include "ScriptValue.h"
#include <wtf/text/WTFString.h>
using namespace JSC;
namespace Deprecated {
void ScriptCallArgumentHandler::appendArgument(const Deprecated::ScriptObject& argument)
{
if (argument.scriptState() != m_exec) {
ASSERT_NOT_REACHED();
return;
}
m_arguments.append(argument.jsObject());
}
void ScriptCallArgumentHandler::appendArgument(const Deprecated::ScriptValue& argument)
{
m_arguments.append(argument.jsValue());
}
void ScriptCallArgumentHandler::appendArgument(const String& argument)
{
JSLockHolder lock(m_exec);
m_arguments.append(jsString(m_exec, argument));
}
void ScriptCallArgumentHandler::appendArgument(const char* argument)
{
JSLockHolder lock(m_exec);
m_arguments.append(jsString(m_exec, String(argument)));
}
void ScriptCallArgumentHandler::appendArgument(JSValue argument)
{
m_arguments.append(argument);
}
void ScriptCallArgumentHandler::appendArgument(long argument)
{
JSLockHolder lock(m_exec);
m_arguments.append(jsNumber(argument));
}
void ScriptCallArgumentHandler::appendArgument(long long argument)
{
JSLockHolder lock(m_exec);
m_arguments.append(jsNumber(argument));
}
void ScriptCallArgumentHandler::appendArgument(unsigned int argument)
{
JSLockHolder lock(m_exec);
m_arguments.append(jsNumber(argument));
}
void ScriptCallArgumentHandler::appendArgument(unsigned long argument)
{
JSLockHolder lock(m_exec);
m_arguments.append(jsNumber(argument));
}
void ScriptCallArgumentHandler::appendArgument(int argument)
{
JSLockHolder lock(m_exec);
m_arguments.append(jsNumber(argument));
}
void ScriptCallArgumentHandler::appendArgument(bool argument)
{
m_arguments.append(jsBoolean(argument));
}
ScriptFunctionCall::ScriptFunctionCall(const Deprecated::ScriptObject& thisObject, const String& name, ScriptFunctionCallHandler callHandler)
: ScriptCallArgumentHandler(thisObject.scriptState())
, m_callHandler(callHandler)
, m_thisObject(thisObject)
, m_name(name)
{
}
Deprecated::ScriptValue ScriptFunctionCall::call(bool& hadException)
{
JSObject* thisObject = m_thisObject.jsObject();
JSLockHolder lock(m_exec);
JSValue function = thisObject->get(m_exec, Identifier(m_exec, m_name));
if (m_exec->hadException()) {
hadException = true;
return Deprecated::ScriptValue();
}
CallData callData;
CallType callType = getCallData(function, callData);
if (callType == CallTypeNone)
return Deprecated::ScriptValue();
JSValue result;
JSValue exception;
if (m_callHandler)
result = m_callHandler(m_exec, function, callType, callData, thisObject, m_arguments, &exception);
else
result = JSC::call(m_exec, function, callType, callData, thisObject, m_arguments, &exception);
if (exception) {
hadException = true;
return Deprecated::ScriptValue();
}
return Deprecated::ScriptValue(m_exec->vm(), result);
}
Deprecated::ScriptValue ScriptFunctionCall::call()
{
bool hadException = false;
return call(hadException);
}
}