summaryrefslogtreecommitdiffstats
path: root/WebCore/bindings/v8/ScriptFunctionCall.cpp
diff options
context:
space:
mode:
authorKristian Monsen <kristianm@google.com>2010-09-30 15:42:16 +0100
committerSteve Block <steveblock@google.com>2010-10-07 10:59:29 +0100
commitbec39347bb3bb5bf1187ccaf471d26247f28b585 (patch)
tree56bdc4c2978fbfd3d79d0d36d5d6c640ecc09cc8 /WebCore/bindings/v8/ScriptFunctionCall.cpp
parent90b7966e7815b262cd19ac25f03aaad9b21fdc06 (diff)
downloadexternal_webkit-bec39347bb3bb5bf1187ccaf471d26247f28b585.zip
external_webkit-bec39347bb3bb5bf1187ccaf471d26247f28b585.tar.gz
external_webkit-bec39347bb3bb5bf1187ccaf471d26247f28b585.tar.bz2
Merge WebKit at r68651 : Initial merge by git.
Change-Id: I3d6bff59f17eedd6722723354f386fec9be8ad12
Diffstat (limited to 'WebCore/bindings/v8/ScriptFunctionCall.cpp')
-rw-r--r--WebCore/bindings/v8/ScriptFunctionCall.cpp72
1 files changed, 54 insertions, 18 deletions
diff --git a/WebCore/bindings/v8/ScriptFunctionCall.cpp b/WebCore/bindings/v8/ScriptFunctionCall.cpp
index e6b22ee..29dbb02 100644
--- a/WebCore/bindings/v8/ScriptFunctionCall.cpp
+++ b/WebCore/bindings/v8/ScriptFunctionCall.cpp
@@ -45,14 +45,7 @@
namespace WebCore {
-ScriptFunctionCall::ScriptFunctionCall(const ScriptObject& thisObject, const String& name)
- : m_scriptState(thisObject.scriptState())
- , m_thisObject(thisObject)
- , m_name(name)
-{
-}
-
-void ScriptFunctionCall::appendArgument(const ScriptObject& argument)
+void ScriptCallArgumentHandler::appendArgument(const ScriptObject& argument)
{
if (argument.scriptState() != m_scriptState) {
ASSERT_NOT_REACHED();
@@ -61,64 +54,71 @@ void ScriptFunctionCall::appendArgument(const ScriptObject& argument)
m_arguments.append(argument);
}
-void ScriptFunctionCall::appendArgument(const ScriptString& argument)
+void ScriptCallArgumentHandler::appendArgument(const ScriptString& argument)
{
ScriptScope scope(m_scriptState);
m_arguments.append(v8String(argument));
}
-void ScriptFunctionCall::appendArgument(const ScriptValue& argument)
+void ScriptCallArgumentHandler::appendArgument(const ScriptValue& argument)
{
m_arguments.append(argument);
}
-void ScriptFunctionCall::appendArgument(const String& argument)
+void ScriptCallArgumentHandler::appendArgument(const String& argument)
{
ScriptScope scope(m_scriptState);
m_arguments.append(v8String(argument));
}
-void ScriptFunctionCall::appendArgument(const char* argument)
+void ScriptCallArgumentHandler::appendArgument(const char* argument)
{
ScriptScope scope(m_scriptState);
m_arguments.append(v8String(argument));
}
-void ScriptFunctionCall::appendArgument(long argument)
+void ScriptCallArgumentHandler::appendArgument(long argument)
{
ScriptScope scope(m_scriptState);
m_arguments.append(v8::Number::New(argument));
}
-void ScriptFunctionCall::appendArgument(long long argument)
+void ScriptCallArgumentHandler::appendArgument(long long argument)
{
ScriptScope scope(m_scriptState);
m_arguments.append(v8::Number::New(argument));
}
-void ScriptFunctionCall::appendArgument(unsigned int argument)
+void ScriptCallArgumentHandler::appendArgument(unsigned int argument)
{
ScriptScope scope(m_scriptState);
m_arguments.append(v8::Number::New(argument));
}
-void ScriptFunctionCall::appendArgument(unsigned long argument)
+void ScriptCallArgumentHandler::appendArgument(unsigned long argument)
{
ScriptScope scope(m_scriptState);
m_arguments.append(v8::Number::New(argument));
}
-void ScriptFunctionCall::appendArgument(int argument)
+void ScriptCallArgumentHandler::appendArgument(int argument)
{
ScriptScope scope(m_scriptState);
m_arguments.append(v8::Number::New(argument));
}
-void ScriptFunctionCall::appendArgument(bool argument)
+void ScriptCallArgumentHandler::appendArgument(bool argument)
{
m_arguments.append(v8Boolean(argument));
}
+ScriptFunctionCall::ScriptFunctionCall(const ScriptObject& thisObject, const String& name)
+ : ScriptCallArgumentHandler(thisObject.scriptState())
+ , m_thisObject(thisObject)
+ , m_name(name)
+{
+}
+
ScriptValue ScriptFunctionCall::call(bool& hadException, bool reportExceptions)
{
ScriptScope scope(m_scriptState, reportExceptions);
@@ -179,4 +179,40 @@ ScriptObject ScriptFunctionCall::construct(bool& hadException, bool reportExcept
return ScriptObject(m_scriptState, result);
}
+ScriptCallback::ScriptCallback(ScriptState* state, ScriptValue function)
+ : ScriptCallArgumentHandler(state)
+ , m_function(function)
+{
+}
+
+ScriptValue ScriptCallback::call()
+{
+ bool hadException = false;
+ return call(hadException);
+}
+
+ScriptValue ScriptCallback::call(bool& hadException)
+{
+ ASSERT(v8::Context::InContext());
+ ASSERT(m_function.v8Value()->IsFunction());
+
+ v8::TryCatch exceptionCatcher;
+ v8::Handle<v8::Object> object = v8::Context::GetCurrent()->Global();
+ v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(m_function.v8Value());
+
+ OwnArrayPtr<v8::Handle<v8::Value> > args(new v8::Handle<v8::Value>[m_arguments.size()]);
+ for (size_t i = 0; i < m_arguments.size(); ++i)
+ args[i] = m_arguments[i].v8Value();
+
+ v8::Handle<v8::Value> result = V8Proxy::callFunctionWithoutFrame(function, object, m_arguments.size(), args.get());
+
+ if (exceptionCatcher.HasCaught()) {
+ hadException = true;
+ m_scriptState->setException(exceptionCatcher.Exception());
+ return ScriptValue();
+ }
+
+ return ScriptValue(result);
+}
+
} // namespace WebCore