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 10 matching lines...) Expand all Loading... | |
| 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "bindings/modules/v8/V8BindingForModules.h" | 27 #include "bindings/modules/v8/V8BindingForModules.h" |
| 28 | 28 |
| 29 #include "bindings/core/v8/SerializedScriptValue.h" | 29 #include "bindings/core/v8/SerializedScriptValue.h" |
| 30 #include "bindings/core/v8/SerializedScriptValueFactory.h" | 30 #include "bindings/core/v8/SerializedScriptValueFactory.h" |
| 31 #include "bindings/core/v8/V8ArrayBuffer.h" | |
| 31 #include "bindings/core/v8/V8ArrayBufferView.h" | 32 #include "bindings/core/v8/V8ArrayBufferView.h" |
| 32 #include "bindings/core/v8/V8Binding.h" | 33 #include "bindings/core/v8/V8Binding.h" |
| 33 #include "bindings/core/v8/V8DOMStringList.h" | 34 #include "bindings/core/v8/V8DOMStringList.h" |
| 34 #include "bindings/core/v8/V8HiddenValue.h" | 35 #include "bindings/core/v8/V8HiddenValue.h" |
| 35 #include "bindings/core/v8/V8Uint8Array.h" | 36 #include "bindings/core/v8/V8Uint8Array.h" |
| 36 #include "bindings/modules/v8/ToV8ForModules.h" | 37 #include "bindings/modules/v8/ToV8ForModules.h" |
| 37 #include "bindings/modules/v8/V8IDBCursor.h" | 38 #include "bindings/modules/v8/V8IDBCursor.h" |
| 38 #include "bindings/modules/v8/V8IDBCursorWithValue.h" | 39 #include "bindings/modules/v8/V8IDBCursorWithValue.h" |
| 39 #include "bindings/modules/v8/V8IDBDatabase.h" | 40 #include "bindings/modules/v8/V8IDBDatabase.h" |
| 40 #include "bindings/modules/v8/V8IDBIndex.h" | 41 #include "bindings/modules/v8/V8IDBIndex.h" |
| 41 #include "bindings/modules/v8/V8IDBKeyRange.h" | 42 #include "bindings/modules/v8/V8IDBKeyRange.h" |
| 42 #include "bindings/modules/v8/V8IDBObjectStore.h" | 43 #include "bindings/modules/v8/V8IDBObjectStore.h" |
| 44 #include "core/dom/DOMArrayBuffer.h" | |
| 45 #include "core/dom/DOMArrayBufferView.h" | |
| 43 #include "modules/indexeddb/IDBKey.h" | 46 #include "modules/indexeddb/IDBKey.h" |
| 44 #include "modules/indexeddb/IDBKeyPath.h" | 47 #include "modules/indexeddb/IDBKeyPath.h" |
| 45 #include "modules/indexeddb/IDBKeyRange.h" | 48 #include "modules/indexeddb/IDBKeyRange.h" |
| 46 #include "modules/indexeddb/IDBTracing.h" | 49 #include "modules/indexeddb/IDBTracing.h" |
| 47 #include "modules/indexeddb/IDBValue.h" | 50 #include "modules/indexeddb/IDBValue.h" |
| 48 #include "platform/RuntimeEnabledFeatures.h" | 51 #include "platform/RuntimeEnabledFeatures.h" |
| 49 #include "platform/SharedBuffer.h" | 52 #include "platform/SharedBuffer.h" |
| 50 #include "wtf/MathExtras.h" | 53 #include "wtf/MathExtras.h" |
| 51 #include "wtf/Vector.h" | 54 #include "wtf/Vector.h" |
| 52 | 55 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 switch (key->type()) { | 87 switch (key->type()) { |
| 85 case IDBKey::InvalidType: | 88 case IDBKey::InvalidType: |
| 86 case IDBKey::MinType: | 89 case IDBKey::MinType: |
| 87 ASSERT_NOT_REACHED(); | 90 ASSERT_NOT_REACHED(); |
| 88 return v8Undefined(); | 91 return v8Undefined(); |
| 89 case IDBKey::NumberType: | 92 case IDBKey::NumberType: |
| 90 return v8::Number::New(isolate, key->number()); | 93 return v8::Number::New(isolate, key->number()); |
| 91 case IDBKey::StringType: | 94 case IDBKey::StringType: |
| 92 return v8String(isolate, key->string()); | 95 return v8String(isolate, key->string()); |
| 93 case IDBKey::BinaryType: | 96 case IDBKey::BinaryType: |
| 94 return toV8(DOMUint8Array::create(reinterpret_cast<const unsigned char*> (key->binary()->data()), key->binary()->size()), creationContext, isolate); | 97 return toV8(DOMArrayBuffer::create(reinterpret_cast<const unsigned char* >(key->binary()->data()), key->binary()->size()), creationContext, isolate); |
| 95 case IDBKey::DateType: | 98 case IDBKey::DateType: |
| 96 return v8::Date::New(isolate->GetCurrentContext(), key->date()).ToLocalC hecked(); | 99 return v8::Date::New(isolate->GetCurrentContext(), key->date()).ToLocalC hecked(); |
| 97 case IDBKey::ArrayType: | 100 case IDBKey::ArrayType: |
| 98 { | 101 { |
| 99 v8::Local<v8::Array> array = v8::Array::New(isolate, key->array().si ze()); | 102 v8::Local<v8::Array> array = v8::Array::New(isolate, key->array().si ze()); |
| 100 for (size_t i = 0; i < key->array().size(); ++i) { | 103 for (size_t i = 0; i < key->array().size(); ++i) { |
| 101 v8::Local<v8::Value> value = toV8(key->array()[i].get(), creatio nContext, isolate); | 104 v8::Local<v8::Value> value = toV8(key->array()[i].get(), creatio nContext, isolate); |
| 102 if (value.IsEmpty()) | 105 if (value.IsEmpty()) |
| 103 value = v8::Undefined(isolate); | 106 value = v8::Undefined(isolate); |
| 104 array->Set(i, value); | 107 array->Set(i, value); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 static const size_t maximumDepth = 2000; | 185 static const size_t maximumDepth = 2000; |
| 183 | 186 |
| 184 static IDBKey* createIDBKeyFromValue(v8::Isolate* isolate, v8::Local<v8::Value> value, Vector<v8::Local<v8::Array>>& stack, bool allowExperimentalTypes = false) | 187 static IDBKey* createIDBKeyFromValue(v8::Isolate* isolate, v8::Local<v8::Value> value, Vector<v8::Local<v8::Array>>& stack, bool allowExperimentalTypes = false) |
| 185 { | 188 { |
| 186 if (value->IsNumber() && !std::isnan(value.As<v8::Number>()->Value())) | 189 if (value->IsNumber() && !std::isnan(value.As<v8::Number>()->Value())) |
| 187 return IDBKey::createNumber(value.As<v8::Number>()->Value()); | 190 return IDBKey::createNumber(value.As<v8::Number>()->Value()); |
| 188 if (value->IsString()) | 191 if (value->IsString()) |
| 189 return IDBKey::createString(toCoreString(value.As<v8::String>())); | 192 return IDBKey::createString(toCoreString(value.As<v8::String>())); |
| 190 if (value->IsDate() && !std::isnan(value.As<v8::Date>()->ValueOf())) | 193 if (value->IsDate() && !std::isnan(value.As<v8::Date>()->ValueOf())) |
| 191 return IDBKey::createDate(value.As<v8::Date>()->ValueOf()); | 194 return IDBKey::createDate(value.As<v8::Date>()->ValueOf()); |
| 192 if (value->IsUint8Array() && (allowExperimentalTypes || RuntimeEnabledFeatur es::indexedDBExperimentalEnabled())) { | 195 if (allowExperimentalTypes || RuntimeEnabledFeatures::indexedDBExperimentalE nabled()) { |
| 193 // Per discussion in https://www.w3.org/Bugs/Public/show_bug.cgi?id=2333 2 the | 196 // Experimental feature: binary keys |
| 194 // input type is constrained to Uint8Array to match the output type. | 197 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=23332 |
| 195 DOMArrayBufferView* view = blink::V8ArrayBufferView::toImpl(value.As<v8: :Object>()); | 198 if (value->IsArrayBuffer()) { |
| 196 const char* start = static_cast<const char*>(view->baseAddress()); | 199 DOMArrayBuffer* buffer = blink::V8ArrayBuffer::toImpl(value.As<v8::O bject>()); |
| 197 size_t length = view->byteLength(); | 200 const char* start = static_cast<const char*>(buffer->data()); |
| 198 return IDBKey::createBinary(SharedBuffer::create(start, length)); | 201 size_t length = buffer->byteLength(); |
| 202 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/
| |
| 203 } | |
| 204 if (value->IsArrayBufferView()) { | |
| 205 DOMArrayBufferView* view = blink::V8ArrayBufferView::toImpl(value.As <v8::Object>()); | |
| 206 const char* start = static_cast<const char*>(view->baseAddress()); | |
| 207 size_t length = view->byteLength(); | |
| 208 return IDBKey::createBinary(SharedBuffer::create(start, length)); | |
| 209 } | |
| 199 } | 210 } |
| 200 if (value->IsArray()) { | 211 if (value->IsArray()) { |
| 201 v8::Local<v8::Array> array = value.As<v8::Array>(); | 212 v8::Local<v8::Array> array = value.As<v8::Array>(); |
| 202 | 213 |
| 203 if (stack.contains(array)) | 214 if (stack.contains(array)) |
| 204 return nullptr; | 215 return nullptr; |
| 205 if (stack.size() >= maximumDepth) | 216 if (stack.size() >= maximumDepth) |
| 206 return nullptr; | 217 return nullptr; |
| 207 stack.append(array); | 218 stack.append(array); |
| 208 | 219 |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 const bool allowExperimentalTypes = true; | 458 const bool allowExperimentalTypes = true; |
| 448 IDBKey* expectedKey = createIDBKeyFromValueAndKeyPath(isolate, scriptValue.v 8Value(), value->keyPath(), allowExperimentalTypes); | 459 IDBKey* expectedKey = createIDBKeyFromValueAndKeyPath(isolate, scriptValue.v 8Value(), value->keyPath(), allowExperimentalTypes); |
| 449 ASSERT(!expectedKey || expectedKey->isEqual(value->primaryKey())); | 460 ASSERT(!expectedKey || expectedKey->isEqual(value->primaryKey())); |
| 450 | 461 |
| 451 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa lue.v8Value(), value->keyPath()); | 462 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa lue.v8Value(), value->keyPath()); |
| 452 ASSERT_UNUSED(injected, injected); | 463 ASSERT_UNUSED(injected, injected); |
| 453 } | 464 } |
| 454 #endif | 465 #endif |
| 455 | 466 |
| 456 } // namespace blink | 467 } // namespace blink |
| OLD | NEW |