| Index: Source/bindings/core/v8/V8Binding.h
|
| diff --git a/Source/bindings/core/v8/V8Binding.h b/Source/bindings/core/v8/V8Binding.h
|
| index 79ea8a9ce8f5e0c03dcab8a20c715d96e73aac26..d4c9550fa9fe4316d7c4e5cd7010626ce222edd2 100644
|
| --- a/Source/bindings/core/v8/V8Binding.h
|
| +++ b/Source/bindings/core/v8/V8Binding.h
|
| @@ -34,6 +34,7 @@
|
|
|
| #include "bindings/core/v8/DOMWrapperWorld.h"
|
| #include "bindings/core/v8/ExceptionMessages.h"
|
| +#include "bindings/core/v8/ExceptionState.h"
|
| #include "bindings/core/v8/ScriptValue.h"
|
| #include "bindings/core/v8/ScriptWrappable.h"
|
| #include "bindings/core/v8/V8BindingMacros.h"
|
| @@ -535,6 +536,9 @@ inline float toFloat(v8::Local<v8::Value> value)
|
| return static_cast<float>(value->NumberValue());
|
| }
|
|
|
| +bool toBoolean(v8::Handle<v8::Value>, ExceptionState&);
|
| +double toDouble(v8::Handle<v8::Value>, ExceptionState&);
|
| +
|
| // Converts a value to a String, throwing if any code unit is outside 0-255.
|
| String toByteString(v8::Handle<v8::Value>, ExceptionState&);
|
|
|
| @@ -568,12 +572,47 @@ PassRefPtrWillBeRawPtr<XPathNSResolver> toXPathNSResolver(v8::Handle<v8::Value>,
|
| template<class T> struct NativeValueTraits;
|
|
|
| template<>
|
| +struct NativeValueTraits<bool> {
|
| + static inline bool nativeValueMayFail(v8::Isolate* isolate, const v8::Handle<v8::Value>& value, ExceptionState& exceptionState)
|
| + {
|
| + return toBoolean(value, exceptionState);
|
| + }
|
| +};
|
| +
|
| +template<>
|
| struct NativeValueTraits<String> {
|
| static inline String nativeValue(const v8::Handle<v8::Value>& value, v8::Isolate* isolate)
|
| {
|
| TOSTRING_DEFAULT(V8StringResource<>, stringValue, value, String());
|
| return stringValue;
|
| }
|
| + static inline String nativeValueMayFail(v8::Isolate* isolate, const v8::Handle<v8::Value>& value, ExceptionState& exceptionState)
|
| + {
|
| + // FIXME: handle failure
|
| + TOSTRING_DEFAULT(V8StringResource<>, stringValue, value, String());
|
| + return stringValue;
|
| + }
|
| +};
|
| +
|
| +template<>
|
| +struct NativeValueTraits<AtomicString> {
|
| + static inline AtomicString nativeValueMayFail(v8::Isolate* isolate, const v8::Handle<v8::Value>& value, ExceptionState& exceptionState)
|
| + {
|
| + TOSTRING_DEFAULT(V8StringResource<>, stringValue, value, AtomicString());
|
| + return stringValue;
|
| + }
|
| +};
|
| +
|
| +template<>
|
| +struct NativeValueTraits<int> {
|
| + static inline int nativeValue(const v8::Handle<v8::Value>& value, v8::Isolate* isolate)
|
| + {
|
| + return toInt32(value);
|
| + }
|
| + static inline int nativeValueMayFail(v8::Isolate* isolate, const v8::Handle<v8::Value>& value, ExceptionState& exceptionState)
|
| + {
|
| + return toInt32(value, NormalConversion, exceptionState);
|
| + }
|
| };
|
|
|
| template<>
|
| @@ -582,6 +621,58 @@ struct NativeValueTraits<unsigned> {
|
| {
|
| return toUInt32(value);
|
| }
|
| + static inline unsigned nativeValueMayFail(v8::Isolate* isolate, const v8::Handle<v8::Value>& value, ExceptionState& exceptionState)
|
| + {
|
| + return toUInt32(value, NormalConversion, exceptionState);
|
| + }
|
| +};
|
| +
|
| +template<>
|
| +struct NativeValueTraits<unsigned long> {
|
| + static inline unsigned long nativeValue(const v8::Handle<v8::Value>& value, v8::Isolate* isolate)
|
| + {
|
| + return toUInt32(value);
|
| + }
|
| + static inline unsigned long nativeValueMayFail(v8::Isolate* isolate, const v8::Handle<v8::Value>& value, ExceptionState& exceptionState)
|
| + {
|
| + return toUInt32(value, NormalConversion, exceptionState);
|
| + }
|
| +};
|
| +
|
| +template<>
|
| +struct NativeValueTraits<unsigned long long> {
|
| + static inline unsigned long long nativeValue(const v8::Handle<v8::Value>& value, v8::Isolate* isolate)
|
| + {
|
| + return toUInt64(value);
|
| + }
|
| + static inline unsigned long long nativeValueMayFail(v8::Isolate* isolate, const v8::Handle<v8::Value>& value, ExceptionState& exceptionState)
|
| + {
|
| + return toUInt64(value, NormalConversion, exceptionState);
|
| + }
|
| +};
|
| +
|
| +template<>
|
| +struct NativeValueTraits<short> {
|
| + static inline short nativeValue(const v8::Handle<v8::Value>& value, v8::Isolate* isolate)
|
| + {
|
| + return toInt16(value);
|
| + }
|
| + static inline short nativeValueMayFail(v8::Isolate* isolate, const v8::Handle<v8::Value>& value, ExceptionState& exceptionState)
|
| + {
|
| + return toInt16(value, NormalConversion, exceptionState);
|
| + }
|
| +};
|
| +
|
| +template<>
|
| +struct NativeValueTraits<unsigned short> {
|
| + static inline unsigned short nativeValue(const v8::Handle<v8::Value>& value, v8::Isolate* isolate)
|
| + {
|
| + return toUInt16(value);
|
| + }
|
| + static inline unsigned short nativeValueMayFail(v8::Isolate* isolate, const v8::Handle<v8::Value>& value, ExceptionState& exceptionState)
|
| + {
|
| + return toUInt16(value, NormalConversion, exceptionState);
|
| + }
|
| };
|
|
|
| template<>
|
| @@ -590,6 +681,10 @@ struct NativeValueTraits<float> {
|
| {
|
| return static_cast<float>(value->NumberValue());
|
| }
|
| + static inline float nativeValueMayFail(v8::Isolate* isolate, const v8::Handle<v8::Value>& value, ExceptionState& exceptionState)
|
| + {
|
| + return toFloat(value, exceptionState);
|
| + }
|
| };
|
|
|
| template<>
|
| @@ -598,6 +693,10 @@ struct NativeValueTraits<double> {
|
| {
|
| return static_cast<double>(value->NumberValue());
|
| }
|
| + static inline double nativeValueMayFail(v8::Isolate* isolate, const v8::Handle<v8::Value>& value, ExceptionState& exceptionState)
|
| + {
|
| + return toDouble(value, exceptionState);
|
| + }
|
| };
|
|
|
| template<>
|
| @@ -614,6 +713,10 @@ struct NativeValueTraits<ScriptValue> {
|
| {
|
| return ScriptValue(ScriptState::current(isolate), value);
|
| }
|
| + static inline ScriptValue nativeValueMayFail(v8::Isolate* isolate, const v8::Handle<v8::Value>& value, ExceptionState& exceptionState)
|
| + {
|
| + return ScriptValue(ScriptState::current(isolate), value);
|
| + }
|
| };
|
|
|
| v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value>, uint32_t& length, v8::Isolate*);
|
| @@ -676,17 +779,17 @@ Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, const String
|
| }
|
|
|
| template <class T, class V8T>
|
| -WillBeHeapVector<RefPtrWillBeMember<T> > toRefPtrWillBeMemberNativeArray(v8::Handle<v8::Value> value, int argumentIndex, v8::Isolate* isolate, bool* success = 0)
|
| +WillBeHeapVector<RefPtrWillBeMember<T> > toRefPtrWillBeMemberNativeArray(v8::Handle<v8::Value> value, int argumentIndex, v8::Isolate* isolate, ExceptionState* exceptionState = 0)
|
| {
|
| - if (success)
|
| - *success = true;
|
| -
|
| v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value));
|
| uint32_t length = 0;
|
| if (value->IsArray()) {
|
| length = v8::Local<v8::Array>::Cast(v8Value)->Length();
|
| } else if (toV8Sequence(value, length, isolate).IsEmpty()) {
|
| - V8ThrowException::throwTypeError(ExceptionMessages::notAnArrayTypeArgumentOrValue(argumentIndex), isolate);
|
| + if (exceptionState)
|
| + exceptionState->throwTypeError(ExceptionMessages::notAnArrayTypeArgumentOrValue(argumentIndex));
|
| + else
|
| + V8ThrowException::throwTypeError(ExceptionMessages::notAnArrayTypeArgumentOrValue(argumentIndex), isolate);
|
| return WillBeHeapVector<RefPtrWillBeMember<T> >();
|
| }
|
|
|
| @@ -699,9 +802,10 @@ WillBeHeapVector<RefPtrWillBeMember<T> > toRefPtrWillBeMemberNativeArray(v8::Han
|
| v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(element);
|
| result.uncheckedAppend(V8T::toImpl(elementObject));
|
| } else {
|
| - if (success)
|
| - *success = false;
|
| - V8ThrowException::throwTypeError("Invalid Array element type", isolate);
|
| + if (exceptionState)
|
| + exceptionState->throwTypeError("Invalid Array element type");
|
| + else
|
| + V8ThrowException::throwTypeError("Invalid Array element type", isolate);
|
| return WillBeHeapVector<RefPtrWillBeMember<T> >();
|
| }
|
| }
|
| @@ -709,17 +813,17 @@ WillBeHeapVector<RefPtrWillBeMember<T> > toRefPtrWillBeMemberNativeArray(v8::Han
|
| }
|
|
|
| template <class T, class V8T>
|
| -WillBeHeapVector<RefPtrWillBeMember<T> > toRefPtrWillBeMemberNativeArray(v8::Handle<v8::Value> value, const String& propertyName, v8::Isolate* isolate, bool* success = 0)
|
| +WillBeHeapVector<RefPtrWillBeMember<T> > toRefPtrWillBeMemberNativeArray(v8::Handle<v8::Value> value, const String& propertyName, v8::Isolate* isolate, ExceptionState* exceptionState = 0)
|
| {
|
| - if (success)
|
| - *success = true;
|
| -
|
| v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value));
|
| uint32_t length = 0;
|
| if (value->IsArray()) {
|
| length = v8::Local<v8::Array>::Cast(v8Value)->Length();
|
| } else if (toV8Sequence(value, length, isolate).IsEmpty()) {
|
| - V8ThrowException::throwTypeError(ExceptionMessages::notASequenceTypeProperty(propertyName), isolate);
|
| + if (exceptionState)
|
| + exceptionState->throwTypeError(ExceptionMessages::notASequenceTypeProperty(propertyName));
|
| + else
|
| + V8ThrowException::throwTypeError(ExceptionMessages::notASequenceTypeProperty(propertyName), isolate);
|
| return WillBeHeapVector<RefPtrWillBeMember<T> >();
|
| }
|
|
|
| @@ -732,9 +836,10 @@ WillBeHeapVector<RefPtrWillBeMember<T> > toRefPtrWillBeMemberNativeArray(v8::Han
|
| v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(element);
|
| result.uncheckedAppend(V8T::toImpl(elementObject));
|
| } else {
|
| - if (success)
|
| - *success = false;
|
| - V8ThrowException::throwTypeError("Invalid Array element type", isolate);
|
| + if (exceptionState)
|
| + exceptionState->throwTypeError("Invalid Array element type");
|
| + else
|
| + V8ThrowException::throwTypeError("Invalid Array element type", isolate);
|
| return WillBeHeapVector<RefPtrWillBeMember<T> >();
|
| }
|
| }
|
|
|