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/V8Blob.h" | 34 #include "bindings/core/v8/V8Blob.h" |
34 #include "bindings/core/v8/V8DOMStringList.h" | 35 #include "bindings/core/v8/V8DOMStringList.h" |
35 #include "bindings/core/v8/V8File.h" | 36 #include "bindings/core/v8/V8File.h" |
36 #include "bindings/core/v8/V8HiddenValue.h" | 37 #include "bindings/core/v8/V8HiddenValue.h" |
37 #include "bindings/core/v8/V8Uint8Array.h" | 38 #include "bindings/core/v8/V8Uint8Array.h" |
38 #include "bindings/modules/v8/ToV8ForModules.h" | 39 #include "bindings/modules/v8/ToV8ForModules.h" |
39 #include "bindings/modules/v8/V8IDBCursor.h" | 40 #include "bindings/modules/v8/V8IDBCursor.h" |
40 #include "bindings/modules/v8/V8IDBCursorWithValue.h" | 41 #include "bindings/modules/v8/V8IDBCursorWithValue.h" |
41 #include "bindings/modules/v8/V8IDBDatabase.h" | 42 #include "bindings/modules/v8/V8IDBDatabase.h" |
42 #include "bindings/modules/v8/V8IDBIndex.h" | 43 #include "bindings/modules/v8/V8IDBIndex.h" |
43 #include "bindings/modules/v8/V8IDBKeyRange.h" | 44 #include "bindings/modules/v8/V8IDBKeyRange.h" |
44 #include "bindings/modules/v8/V8IDBObjectStore.h" | 45 #include "bindings/modules/v8/V8IDBObjectStore.h" |
| 46 #include "core/dom/DOMArrayBuffer.h" |
| 47 #include "core/dom/DOMArrayBufferView.h" |
45 #include "modules/indexeddb/IDBKey.h" | 48 #include "modules/indexeddb/IDBKey.h" |
46 #include "modules/indexeddb/IDBKeyPath.h" | 49 #include "modules/indexeddb/IDBKeyPath.h" |
47 #include "modules/indexeddb/IDBKeyRange.h" | 50 #include "modules/indexeddb/IDBKeyRange.h" |
48 #include "modules/indexeddb/IDBTracing.h" | 51 #include "modules/indexeddb/IDBTracing.h" |
49 #include "modules/indexeddb/IDBValue.h" | 52 #include "modules/indexeddb/IDBValue.h" |
50 #include "platform/RuntimeEnabledFeatures.h" | 53 #include "platform/RuntimeEnabledFeatures.h" |
51 #include "platform/SharedBuffer.h" | 54 #include "platform/SharedBuffer.h" |
52 #include "wtf/MathExtras.h" | 55 #include "wtf/MathExtras.h" |
53 #include "wtf/Vector.h" | 56 #include "wtf/Vector.h" |
54 | 57 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 switch (key->type()) { | 93 switch (key->type()) { |
91 case IDBKey::InvalidType: | 94 case IDBKey::InvalidType: |
92 case IDBKey::MinType: | 95 case IDBKey::MinType: |
93 ASSERT_NOT_REACHED(); | 96 ASSERT_NOT_REACHED(); |
94 return v8Undefined(); | 97 return v8Undefined(); |
95 case IDBKey::NumberType: | 98 case IDBKey::NumberType: |
96 return v8::Number::New(isolate, key->number()); | 99 return v8::Number::New(isolate, key->number()); |
97 case IDBKey::StringType: | 100 case IDBKey::StringType: |
98 return v8String(isolate, key->string()); | 101 return v8String(isolate, key->string()); |
99 case IDBKey::BinaryType: | 102 case IDBKey::BinaryType: |
100 return toV8(DOMUint8Array::create(reinterpret_cast<const unsigned char*>
(key->binary()->data()), key->binary()->size()), creationContext, isolate); | 103 // Experimental feature: binary keys |
| 104 // https://w3c.github.io/IndexedDB/#steps-to-convert-a-key-to-a-value |
| 105 return toV8(DOMArrayBuffer::create(reinterpret_cast<const unsigned char*
>(key->binary()->data()), key->binary()->size()), creationContext, isolate); |
101 case IDBKey::DateType: | 106 case IDBKey::DateType: |
102 return v8::Date::New(context, key->date()).ToLocalChecked(); | 107 return v8::Date::New(context, key->date()).ToLocalChecked(); |
103 case IDBKey::ArrayType: | 108 case IDBKey::ArrayType: |
104 { | 109 { |
105 v8::Local<v8::Array> array = v8::Array::New(isolate, key->array().si
ze()); | 110 v8::Local<v8::Array> array = v8::Array::New(isolate, key->array().si
ze()); |
106 for (size_t i = 0; i < key->array().size(); ++i) { | 111 for (size_t i = 0; i < key->array().size(); ++i) { |
107 v8::Local<v8::Value> value = toV8(key->array()[i].get(), creatio
nContext, isolate); | 112 v8::Local<v8::Value> value = toV8(key->array()[i].get(), creatio
nContext, isolate); |
108 if (value.IsEmpty()) | 113 if (value.IsEmpty()) |
109 value = v8::Undefined(isolate); | 114 value = v8::Undefined(isolate); |
110 // TODO(jsbell): Use DefineOwnProperty when exposed by V8. http:
//crbug.com/475206 | 115 // TODO(jsbell): Use DefineOwnProperty when exposed by V8. http:
//crbug.com/475206 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 static const size_t maximumDepth = 2000; | 188 static const size_t maximumDepth = 2000; |
184 | 189 |
185 static IDBKey* createIDBKeyFromValue(v8::Isolate* isolate, v8::Local<v8::Value>
value, Vector<v8::Local<v8::Array>>& stack, bool allowExperimentalTypes = false) | 190 static IDBKey* createIDBKeyFromValue(v8::Isolate* isolate, v8::Local<v8::Value>
value, Vector<v8::Local<v8::Array>>& stack, bool allowExperimentalTypes = false) |
186 { | 191 { |
187 if (value->IsNumber() && !std::isnan(value.As<v8::Number>()->Value())) | 192 if (value->IsNumber() && !std::isnan(value.As<v8::Number>()->Value())) |
188 return IDBKey::createNumber(value.As<v8::Number>()->Value()); | 193 return IDBKey::createNumber(value.As<v8::Number>()->Value()); |
189 if (value->IsString()) | 194 if (value->IsString()) |
190 return IDBKey::createString(toCoreString(value.As<v8::String>())); | 195 return IDBKey::createString(toCoreString(value.As<v8::String>())); |
191 if (value->IsDate() && !std::isnan(value.As<v8::Date>()->ValueOf())) | 196 if (value->IsDate() && !std::isnan(value.As<v8::Date>()->ValueOf())) |
192 return IDBKey::createDate(value.As<v8::Date>()->ValueOf()); | 197 return IDBKey::createDate(value.As<v8::Date>()->ValueOf()); |
193 if (value->IsUint8Array() && (allowExperimentalTypes || RuntimeEnabledFeatur
es::indexedDBExperimentalEnabled())) { | 198 if (allowExperimentalTypes || RuntimeEnabledFeatures::indexedDBExperimentalE
nabled()) { |
194 // Per discussion in https://www.w3.org/Bugs/Public/show_bug.cgi?id=2333
2 the | 199 // Experimental feature: binary keys |
195 // input type is constrained to Uint8Array to match the output type. | 200 // https://w3c.github.io/IndexedDB/#dfn-convert-a-value-to-a-key |
196 DOMArrayBufferView* view = V8ArrayBufferView::toImpl(value.As<v8::Object
>()); | 201 if (value->IsArrayBuffer()) { |
197 const char* start = static_cast<const char*>(view->baseAddress()); | 202 DOMArrayBuffer* buffer = V8ArrayBuffer::toImpl(value.As<v8::Object>(
)); |
198 size_t length = view->byteLength(); | 203 const char* start = static_cast<const char*>(buffer->data()); |
199 return IDBKey::createBinary(SharedBuffer::create(start, length)); | 204 size_t length = buffer->byteLength(); |
| 205 return IDBKey::createBinary(SharedBuffer::create(start, length)); |
| 206 } |
| 207 if (value->IsArrayBufferView()) { |
| 208 DOMArrayBufferView* view = V8ArrayBufferView::toImpl(value.As<v8::Ob
ject>()); |
| 209 const char* start = static_cast<const char*>(view->baseAddress()); |
| 210 size_t length = view->byteLength(); |
| 211 return IDBKey::createBinary(SharedBuffer::create(start, length)); |
| 212 } |
200 } | 213 } |
201 if (value->IsArray()) { | 214 if (value->IsArray()) { |
202 v8::Local<v8::Array> array = value.As<v8::Array>(); | 215 v8::Local<v8::Array> array = value.As<v8::Array>(); |
203 | 216 |
204 if (stack.contains(array)) | 217 if (stack.contains(array)) |
205 return nullptr; | 218 return nullptr; |
206 if (stack.size() >= maximumDepth) | 219 if (stack.size() >= maximumDepth) |
207 return nullptr; | 220 return nullptr; |
208 stack.append(array); | 221 stack.append(array); |
209 | 222 |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 IDBKey* expectedKey = createIDBKeyFromValueAndKeyPath(isolate, scriptValue.v
8Value(), value->keyPath(), allowExperimentalTypes); | 534 IDBKey* expectedKey = createIDBKeyFromValueAndKeyPath(isolate, scriptValue.v
8Value(), value->keyPath(), allowExperimentalTypes); |
522 if (expectedKey && expectedKey->isEqual(value->primaryKey())) | 535 if (expectedKey && expectedKey->isEqual(value->primaryKey())) |
523 return; | 536 return; |
524 | 537 |
525 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa
lue.v8Value(), value->keyPath()); | 538 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa
lue.v8Value(), value->keyPath()); |
526 ASSERT_UNUSED(injected, injected); | 539 ASSERT_UNUSED(injected, injected); |
527 } | 540 } |
528 #endif | 541 #endif |
529 | 542 |
530 } // namespace blink | 543 } // namespace blink |
OLD | NEW |