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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ToV8.h

Issue 1936433002: Use [[DefineOwnProperty]] when converting IDL array values (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months 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
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/js/webidl-sequence-conversion.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef ToV8_h 5 #ifndef ToV8_h
6 #define ToV8_h 6 #define ToV8_h
7 7
8 // toV8() provides C++ -> V8 conversion. Note that toV8() can return an empty 8 // toV8() provides C++ -> V8 conversion. Note that toV8() can return an empty
9 // handle. Call sites must check IsEmpty() before using return value. 9 // handle. Call sites must check IsEmpty() before using return value.
10 10
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 { 202 {
203 v8::Context::Scope contextScope(creationContext->CreationContext()); 203 v8::Context::Scope contextScope(creationContext->CreationContext());
204 array = v8::Array::New(isolate, sequence.size()); 204 array = v8::Array::New(isolate, sequence.size());
205 } 205 }
206 uint32_t index = 0; 206 uint32_t index = 0;
207 typename Sequence::const_iterator end = sequence.end(); 207 typename Sequence::const_iterator end = sequence.end();
208 for (typename Sequence::const_iterator iter = sequence.begin(); iter != end; ++iter) { 208 for (typename Sequence::const_iterator iter = sequence.begin(); iter != end; ++iter) {
209 v8::Local<v8::Value> value = toV8(*iter, array, isolate); 209 v8::Local<v8::Value> value = toV8(*iter, array, isolate);
210 if (value.IsEmpty()) 210 if (value.IsEmpty())
211 value = v8::Undefined(isolate); 211 value = v8::Undefined(isolate);
212 if (!v8CallBoolean(array->Set(isolate->GetCurrentContext(), v8::Integer: :New(isolate, index++), value))) 212 if (!v8CallBoolean(array->CreateDataProperty(isolate->GetCurrentContext( ), index++, value)))
213 return v8::Local<v8::Value>(); 213 return v8::Local<v8::Value>();
214 } 214 }
215 return array; 215 return array;
216 } 216 }
217 217
218 template<typename T, size_t inlineCapacity> 218 template<typename T, size_t inlineCapacity>
219 inline v8::Local<v8::Value> toV8(const Vector<T, inlineCapacity>& value, v8::Loc al<v8::Object> creationContext, v8::Isolate* isolate) 219 inline v8::Local<v8::Value> toV8(const Vector<T, inlineCapacity>& value, v8::Loc al<v8::Object> creationContext, v8::Isolate* isolate)
220 { 220 {
221 return toV8SequenceInternal(value, creationContext, isolate); 221 return toV8SequenceInternal(value, creationContext, isolate);
222 } 222 }
223 223
224 template<typename T, size_t inlineCapacity> 224 template<typename T, size_t inlineCapacity>
225 inline v8::Local<v8::Value> toV8(const HeapVector<T, inlineCapacity>& value, v8: :Local<v8::Object> creationContext, v8::Isolate* isolate) 225 inline v8::Local<v8::Value> toV8(const HeapVector<T, inlineCapacity>& value, v8: :Local<v8::Object> creationContext, v8::Isolate* isolate)
226 { 226 {
227 return toV8SequenceInternal(value, creationContext, isolate); 227 return toV8SequenceInternal(value, creationContext, isolate);
228 } 228 }
229 229
230 template<typename T> 230 template<typename T>
231 inline v8::Local<v8::Value> toV8(const Vector<std::pair<String, T>>& value, v8:: Local<v8::Object> creationContext, v8::Isolate* isolate) 231 inline v8::Local<v8::Value> toV8(const Vector<std::pair<String, T>>& value, v8:: Local<v8::Object> creationContext, v8::Isolate* isolate)
232 { 232 {
233 v8::Local<v8::Object> object; 233 v8::Local<v8::Object> object;
234 { 234 {
235 v8::Context::Scope contextScope(creationContext->CreationContext()); 235 v8::Context::Scope contextScope(creationContext->CreationContext());
236 object = v8::Object::New(isolate); 236 object = v8::Object::New(isolate);
237 } 237 }
238 for (unsigned i = 0; i < value.size(); ++i) { 238 for (unsigned i = 0; i < value.size(); ++i) {
239 v8::Local<v8::Value> v8Value = toV8(value[i].second, object, isolate); 239 v8::Local<v8::Value> v8Value = toV8(value[i].second, object, isolate);
240 if (v8Value.IsEmpty()) 240 if (v8Value.IsEmpty())
241 v8Value = v8::Undefined(isolate); 241 v8Value = v8::Undefined(isolate);
242 if (!v8CallBoolean(object->Set(isolate->GetCurrentContext(), v8String(is olate, value[i].first), v8Value))) 242 if (!v8CallBoolean(object->CreateDataProperty(isolate->GetCurrentContext (), v8String(isolate, value[i].first), v8Value)))
243 return v8::Local<v8::Value>(); 243 return v8::Local<v8::Value>();
244 } 244 }
245 return object; 245 return object;
246 } 246 }
247 247
248 // In all cases allow script state instead of creation context + isolate. 248 // In all cases allow script state instead of creation context + isolate.
249 // Use this function only if the call site does not otherwise need the global, 249 // Use this function only if the call site does not otherwise need the global,
250 // since v8::Context::Global is heavy. 250 // since v8::Context::Global is heavy.
251 template<typename T> 251 template<typename T>
252 inline v8::Local<v8::Value> toV8(T&& value, ScriptState* scriptState) 252 inline v8::Local<v8::Value> toV8(T&& value, ScriptState* scriptState)
(...skipping 14 matching lines...) Expand all
267 // Cannot define in ScriptValue because of the circular dependency between toV8 and ScriptValue 267 // Cannot define in ScriptValue because of the circular dependency between toV8 and ScriptValue
268 template<typename T> 268 template<typename T>
269 inline ScriptValue ScriptValue::from(ScriptState* scriptState, T&& value) 269 inline ScriptValue ScriptValue::from(ScriptState* scriptState, T&& value)
270 { 270 {
271 return ScriptValue(scriptState, toV8(std::forward<T>(value), scriptState)); 271 return ScriptValue(scriptState, toV8(std::forward<T>(value), scriptState));
272 } 272 }
273 273
274 } // namespace blink 274 } // namespace blink
275 275
276 #endif // ToV8_h 276 #endif // ToV8_h
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/js/webidl-sequence-conversion.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698