diff options
Diffstat (limited to 'Source/WebCore/bindings/v8/V8Utilities.h')
-rw-r--r-- | Source/WebCore/bindings/v8/V8Utilities.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Source/WebCore/bindings/v8/V8Utilities.h b/Source/WebCore/bindings/v8/V8Utilities.h index 1892bb7..4a44f3c 100644 --- a/Source/WebCore/bindings/v8/V8Utilities.h +++ b/Source/WebCore/bindings/v8/V8Utilities.h @@ -55,6 +55,36 @@ namespace WebCore { ScriptExecutionContext* getScriptExecutionContext(); + void throwTypeMismatchException(); + + enum CallbackAllowedValueFlag { + 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, bool& succeeded, CallbackAllowedValueFlags acceptedValues = 0) + { + succeeded = true; + + if (value->IsUndefined() && (acceptedValues & CallbackAllowUndefined)) + return 0; + + if (value->IsNull() && (acceptedValues & CallbackAllowNull)) + return 0; + + if (!value->IsFunction()) { + succeeded = false; + throwTypeMismatchException(); + return 0; + } + + return V8CallbackType::create(value, getScriptExecutionContext()); + } + class AllowAllocation { public: inline AllowAllocation() |