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