OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 28 matching lines...) Expand all Loading... |
39 #include "wtf/text/AtomicString.h" | 39 #include "wtf/text/AtomicString.h" |
40 #include "wtf/text/WTFString.h" | 40 #include "wtf/text/WTFString.h" |
41 #include <v8.h> | 41 #include <v8.h> |
42 | 42 |
43 namespace blink { | 43 namespace blink { |
44 | 44 |
45 // Dictionary class provides ways to retrieve property values as C++ objects | 45 // Dictionary class provides ways to retrieve property values as C++ objects |
46 // from a V8 object. Instances of this class must not outlive V8's handle scope | 46 // from a V8 object. Instances of this class must not outlive V8's handle scope |
47 // because they hold a V8 value without putting it on persistent handles. | 47 // because they hold a V8 value without putting it on persistent handles. |
48 class CORE_EXPORT Dictionary final { | 48 class CORE_EXPORT Dictionary final { |
| 49 ALLOW_ONLY_INLINE_ALLOCATION(); |
49 public: | 50 public: |
50 Dictionary(); | 51 Dictionary(); |
51 Dictionary(const v8::Local<v8::Value>& options, v8::Isolate*, ExceptionState
&); | 52 Dictionary(const v8::Local<v8::Value>& options, v8::Isolate*, ExceptionState
&); |
52 ~Dictionary(); | 53 ~Dictionary(); |
53 | 54 |
54 Dictionary& operator=(const Dictionary&); | 55 Dictionary& operator=(const Dictionary&); |
55 | 56 |
56 bool isObject() const; | 57 bool isObject() const; |
57 bool isUndefinedOrNull() const; | 58 bool isUndefinedOrNull() const; |
58 | 59 |
(...skipping 28 matching lines...) Expand all Loading... |
87 struct NativeValueTraits<Dictionary> { | 88 struct NativeValueTraits<Dictionary> { |
88 static inline Dictionary nativeValue(v8::Isolate* isolate, v8::Local<v8::Val
ue> value, ExceptionState& exceptionState) | 89 static inline Dictionary nativeValue(v8::Isolate* isolate, v8::Local<v8::Val
ue> value, ExceptionState& exceptionState) |
89 { | 90 { |
90 return Dictionary(value, isolate, exceptionState); | 91 return Dictionary(value, isolate, exceptionState); |
91 } | 92 } |
92 }; | 93 }; |
93 | 94 |
94 // DictionaryHelper is a collection of static methods for getting or | 95 // DictionaryHelper is a collection of static methods for getting or |
95 // converting a value from Dictionary. | 96 // converting a value from Dictionary. |
96 struct DictionaryHelper { | 97 struct DictionaryHelper { |
| 98 STATIC_ONLY(DictionaryHelper); |
97 template <typename T> | 99 template <typename T> |
98 static bool get(const Dictionary&, const String& key, T& value); | 100 static bool get(const Dictionary&, const String& key, T& value); |
99 template <typename T> | 101 template <typename T> |
100 static bool get(const Dictionary&, const String& key, T& value, bool& hasVal
ue); | 102 static bool get(const Dictionary&, const String& key, T& value, bool& hasVal
ue); |
101 template <typename T> | 103 template <typename T> |
102 static bool get(const Dictionary&, const String& key, T& value, ExceptionSta
te&); | 104 static bool get(const Dictionary&, const String& key, T& value, ExceptionSta
te&); |
103 template <typename T> | 105 template <typename T> |
104 static bool getWithUndefinedOrNullCheck(const Dictionary& dictionary, const
String& key, T& value) | 106 static bool getWithUndefinedOrNullCheck(const Dictionary& dictionary, const
String& key, T& value) |
105 { | 107 { |
106 v8::Local<v8::Value> v8Value; | 108 v8::Local<v8::Value> v8Value; |
107 if (!dictionary.getKey(key, v8Value) || isUndefinedOrNull(v8Value)) | 109 if (!dictionary.getKey(key, v8Value) || isUndefinedOrNull(v8Value)) |
108 return false; | 110 return false; |
109 return DictionaryHelper::get(dictionary, key, value); | 111 return DictionaryHelper::get(dictionary, key, value); |
110 } | 112 } |
111 template <template <typename> class PointerType, typename T> | 113 template <template <typename> class PointerType, typename T> |
112 static bool get(const Dictionary&, const String& key, PointerType<T>& value)
; | 114 static bool get(const Dictionary&, const String& key, PointerType<T>& value)
; |
113 }; | 115 }; |
114 | 116 |
115 } | 117 } |
116 | 118 |
117 #endif // Dictionary_h | 119 #endif // Dictionary_h |
OLD | NEW |