Changeset 125324 in webkit


Ignore:
Timestamp:
Aug 10, 2012 1:40:11 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Introduce JavaScriptVariant object.
https://bugs.webkit.org/show_bug.cgi?id=93644

The JavaScriptVariant can be used for functions that return results from
JavaScript such as executeJavaScript or functions that take arguments
to pass a variable to JavaScript and they want to make sure the type
is correct.

Convert executeJavaScriptFunction() to use this data type as the
example, other functions will be converted in the future.

PR 14929

Internally reviewed by Joe Mason
Patch by Benjamin C Meyer <bmeyer@rim.com> on 2012-08-10
Reviewed by Adam Treat

Source/WebKit:

  • PlatformBlackBerry.cmake:

Source/WebKit/blackberry:

  • Api/JavaScriptVariant.cpp: Added.

(WebKit):
(BlackBerry::WebKit::JSValueRefToBlackBerryJavaScriptVariant):
(BlackBerry::WebKit::BlackBerryJavaScriptVariantToJSValueRef):
(BlackBerry::WebKit::JavaScriptVariant::JavaScriptVariant):
(BlackBerry::WebKit::JavaScriptVariant::~JavaScriptVariant):
(BlackBerry::WebKit::JavaScriptVariant::operator=):
(BlackBerry::WebKit::JavaScriptVariant::setType):
(BlackBerry::WebKit::JavaScriptVariant::type):
(BlackBerry::WebKit::JavaScriptVariant::setDouble):
(BlackBerry::WebKit::JavaScriptVariant::doubleValue):
(BlackBerry::WebKit::JavaScriptVariant::setString):
(BlackBerry::WebKit::JavaScriptVariant::stringValue):
(BlackBerry::WebKit::JavaScriptVariant::setBoolean):
(BlackBerry::WebKit::JavaScriptVariant::booleanValue):

  • Api/JavaScriptVariant.h: Added.

(WebKit):

  • Api/JavaScriptVariant_p.h: Added.

(WebKit):

  • Api/WebPage.cpp:

(BlackBerry::WebKit::WebPage::executeJavaScriptFunction):

  • Api/WebPage.h:
Location:
trunk/Source/WebKit
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r125300 r125324  
     12012-08-10  Benjamin C Meyer  <bmeyer@rim.com>
     2
     3        Introduce JavaScriptVariant object.
     4        https://bugs.webkit.org/show_bug.cgi?id=93644
     5
     6        The JavaScriptVariant can be used for functions that return results from
     7        JavaScript such as executeJavaScript or functions that take arguments
     8        to pass a variable to JavaScript and they want to make sure the type
     9        is correct.
     10
     11        Convert executeJavaScriptFunction() to use this data type as the
     12        example, other functions will be converted in the future.
     13
     14        PR 14929
     15
     16        Internally reviewed by Joe Mason
     17        Reviewed by Adam Treat
     18
     19        * PlatformBlackBerry.cmake:
     20
    1212012-08-10  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
    222
  • trunk/Source/WebKit/PlatformBlackBerry.cmake

    r125300 r125324  
    7070    blackberry/Api/WebString.cpp
    7171    blackberry/Api/WebViewportArguments.cpp
     72    blackberry/Api/JavaScriptVariant.cpp
    7273    blackberry/WebCoreSupport/AutofillManager.cpp
    7374    blackberry/WebCoreSupport/CacheClientBlackBerry.cpp
  • trunk/Source/WebKit/blackberry/Api/WebPage.cpp

    r125071 r125324  
    7979#include "InspectorOverlay.h"
    8080#include "JavaScriptDebuggerBlackBerry.h"
     81#include "JavaScriptVariant_p.h"
    8182#include "LayerWebKitThread.h"
    8283#include "NetworkManager.h"
     
    847848}
    848849
    849 bool WebPage::executeJavaScriptFunction(const std::vector<std::string> &function, const std::vector<std::string> &args, JavaScriptDataType& returnType, WebString& returnValue)
    850 {
    851     if (!d->m_mainFrame)
    852         return false;
     850void WebPage::executeJavaScriptFunction(const std::vector<std::string> &function, const std::vector<JavaScriptVariant> &args, JavaScriptVariant& returnValue)
     851{
     852    if (!d->m_mainFrame) {
     853        returnValue.setType(JavaScriptVariant::Exception);
     854        return;
     855    }
     856
    853857    JSC::Bindings::RootObject* root = d->m_mainFrame->script()->bindingRootObject();
    854     if (!root)
    855         return false;
     858    if (!root) {
     859        returnValue.setType(JavaScriptVariant::Exception);
     860        return;
     861    }
     862
    856863    JSC::ExecState* exec = root->globalObject()->globalExec();
    857864    JSGlobalContextRef ctx = toGlobalRef(exec);
    858865
    859     WTF::Vector<JSStringRef> argList(args.size());
    860866    WTF::Vector<JSValueRef> argListRef(args.size());
    861     for (unsigned i = 0; i < args.size(); ++i) {
    862         JSStringRef str = JSStringCreateWithUTF8CString(args[i].c_str());
    863         argList[i] = str;
    864         JSValueRef strRef = JSValueMakeString(ctx, str);
    865         argListRef[i] = strRef;
    866     }
     867    for (unsigned i = 0; i < args.size(); ++i)
     868        argListRef[i] = BlackBerryJavaScriptVariantToJSValueRef(ctx, args[i]);
    867869
    868870    JSValueRef windowObjectValue = windowObject();
     
    883885        result = JSObjectCallAsFunction(ctx, functionObject, thisObject, args.size(), argListRef.data(), 0);
    884886
    885     for (unsigned i = 0; i < args.size(); ++i)
    886         JSStringRelease(argList[i]);
    887 
    888887    JSC::JSValue value = toJS(exec, result);
    889 
    890888    if (!value) {
    891         returnType = JSException;
    892         return false;
    893     }
    894 
    895     JSType type = JSValueGetType(ctx, result);
    896 
    897     switch (type) {
    898     case kJSTypeNull:
    899         returnType = JSNull;
    900         break;
    901     case kJSTypeBoolean:
    902         returnType = JSBoolean;
    903         break;
    904     case kJSTypeNumber:
    905         returnType = JSNumber;
    906         break;
    907     case kJSTypeString:
    908         returnType = JSString;
    909         break;
    910     case kJSTypeObject:
    911         returnType = JSObject;
    912         break;
    913     case kJSTypeUndefined:
    914     default:
    915         returnType = JSUndefined;
    916         break;
    917     }
    918 
    919     if (returnType == JSBoolean || returnType == JSNumber || returnType == JSString || returnType == JSObject) {
    920         JSStringRef stringRef = JSValueToStringCopy(ctx, result, 0);
    921         size_t bufferSize = JSStringGetMaximumUTF8CStringSize(stringRef);
    922         WTF::Vector<char> buffer(bufferSize);
    923         JSStringGetUTF8CString(stringRef, buffer.data(), bufferSize);
    924         returnValue = WebString::fromUtf8(buffer.data());
    925     }
    926 
    927     return true;
     889        returnValue.setType(JavaScriptVariant::Exception);
     890        return;
     891    }
     892
     893    returnValue = JSValueRefToBlackBerryJavaScriptVariant(ctx, result);
    928894}
    929895
  • trunk/Source/WebKit/blackberry/Api/WebPage.h

    r125071 r125324  
    2121
    2222#include "BlackBerryGlobal.h"
     23#include "JavaScriptVariant.h"
    2324#include "WebString.h"
    2425
     
    107108    bool executeJavaScriptInIsolatedWorld(const std::wstring& script, JavaScriptDataType& returnType, WebString& returnValue);
    108109
    109     bool executeJavaScriptFunction(const std::vector<std::string> &script, const std::vector<std::string> &args, JavaScriptDataType& returnType, WebString& returnValue);
     110    void executeJavaScriptFunction(const std::vector<std::string> &function, const std::vector<JavaScriptVariant> &args, JavaScriptVariant& returnValue);
    110111
    111112    void initializeIconDataBase();
  • trunk/Source/WebKit/blackberry/ChangeLog

    r125207 r125324  
     12012-08-10  Benjamin C Meyer  <bmeyer@rim.com>
     2
     3        Introduce JavaScriptVariant object.
     4        https://bugs.webkit.org/show_bug.cgi?id=93644
     5
     6        The JavaScriptVariant can be used for functions that return results from
     7        JavaScript such as executeJavaScript or functions that take arguments
     8        to pass a variable to JavaScript and they want to make sure the type
     9        is correct.
     10
     11        Convert executeJavaScriptFunction() to use this data type as the
     12        example, other functions will be converted in the future.
     13
     14        PR 14929
     15
     16        Internally reviewed by Joe Mason
     17        Reviewed by Adam Treat
     18
     19        * Api/JavaScriptVariant.cpp: Added.
     20        (WebKit):
     21        (BlackBerry::WebKit::JSValueRefToBlackBerryJavaScriptVariant):
     22        (BlackBerry::WebKit::BlackBerryJavaScriptVariantToJSValueRef):
     23        (BlackBerry::WebKit::JavaScriptVariant::JavaScriptVariant):
     24        (BlackBerry::WebKit::JavaScriptVariant::~JavaScriptVariant):
     25        (BlackBerry::WebKit::JavaScriptVariant::operator=):
     26        (BlackBerry::WebKit::JavaScriptVariant::setType):
     27        (BlackBerry::WebKit::JavaScriptVariant::type):
     28        (BlackBerry::WebKit::JavaScriptVariant::setDouble):
     29        (BlackBerry::WebKit::JavaScriptVariant::doubleValue):
     30        (BlackBerry::WebKit::JavaScriptVariant::setString):
     31        (BlackBerry::WebKit::JavaScriptVariant::stringValue):
     32        (BlackBerry::WebKit::JavaScriptVariant::setBoolean):
     33        (BlackBerry::WebKit::JavaScriptVariant::booleanValue):
     34        * Api/JavaScriptVariant.h: Added.
     35        (WebKit):
     36        * Api/JavaScriptVariant_p.h: Added.
     37        (WebKit):
     38        * Api/WebPage.cpp:
     39        (BlackBerry::WebKit::WebPage::executeJavaScriptFunction):
     40        * Api/WebPage.h:
     41
    1422012-08-09  Leo Yang  <leoyang@rim.com>
    243
Note: See TracChangeset for help on using the changeset viewer.