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 |
11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
13 * | 13 * |
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
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/IDBBindingUtilities.h" | 27 #include "bindings/modules/v8/IDBBindingUtilities.h" |
28 | 28 |
29 #include "bindings/core/v8/SerializedScriptValue.h" | 29 #include "bindings/core/v8/SerializedScriptValue.h" |
| 30 #include "bindings/core/v8/V8ArrayBufferView.h" |
30 #include "bindings/core/v8/V8Binding.h" | 31 #include "bindings/core/v8/V8Binding.h" |
31 #include "bindings/core/v8/V8DOMStringList.h" | 32 #include "bindings/core/v8/V8DOMStringList.h" |
32 #include "bindings/core/v8/V8HiddenValue.h" | 33 #include "bindings/core/v8/V8HiddenValue.h" |
33 #include "bindings/core/v8/custom/V8ArrayBufferViewCustom.h" | 34 #include "bindings/core/v8/V8Uint8Array.h" |
34 #include "bindings/core/v8/custom/V8Uint8ArrayCustom.h" | |
35 #include "bindings/modules/v8/V8IDBCursor.h" | 35 #include "bindings/modules/v8/V8IDBCursor.h" |
36 #include "bindings/modules/v8/V8IDBCursorWithValue.h" | 36 #include "bindings/modules/v8/V8IDBCursorWithValue.h" |
37 #include "bindings/modules/v8/V8IDBDatabase.h" | 37 #include "bindings/modules/v8/V8IDBDatabase.h" |
38 #include "bindings/modules/v8/V8IDBIndex.h" | 38 #include "bindings/modules/v8/V8IDBIndex.h" |
39 #include "bindings/modules/v8/V8IDBKeyRange.h" | 39 #include "bindings/modules/v8/V8IDBKeyRange.h" |
40 #include "bindings/modules/v8/V8IDBObjectStore.h" | 40 #include "bindings/modules/v8/V8IDBObjectStore.h" |
41 #include "bindings/modules/v8/V8IDBRequest.h" | 41 #include "bindings/modules/v8/V8IDBRequest.h" |
42 #include "bindings/modules/v8/V8IDBTransaction.h" | 42 #include "bindings/modules/v8/V8IDBTransaction.h" |
43 #include "modules/indexeddb/IDBKey.h" | 43 #include "modules/indexeddb/IDBKey.h" |
44 #include "modules/indexeddb/IDBKeyPath.h" | 44 #include "modules/indexeddb/IDBKeyPath.h" |
45 #include "modules/indexeddb/IDBKeyRange.h" | 45 #include "modules/indexeddb/IDBKeyRange.h" |
46 #include "modules/indexeddb/IDBTracing.h" | 46 #include "modules/indexeddb/IDBTracing.h" |
47 #include "platform/RuntimeEnabledFeatures.h" | 47 #include "platform/RuntimeEnabledFeatures.h" |
48 #include "platform/SharedBuffer.h" | 48 #include "platform/SharedBuffer.h" |
49 #include "wtf/ArrayBufferView.h" | |
50 #include "wtf/MathExtras.h" | 49 #include "wtf/MathExtras.h" |
51 #include "wtf/Uint8Array.h" | 50 #include "wtf/Uint8Array.h" |
52 #include "wtf/Vector.h" | 51 #include "wtf/Vector.h" |
53 | 52 |
54 namespace blink { | 53 namespace blink { |
55 | 54 |
56 static v8::Local<v8::Value> deserializeIDBValueBuffer(v8::Isolate*, SharedBuffer
*, const Vector<blink::WebBlobInfo>*); | 55 static v8::Local<v8::Value> deserializeIDBValueBuffer(v8::Isolate*, SharedBuffer
*, const Vector<blink::WebBlobInfo>*); |
57 | 56 |
58 static v8::Local<v8::Value> toV8(const IDBKeyPath& value, v8::Local<v8::Object>
creationContext, v8::Isolate* isolate) | 57 static v8::Local<v8::Value> toV8(const IDBKeyPath& value, v8::Local<v8::Object>
creationContext, v8::Isolate* isolate) |
59 { | 58 { |
(...skipping 23 matching lines...) Expand all Loading... |
83 switch (key->type()) { | 82 switch (key->type()) { |
84 case IDBKey::InvalidType: | 83 case IDBKey::InvalidType: |
85 case IDBKey::MinType: | 84 case IDBKey::MinType: |
86 ASSERT_NOT_REACHED(); | 85 ASSERT_NOT_REACHED(); |
87 return v8Undefined(); | 86 return v8Undefined(); |
88 case IDBKey::NumberType: | 87 case IDBKey::NumberType: |
89 return v8::Number::New(isolate, key->number()); | 88 return v8::Number::New(isolate, key->number()); |
90 case IDBKey::StringType: | 89 case IDBKey::StringType: |
91 return v8String(isolate, key->string()); | 90 return v8String(isolate, key->string()); |
92 case IDBKey::BinaryType: | 91 case IDBKey::BinaryType: |
93 return toV8(Uint8Array::create(reinterpret_cast<const unsigned char*>(ke
y->binary()->data()), key->binary()->size()), creationContext, isolate); | 92 return toV8(DOMUint8Array::create(reinterpret_cast<const unsigned char*>
(key->binary()->data()), key->binary()->size()), creationContext, isolate); |
94 case IDBKey::DateType: | 93 case IDBKey::DateType: |
95 return v8::Date::New(isolate, key->date()); | 94 return v8::Date::New(isolate, key->date()); |
96 case IDBKey::ArrayType: | 95 case IDBKey::ArrayType: |
97 { | 96 { |
98 v8::Local<v8::Array> array = v8::Array::New(isolate, key->array().si
ze()); | 97 v8::Local<v8::Array> array = v8::Array::New(isolate, key->array().si
ze()); |
99 for (size_t i = 0; i < key->array().size(); ++i) | 98 for (size_t i = 0; i < key->array().size(); ++i) |
100 array->Set(i, toV8(key->array()[i].get(), creationContext, isola
te)); | 99 array->Set(i, toV8(key->array()[i].get(), creationContext, isola
te)); |
101 return array; | 100 return array; |
102 } | 101 } |
103 } | 102 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 { | 176 { |
178 if (value->IsNumber() && !std::isnan(value->NumberValue())) | 177 if (value->IsNumber() && !std::isnan(value->NumberValue())) |
179 return IDBKey::createNumber(value->NumberValue()); | 178 return IDBKey::createNumber(value->NumberValue()); |
180 if (value->IsString()) | 179 if (value->IsString()) |
181 return IDBKey::createString(toCoreString(value.As<v8::String>())); | 180 return IDBKey::createString(toCoreString(value.As<v8::String>())); |
182 if (value->IsDate() && !std::isnan(value->NumberValue())) | 181 if (value->IsDate() && !std::isnan(value->NumberValue())) |
183 return IDBKey::createDate(value->NumberValue()); | 182 return IDBKey::createDate(value->NumberValue()); |
184 if (value->IsUint8Array() && (allowExperimentalTypes || RuntimeEnabledFeatur
es::indexedDBExperimentalEnabled())) { | 183 if (value->IsUint8Array() && (allowExperimentalTypes || RuntimeEnabledFeatur
es::indexedDBExperimentalEnabled())) { |
185 // Per discussion in https://www.w3.org/Bugs/Public/show_bug.cgi?id=2333
2 the | 184 // Per discussion in https://www.w3.org/Bugs/Public/show_bug.cgi?id=2333
2 the |
186 // input type is constrained to Uint8Array to match the output type. | 185 // input type is constrained to Uint8Array to match the output type. |
187 ArrayBufferView* view = blink::V8ArrayBufferView::toImpl(value->ToObject
()); | 186 DOMArrayBufferView* view = blink::V8ArrayBufferView::toImpl(value->ToObj
ect()); |
188 const char* start = static_cast<const char*>(view->baseAddress()); | 187 const char* start = static_cast<const char*>(view->baseAddress()); |
189 size_t length = view->byteLength(); | 188 size_t length = view->byteLength(); |
190 return IDBKey::createBinary(SharedBuffer::create(start, length)); | 189 return IDBKey::createBinary(SharedBuffer::create(start, length)); |
191 } | 190 } |
192 if (value->IsArray()) { | 191 if (value->IsArray()) { |
193 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(value); | 192 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(value); |
194 | 193 |
195 if (stack.contains(array)) | 194 if (stack.contains(array)) |
196 return 0; | 195 return 0; |
197 if (stack.size() >= maximumDepth) | 196 if (stack.size() >= maximumDepth) |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 const bool allowExperimentalTypes = true; | 457 const bool allowExperimentalTypes = true; |
459 IDBKey* expectedKey = createIDBKeyFromScriptValueAndKeyPathInternal(isolate,
scriptValue, keyPath, allowExperimentalTypes); | 458 IDBKey* expectedKey = createIDBKeyFromScriptValueAndKeyPathInternal(isolate,
scriptValue, keyPath, allowExperimentalTypes); |
460 ASSERT(!expectedKey || expectedKey->isEqual(key)); | 459 ASSERT(!expectedKey || expectedKey->isEqual(key)); |
461 | 460 |
462 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa
lue.v8Value(), keyPath); | 461 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa
lue.v8Value(), keyPath); |
463 ASSERT_UNUSED(injected, injected); | 462 ASSERT_UNUSED(injected, injected); |
464 } | 463 } |
465 #endif | 464 #endif |
466 | 465 |
467 } // namespace blink | 466 } // namespace blink |
OLD | NEW |