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):

git-svn-id: svn://svn.chromium.org/blink/trunk@82940 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 92112644
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):
2011-04-05 Nikolas Zimmermann <nzimmermann@rim.com> 2011-04-05 Nikolas Zimmermann <nzimmermann@rim.com>
Reviewed by Andreas Kling. Reviewed by Andreas Kling.
...@@ -127,4 +127,9 @@ ScriptExecutionContext* getScriptExecutionContext() ...@@ -127,4 +127,9 @@ ScriptExecutionContext* getScriptExecutionContext()
return 0; return 0;
} }
void throwTypeMismatchException()
{
V8Proxy::throwError(V8Proxy::GeneralError, "TYPE_MISMATCH_ERR: DOM Exception 17");
}
} // namespace WebCore } // namespace WebCore
...@@ -55,6 +55,35 @@ namespace WebCore { ...@@ -55,6 +55,35 @@ namespace WebCore {
ScriptExecutionContext* getScriptExecutionContext(); ScriptExecutionContext* getScriptExecutionContext();
void throwTypeMismatchException();
enum CallbackAllowedValueFlag {
CallbackAllowFunction = 0,
CallbackAllowUndefined = 1,
CallbackAllowNull = 1 << 1
};
typedef unsigned CallbackAllowedValueFlags;
// 'FunctionOnly' is assumed for the created callback.
template <typename V8CallbackType>
PassRefPtr<V8CallbackType> createFunctionOnlyCallback(v8::Local<v8::Value> value, CallbackAllowedValueFlags acceptedValues, bool& succeeded)
{
succeeded = true;
if ((value->IsUndefined() && (acceptedValues & CallbackAllowUndefined))
|| (value->IsNull() && (acceptedValues & CallbackAllowNull)))
return 0;
if (!value->IsFunction()) {
succeeded = false;
throwTypeMismatchException();
return 0;
}
return V8CallbackType::create(value, getScriptExecutionContext());
}
class AllowAllocation { class AllowAllocation {
public: public:
inline AllowAllocation() inline AllowAllocation()
......
...@@ -33,52 +33,13 @@ ...@@ -33,52 +33,13 @@
#include "V8Binding.h" #include "V8Binding.h"
#include "V8CustomPositionCallback.h" #include "V8CustomPositionCallback.h"
#include "V8CustomPositionErrorCallback.h" #include "V8CustomPositionErrorCallback.h"
#include "V8Proxy.h" #include "V8Utilities.h"
using namespace std; using namespace std;
using namespace WTF; using namespace WTF;
namespace WebCore { namespace WebCore {
static const char typeMismatchError[] = "TYPE_MISMATCH_ERR: DOM Exception 17";
static void throwTypeMismatchException()
{
V8Proxy::throwError(V8Proxy::GeneralError, typeMismatchError);
}
static PassRefPtr<PositionCallback> createPositionCallback(v8::Local<v8::Value> value, bool& succeeded)
{
succeeded = true;
// The spec specifies 'FunctionOnly' for this object.
if (!value->IsFunction()) {
succeeded = false;
throwTypeMismatchException();
return 0;
}
return V8CustomPositionCallback::create(value, getScriptExecutionContext());
}
static PassRefPtr<PositionErrorCallback> createPositionErrorCallback(v8::Local<v8::Value> value, bool& succeeded)
{
succeeded = true;
// Argument is optional (hence undefined is allowed), and null is allowed.
if (isUndefinedOrNull(value))
return 0;
// The spec specifies 'FunctionOnly' for this object.
if (!value->IsFunction()) {
succeeded = false;
throwTypeMismatchException();
return 0;
}
return V8CustomPositionErrorCallback::create(value, getScriptExecutionContext());
}
static PassRefPtr<PositionOptions> createPositionOptions(v8::Local<v8::Value> value, bool& succeeded) static PassRefPtr<PositionOptions> createPositionOptions(v8::Local<v8::Value> value, bool& succeeded)
{ {
succeeded = true; succeeded = true;
...@@ -172,12 +133,13 @@ v8::Handle<v8::Value> V8Geolocation::getCurrentPositionCallback(const v8::Argume ...@@ -172,12 +133,13 @@ v8::Handle<v8::Value> V8Geolocation::getCurrentPositionCallback(const v8::Argume
bool succeeded = false; bool succeeded = false;
RefPtr<PositionCallback> positionCallback = createPositionCallback(args[0], succeeded); RefPtr<PositionCallback> positionCallback = createFunctionOnlyCallback<V8CustomPositionCallback>(args[0], CallbackAllowFunction, succeeded);
if (!succeeded) if (!succeeded)
return v8::Undefined(); return v8::Undefined();
ASSERT(positionCallback); ASSERT(positionCallback);
RefPtr<PositionErrorCallback> positionErrorCallback = createPositionErrorCallback(args[1], succeeded); // Argument is optional (hence undefined is allowed), and null is allowed.
RefPtr<PositionErrorCallback> positionErrorCallback = createFunctionOnlyCallback<V8CustomPositionErrorCallback>(args[1], CallbackAllowUndefined | CallbackAllowNull, succeeded);
if (!succeeded) if (!succeeded)
return v8::Undefined(); return v8::Undefined();
...@@ -197,12 +159,13 @@ v8::Handle<v8::Value> V8Geolocation::watchPositionCallback(const v8::Arguments& ...@@ -197,12 +159,13 @@ v8::Handle<v8::Value> V8Geolocation::watchPositionCallback(const v8::Arguments&
bool succeeded = false; bool succeeded = false;
RefPtr<PositionCallback> positionCallback = createPositionCallback(args[0], succeeded); RefPtr<PositionCallback> positionCallback = createFunctionOnlyCallback<V8CustomPositionCallback>(args[0], CallbackAllowFunction, succeeded);
if (!succeeded) if (!succeeded)
return v8::Undefined(); return v8::Undefined();
ASSERT(positionCallback); ASSERT(positionCallback);
RefPtr<PositionErrorCallback> positionErrorCallback = createPositionErrorCallback(args[1], succeeded); // Argument is optional (hence undefined is allowed), and null is allowed.
RefPtr<PositionErrorCallback> positionErrorCallback = createFunctionOnlyCallback<V8CustomPositionErrorCallback>(args[1], CallbackAllowUndefined | CallbackAllowNull, succeeded);
if (!succeeded) if (!succeeded)
return v8::Undefined(); return v8::Undefined();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment