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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 | 146 |
147 if (v8Value->IsObject()) { | 147 if (v8Value->IsObject()) { |
148 ASSERT(m_isolate); | 148 ASSERT(m_isolate); |
149 ASSERT(m_isolate == v8::Isolate::GetCurrent()); | 149 ASSERT(m_isolate == v8::Isolate::GetCurrent()); |
150 value = Dictionary(v8Value, m_isolate, *m_exceptionState); | 150 value = Dictionary(v8Value, m_isolate, *m_exceptionState); |
151 } | 151 } |
152 | 152 |
153 return true; | 153 return true; |
154 } | 154 } |
155 | 155 |
156 bool Dictionary::convert(ConversionContext& context, const String& key, Dictiona
ry& value) const | |
157 { | |
158 ConversionContextScope scope(context); | |
159 | |
160 v8::Local<v8::Value> v8Value; | |
161 if (!getKey(key, v8Value)) | |
162 return true; | |
163 | |
164 if (v8Value->IsObject()) | |
165 return get(key, value); | |
166 | |
167 if (context.isNullable() && blink::isUndefinedOrNull(v8Value)) | |
168 return true; | |
169 | |
170 context.throwTypeError(ExceptionMessages::incorrectPropertyType(key, "does n
ot have a Dictionary type.")); | |
171 return false; | |
172 } | |
173 | |
174 static inline bool propertyKey(v8::Local<v8::Context> v8Context, v8::Local<v8::A
rray> properties, uint32_t index, v8::Local<v8::String>& key) | 156 static inline bool propertyKey(v8::Local<v8::Context> v8Context, v8::Local<v8::A
rray> properties, uint32_t index, v8::Local<v8::String>& key) |
175 { | 157 { |
176 v8::Local<v8::Value> property; | 158 v8::Local<v8::Value> property; |
177 if (!properties->Get(v8Context, index).ToLocal(&property)) | 159 if (!properties->Get(v8Context, index).ToLocal(&property)) |
178 return false; | 160 return false; |
179 return property->ToString(v8Context).ToLocal(&key); | 161 return property->ToString(v8Context).ToLocal(&key); |
180 } | 162 } |
181 | 163 |
182 bool Dictionary::getOwnPropertiesAsStringHashMap(HashMap<String, String>& hashMa
p) const | 164 bool Dictionary::getOwnPropertiesAsStringHashMap(HashMap<String, String>& hashMa
p) const |
183 { | 165 { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 continue; | 204 continue; |
223 if (!v8CallBoolean(object->Has(v8Context(), key))) | 205 if (!v8CallBoolean(object->Has(v8Context(), key))) |
224 continue; | 206 continue; |
225 TOSTRING_DEFAULT(V8StringResource<>, stringKey, key, false); | 207 TOSTRING_DEFAULT(V8StringResource<>, stringKey, key, false); |
226 names.append(stringKey); | 208 names.append(stringKey); |
227 } | 209 } |
228 | 210 |
229 return true; | 211 return true; |
230 } | 212 } |
231 | 213 |
232 void Dictionary::ConversionContext::resetPerPropertyContext() | |
233 { | |
234 if (m_dirty) { | |
235 m_dirty = false; | |
236 m_isNullable = false; | |
237 m_propertyTypeName = ""; | |
238 } | |
239 } | |
240 | |
241 Dictionary::ConversionContext& Dictionary::ConversionContext::setConversionType(
const String& typeName, bool isNullable) | |
242 { | |
243 ASSERT(!m_dirty); | |
244 m_dirty = true; | |
245 m_isNullable = isNullable; | |
246 m_propertyTypeName = typeName; | |
247 | |
248 return *this; | |
249 } | |
250 | |
251 void Dictionary::ConversionContext::throwTypeError(const String& detail) | |
252 { | |
253 exceptionState().throwTypeError(detail); | |
254 } | |
255 | |
256 bool Dictionary::toObject(v8::Local<v8::Object>& object) const | 214 bool Dictionary::toObject(v8::Local<v8::Object>& object) const |
257 { | 215 { |
258 return !isUndefinedOrNull() && m_options->ToObject(v8Context()).ToLocal(&obj
ect); | 216 return !isUndefinedOrNull() && m_options->ToObject(v8Context()).ToLocal(&obj
ect); |
259 } | 217 } |
260 | 218 |
261 } // namespace blink | 219 } // namespace blink |
OLD | NEW |