Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/Dictionary.cpp

Issue 2496533002: binding: Makes Dictionary handle a possible exception in [[Get]]. (Closed)
Patch Set: Fixed a coding style. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 bool Dictionary::get(const StringView& key, v8::Local<v8::Value>& value) const { 60 bool Dictionary::get(const StringView& key, v8::Local<v8::Value>& value) const {
61 if (!m_isolate) 61 if (!m_isolate)
62 return false; 62 return false;
63 return getInternal(v8String(m_isolate, key), value); 63 return getInternal(v8String(m_isolate, key), value);
64 } 64 }
65 65
66 DictionaryIterator Dictionary::getIterator( 66 DictionaryIterator Dictionary::getIterator(
67 ExecutionContext* executionContext) const { 67 ExecutionContext* executionContext) const {
68 v8::Local<v8::Value> iteratorGetter; 68 v8::Local<v8::Value> iteratorGetter;
69 // TODO(alancutter): Support callable objects as well as functions.
70 if (!getInternal(v8::Symbol::GetIterator(m_isolate), iteratorGetter) || 69 if (!getInternal(v8::Symbol::GetIterator(m_isolate), iteratorGetter) ||
71 !iteratorGetter->IsFunction()) 70 !iteratorGetter->IsFunction())
72 return nullptr; 71 return nullptr;
73 v8::Local<v8::Value> iterator; 72 v8::Local<v8::Value> iterator;
74 if (!v8Call(V8ScriptRunner::callFunction( 73 if (!v8Call(V8ScriptRunner::callFunction(
75 v8::Local<v8::Function>::Cast(iteratorGetter), 74 v8::Local<v8::Function>::Cast(iteratorGetter),
76 executionContext, m_options, 0, nullptr, m_isolate), 75 executionContext, m_options, 0, nullptr, m_isolate),
77 iterator)) 76 iterator))
78 return nullptr; 77 return nullptr;
79 if (!iterator->IsObject()) 78 if (!iterator->IsObject())
(...skipping 18 matching lines...) Expand all
98 bool Dictionary::getInternal(const v8::Local<v8::Value>& key, 97 bool Dictionary::getInternal(const v8::Local<v8::Value>& key,
99 v8::Local<v8::Value>& result) const { 98 v8::Local<v8::Value>& result) const {
100 v8::Local<v8::Object> object; 99 v8::Local<v8::Object> object;
101 if (!toObject(object)) 100 if (!toObject(object))
102 return false; 101 return false;
103 102
104 DCHECK(m_isolate); 103 DCHECK(m_isolate);
105 DCHECK_EQ(m_isolate, v8::Isolate::GetCurrent()); 104 DCHECK_EQ(m_isolate, v8::Isolate::GetCurrent());
106 if (!v8CallBoolean(object->Has(v8Context(), key))) 105 if (!v8CallBoolean(object->Has(v8Context(), key)))
107 return false; 106 return false;
107
108 // Swallow a possible exception in v8::Object::Get().
109 // TODO(bashi,yukishiino): Should rethrow the exception.
110 v8::TryCatch tryCatch(isolate());
108 return object->Get(v8Context(), key).ToLocal(&result); 111 return object->Get(v8Context(), key).ToLocal(&result);
109 } 112 }
110 113
111 static inline bool propertyKey(v8::Local<v8::Context> v8Context, 114 static inline bool propertyKey(v8::Local<v8::Context> v8Context,
112 v8::Local<v8::Array> properties, 115 v8::Local<v8::Array> properties,
113 uint32_t index, 116 uint32_t index,
114 v8::Local<v8::String>& key) { 117 v8::Local<v8::String>& key) {
115 v8::Local<v8::Value> property; 118 v8::Local<v8::Value> property;
116 if (!properties->Get(v8Context, index).ToLocal(&property)) 119 if (!properties->Get(v8Context, index).ToLocal(&property))
117 return false; 120 return false;
118 return property->ToString(v8Context).ToLocal(&key); 121 return property->ToString(v8Context).ToLocal(&key);
119 } 122 }
120 123
121 bool Dictionary::getOwnPropertiesAsStringHashMap( 124 bool Dictionary::getOwnPropertiesAsStringHashMap(
122 HashMap<String, String>& hashMap) const { 125 HashMap<String, String>& hashMap) const {
123 v8::Local<v8::Object> object; 126 v8::Local<v8::Object> object;
124 if (!toObject(object)) 127 if (!toObject(object))
125 return false; 128 return false;
126 129
127 v8::Local<v8::Array> properties; 130 v8::Local<v8::Array> properties;
128 if (!object->GetOwnPropertyNames(v8Context()).ToLocal(&properties)) 131 if (!object->GetOwnPropertyNames(v8Context()).ToLocal(&properties))
129 return false; 132 return false;
133 // Swallow a possible exception in v8::Object::Get().
134 // TODO(bashi,yukishiino): Should rethrow the exception.
135 // Note that propertyKey() may throw an exception.
136 v8::TryCatch tryCatch(isolate());
130 for (uint32_t i = 0; i < properties->Length(); ++i) { 137 for (uint32_t i = 0; i < properties->Length(); ++i) {
131 v8::Local<v8::String> key; 138 v8::Local<v8::String> key;
132 if (!propertyKey(v8Context(), properties, i, key)) 139 if (!propertyKey(v8Context(), properties, i, key))
133 continue; 140 continue;
134 if (!v8CallBoolean(object->Has(v8Context(), key))) 141 if (!v8CallBoolean(object->Has(v8Context(), key)))
135 continue; 142 continue;
136 143
137 v8::Local<v8::Value> value; 144 v8::Local<v8::Value> value;
138 if (!object->Get(v8Context(), key).ToLocal(&value)) 145 if (!object->Get(v8Context(), key).ToLocal(&value)) {
146 tryCatch.Reset();
139 continue; 147 continue;
148 }
140 TOSTRING_DEFAULT(V8StringResource<>, stringKey, key, false); 149 TOSTRING_DEFAULT(V8StringResource<>, stringKey, key, false);
141 TOSTRING_DEFAULT(V8StringResource<>, stringValue, value, false); 150 TOSTRING_DEFAULT(V8StringResource<>, stringValue, value, false);
142 if (!static_cast<const String&>(stringKey).isEmpty()) 151 if (!static_cast<const String&>(stringKey).isEmpty())
143 hashMap.set(stringKey, stringValue); 152 hashMap.set(stringKey, stringValue);
144 } 153 }
145 154
146 return true; 155 return true;
147 } 156 }
148 157
149 bool Dictionary::getPropertyNames(Vector<String>& names) const { 158 bool Dictionary::getPropertyNames(Vector<String>& names) const {
(...skipping 16 matching lines...) Expand all
166 175
167 return true; 176 return true;
168 } 177 }
169 178
170 bool Dictionary::toObject(v8::Local<v8::Object>& object) const { 179 bool Dictionary::toObject(v8::Local<v8::Object>& object) const {
171 return !isUndefinedOrNull() && 180 return !isUndefinedOrNull() &&
172 m_options->ToObject(v8Context()).ToLocal(&object); 181 m_options->ToObject(v8Context()).ToLocal(&object);
173 } 182 }
174 183
175 } // namespace blink 184 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698