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

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

Issue 1961343003: Use [[DefineOwnProperty]] when converting IDL array values (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 { 208 {
209 v8::Context::Scope contextScope(creationContext->CreationContext()); 209 v8::Context::Scope contextScope(creationContext->CreationContext());
210 array = v8::Array::New(isolate, sequence.size()); 210 array = v8::Array::New(isolate, sequence.size());
211 } 211 }
212 uint32_t index = 0; 212 uint32_t index = 0;
213 typename Sequence::const_iterator end = sequence.end(); 213 typename Sequence::const_iterator end = sequence.end();
214 for (typename Sequence::const_iterator iter = sequence.begin(); iter != end; ++iter) { 214 for (typename Sequence::const_iterator iter = sequence.begin(); iter != end; ++iter) {
215 v8::Local<v8::Value> value = toV8(*iter, array, isolate); 215 v8::Local<v8::Value> value = toV8(*iter, array, isolate);
216 if (value.IsEmpty()) 216 if (value.IsEmpty())
217 value = v8::Undefined(isolate); 217 value = v8::Undefined(isolate);
218 if (!v8CallBoolean(array->Set(isolate->GetCurrentContext(), v8::Integer: :New(isolate, index++), value))) 218 if (!v8CallBoolean(array->CreateDataProperty(isolate->GetCurrentContext( ), index++, value)))
219 return v8::Local<v8::Value>(); 219 return v8::Local<v8::Value>();
220 } 220 }
221 return array; 221 return array;
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 Vector<T, inlineCapacity>& value, v8::Loc al<v8::Object> creationContext, v8::Isolate* isolate) 225 inline v8::Local<v8::Value> toV8(const Vector<T, inlineCapacity>& value, v8::Loc al<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, size_t inlineCapacity> 230 template<typename T, size_t inlineCapacity>
231 inline v8::Local<v8::Value> toV8(const HeapVector<T, inlineCapacity>& value, v8: :Local<v8::Object> creationContext, v8::Isolate* isolate) 231 inline v8::Local<v8::Value> toV8(const HeapVector<T, inlineCapacity>& value, v8: :Local<v8::Object> creationContext, v8::Isolate* isolate)
232 { 232 {
233 return toV8SequenceInternal(value, creationContext, isolate); 233 return toV8SequenceInternal(value, creationContext, isolate);
234 } 234 }
235 235
236 template<typename T> 236 template<typename T>
237 inline v8::Local<v8::Value> toV8(const Vector<std::pair<String, T>>& value, v8:: Local<v8::Object> creationContext, v8::Isolate* isolate) 237 inline v8::Local<v8::Value> toV8(const Vector<std::pair<String, T>>& value, v8:: Local<v8::Object> creationContext, v8::Isolate* isolate)
238 { 238 {
239 v8::Local<v8::Object> object; 239 v8::Local<v8::Object> object;
240 { 240 {
241 v8::Context::Scope contextScope(creationContext->CreationContext()); 241 v8::Context::Scope contextScope(creationContext->CreationContext());
242 object = v8::Object::New(isolate); 242 object = v8::Object::New(isolate);
243 } 243 }
244 for (unsigned i = 0; i < value.size(); ++i) { 244 for (unsigned i = 0; i < value.size(); ++i) {
245 v8::Local<v8::Value> v8Value = toV8(value[i].second, object, isolate); 245 v8::Local<v8::Value> v8Value = toV8(value[i].second, object, isolate);
246 if (v8Value.IsEmpty()) 246 if (v8Value.IsEmpty())
247 v8Value = v8::Undefined(isolate); 247 v8Value = v8::Undefined(isolate);
248 if (!v8CallBoolean(object->Set(isolate->GetCurrentContext(), v8String(is olate, value[i].first), v8Value))) 248 if (!v8CallBoolean(object->CreateDataProperty(isolate->GetCurrentContext (), v8String(isolate, value[i].first), v8Value)))
249 return v8::Local<v8::Value>(); 249 return v8::Local<v8::Value>();
250 } 250 }
251 return object; 251 return object;
252 } 252 }
253 253
254 // In all cases allow script state instead of creation context + isolate. 254 // In all cases allow script state instead of creation context + isolate.
255 // Use this function only if the call site does not otherwise need the global, 255 // Use this function only if the call site does not otherwise need the global,
256 // since v8::Context::Global is heavy. 256 // since v8::Context::Global is heavy.
257 template<typename T> 257 template<typename T>
258 inline v8::Local<v8::Value> toV8(T&& value, ScriptState* scriptState) 258 inline v8::Local<v8::Value> toV8(T&& value, ScriptState* scriptState)
(...skipping 14 matching lines...) Expand all
273 // Cannot define in ScriptValue because of the circular dependency between toV8 and ScriptValue 273 // Cannot define in ScriptValue because of the circular dependency between toV8 and ScriptValue
274 template<typename T> 274 template<typename T>
275 inline ScriptValue ScriptValue::from(ScriptState* scriptState, T&& value) 275 inline ScriptValue ScriptValue::from(ScriptState* scriptState, T&& value)
276 { 276 {
277 return ScriptValue(scriptState, toV8(std::forward<T>(value), scriptState)); 277 return ScriptValue(scriptState, toV8(std::forward<T>(value), scriptState));
278 } 278 }
279 279
280 } // namespace blink 280 } // namespace blink
281 281
282 #endif // ToV8_h 282 #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