| OLD | NEW |
| 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 Loading... |
| 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 static v8::Local<v8::Value> deserializeIDBValueArray(v8::Isolate* isolate, v8::L
ocal<v8::Object> creationContext, const Vector<RefPtr<IDBValue>>* values) | 364 static v8::Local<v8::Value> deserializeIDBValueArray(v8::Isolate* isolate, v8::L
ocal<v8::Object> creationContext, const Vector<RefPtr<IDBValue>>* values) |
| 366 { | 365 { |
| 367 ASSERT(isolate->InContext()); | 366 ASSERT(isolate->InContext()); |
| 368 | 367 |
| 369 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 368 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 370 v8::Local<v8::Array> array = v8::Array::New(isolate, values->size()); | 369 v8::Local<v8::Array> array = v8::Array::New(isolate, values->size()); |
| 371 for (size_t i = 0; i < values->size(); ++i) { | 370 for (size_t i = 0; i < values->size(); ++i) { |
| 372 v8::Local<v8::Value> v8Value = deserializeIDBValue(isolate, creationCont
ext, values->at(i).get()); | 371 v8::Local<v8::Value> v8Value = deserializeIDBValue(isolate, creationCont
ext, values->at(i).get()); |
| 373 if (v8Value.IsEmpty()) | 372 if (v8Value.IsEmpty()) |
| 374 v8Value = v8::Undefined(isolate); | 373 v8Value = v8::Undefined(isolate); |
| 375 // TODO(cmumford): Use DefineOwnProperty when exposed by V8. http://crbu
g.com/475206 | 374 if (!v8CallBoolean(array->CreateDataProperty(context, i, v8Value))) |
| 376 if (!v8CallBoolean(array->ForceSet(context, v8::Integer::New(isolate, i)
, v8Value))) | |
| 377 return v8Undefined(); | 375 return v8Undefined(); |
| 378 } | 376 } |
| 379 | 377 |
| 380 return array; | 378 return array; |
| 381 } | 379 } |
| 382 | 380 |
| 383 // This is only applied to deserialized values which were validated before | 381 // This is only applied to deserialized values which were validated before |
| 384 // serialization, so various assumptions/assertions can be made. | 382 // serialization, so various assumptions/assertions can be made. |
| 385 bool injectV8KeyIntoV8Value(v8::Isolate* isolate, v8::Local<v8::Value> key, v8::
Local<v8::Value> value, const IDBKeyPath& keyPath) | 383 bool injectV8KeyIntoV8Value(v8::Isolate* isolate, v8::Local<v8::Value> key, v8::
Local<v8::Value> value, const IDBKeyPath& keyPath) |
| 386 { | 384 { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 410 v8::Local<v8::Object> object = value.As<v8::Object>(); | 408 v8::Local<v8::Object> object = value.As<v8::Object>(); |
| 411 v8::Local<v8::String> property = v8String(isolate, keyPathElement); | 409 v8::Local<v8::String> property = v8String(isolate, keyPathElement); |
| 412 bool hasOwnProperty; | 410 bool hasOwnProperty; |
| 413 if (!v8Call(object->HasOwnProperty(context, property), hasOwnProperty)) | 411 if (!v8Call(object->HasOwnProperty(context, property), hasOwnProperty)) |
| 414 return false; | 412 return false; |
| 415 if (hasOwnProperty) { | 413 if (hasOwnProperty) { |
| 416 if (!object->Get(context, property).ToLocal(&value)) | 414 if (!object->Get(context, property).ToLocal(&value)) |
| 417 return false; | 415 return false; |
| 418 } else { | 416 } else { |
| 419 value = v8::Object::New(isolate); | 417 value = v8::Object::New(isolate); |
| 420 // TODO(jsbell): Use DefineOwnProperty when exposed by V8. http://cr
bug.com/475206 | 418 if (!v8CallBoolean(object->CreateDataProperty(context, property, val
ue))) |
| 421 if (!v8CallBoolean(object->ForceSet(context, property, value))) | |
| 422 return false; | 419 return false; |
| 423 } | 420 } |
| 424 } | 421 } |
| 425 | 422 |
| 426 // Implicit properties don't need to be set. The caller is not required to | 423 // Implicit properties don't need to be set. The caller is not required to |
| 427 // be aware of this, so this is an expected no-op. The caller can verify | 424 // be aware of this, so this is an expected no-op. The caller can verify |
| 428 // that the value is correct via assertPrimaryKeyValidOrInjectable. | 425 // that the value is correct via assertPrimaryKeyValidOrInjectable. |
| 429 if (isImplicitProperty(isolate, value, keyPathElements.last())) | 426 if (isImplicitProperty(isolate, value, keyPathElements.last())) |
| 430 return true; | 427 return true; |
| 431 | 428 |
| 432 // If it's not an implicit property of value, value must be an object. | 429 // If it's not an implicit property of value, value must be an object. |
| 433 v8::Local<v8::Object> object = value.As<v8::Object>(); | 430 v8::Local<v8::Object> object = value.As<v8::Object>(); |
| 434 v8::Local<v8::String> property = v8String(isolate, keyPathElements.last()); | 431 v8::Local<v8::String> property = v8String(isolate, keyPathElements.last()); |
| 435 // TODO(jsbell): Use DefineOwnProperty when exposed by V8. http://crbug.com/
475206 | 432 if (!v8CallBoolean(object->CreateDataProperty(context, property, key))) |
| 436 if (!v8CallBoolean(object->ForceSet(context, property, key))) | |
| 437 return false; | 433 return false; |
| 438 | 434 |
| 439 return true; | 435 return true; |
| 440 } | 436 } |
| 441 | 437 |
| 442 // Verify that an value can have an generated key inserted at the location | 438 // Verify that an value can have an generated key inserted at the location |
| 443 // specified by the key path (by injectV8KeyIntoV8Value) when the object is | 439 // specified by the key path (by injectV8KeyIntoV8Value) when the object is |
| 444 // later deserialized. | 440 // later deserialized. |
| 445 bool canInjectIDBKeyIntoScriptValue(v8::Isolate* isolate, const ScriptValue& scr
iptValue, const IDBKeyPath& keyPath) | 441 bool canInjectIDBKeyIntoScriptValue(v8::Isolate* isolate, const ScriptValue& scr
iptValue, const IDBKeyPath& keyPath) |
| 446 { | 442 { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 IDBKey* expectedKey = createIDBKeyFromValueAndKeyPath(isolate, scriptValue.v
8Value(), value->keyPath(), allowExperimentalTypes); | 530 IDBKey* expectedKey = createIDBKeyFromValueAndKeyPath(isolate, scriptValue.v
8Value(), value->keyPath(), allowExperimentalTypes); |
| 535 if (expectedKey && expectedKey->isEqual(value->primaryKey())) | 531 if (expectedKey && expectedKey->isEqual(value->primaryKey())) |
| 536 return; | 532 return; |
| 537 | 533 |
| 538 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa
lue.v8Value(), value->keyPath()); | 534 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa
lue.v8Value(), value->keyPath()); |
| 539 ASSERT_UNUSED(injected, injected); | 535 ASSERT_UNUSED(injected, injected); |
| 540 } | 536 } |
| 541 #endif | 537 #endif |
| 542 | 538 |
| 543 } // namespace blink | 539 } // namespace blink |
| OLD | NEW |