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

Side by Side Diff: Source/bindings/modules/v8/V8BindingForModules.cpp

Issue 1153613007: bindings: Use CreateDataProperty() instead of ForceSet() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 return toV8(DOMArrayBuffer::create(reinterpret_cast<const unsigned char* >(key->binary()->data()), key->binary()->size()), creationContext, isolate); 105 return toV8(DOMArrayBuffer::create(reinterpret_cast<const unsigned char* >(key->binary()->data()), key->binary()->size()), creationContext, isolate);
106 case IDBKey::DateType: 106 case IDBKey::DateType:
107 return v8::Date::New(context, key->date()).ToLocalChecked(); 107 return v8::Date::New(context, key->date()).ToLocalChecked();
108 case IDBKey::ArrayType: 108 case IDBKey::ArrayType:
109 { 109 {
110 v8::Local<v8::Array> array = v8::Array::New(isolate, key->array().si ze()); 110 v8::Local<v8::Array> array = v8::Array::New(isolate, key->array().si ze());
111 for (size_t i = 0; i < key->array().size(); ++i) { 111 for (size_t i = 0; i < key->array().size(); ++i) {
112 v8::Local<v8::Value> value = toV8(key->array()[i].get(), creatio nContext, isolate); 112 v8::Local<v8::Value> value = toV8(key->array()[i].get(), creatio nContext, isolate);
113 if (value.IsEmpty()) 113 if (value.IsEmpty())
114 value = v8::Undefined(isolate); 114 value = v8::Undefined(isolate);
115 // TODO(jsbell): Use DefineOwnProperty when exposed by V8. http: //crbug.com/475206 115 if (!v8CallBoolean(array->CreateDataProperty(context, i, value)) )
116 if (!v8CallBoolean(array->ForceSet(context, v8::Integer::New(iso late, i), value)))
117 return v8Undefined(); 116 return v8Undefined();
118 } 117 }
119 return array; 118 return array;
120 } 119 }
121 } 120 }
122 121
123 ASSERT_NOT_REACHED(); 122 ASSERT_NOT_REACHED();
124 return v8Undefined(); 123 return v8Undefined();
125 } 124 }
126 125
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 static v8::Local<v8::Value> deserializeIDBValueArray(v8::Isolate* isolate, v8::L ocal<v8::Object> creationContext, const Vector<RefPtr<IDBValue>>* values) 367 static v8::Local<v8::Value> deserializeIDBValueArray(v8::Isolate* isolate, v8::L ocal<v8::Object> creationContext, const Vector<RefPtr<IDBValue>>* values)
369 { 368 {
370 ASSERT(isolate->InContext()); 369 ASSERT(isolate->InContext());
371 370
372 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 371 v8::Local<v8::Context> context = isolate->GetCurrentContext();
373 v8::Local<v8::Array> array = v8::Array::New(isolate, values->size()); 372 v8::Local<v8::Array> array = v8::Array::New(isolate, values->size());
374 for (size_t i = 0; i < values->size(); ++i) { 373 for (size_t i = 0; i < values->size(); ++i) {
375 v8::Local<v8::Value> v8Value = deserializeIDBValue(isolate, creationCont ext, values->at(i).get()); 374 v8::Local<v8::Value> v8Value = deserializeIDBValue(isolate, creationCont ext, values->at(i).get());
376 if (v8Value.IsEmpty()) 375 if (v8Value.IsEmpty())
377 v8Value = v8::Undefined(isolate); 376 v8Value = v8::Undefined(isolate);
378 // TODO(cmumford): Use DefineOwnProperty when exposed by V8. http://crbu g.com/475206 377 if (!v8CallBoolean(array->CreateDataProperty(context, i, v8Value)))
379 if (!v8CallBoolean(array->ForceSet(context, v8::Integer::New(isolate, i) , v8Value)))
380 return v8Undefined(); 378 return v8Undefined();
381 } 379 }
382 380
383 return array; 381 return array;
384 } 382 }
385 383
386 // This is only applied to deserialized values which were validated before 384 // This is only applied to deserialized values which were validated before
387 // serialization, so various assumptions/assertions can be made. 385 // serialization, so various assumptions/assertions can be made.
388 bool injectV8KeyIntoV8Value(v8::Isolate* isolate, v8::Local<v8::Value> key, v8:: Local<v8::Value> value, const IDBKeyPath& keyPath) 386 bool injectV8KeyIntoV8Value(v8::Isolate* isolate, v8::Local<v8::Value> key, v8:: Local<v8::Value> value, const IDBKeyPath& keyPath)
389 { 387 {
(...skipping 23 matching lines...) Expand all
413 v8::Local<v8::Object> object = value.As<v8::Object>(); 411 v8::Local<v8::Object> object = value.As<v8::Object>();
414 v8::Local<v8::String> property = v8String(isolate, keyPathElement); 412 v8::Local<v8::String> property = v8String(isolate, keyPathElement);
415 bool hasOwnProperty; 413 bool hasOwnProperty;
416 if (!v8Call(object->HasOwnProperty(context, property), hasOwnProperty)) 414 if (!v8Call(object->HasOwnProperty(context, property), hasOwnProperty))
417 return false; 415 return false;
418 if (hasOwnProperty) { 416 if (hasOwnProperty) {
419 if (!object->Get(context, property).ToLocal(&value)) 417 if (!object->Get(context, property).ToLocal(&value))
420 return false; 418 return false;
421 } else { 419 } else {
422 value = v8::Object::New(isolate); 420 value = v8::Object::New(isolate);
423 // TODO(jsbell): Use DefineOwnProperty when exposed by V8. http://cr bug.com/475206 421 if (!v8CallBoolean(object->CreateDataProperty(context, property, val ue)))
424 if (!v8CallBoolean(object->ForceSet(context, property, value)))
425 return false; 422 return false;
426 } 423 }
427 } 424 }
428 425
429 // Implicit properties don't need to be set. The caller is not required to 426 // Implicit properties don't need to be set. The caller is not required to
430 // be aware of this, so this is an expected no-op. The caller can verify 427 // be aware of this, so this is an expected no-op. The caller can verify
431 // that the value is correct via assertPrimaryKeyValidOrInjectable. 428 // that the value is correct via assertPrimaryKeyValidOrInjectable.
432 if (isImplicitProperty(isolate, value, keyPathElements.last())) 429 if (isImplicitProperty(isolate, value, keyPathElements.last()))
433 return true; 430 return true;
434 431
435 // If it's not an implicit property of value, value must be an object. 432 // If it's not an implicit property of value, value must be an object.
436 v8::Local<v8::Object> object = value.As<v8::Object>(); 433 v8::Local<v8::Object> object = value.As<v8::Object>();
437 v8::Local<v8::String> property = v8String(isolate, keyPathElements.last()); 434 v8::Local<v8::String> property = v8String(isolate, keyPathElements.last());
438 // TODO(jsbell): Use DefineOwnProperty when exposed by V8. http://crbug.com/ 475206 435 if (!v8CallBoolean(object->CreateDataProperty(context, property, key)))
439 if (!v8CallBoolean(object->ForceSet(context, property, key)))
440 return false; 436 return false;
441 437
442 return true; 438 return true;
443 } 439 }
444 440
445 // Verify that an value can have an generated key inserted at the location 441 // Verify that an value can have an generated key inserted at the location
446 // specified by the key path (by injectV8KeyIntoV8Value) when the object is 442 // specified by the key path (by injectV8KeyIntoV8Value) when the object is
447 // later deserialized. 443 // later deserialized.
448 bool canInjectIDBKeyIntoScriptValue(v8::Isolate* isolate, const ScriptValue& scr iptValue, const IDBKeyPath& keyPath) 444 bool canInjectIDBKeyIntoScriptValue(v8::Isolate* isolate, const ScriptValue& scr iptValue, const IDBKeyPath& keyPath)
449 { 445 {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 ASSERT(!exceptionState.hadException()); 535 ASSERT(!exceptionState.hadException());
540 if (expectedKey && expectedKey->isEqual(value->primaryKey())) 536 if (expectedKey && expectedKey->isEqual(value->primaryKey()))
541 return; 537 return;
542 538
543 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa lue.v8Value(), value->keyPath()); 539 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa lue.v8Value(), value->keyPath());
544 ASSERT_UNUSED(injected, injected); 540 ASSERT_UNUSED(injected, injected);
545 } 541 }
546 #endif 542 #endif
547 543
548 } // namespace blink 544 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698