Changeset 82940 in webkit


Ignore:
Timestamp:
Apr 5, 2011 8:10:18 AM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2011-04-05 Leandro Gracia Gil <leandrogracia@chromium.org>

Reviewed by Steve Block.

Factoring the creation of 'FunctionOnly' callbacks in V8.
https://bugs.webkit.org/show_bug.cgi?id=57760

This method creates a template from an existing functionality in V8GeolocationCustom.cpp
to V8Utilities to be used by the custom bindings of both Geolocation and the Media Stream API.

No new tests. LayoutTests/fast/dom/Geolocation/argument-types.html

  • bindings/v8/V8Utilities.cpp: (WebCore::throwTypeMismatchException):
  • bindings/v8/V8Utilities.h: (WebCore::createFunctionOnlyCallback):
  • bindings/v8/custom/V8GeolocationCustom.cpp: (WebCore::V8Geolocation::getCurrentPositionCallback): (WebCore::V8Geolocation::watchPositionCallback):
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r82935 r82940  
     12011-04-05  Leandro Gracia Gil  <leandrogracia@chromium.org>
     2
     3        Reviewed by Steve Block.
     4
     5        Factoring the creation of 'FunctionOnly' callbacks in V8.
     6        https://bugs.webkit.org/show_bug.cgi?id=57760
     7
     8        This method creates a template from an existing functionality in V8GeolocationCustom.cpp
     9        to V8Utilities to be used by the custom bindings of both Geolocation and the Media Stream API.
     10
     11        No new tests. LayoutTests/fast/dom/Geolocation/argument-types.html
     12
     13        * bindings/v8/V8Utilities.cpp:
     14        (WebCore::throwTypeMismatchException):
     15        * bindings/v8/V8Utilities.h:
     16        (WebCore::createFunctionOnlyCallback):
     17        * bindings/v8/custom/V8GeolocationCustom.cpp:
     18        (WebCore::V8Geolocation::getCurrentPositionCallback):
     19        (WebCore::V8Geolocation::watchPositionCallback):
     20
    1212011-04-05  Nikolas Zimmermann  <nzimmermann@rim.com>
    222
  • trunk/Source/WebCore/bindings/v8/V8Utilities.cpp

    r74833 r82940  
    128128}
    129129
     130void throwTypeMismatchException()
     131{
     132    V8Proxy::throwError(V8Proxy::GeneralError, "TYPE_MISMATCH_ERR: DOM Exception 17");
     133}
     134
    130135} // namespace WebCore
  • trunk/Source/WebCore/bindings/v8/V8Utilities.h

    r74833 r82940  
    5656    ScriptExecutionContext* getScriptExecutionContext();
    5757
     58    void throwTypeMismatchException();
     59
     60    enum CallbackAllowedValueFlag {
     61        CallbackAllowFunction = 0,
     62        CallbackAllowUndefined = 1,
     63        CallbackAllowNull = 1 << 1
     64    };
     65
     66    typedef unsigned CallbackAllowedValueFlags;
     67
     68    // 'FunctionOnly' is assumed for the created callback.
     69    template <typename V8CallbackType>
     70    PassRefPtr<V8CallbackType> createFunctionOnlyCallback(v8::Local<v8::Value> value, CallbackAllowedValueFlags acceptedValues, bool& succeeded)
     71    {
     72        succeeded = true;
     73
     74        if ((value->IsUndefined() && (acceptedValues & CallbackAllowUndefined))
     75            || (value->IsNull() && (acceptedValues & CallbackAllowNull)))
     76            return 0;
     77
     78        if (!value->IsFunction()) {
     79            succeeded = false;
     80            throwTypeMismatchException();
     81            return 0;
     82        }
     83
     84        return V8CallbackType::create(value, getScriptExecutionContext());
     85    }
     86
    5887    class AllowAllocation {
    5988    public:
  • trunk/Source/WebCore/bindings/v8/custom/V8GeolocationCustom.cpp

    r65199 r82940  
    3434#include "V8CustomPositionCallback.h"
    3535#include "V8CustomPositionErrorCallback.h"
    36 #include "V8Proxy.h"
     36#include "V8Utilities.h"
    3737
    3838using namespace std;
     
    4040
    4141namespace WebCore {
    42 
    43 static const char typeMismatchError[] = "TYPE_MISMATCH_ERR: DOM Exception 17";
    44 
    45 static void throwTypeMismatchException()
    46 {
    47     V8Proxy::throwError(V8Proxy::GeneralError, typeMismatchError);
    48 }
    49 
    50 static PassRefPtr<PositionCallback> createPositionCallback(v8::Local<v8::Value> value, bool& succeeded)
    51 {
    52     succeeded = true;
    53 
    54     // The spec specifies 'FunctionOnly' for this object.
    55     if (!value->IsFunction()) {
    56         succeeded = false;
    57         throwTypeMismatchException();
    58         return 0;
    59     }
    60 
    61     return V8CustomPositionCallback::create(value, getScriptExecutionContext());
    62 }
    63 
    64 static PassRefPtr<PositionErrorCallback> createPositionErrorCallback(v8::Local<v8::Value> value, bool& succeeded)
    65 {
    66     succeeded = true;
    67 
    68     // Argument is optional (hence undefined is allowed), and null is allowed.
    69     if (isUndefinedOrNull(value))
    70         return 0;
    71 
    72     // The spec specifies 'FunctionOnly' for this object.
    73     if (!value->IsFunction()) {
    74         succeeded = false;
    75         throwTypeMismatchException();
    76         return 0;
    77     }
    78 
    79     return V8CustomPositionErrorCallback::create(value, getScriptExecutionContext());
    80 }
    8142
    8243static PassRefPtr<PositionOptions> createPositionOptions(v8::Local<v8::Value> value, bool& succeeded)
     
    173134    bool succeeded = false;
    174135
    175     RefPtr<PositionCallback> positionCallback = createPositionCallback(args[0], succeeded);
     136    RefPtr<PositionCallback> positionCallback = createFunctionOnlyCallback<V8CustomPositionCallback>(args[0], CallbackAllowFunction, succeeded);
    176137    if (!succeeded)
    177138        return v8::Undefined();
    178139    ASSERT(positionCallback);
    179140
    180     RefPtr<PositionErrorCallback> positionErrorCallback = createPositionErrorCallback(args[1], succeeded);
     141    // Argument is optional (hence undefined is allowed), and null is allowed.
     142    RefPtr<PositionErrorCallback> positionErrorCallback = createFunctionOnlyCallback<V8CustomPositionErrorCallback>(args[1], CallbackAllowUndefined | CallbackAllowNull, succeeded);
    181143    if (!succeeded)
    182144        return v8::Undefined();
     
    198160    bool succeeded = false;
    199161
    200     RefPtr<PositionCallback> positionCallback = createPositionCallback(args[0], succeeded);
     162    RefPtr<PositionCallback> positionCallback = createFunctionOnlyCallback<V8CustomPositionCallback>(args[0], CallbackAllowFunction, succeeded);
    201163    if (!succeeded)
    202164        return v8::Undefined();
    203165    ASSERT(positionCallback);
    204166
    205     RefPtr<PositionErrorCallback> positionErrorCallback = createPositionErrorCallback(args[1], succeeded);
     167    // Argument is optional (hence undefined is allowed), and null is allowed.
     168    RefPtr<PositionErrorCallback> positionErrorCallback = createFunctionOnlyCallback<V8CustomPositionErrorCallback>(args[1], CallbackAllowUndefined | CallbackAllowNull, succeeded);
    206169    if (!succeeded)
    207170        return v8::Undefined();
Note: See TracChangeset for help on using the changeset viewer.