Changeset 82940 in webkit
- Timestamp:
- Apr 5, 2011 8:10:18 AM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r82935 r82940 1 2011-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 1 21 2011-04-05 Nikolas Zimmermann <nzimmermann@rim.com> 2 22 -
trunk/Source/WebCore/bindings/v8/V8Utilities.cpp
r74833 r82940 128 128 } 129 129 130 void throwTypeMismatchException() 131 { 132 V8Proxy::throwError(V8Proxy::GeneralError, "TYPE_MISMATCH_ERR: DOM Exception 17"); 133 } 134 130 135 } // namespace WebCore -
trunk/Source/WebCore/bindings/v8/V8Utilities.h
r74833 r82940 56 56 ScriptExecutionContext* getScriptExecutionContext(); 57 57 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 58 87 class AllowAllocation { 59 88 public: -
trunk/Source/WebCore/bindings/v8/custom/V8GeolocationCustom.cpp
r65199 r82940 34 34 #include "V8CustomPositionCallback.h" 35 35 #include "V8CustomPositionErrorCallback.h" 36 #include "V8 Proxy.h"36 #include "V8Utilities.h" 37 37 38 38 using namespace std; … … 40 40 41 41 namespace 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 }81 42 82 43 static PassRefPtr<PositionOptions> createPositionOptions(v8::Local<v8::Value> value, bool& succeeded) … … 173 134 bool succeeded = false; 174 135 175 RefPtr<PositionCallback> positionCallback = create PositionCallback(args[0], succeeded);136 RefPtr<PositionCallback> positionCallback = createFunctionOnlyCallback<V8CustomPositionCallback>(args[0], CallbackAllowFunction, succeeded); 176 137 if (!succeeded) 177 138 return v8::Undefined(); 178 139 ASSERT(positionCallback); 179 140 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); 181 143 if (!succeeded) 182 144 return v8::Undefined(); … … 198 160 bool succeeded = false; 199 161 200 RefPtr<PositionCallback> positionCallback = create PositionCallback(args[0], succeeded);162 RefPtr<PositionCallback> positionCallback = createFunctionOnlyCallback<V8CustomPositionCallback>(args[0], CallbackAllowFunction, succeeded); 201 163 if (!succeeded) 202 164 return v8::Undefined(); 203 165 ASSERT(positionCallback); 204 166 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); 206 169 if (!succeeded) 207 170 return v8::Undefined();
Note: See TracChangeset
for help on using the changeset viewer.