[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

commit-queue at webkit.org commit-queue at webkit.org
Wed Dec 22 13:39:46 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit b7c66204dff63813c85338f089cd976738b840e7
Author: commit-queue at webkit.org <commit-queue at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Sep 22 19:46:33 2010 +0000

    2010-09-22  Luiz Agostini  <luiz.agostini at openbossa.org>
    
            Reviewed by Oliver Hunt.
    
            Script engine agnostic ScriptCallback class
            https://bugs.webkit.org/show_bug.cgi?id=43216
    
            Refactoring class ScriptFunctionCall to create a class (ScriptCallback) that
            receives a script function as a ScriptValue and calls that function with provided parameters.
    
            * bindings/js/ScriptFunctionCall.cpp:
            (WebCore::ScriptCallArgumentHandler::appendArgument):
            (WebCore::ScriptFunctionCall::ScriptFunctionCall):
            (WebCore::ScriptCallback::ScriptCallback):
            (WebCore::ScriptCallback::call):
            * bindings/js/ScriptFunctionCall.h:
            (WebCore::ScriptCallArgumentHandler::ScriptCallArgumentHandler):
            * bindings/v8/ScriptFunctionCall.cpp:
            (WebCore::ScriptCallArgumentHandler::appendArgument):
            (WebCore::ScriptFunctionCall::ScriptFunctionCall):
            (WebCore::ScriptCallback::ScriptCallback):
            (WebCore::ScriptCallback::call):
            * bindings/v8/ScriptFunctionCall.h:
            (WebCore::ScriptCallArgumentHandler::ScriptCallArgumentHandler):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@68074 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 541fa44..76b2298 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,28 @@
+2010-09-22  Luiz Agostini  <luiz.agostini at openbossa.org>
+
+        Reviewed by Oliver Hunt.
+
+        Script engine agnostic ScriptCallback class
+        https://bugs.webkit.org/show_bug.cgi?id=43216
+
+        Refactoring class ScriptFunctionCall to create a class (ScriptCallback) that
+        receives a script function as a ScriptValue and calls that function with provided parameters.
+
+        * bindings/js/ScriptFunctionCall.cpp:
+        (WebCore::ScriptCallArgumentHandler::appendArgument):
+        (WebCore::ScriptFunctionCall::ScriptFunctionCall):
+        (WebCore::ScriptCallback::ScriptCallback):
+        (WebCore::ScriptCallback::call):
+        * bindings/js/ScriptFunctionCall.h:
+        (WebCore::ScriptCallArgumentHandler::ScriptCallArgumentHandler):
+        * bindings/v8/ScriptFunctionCall.cpp:
+        (WebCore::ScriptCallArgumentHandler::appendArgument):
+        (WebCore::ScriptFunctionCall::ScriptFunctionCall):
+        (WebCore::ScriptCallback::ScriptCallback):
+        (WebCore::ScriptCallback::call):
+        * bindings/v8/ScriptFunctionCall.h:
+        (WebCore::ScriptCallArgumentHandler::ScriptCallArgumentHandler):
+
 2010-09-22  Brent Fulgham  <bfulgham at webkit.org>
 
         Unreviewed.
diff --git a/WebCore/bindings/js/ScriptFunctionCall.cpp b/WebCore/bindings/js/ScriptFunctionCall.cpp
index 9baf809..6146712 100644
--- a/WebCore/bindings/js/ScriptFunctionCall.cpp
+++ b/WebCore/bindings/js/ScriptFunctionCall.cpp
@@ -43,14 +43,7 @@ using namespace JSC;
 
 namespace WebCore {
 
-ScriptFunctionCall::ScriptFunctionCall(const ScriptObject& thisObject, const String& name)
-    : m_exec(thisObject.scriptState())
-    , m_thisObject(thisObject)
-    , m_name(name)
-{
-}
-
-void ScriptFunctionCall::appendArgument(const ScriptObject& argument)
+void ScriptCallArgumentHandler::appendArgument(const ScriptObject& argument)
 {
     if (argument.scriptState() != m_exec) {
         ASSERT_NOT_REACHED();
@@ -59,74 +52,81 @@ void ScriptFunctionCall::appendArgument(const ScriptObject& argument)
     m_arguments.append(argument.jsObject());
 }
 
-void ScriptFunctionCall::appendArgument(const ScriptString& argument)
+void ScriptCallArgumentHandler::appendArgument(const ScriptString& argument)
 {
     m_arguments.append(jsString(m_exec, argument.ustring()));
 }
 
-void ScriptFunctionCall::appendArgument(const ScriptValue& argument)
+void ScriptCallArgumentHandler::appendArgument(const ScriptValue& argument)
 {
     m_arguments.append(argument.jsValue());
 }
 
-void ScriptFunctionCall::appendArgument(const String& argument)
+void ScriptCallArgumentHandler::appendArgument(const String& argument)
 {
     JSLock lock(SilenceAssertionsOnly);
     m_arguments.append(jsString(m_exec, argument));
 }
 
-void ScriptFunctionCall::appendArgument(const JSC::UString& argument)
+void ScriptCallArgumentHandler::appendArgument(const JSC::UString& argument)
 {
     JSLock lock(SilenceAssertionsOnly);
     m_arguments.append(jsString(m_exec, argument));
 }
 
-void ScriptFunctionCall::appendArgument(const char* argument)
+void ScriptCallArgumentHandler::appendArgument(const char* argument)
 {
     JSLock lock(SilenceAssertionsOnly);
     m_arguments.append(jsString(m_exec, UString(argument)));
 }
 
-void ScriptFunctionCall::appendArgument(JSC::JSValue argument)
+void ScriptCallArgumentHandler::appendArgument(JSC::JSValue argument)
 {
     m_arguments.append(argument);
 }
 
-void ScriptFunctionCall::appendArgument(long argument)
+void ScriptCallArgumentHandler::appendArgument(long argument)
 {
     JSLock lock(SilenceAssertionsOnly);
     m_arguments.append(jsNumber(m_exec, argument));
 }
 
-void ScriptFunctionCall::appendArgument(long long argument)
+void ScriptCallArgumentHandler::appendArgument(long long argument)
 {
     JSLock lock(SilenceAssertionsOnly);
     m_arguments.append(jsNumber(m_exec, argument));
 }
 
-void ScriptFunctionCall::appendArgument(unsigned int argument)
+void ScriptCallArgumentHandler::appendArgument(unsigned int argument)
 {
     JSLock lock(SilenceAssertionsOnly);
     m_arguments.append(jsNumber(m_exec, argument));
 }
 
-void ScriptFunctionCall::appendArgument(unsigned long argument)
+void ScriptCallArgumentHandler::appendArgument(unsigned long argument)
 {
     JSLock lock(SilenceAssertionsOnly);
     m_arguments.append(jsNumber(m_exec, argument));
 }
 
-void ScriptFunctionCall::appendArgument(int argument)
+void ScriptCallArgumentHandler::appendArgument(int argument)
 {
     JSLock lock(SilenceAssertionsOnly);
     m_arguments.append(jsNumber(m_exec, argument));
 }
 
-void ScriptFunctionCall::appendArgument(bool argument)
+void ScriptCallArgumentHandler::appendArgument(bool argument)
 {
     m_arguments.append(jsBoolean(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)
 {
     JSObject* thisObject = m_thisObject.jsObject();
@@ -197,4 +197,36 @@ ScriptObject ScriptFunctionCall::construct(bool& hadException, bool reportExcept
     return ScriptObject(m_exec, asObject(result));
 }
 
+ScriptCallback::ScriptCallback(ScriptState* state, ScriptValue function)
+    : ScriptCallArgumentHandler(state)
+    , m_function(function)
+{
+}
+
+ScriptValue ScriptCallback::call()
+{
+    bool hadException;
+    return call(hadException);
+}
+
+ScriptValue ScriptCallback::call(bool& hadException)
+{
+    JSLock lock(SilenceAssertionsOnly);
+
+    CallData callData;
+    CallType callType = getCallData(m_function.jsValue(), callData);
+
+    ASSERT(callType != CallTypeNone);
+
+    JSValue result = JSC::call(m_exec, m_function.jsValue(), callType, callData, m_function.jsValue(), m_arguments);
+    hadException = m_exec->hadException();
+
+    if (hadException) {
+        reportException(m_exec, m_exec->exception());
+        return ScriptValue();
+    }
+
+    return ScriptValue(result);
+}
+
 } // namespace WebCore
diff --git a/WebCore/bindings/js/ScriptFunctionCall.h b/WebCore/bindings/js/ScriptFunctionCall.h
index 9742e8f..037a336 100644
--- a/WebCore/bindings/js/ScriptFunctionCall.h
+++ b/WebCore/bindings/js/ScriptFunctionCall.h
@@ -46,10 +46,9 @@ namespace WebCore {
     class ScriptValue;
     class ScriptString;
 
-    class ScriptFunctionCall {
+    class ScriptCallArgumentHandler {
     public:
-        ScriptFunctionCall(const ScriptObject& thisObject, const String& name);
-        virtual ~ScriptFunctionCall() {};
+        ScriptCallArgumentHandler(ScriptState* state) : m_exec(state) { }
 
         void appendArgument(const ScriptObject&);
         void appendArgument(const ScriptString&);
@@ -64,15 +63,10 @@ namespace WebCore {
         void appendArgument(unsigned long);
         void appendArgument(int);
         void appendArgument(bool);
-        ScriptValue call(bool& hadException, bool reportExceptions = true);
-        ScriptValue call();
-        ScriptObject construct(bool& hadException, bool reportExceptions = true);
 
     protected:
-        ScriptState* m_exec;
-        ScriptObject m_thisObject;
-        String m_name;
         JSC::MarkedArgumentBuffer m_arguments;
+        ScriptState* m_exec;
 
     private:
         // MarkedArgumentBuffer must be stack allocated, so prevent heap
@@ -81,6 +75,29 @@ namespace WebCore {
         void* operator new[](size_t) { ASSERT_NOT_REACHED(); return reinterpret_cast<void*>(0xbadbeef); }
     };
 
+    class ScriptFunctionCall : public ScriptCallArgumentHandler {
+    public:
+        ScriptFunctionCall(const ScriptObject& thisObject, const String& name);
+        ScriptValue call(bool& hadException, bool reportExceptions = true);
+        ScriptValue call();
+        ScriptObject construct(bool& hadException, bool reportExceptions = true);
+
+    protected:
+        ScriptObject m_thisObject;
+        String m_name;
+    };
+
+    class ScriptCallback : public ScriptCallArgumentHandler {
+    public:
+        ScriptCallback(ScriptState*, ScriptValue);
+
+        ScriptValue call();
+        ScriptValue call(bool& hadException);
+
+    private:
+        ScriptValue m_function;
+    };
+
 } // namespace WebCore
 
 #endif // ScriptFunctionCall
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
diff --git a/WebCore/bindings/v8/ScriptFunctionCall.h b/WebCore/bindings/v8/ScriptFunctionCall.h
index 4cbbf7e..04dddc8 100644
--- a/WebCore/bindings/v8/ScriptFunctionCall.h
+++ b/WebCore/bindings/v8/ScriptFunctionCall.h
@@ -41,10 +41,9 @@ namespace WebCore {
     class ScriptState;
     class ScriptString;
 
-    class ScriptFunctionCall {
+    class ScriptCallArgumentHandler {
     public:
-        ScriptFunctionCall(const ScriptObject& thisObject, const String& name);
-        virtual ~ScriptFunctionCall() {};
+        ScriptCallArgumentHandler(ScriptState* scriptState) : m_scriptState(scriptState) { }
 
         void appendArgument(const ScriptObject&);
         void appendArgument(const ScriptString&);
@@ -57,15 +56,33 @@ namespace WebCore {
         void appendArgument(unsigned long);
         void appendArgument(int);
         void appendArgument(bool);
+
+    protected:
+        ScriptState* m_scriptState;
+        Vector<ScriptValue> m_arguments;
+    };
+
+    class ScriptFunctionCall : public ScriptCallArgumentHandler {
+    public:
+        ScriptFunctionCall(const ScriptObject& thisObject, const String& name);
         ScriptValue call(bool& hadException, bool reportExceptions = true);
         ScriptValue call();
         ScriptObject construct(bool& hadException, bool reportExceptions = true);
 
     protected:
-        ScriptState* m_scriptState;
         ScriptObject m_thisObject;
         String m_name;
-        Vector<ScriptValue> m_arguments;
+    };
+
+    class ScriptCallback : public ScriptCallArgumentHandler {
+    public:
+        ScriptCallback(ScriptState*, ScriptValue);
+
+        ScriptValue call();
+        ScriptValue call(bool& hadException);
+
+    private:
+        ScriptValue m_function;
     };
 
 } // namespace WebCore

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list