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

Unified Diff: Source/bindings/modules/v8/V8BindingForModules.cpp

Issue 1087923003: Indexed DB: Adopt BufferSource model for binary keys (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: Source/bindings/modules/v8/V8BindingForModules.cpp
diff --git a/Source/bindings/modules/v8/V8BindingForModules.cpp b/Source/bindings/modules/v8/V8BindingForModules.cpp
index f12ee1c8aca48bc9983e81e8894c6a5ab913a712..f9df8232b0e67805d3095c93c886e2dff6c10227 100644
--- a/Source/bindings/modules/v8/V8BindingForModules.cpp
+++ b/Source/bindings/modules/v8/V8BindingForModules.cpp
@@ -28,6 +28,7 @@
#include "bindings/core/v8/SerializedScriptValue.h"
#include "bindings/core/v8/SerializedScriptValueFactory.h"
+#include "bindings/core/v8/V8ArrayBuffer.h"
#include "bindings/core/v8/V8ArrayBufferView.h"
#include "bindings/core/v8/V8Binding.h"
#include "bindings/core/v8/V8DOMStringList.h"
@@ -40,6 +41,8 @@
#include "bindings/modules/v8/V8IDBIndex.h"
#include "bindings/modules/v8/V8IDBKeyRange.h"
#include "bindings/modules/v8/V8IDBObjectStore.h"
+#include "core/dom/DOMArrayBuffer.h"
+#include "core/dom/DOMArrayBufferView.h"
#include "modules/indexeddb/IDBKey.h"
#include "modules/indexeddb/IDBKeyPath.h"
#include "modules/indexeddb/IDBKeyRange.h"
@@ -91,7 +94,7 @@ v8::Local<v8::Value> toV8(const IDBKey* key, v8::Local<v8::Object> creationConte
case IDBKey::StringType:
return v8String(isolate, key->string());
case IDBKey::BinaryType:
- return toV8(DOMUint8Array::create(reinterpret_cast<const unsigned char*>(key->binary()->data()), key->binary()->size()), creationContext, isolate);
+ return toV8(DOMArrayBuffer::create(reinterpret_cast<const unsigned char*>(key->binary()->data()), key->binary()->size()), creationContext, isolate);
case IDBKey::DateType:
return v8::Date::New(isolate->GetCurrentContext(), key->date()).ToLocalChecked();
case IDBKey::ArrayType:
@@ -189,13 +192,21 @@ static IDBKey* createIDBKeyFromValue(v8::Isolate* isolate, v8::Local<v8::Value>
return IDBKey::createString(toCoreString(value.As<v8::String>()));
if (value->IsDate() && !std::isnan(value.As<v8::Date>()->ValueOf()))
return IDBKey::createDate(value.As<v8::Date>()->ValueOf());
- if (value->IsUint8Array() && (allowExperimentalTypes || RuntimeEnabledFeatures::indexedDBExperimentalEnabled())) {
- // Per discussion in https://www.w3.org/Bugs/Public/show_bug.cgi?id=23332 the
- // input type is constrained to Uint8Array to match the output type.
- DOMArrayBufferView* view = blink::V8ArrayBufferView::toImpl(value.As<v8::Object>());
- const char* start = static_cast<const char*>(view->baseAddress());
- size_t length = view->byteLength();
- return IDBKey::createBinary(SharedBuffer::create(start, length));
+ if (allowExperimentalTypes || RuntimeEnabledFeatures::indexedDBExperimentalEnabled()) {
+ // Experimental feature: binary keys
+ // https://www.w3.org/Bugs/Public/show_bug.cgi?id=23332
+ if (value->IsArrayBuffer()) {
+ DOMArrayBuffer* buffer = blink::V8ArrayBuffer::toImpl(value.As<v8::Object>());
+ const char* start = static_cast<const char*>(buffer->data());
+ size_t length = buffer->byteLength();
+ return IDBKey::createBinary(SharedBuffer::create(start, length));
cmumford 2015/04/27 17:14:23 How much do we care about overflow? length is goin
jsbell 2015/04/27 22:39:47 Covered by the FIXME at: https://code.google.com/
+ }
+ if (value->IsArrayBufferView()) {
+ DOMArrayBufferView* view = blink::V8ArrayBufferView::toImpl(value.As<v8::Object>());
+ const char* start = static_cast<const char*>(view->baseAddress());
+ size_t length = view->byteLength();
+ return IDBKey::createBinary(SharedBuffer::create(start, length));
+ }
}
if (value->IsArray()) {
v8::Local<v8::Array> array = value.As<v8::Array>();

Powered by Google App Engine
This is Rietveld 408576698