Chromium Code Reviews| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 #include "modules/indexeddb/IDBValue.h" | 50 #include "modules/indexeddb/IDBValue.h" |
| 51 #include "platform/RuntimeEnabledFeatures.h" | 51 #include "platform/RuntimeEnabledFeatures.h" |
| 52 #include "platform/SharedBuffer.h" | 52 #include "platform/SharedBuffer.h" |
| 53 #include "wtf/MathExtras.h" | 53 #include "wtf/MathExtras.h" |
| 54 #include "wtf/Vector.h" | 54 #include "wtf/Vector.h" |
| 55 | 55 |
| 56 namespace blink { | 56 namespace blink { |
| 57 | 57 |
| 58 static v8::Local<v8::Value> deserializeIDBValueData(v8::Isolate*, | 58 static v8::Local<v8::Value> deserializeIDBValueData(v8::Isolate*, |
| 59 const IDBValue*); | 59 const IDBValue*); |
| 60 static v8::Local<v8::Value> deserializeIDBValue( | |
| 61 v8::Isolate*, | |
| 62 v8::Local<v8::Object> creationContext, | |
| 63 const IDBValue*); | |
| 64 static v8::Local<v8::Value> deserializeIDBValueArray( | 60 static v8::Local<v8::Value> deserializeIDBValueArray( |
| 65 v8::Isolate*, | 61 v8::Isolate*, |
| 66 v8::Local<v8::Object> creationContext, | 62 v8::Local<v8::Object> creationContext, |
| 67 const Vector<RefPtr<IDBValue>>*); | 63 const Vector<RefPtr<IDBValue>>*); |
| 68 | 64 |
| 69 v8::Local<v8::Value> ToV8(const IDBKeyPath& value, | 65 v8::Local<v8::Value> ToV8(const IDBKeyPath& value, |
| 70 v8::Local<v8::Object> creationContext, | 66 v8::Local<v8::Object> creationContext, |
| 71 v8::Isolate* isolate) { | 67 v8::Isolate* isolate) { |
| 72 switch (value.getType()) { | 68 switch (value.getType()) { |
| 73 case IDBKeyPath::NullType: | 69 case IDBKeyPath::NullType: |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 | 383 |
| 388 RefPtr<SerializedScriptValue> serializedValue = | 384 RefPtr<SerializedScriptValue> serializedValue = |
| 389 value->createSerializedValue(); | 385 value->createSerializedValue(); |
| 390 SerializedScriptValue::DeserializeOptions options; | 386 SerializedScriptValue::DeserializeOptions options; |
| 391 options.blobInfo = value->blobInfo(); | 387 options.blobInfo = value->blobInfo(); |
| 392 options.readWasmFromStream = true; | 388 options.readWasmFromStream = true; |
| 393 return serializedValue->deserialize(isolate, options); | 389 return serializedValue->deserialize(isolate, options); |
| 394 } | 390 } |
| 395 | 391 |
| 396 // Deserialize the entire IDBValue (injecting key & keypath if present). | 392 // Deserialize the entire IDBValue (injecting key & keypath if present). |
| 397 static v8::Local<v8::Value> deserializeIDBValue( | 393 v8::Local<v8::Value> deserializeIDBValue(v8::Isolate* isolate, |
| 398 v8::Isolate* isolate, | 394 v8::Local<v8::Object> creationContext, |
| 399 v8::Local<v8::Object> creationContext, | 395 const IDBValue* value) { |
| 400 const IDBValue* value) { | |
| 401 ASSERT(isolate->InContext()); | 396 ASSERT(isolate->InContext()); |
| 402 if (!value || value->isNull()) | 397 if (!value || value->isNull()) |
| 403 return v8::Null(isolate); | 398 return v8::Null(isolate); |
| 404 | 399 |
| 405 v8::Local<v8::Value> v8Value = deserializeIDBValueData(isolate, value); | 400 v8::Local<v8::Value> v8Value = deserializeIDBValueData(isolate, value); |
| 406 if (value->primaryKey()) { | 401 |
| 402 // De-serialization failures are currently handled by returning null. This is | |
| 403 // sub-optimal, as it can cause IndexedDB to return incorrect data. The check | |
|
jsbell
2017/04/03 19:31:52
Maybe note that null is a perfectly valid IDB valu
pwnall
2017/04/04 00:55:12
Done.
| |
| 404 // below is the minimal work needed to avoid a crash. A proper solution would | |
|
jsbell
2017/04/03 19:31:52
Since this comment tracks future work, rephrase as
pwnall
2017/04/04 00:55:12
I used the crbug targeted by this CL, because the
| |
| 405 // require SerializedScriptValue to throw rather than returning null when it | |
|
jsbell
2017/04/03 19:31:52
Return an empty handle?
I wouldn't expect SSV API
pwnall
2017/04/04 00:55:12
Done.
I switched to your suggestion of suggesting
| |
| 406 // encounters errors. | |
| 407 if (value->primaryKey() && !v8Value->IsNull()) { | |
|
jsbell
2017/04/03 19:31:52
I wonder if we want to have more comments/DCHECKs
pwnall
2017/04/04 00:55:12
I think that there is a check at a higher level --
| |
| 407 v8::Local<v8::Value> key = | 408 v8::Local<v8::Value> key = |
| 408 ToV8(value->primaryKey(), creationContext, isolate); | 409 ToV8(value->primaryKey(), creationContext, isolate); |
| 409 if (key.IsEmpty()) | 410 if (key.IsEmpty()) |
| 410 return v8::Local<v8::Value>(); | 411 return v8::Local<v8::Value>(); |
| 411 bool injected = | 412 bool injected = |
| 412 injectV8KeyIntoV8Value(isolate, key, v8Value, value->keyPath()); | 413 injectV8KeyIntoV8Value(isolate, key, v8Value, value->keyPath()); |
| 413 DCHECK(injected); | 414 DCHECK(injected); |
| 414 } | 415 } |
| 415 | 416 |
| 416 return v8Value; | 417 return v8Value; |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 if (expectedKey && expectedKey->isEqual(value->primaryKey())) | 610 if (expectedKey && expectedKey->isEqual(value->primaryKey())) |
| 610 return; | 611 return; |
| 611 | 612 |
| 612 bool injected = injectV8KeyIntoV8Value( | 613 bool injected = injectV8KeyIntoV8Value( |
| 613 isolate, keyValue.v8Value(), scriptValue.v8Value(), value->keyPath()); | 614 isolate, keyValue.v8Value(), scriptValue.v8Value(), value->keyPath()); |
| 614 DCHECK(injected); | 615 DCHECK(injected); |
| 615 } | 616 } |
| 616 #endif | 617 #endif |
| 617 | 618 |
| 618 } // namespace blink | 619 } // namespace blink |
| OLD | NEW |