| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 if (!v8CallBoolean(m_dictionaryObject->Has(v8Context(), key))) | 115 if (!v8CallBoolean(m_dictionaryObject->Has(v8Context(), key))) |
| 116 return false; | 116 return false; |
| 117 | 117 |
| 118 // Swallow a possible exception in v8::Object::Get(). | 118 // Swallow a possible exception in v8::Object::Get(). |
| 119 // TODO(bashi,yukishiino): Should rethrow the exception. | 119 // TODO(bashi,yukishiino): Should rethrow the exception. |
| 120 // http://crbug.com/666661 | 120 // http://crbug.com/666661 |
| 121 v8::TryCatch tryCatch(isolate()); | 121 v8::TryCatch tryCatch(isolate()); |
| 122 return m_dictionaryObject->Get(v8Context(), key).ToLocal(&result); | 122 return m_dictionaryObject->Get(v8Context(), key).ToLocal(&result); |
| 123 } | 123 } |
| 124 | 124 |
| 125 static inline bool propertyKey(v8::Local<v8::Context> v8Context, | 125 WARN_UNUSED_RESULT static v8::MaybeLocal<v8::String> getStringValueInArray( |
| 126 v8::Local<v8::Array> properties, | 126 v8::Local<v8::Context> context, |
| 127 uint32_t index, | 127 v8::Local<v8::Array> array, |
| 128 v8::Local<v8::String>& key) { | 128 uint32_t index) { |
| 129 v8::Local<v8::Value> property; | 129 v8::Local<v8::Value> value; |
| 130 if (!properties->Get(v8Context, index).ToLocal(&property)) | 130 if (!array->Get(context, index).ToLocal(&value)) |
| 131 return false; | 131 return v8::MaybeLocal<v8::String>(); |
| 132 return property->ToString(v8Context).ToLocal(&key); | 132 return value->ToString(context); |
| 133 } | 133 } |
| 134 | 134 |
| 135 bool Dictionary::getOwnPropertiesAsStringHashMap( | 135 HashMap<String, String> Dictionary::getOwnPropertiesAsStringHashMap( |
| 136 HashMap<String, String>& hashMap) const { | 136 ExceptionState& exceptionState) const { |
| 137 if (m_dictionaryObject.IsEmpty()) | 137 if (m_dictionaryObject.IsEmpty()) |
| 138 return false; | 138 return HashMap<String, String>(); |
| 139 | 139 |
| 140 v8::Local<v8::Array> properties; | 140 v8::TryCatch tryCatch(isolate()); |
| 141 v8::Local<v8::Array> propertyNames; |
| 141 if (!m_dictionaryObject->GetOwnPropertyNames(v8Context()) | 142 if (!m_dictionaryObject->GetOwnPropertyNames(v8Context()) |
| 142 .ToLocal(&properties)) | 143 .ToLocal(&propertyNames)) { |
| 143 return false; | 144 exceptionState.rethrowV8Exception(tryCatch.Exception()); |
| 144 // Swallow a possible exception in v8::Object::Get(). | 145 return HashMap<String, String>(); |
| 145 // TODO(bashi,yukishiino): Should rethrow the exception. | 146 } |
| 146 // Note that propertyKey() may throw an exception. | 147 |
| 147 // http://crbug.com/666661 | 148 HashMap<String, String> ownProperties; |
| 148 v8::TryCatch tryCatch(isolate()); | 149 for (uint32_t i = 0; i < propertyNames->Length(); ++i) { |
| 149 for (uint32_t i = 0; i < properties->Length(); ++i) { | |
| 150 v8::Local<v8::String> key; | 150 v8::Local<v8::String> key; |
| 151 if (!propertyKey(v8Context(), properties, i, key)) | 151 if (!getStringValueInArray(v8Context(), propertyNames, i).ToLocal(&key)) { |
| 152 continue; | 152 exceptionState.rethrowV8Exception(tryCatch.Exception()); |
| 153 if (!v8CallBoolean(m_dictionaryObject->Has(v8Context(), key))) | 153 return HashMap<String, String>(); |
| 154 continue; | 154 } |
| 155 V8StringResource<> stringKey(key); |
| 156 if (!stringKey.prepare(isolate(), exceptionState)) |
| 157 return HashMap<String, String>(); |
| 155 | 158 |
| 156 v8::Local<v8::Value> value; | 159 v8::Local<v8::Value> value; |
| 157 if (!m_dictionaryObject->Get(v8Context(), key).ToLocal(&value)) { | 160 if (!m_dictionaryObject->Get(v8Context(), key).ToLocal(&value)) { |
| 158 tryCatch.Reset(); | 161 exceptionState.rethrowV8Exception(tryCatch.Exception()); |
| 159 continue; | 162 return HashMap<String, String>(); |
| 160 } | 163 } |
| 161 TOSTRING_DEFAULT(V8StringResource<>, stringKey, key, false); | 164 V8StringResource<> stringValue(value); |
| 162 TOSTRING_DEFAULT(V8StringResource<>, stringValue, value, false); | 165 if (!stringValue.prepare(isolate(), exceptionState)) |
| 166 return HashMap<String, String>(); |
| 167 |
| 163 if (!static_cast<const String&>(stringKey).isEmpty()) | 168 if (!static_cast<const String&>(stringKey).isEmpty()) |
| 164 hashMap.set(stringKey, stringValue); | 169 ownProperties.set(stringKey, stringValue); |
| 165 } | 170 } |
| 166 | 171 |
| 167 return true; | 172 return ownProperties; |
| 168 } | 173 } |
| 169 | 174 |
| 170 bool Dictionary::getPropertyNames(Vector<String>& names) const { | 175 Vector<String> Dictionary::getPropertyNames( |
| 176 ExceptionState& exceptionState) const { |
| 171 if (m_dictionaryObject.IsEmpty()) | 177 if (m_dictionaryObject.IsEmpty()) |
| 172 return false; | 178 return Vector<String>(); |
| 173 | 179 |
| 174 v8::Local<v8::Array> properties; | 180 v8::TryCatch tryCatch(isolate()); |
| 175 if (!m_dictionaryObject->GetPropertyNames(v8Context()).ToLocal(&properties)) | 181 v8::Local<v8::Array> propertyNames; |
| 176 return false; | 182 if (!m_dictionaryObject->GetPropertyNames(v8Context()) |
| 177 for (uint32_t i = 0; i < properties->Length(); ++i) { | 183 .ToLocal(&propertyNames)) { |
| 184 exceptionState.rethrowV8Exception(tryCatch.Exception()); |
| 185 return Vector<String>(); |
| 186 } |
| 187 |
| 188 Vector<String> names; |
| 189 for (uint32_t i = 0; i < propertyNames->Length(); ++i) { |
| 178 v8::Local<v8::String> key; | 190 v8::Local<v8::String> key; |
| 179 if (!propertyKey(v8Context(), properties, i, key)) | 191 if (!getStringValueInArray(v8Context(), propertyNames, i).ToLocal(&key)) { |
| 180 continue; | 192 exceptionState.rethrowV8Exception(tryCatch.Exception()); |
| 181 if (!v8CallBoolean(m_dictionaryObject->Has(v8Context(), key))) | 193 return Vector<String>(); |
| 182 continue; | 194 } |
| 183 TOSTRING_DEFAULT(V8StringResource<>, stringKey, key, false); | 195 V8StringResource<> stringKey(key); |
| 196 if (!stringKey.prepare(isolate(), exceptionState)) |
| 197 return Vector<String>(); |
| 198 |
| 184 names.append(stringKey); | 199 names.append(stringKey); |
| 185 } | 200 } |
| 186 | 201 |
| 187 return true; | 202 return names; |
| 188 } | 203 } |
| 189 | 204 |
| 190 } // namespace blink | 205 } // namespace blink |
| OLD | NEW |