| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 return toV8(DOMArrayBuffer::create(reinterpret_cast<const unsigned char*
>(key->binary()->data()), key->binary()->size()), creationContext, isolate); | 102 return toV8(DOMArrayBuffer::create(reinterpret_cast<const unsigned char*
>(key->binary()->data()), key->binary()->size()), creationContext, isolate); |
| 103 case IDBKey::DateType: | 103 case IDBKey::DateType: |
| 104 return v8::Date::New(context, key->date()).ToLocalChecked(); | 104 return v8::Date::New(context, key->date()).ToLocalChecked(); |
| 105 case IDBKey::ArrayType: | 105 case IDBKey::ArrayType: |
| 106 { | 106 { |
| 107 v8::Local<v8::Array> array = v8::Array::New(isolate, key->array().si
ze()); | 107 v8::Local<v8::Array> array = v8::Array::New(isolate, key->array().si
ze()); |
| 108 for (size_t i = 0; i < key->array().size(); ++i) { | 108 for (size_t i = 0; i < key->array().size(); ++i) { |
| 109 v8::Local<v8::Value> value = toV8(key->array()[i].get(), creatio
nContext, isolate); | 109 v8::Local<v8::Value> value = toV8(key->array()[i].get(), creatio
nContext, isolate); |
| 110 if (value.IsEmpty()) | 110 if (value.IsEmpty()) |
| 111 value = v8::Undefined(isolate); | 111 value = v8::Undefined(isolate); |
| 112 // TODO(jsbell): Use DefineOwnProperty when exposed by V8. http:
//crbug.com/475206 | 112 if (!v8CallBoolean(array->CreateDataProperty(context, i, value))
) |
| 113 if (!v8CallBoolean(array->ForceSet(context, v8::Integer::New(iso
late, i), value))) | |
| 114 return v8Undefined(); | 113 return v8Undefined(); |
| 115 } | 114 } |
| 116 return array; | 115 return array; |
| 117 } | 116 } |
| 118 } | 117 } |
| 119 | 118 |
| 120 ASSERT_NOT_REACHED(); | 119 ASSERT_NOT_REACHED(); |
| 121 return v8Undefined(); | 120 return v8Undefined(); |
| 122 } | 121 } |
| 123 | 122 |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 static v8::Local<v8::Value> deserializeIDBValueArray(v8::Isolate* isolate, v8::L
ocal<v8::Object> creationContext, const Vector<RefPtr<IDBValue>>* values) | 355 static v8::Local<v8::Value> deserializeIDBValueArray(v8::Isolate* isolate, v8::L
ocal<v8::Object> creationContext, const Vector<RefPtr<IDBValue>>* values) |
| 357 { | 356 { |
| 358 ASSERT(isolate->InContext()); | 357 ASSERT(isolate->InContext()); |
| 359 | 358 |
| 360 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 359 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 361 v8::Local<v8::Array> array = v8::Array::New(isolate, values->size()); | 360 v8::Local<v8::Array> array = v8::Array::New(isolate, values->size()); |
| 362 for (size_t i = 0; i < values->size(); ++i) { | 361 for (size_t i = 0; i < values->size(); ++i) { |
| 363 v8::Local<v8::Value> v8Value = deserializeIDBValue(isolate, creationCont
ext, values->at(i).get()); | 362 v8::Local<v8::Value> v8Value = deserializeIDBValue(isolate, creationCont
ext, values->at(i).get()); |
| 364 if (v8Value.IsEmpty()) | 363 if (v8Value.IsEmpty()) |
| 365 v8Value = v8::Undefined(isolate); | 364 v8Value = v8::Undefined(isolate); |
| 366 // TODO(cmumford): Use DefineOwnProperty when exposed by V8. http://crbu
g.com/475206 | 365 if (!v8CallBoolean(array->CreateDataProperty(context, i, v8Value))) |
| 367 if (!v8CallBoolean(array->ForceSet(context, v8::Integer::New(isolate, i)
, v8Value))) | |
| 368 return v8Undefined(); | 366 return v8Undefined(); |
| 369 } | 367 } |
| 370 | 368 |
| 371 return array; | 369 return array; |
| 372 } | 370 } |
| 373 | 371 |
| 374 // This is only applied to deserialized values which were validated before | 372 // This is only applied to deserialized values which were validated before |
| 375 // serialization, so various assumptions/assertions can be made. | 373 // serialization, so various assumptions/assertions can be made. |
| 376 bool injectV8KeyIntoV8Value(v8::Isolate* isolate, v8::Local<v8::Value> key, v8::
Local<v8::Value> value, const IDBKeyPath& keyPath) | 374 bool injectV8KeyIntoV8Value(v8::Isolate* isolate, v8::Local<v8::Value> key, v8::
Local<v8::Value> value, const IDBKeyPath& keyPath) |
| 377 { | 375 { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 402 v8::Local<v8::Object> object = value.As<v8::Object>(); | 400 v8::Local<v8::Object> object = value.As<v8::Object>(); |
| 403 v8::Local<v8::String> property = v8String(isolate, keyPathElement); | 401 v8::Local<v8::String> property = v8String(isolate, keyPathElement); |
| 404 bool hasOwnProperty; | 402 bool hasOwnProperty; |
| 405 if (!v8Call(object->HasOwnProperty(context, property), hasOwnProperty)) | 403 if (!v8Call(object->HasOwnProperty(context, property), hasOwnProperty)) |
| 406 return false; | 404 return false; |
| 407 if (hasOwnProperty) { | 405 if (hasOwnProperty) { |
| 408 if (!object->Get(context, property).ToLocal(&value)) | 406 if (!object->Get(context, property).ToLocal(&value)) |
| 409 return false; | 407 return false; |
| 410 } else { | 408 } else { |
| 411 value = v8::Object::New(isolate); | 409 value = v8::Object::New(isolate); |
| 412 // TODO(jsbell): Use DefineOwnProperty when exposed by V8. http://cr
bug.com/475206 | 410 if (!v8CallBoolean(object->CreateDataProperty(context, property, val
ue))) |
| 413 if (!v8CallBoolean(object->ForceSet(context, property, value))) | |
| 414 return false; | 411 return false; |
| 415 } | 412 } |
| 416 } | 413 } |
| 417 | 414 |
| 418 // Implicit properties don't need to be set. The caller is not required to | 415 // Implicit properties don't need to be set. The caller is not required to |
| 419 // be aware of this, so this is an expected no-op. The caller can verify | 416 // be aware of this, so this is an expected no-op. The caller can verify |
| 420 // that the value is correct via assertPrimaryKeyValidOrInjectable. | 417 // that the value is correct via assertPrimaryKeyValidOrInjectable. |
| 421 if (isImplicitProperty(isolate, value, keyPathElements.last())) | 418 if (isImplicitProperty(isolate, value, keyPathElements.last())) |
| 422 return true; | 419 return true; |
| 423 | 420 |
| 424 // If it's not an implicit property of value, value must be an object. | 421 // If it's not an implicit property of value, value must be an object. |
| 425 v8::Local<v8::Object> object = value.As<v8::Object>(); | 422 v8::Local<v8::Object> object = value.As<v8::Object>(); |
| 426 v8::Local<v8::String> property = v8String(isolate, keyPathElements.last()); | 423 v8::Local<v8::String> property = v8String(isolate, keyPathElements.last()); |
| 427 // TODO(jsbell): Use DefineOwnProperty when exposed by V8. http://crbug.com/
475206 | 424 if (!v8CallBoolean(object->CreateDataProperty(context, property, key))) |
| 428 if (!v8CallBoolean(object->ForceSet(context, property, key))) | |
| 429 return false; | 425 return false; |
| 430 | 426 |
| 431 return true; | 427 return true; |
| 432 } | 428 } |
| 433 | 429 |
| 434 // Verify that an value can have an generated key inserted at the location | 430 // Verify that an value can have an generated key inserted at the location |
| 435 // specified by the key path (by injectV8KeyIntoV8Value) when the object is | 431 // specified by the key path (by injectV8KeyIntoV8Value) when the object is |
| 436 // later deserialized. | 432 // later deserialized. |
| 437 bool canInjectIDBKeyIntoScriptValue(v8::Isolate* isolate, const ScriptValue& scr
iptValue, const IDBKeyPath& keyPath) | 433 bool canInjectIDBKeyIntoScriptValue(v8::Isolate* isolate, const ScriptValue& scr
iptValue, const IDBKeyPath& keyPath) |
| 438 { | 434 { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 ASSERT(!exceptionState.hadException()); | 524 ASSERT(!exceptionState.hadException()); |
| 529 if (expectedKey && expectedKey->isEqual(value->primaryKey())) | 525 if (expectedKey && expectedKey->isEqual(value->primaryKey())) |
| 530 return; | 526 return; |
| 531 | 527 |
| 532 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa
lue.v8Value(), value->keyPath()); | 528 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa
lue.v8Value(), value->keyPath()); |
| 533 ASSERT_UNUSED(injected, injected); | 529 ASSERT_UNUSED(injected, injected); |
| 534 } | 530 } |
| 535 #endif | 531 #endif |
| 536 | 532 |
| 537 } // namespace blink | 533 } // namespace blink |
| OLD | NEW |