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

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: Update test's shared lib usage Created 5 years, 7 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
« no previous file with comments | « LayoutTests/storage/indexeddb/resources/key-type-binary.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/modules/v8/V8BindingForModules.cpp
diff --git a/Source/bindings/modules/v8/V8BindingForModules.cpp b/Source/bindings/modules/v8/V8BindingForModules.cpp
index a1e28358b638742e3139624a5e297adb831d1754..f3da17f0aadd45b946f1a237dbfe9adca5e12d81 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/V8Blob.h"
@@ -42,6 +43,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"
@@ -97,7 +100,9 @@ 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);
+ // Experimental feature: binary keys
+ // https://w3c.github.io/IndexedDB/#steps-to-convert-a-key-to-a-value
+ return toV8(DOMArrayBuffer::create(reinterpret_cast<const unsigned char*>(key->binary()->data()), key->binary()->size()), creationContext, isolate);
case IDBKey::DateType:
return v8::Date::New(context, key->date()).ToLocalChecked();
case IDBKey::ArrayType:
@@ -190,13 +195,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 = 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://w3c.github.io/IndexedDB/#dfn-convert-a-value-to-a-key
+ if (value->IsArrayBuffer()) {
+ DOMArrayBuffer* buffer = 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));
+ }
+ if (value->IsArrayBufferView()) {
+ DOMArrayBufferView* view = 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>();
« no previous file with comments | « LayoutTests/storage/indexeddb/resources/key-type-binary.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698