summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/WebKit/Source/bindings/v8/Dictionary.h
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/WebKit/Source/bindings/v8/Dictionary.h')
-rw-r--r--chromium/third_party/WebKit/Source/bindings/v8/Dictionary.h131
1 files changed, 77 insertions, 54 deletions
diff --git a/chromium/third_party/WebKit/Source/bindings/v8/Dictionary.h b/chromium/third_party/WebKit/Source/bindings/v8/Dictionary.h
index 3f29651e876..2268c63bd2f 100644
--- a/chromium/third_party/WebKit/Source/bindings/v8/Dictionary.h
+++ b/chromium/third_party/WebKit/Source/bindings/v8/Dictionary.h
@@ -28,6 +28,7 @@
#include "bindings/v8/ExceptionMessages.h"
#include "bindings/v8/ExceptionState.h"
+#include "bindings/v8/Nullable.h"
#include "bindings/v8/ScriptValue.h"
#include "bindings/v8/V8Binding.h"
#include "bindings/v8/V8BindingMacros.h"
@@ -44,12 +45,14 @@ namespace WebCore {
class ArrayValue;
class DOMError;
-class DOMWindow;
+class LocalDOMWindow;
+class Gamepad;
+class MediaStream;
+class HeaderMap;
class IDBKeyRange;
class MIDIPort;
class MediaKeyError;
class Notification;
-class SpeechRecognitionError;
class SpeechRecognitionResult;
class SpeechRecognitionResultList;
class Storage;
@@ -57,6 +60,7 @@ class TrackBase;
class VoidCallback;
class Dictionary {
+ ALLOW_ONLY_INLINE_ALLOCATION();
public:
Dictionary();
Dictionary(const v8::Handle<v8::Value>& options, v8::Isolate*);
@@ -72,32 +76,33 @@ public:
bool get(const String&, double&, bool& hasValue) const;
bool get(const String&, double&) const;
bool get(const String&, String&) const;
+ bool get(const String&, AtomicString&) const;
bool get(const String&, ScriptValue&) const;
bool get(const String&, short&) const;
bool get(const String&, unsigned short&) const;
bool get(const String&, unsigned&) const;
bool get(const String&, unsigned long&) const;
bool get(const String&, unsigned long long&) const;
- bool get(const String&, RefPtr<DOMWindow>&) const;
- bool get(const String&, RefPtr<Storage>&) const;
+ bool get(const String&, RefPtrWillBeMember<LocalDOMWindow>&) const;
+ bool get(const String&, RefPtrWillBeMember<Storage>&) const;
bool get(const String&, MessagePortArray&) const;
bool get(const String&, RefPtr<Uint8Array>&) const;
bool get(const String&, RefPtr<ArrayBufferView>&) const;
- bool get(const String&, RefPtr<MIDIPort>&) const;
+ bool get(const String&, RefPtrWillBeMember<MIDIPort>&) const;
bool get(const String&, RefPtr<MediaKeyError>&) const;
- bool get(const String&, RefPtr<TrackBase>&) const;
- bool get(const String&, RefPtr<SpeechRecognitionError>&) const;
- bool get(const String&, RefPtr<SpeechRecognitionResult>&) const;
- bool get(const String&, RefPtr<SpeechRecognitionResultList>&) const;
+ bool get(const String&, RefPtrWillBeMember<TrackBase>&) const;
+ bool get(const String&, Member<SpeechRecognitionResult>&) const;
+ bool get(const String&, Member<SpeechRecognitionResultList>&) const;
+ bool get(const String&, Member<Gamepad>&) const;
bool get(const String&, RefPtr<MediaStream>&) const;
- bool get(const String&, RefPtr<EventTarget>&) const;
+ bool get(const String&, RefPtrWillBeMember<EventTarget>&) const;
bool get(const String&, HashSet<AtomicString>&) const;
bool get(const String&, Dictionary&) const;
bool get(const String&, Vector<String>&) const;
bool get(const String&, ArrayValue&) const;
- bool get(const String&, RefPtr<DOMError>&) const;
- bool get(const String&, OwnPtr<VoidCallback>&) const;
+ bool get(const String&, RefPtrWillBeMember<DOMError>&) const;
bool get(const String&, v8::Local<v8::Value>&) const;
+ bool get(const String&, RefPtr<HeaderMap>&) const;
class ConversionContext {
public:
@@ -152,14 +157,20 @@ public:
bool convert(ConversionContext&, const String&, ScriptValue&) const;
template<typename IntegralType>
- bool convert(ConversionContext &, const String&, IntegralType&) const;
- bool convert(ConversionContext &, const String&, MessagePortArray&) const;
- bool convert(ConversionContext &, const String&, HashSet<AtomicString>&) const;
- bool convert(ConversionContext &, const String&, Dictionary&) const;
- bool convert(ConversionContext &, const String&, Vector<String>&) const;
- bool convert(ConversionContext &, const String&, ArrayValue&) const;
- template<typename T>
- bool convert(ConversionContext &, const String&, RefPtr<T>&) const;
+ bool convert(ConversionContext&, const String&, IntegralType&) const;
+ template<typename IntegralType>
+ bool convert(ConversionContext&, const String&, Nullable<IntegralType>&) const;
+
+ bool convert(ConversionContext&, const String&, MessagePortArray&) const;
+ bool convert(ConversionContext&, const String&, HashSet<AtomicString>&) const;
+ bool convert(ConversionContext&, const String&, Dictionary&) const;
+ bool convert(ConversionContext&, const String&, Vector<String>&) const;
+ bool convert(ConversionContext&, const String&, ArrayValue&) const;
+ template<template <typename> class PointerType, typename T>
+ bool convert(ConversionContext&, const String&, PointerType<T>&) const;
+
+ template<typename StringType>
+ bool getStringType(const String&, StringType&) const;
bool getOwnPropertiesAsStringHashMap(HashMap<String, String>&) const;
bool getOwnPropertyNames(Vector<String>&) const;
@@ -168,13 +179,7 @@ public:
bool hasProperty(const String&) const;
- // Only allow inline allocation.
- void* operator new(size_t, NotNullTag, void* location) { return location; }
-
private:
- // Disallow new allocation.
- void* operator new(size_t);
-
bool getKey(const String& key, v8::Local<v8::Value>&) const;
v8::Handle<v8::Value> m_options;
@@ -195,90 +200,90 @@ struct IntegralTypeTraits {
template <>
struct IntegralTypeTraits<uint8_t> {
- static inline uint8_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, bool& ok)
+ static inline uint8_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState)
{
- return toUInt8(value, configuration, ok);
+ return toUInt8(value, configuration, exceptionState);
}
static const String typeName() { return "UInt8"; }
};
template <>
struct IntegralTypeTraits<int8_t> {
- static inline int8_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, bool& ok)
+ static inline int8_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState)
{
- return toInt8(value, configuration, ok);
+ return toInt8(value, configuration, exceptionState);
}
static const String typeName() { return "Int8"; }
};
template <>
struct IntegralTypeTraits<unsigned short> {
- static inline uint16_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, bool& ok)
+ static inline uint16_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState)
{
- return toUInt16(value, configuration, ok);
+ return toUInt16(value, configuration, exceptionState);
}
static const String typeName() { return "UInt16"; }
};
template <>
struct IntegralTypeTraits<short> {
- static inline int16_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, bool& ok)
+ static inline int16_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState)
{
- return toInt16(value, configuration, ok);
+ return toInt16(value, configuration, exceptionState);
}
static const String typeName() { return "Int16"; }
};
template <>
struct IntegralTypeTraits<unsigned> {
- static inline uint32_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, bool& ok)
+ static inline uint32_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState)
{
- return toUInt32(value, configuration, ok);
+ return toUInt32(value, configuration, exceptionState);
}
static const String typeName() { return "UInt32"; }
};
template <>
struct IntegralTypeTraits<unsigned long> {
- static inline uint32_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, bool& ok)
+ static inline uint32_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState)
{
- return toUInt32(value, configuration, ok);
+ return toUInt32(value, configuration, exceptionState);
}
static const String typeName() { return "UInt32"; }
};
template <>
struct IntegralTypeTraits<int> {
- static inline int32_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, bool& ok)
+ static inline int32_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState)
{
- return toInt32(value, configuration, ok);
+ return toInt32(value, configuration, exceptionState);
}
static const String typeName() { return "Int32"; }
};
template <>
struct IntegralTypeTraits<long> {
- static inline int32_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, bool& ok)
+ static inline int32_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState)
{
- return toInt32(value, configuration, ok);
+ return toInt32(value, configuration, exceptionState);
}
static const String typeName() { return "Int32"; }
};
template <>
struct IntegralTypeTraits<unsigned long long> {
- static inline unsigned long long toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, bool& ok)
+ static inline unsigned long long toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState)
{
- return toUInt64(value, configuration, ok);
+ return toUInt64(value, configuration, exceptionState);
}
static const String typeName() { return "UInt64"; }
};
template <>
struct IntegralTypeTraits<long long> {
- static inline long long toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, bool& ok)
+ static inline long long toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState)
{
- return toInt64(value, configuration, ok);
+ return toInt64(value, configuration, exceptionState);
}
static const String typeName() { return "Int64"; }
};
@@ -291,18 +296,36 @@ template<typename T> bool Dictionary::convert(ConversionContext& context, const
if (!getKey(key, v8Value))
return true;
- bool ok = false;
- value = IntegralTypeTraits<T>::toIntegral(v8Value, NormalConversion, ok);
- if (ok)
+ value = IntegralTypeTraits<T>::toIntegral(v8Value, NormalConversion, context.exceptionState());
+ if (context.exceptionState().throwIfNeeded())
+ return false;
+
+ return true;
+}
+
+template<typename T> bool Dictionary::convert(ConversionContext& context, const String& key, Nullable<T>& value) const
+{
+ ConversionContextScope scope(context);
+
+ v8::Local<v8::Value> v8Value;
+ if (!getKey(key, v8Value))
return true;
- V8TRYCATCH_RETURN(v8::Local<v8::Number>, v8Number, v8Value->ToNumber(), false);
- ASSERT(v8Number.IsEmpty());
- context.throwTypeError(ExceptionMessages::incorrectPropertyType(key, "does not have type " + IntegralTypeTraits<T>::typeName() + "."));
- return false;
+ if (context.isNullable() && WebCore::isUndefinedOrNull(v8Value)) {
+ value = Nullable<T>();
+ return true;
+ }
+
+ T converted = IntegralTypeTraits<T>::toIntegral(v8Value, NormalConversion, context.exceptionState());
+
+ if (context.exceptionState().throwIfNeeded())
+ return false;
+
+ value = Nullable<T>(converted);
+ return true;
}
-template<typename T> bool Dictionary::convert(ConversionContext& context, const String& key, RefPtr<T>& value) const
+template<template <typename> class PointerType, typename T> bool Dictionary::convert(ConversionContext& context, const String& key, PointerType<T>& value) const
{
ConversionContextScope scope(context);