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/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/V8ArrayBufferView.h" | 31 #include "bindings/core/v8/V8ArrayBufferView.h" |
32 #include "bindings/core/v8/V8Binding.h" | 32 #include "bindings/core/v8/V8Binding.h" |
33 #include "bindings/core/v8/V8DOMStringList.h" | 33 #include "bindings/core/v8/V8DOMStringList.h" |
34 #include "bindings/core/v8/V8HiddenValue.h" | 34 #include "bindings/core/v8/V8HiddenValue.h" |
35 #include "bindings/core/v8/V8Uint8Array.h" | 35 #include "bindings/core/v8/V8Uint8Array.h" |
36 #include "bindings/modules/v8/V8IDBCursor.h" | 36 #include "bindings/modules/v8/V8IDBCursor.h" |
37 #include "bindings/modules/v8/V8IDBCursorWithValue.h" | 37 #include "bindings/modules/v8/V8IDBCursorWithValue.h" |
38 #include "bindings/modules/v8/V8IDBDatabase.h" | 38 #include "bindings/modules/v8/V8IDBDatabase.h" |
39 #include "bindings/modules/v8/V8IDBIndex.h" | 39 #include "bindings/modules/v8/V8IDBIndex.h" |
40 #include "bindings/modules/v8/V8IDBKeyRange.h" | 40 #include "bindings/modules/v8/V8IDBKeyRange.h" |
41 #include "bindings/modules/v8/V8IDBObjectStore.h" | 41 #include "bindings/modules/v8/V8IDBObjectStore.h" |
42 #include "bindings/modules/v8/V8IDBRequest.h" | 42 #include "bindings/modules/v8/V8IDBRequest.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/MathExtras.h" | 49 #include "wtf/MathExtras.h" |
50 #include "wtf/Vector.h" | 50 #include "wtf/Vector.h" |
51 | 51 |
52 namespace blink { | 52 namespace blink { |
53 | 53 |
54 static v8::Local<v8::Value> deserializeIDBValueBuffer(v8::Isolate*, SharedBuffer *, const Vector<blink::WebBlobInfo>*); | 54 static v8::Local<v8::Value> deserializeIDBValueBuffer(v8::Isolate*, SharedBuffer *, const Vector<blink::WebBlobInfo>*); |
55 | 55 |
56 static v8::Local<v8::Value> toV8(const IDBKeyPath& value, v8::Local<v8::Object> creationContext, v8::Isolate* isolate) | 56 v8::Local<v8::Value> toV8(const IDBKeyPath& value, v8::Local<v8::Object> creatio nContext, v8::Isolate* isolate) |
57 { | 57 { |
58 switch (value.type()) { | 58 switch (value.type()) { |
59 case IDBKeyPath::NullType: | 59 case IDBKeyPath::NullType: |
60 return v8::Null(isolate); | 60 return v8::Null(isolate); |
61 case IDBKeyPath::StringType: | 61 case IDBKeyPath::StringType: |
62 return v8String(isolate, value.string()); | 62 return v8String(isolate, value.string()); |
63 case IDBKeyPath::ArrayType: | 63 case IDBKeyPath::ArrayType: |
64 RefPtrWillBeRawPtr<DOMStringList> keyPaths = DOMStringList::create(); | 64 RefPtrWillBeRawPtr<DOMStringList> keyPaths = DOMStringList::create(); |
65 for (Vector<String>::const_iterator it = value.array().begin(); it != va lue.array().end(); ++it) | 65 for (Vector<String>::const_iterator it = value.array().begin(); it != va lue.array().end(); ++it) |
66 keyPaths->append(*it); | 66 keyPaths->append(*it); |
67 return toV8(keyPaths.release(), creationContext, isolate); | 67 return toV8(keyPaths.release(), creationContext, isolate); |
68 } | 68 } |
69 ASSERT_NOT_REACHED(); | 69 ASSERT_NOT_REACHED(); |
70 return v8::Undefined(isolate); | 70 return v8::Undefined(isolate); |
71 } | 71 } |
72 | 72 |
73 static v8::Local<v8::Value> toV8(const IDBKey* key, v8::Local<v8::Object> creati onContext, v8::Isolate* isolate) | 73 v8::Local<v8::Value> toV8(const IDBKey* key, v8::Local<v8::Object> creationConte xt, v8::Isolate* isolate) |
74 { | 74 { |
75 if (!key) { | 75 if (!key) { |
76 // This should be undefined, not null. | 76 // This should be undefined, not null. |
77 // Spec: http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#idl- def-IDBKeyRange | 77 // Spec: http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#idl- def-IDBKeyRange |
78 return v8Undefined(); | 78 return v8Undefined(); |
79 } | 79 } |
80 | 80 |
81 switch (key->type()) { | 81 switch (key->type()) { |
82 case IDBKey::InvalidType: | 82 case IDBKey::InvalidType: |
83 case IDBKey::MinType: | 83 case IDBKey::MinType: |
(...skipping 13 matching lines...) Expand all Loading... | |
97 for (size_t i = 0; i < key->array().size(); ++i) | 97 for (size_t i = 0; i < key->array().size(); ++i) |
98 array->Set(i, toV8(key->array()[i].get(), creationContext, isola te)); | 98 array->Set(i, toV8(key->array()[i].get(), creationContext, isola te)); |
99 return array; | 99 return array; |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 ASSERT_NOT_REACHED(); | 103 ASSERT_NOT_REACHED(); |
104 return v8Undefined(); | 104 return v8Undefined(); |
105 } | 105 } |
106 | 106 |
107 static v8::Local<v8::Value> toV8(const IDBAny* impl, v8::Local<v8::Object> creat ionContext, v8::Isolate* isolate) | 107 v8::Local<v8::Value> toV8(const IDBAny* impl, v8::Local<v8::Object> creationCont ext, v8::Isolate* isolate) |
108 { | 108 { |
109 if (!impl) | 109 if (!impl) |
110 return v8::Null(isolate); | 110 return v8::Null(isolate); |
111 | 111 |
112 switch (impl->type()) { | 112 switch (impl->type()) { |
113 case IDBAny::UndefinedType: | 113 case IDBAny::UndefinedType: |
114 return v8::Undefined(isolate); | 114 return v8::Undefined(isolate); |
115 case IDBAny::NullType: | 115 case IDBAny::NullType: |
116 return v8::Null(isolate); | 116 return v8::Null(isolate); |
117 case IDBAny::DOMStringListType: | 117 case IDBAny::DOMStringListType: |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
391 IDBParseKeyPath(keyPath.string(), keyPathElements, error); | 391 IDBParseKeyPath(keyPath.string(), keyPathElements, error); |
392 ASSERT(error == IDBKeyPathParseErrorNone); | 392 ASSERT(error == IDBKeyPathParseErrorNone); |
393 | 393 |
394 if (!keyPathElements.size()) | 394 if (!keyPathElements.size()) |
395 return false; | 395 return false; |
396 | 396 |
397 v8::Local<v8::Value> v8Value(scriptValue.v8Value()); | 397 v8::Local<v8::Value> v8Value(scriptValue.v8Value()); |
398 return canInjectNthValueOnKeyPath(isolate, v8Value, keyPathElements, keyPath Elements.size() - 1); | 398 return canInjectNthValueOnKeyPath(isolate, v8Value, keyPathElements, keyPath Elements.size() - 1); |
399 } | 399 } |
400 | 400 |
401 ScriptValue idbAnyToScriptValue(ScriptState* scriptState, IDBAny* any) | |
402 { | |
403 v8::Isolate* isolate = scriptState->isolate(); | |
404 v8::HandleScope handleScope(isolate); | |
405 v8::Local<v8::Value> v8Value(toV8(any, scriptState->context()->Global(), iso late)); | |
406 return ScriptValue(scriptState, v8Value); | |
407 } | |
408 | |
409 ScriptValue idbKeyToScriptValue(ScriptState* scriptState, const IDBKey* key) | |
410 { | |
411 v8::Isolate* isolate = scriptState->isolate(); | |
412 v8::HandleScope handleScope(isolate); | |
413 v8::Local<v8::Value> v8Value(toV8(key, scriptState->context()->Global(), iso late)); | |
414 return ScriptValue(scriptState, v8Value); | |
415 } | |
416 | |
417 ScriptValue idbKeyPathToScriptValue(ScriptState* scriptState, const IDBKeyPath& keyPath) | |
418 { | |
419 v8::Isolate* isolate = scriptState->isolate(); | |
420 v8::HandleScope handleScope(isolate); | |
421 v8::Local<v8::Value> v8Value(toV8(keyPath, scriptState->context()->Global(), isolate)); | |
422 return ScriptValue(scriptState, v8Value); | |
423 } | |
424 | |
425 IDBKey* scriptValueToIDBKey(v8::Isolate* isolate, const ScriptValue& scriptValue ) | |
426 { | |
427 ASSERT(isolate->InContext()); | |
428 v8::HandleScope handleScope(isolate); | |
429 v8::Local<v8::Value> v8Value(scriptValue.v8Value()); | |
430 return createIDBKeyFromValue(isolate, v8Value); | |
431 } | |
432 | |
433 IDBKeyRange* scriptValueToIDBKeyRange(v8::Isolate* isolate, const ScriptValue& s criptValue) | |
434 { | |
435 v8::HandleScope handleScope(isolate); | |
436 v8::Local<v8::Value> value(scriptValue.v8Value()); | |
437 return V8IDBKeyRange::toImplWithTypeCheck(isolate, value); | |
438 } | |
439 | |
440 ScriptValue deserializeScriptValue(ScriptState* scriptState, SerializedScriptVal ue* serializedValue, const Vector<blink::WebBlobInfo>* blobInfo) | 401 ScriptValue deserializeScriptValue(ScriptState* scriptState, SerializedScriptVal ue* serializedValue, const Vector<blink::WebBlobInfo>* blobInfo) |
441 { | 402 { |
442 v8::Isolate* isolate = scriptState->isolate(); | 403 v8::Isolate* isolate = scriptState->isolate(); |
443 v8::HandleScope handleScope(isolate); | 404 v8::HandleScope handleScope(isolate); |
444 if (serializedValue) | 405 if (serializedValue) |
445 return ScriptValue(scriptState, serializedValue->deserialize(isolate, 0, blobInfo)); | 406 return ScriptValue(scriptState, serializedValue->deserialize(isolate, 0, blobInfo)); |
446 return ScriptValue(scriptState, v8::Null(isolate)); | 407 return ScriptValue(scriptState, v8::Null(isolate)); |
447 } | 408 } |
448 | 409 |
449 #if ENABLE(ASSERT) | 410 #if ENABLE(ASSERT) |
450 void assertPrimaryKeyValidOrInjectable(ScriptState* scriptState, PassRefPtr<Shar edBuffer> buffer, const Vector<blink::WebBlobInfo>* blobInfo, IDBKey* key, const IDBKeyPath& keyPath) | 411 void assertPrimaryKeyValidOrInjectable(ScriptState* scriptState, PassRefPtr<Shar edBuffer> buffer, const Vector<blink::WebBlobInfo>* blobInfo, IDBKey* key, const IDBKeyPath& keyPath) |
451 { | 412 { |
452 ScriptState::Scope scope(scriptState); | 413 ScriptState::Scope scope(scriptState); |
453 v8::Isolate* isolate = scriptState->isolate(); | 414 v8::Isolate* isolate = scriptState->isolate(); |
454 ScriptValue keyValue = idbKeyToScriptValue(scriptState, key); | 415 ScriptValue keyValue = ScriptValue::from(scriptState, key); |
455 ScriptValue scriptValue(scriptState, deserializeIDBValueBuffer(isolate, buff er.get(), blobInfo)); | 416 ScriptValue scriptValue(scriptState, deserializeIDBValueBuffer(isolate, buff er.get(), blobInfo)); |
456 | 417 |
457 // This assertion is about already persisted data, so allow experimental typ es. | 418 // This assertion is about already persisted data, so allow experimental typ es. |
458 const bool allowExperimentalTypes = true; | 419 const bool allowExperimentalTypes = true; |
459 IDBKey* expectedKey = createIDBKeyFromScriptValueAndKeyPathInternal(isolate, scriptValue, keyPath, allowExperimentalTypes); | 420 IDBKey* expectedKey = createIDBKeyFromScriptValueAndKeyPathInternal(isolate, scriptValue, keyPath, allowExperimentalTypes); |
460 ASSERT(!expectedKey || expectedKey->isEqual(key)); | 421 ASSERT(!expectedKey || expectedKey->isEqual(key)); |
461 | 422 |
462 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa lue.v8Value(), keyPath); | 423 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa lue.v8Value(), keyPath); |
463 ASSERT_UNUSED(injected, injected); | 424 ASSERT_UNUSED(injected, injected); |
464 } | 425 } |
465 #endif | 426 #endif |
466 | 427 |
428 SQLValue NativeValueTraits<SQLValue>::nativeValue(const v8::Local<v8::Value>& va lue, v8::Isolate* isolate, ExceptionState& exceptionState) | |
429 { | |
430 if (value.IsEmpty() || value->IsNull()) | |
431 return SQLValue(); | |
432 if (value->IsNumber()) | |
433 return SQLValue(value->NumberValue()); | |
434 V8StringResource<> stringValue(value); | |
435 if (!stringValue.prepare(exceptionState)) | |
436 return SQLValue(); | |
437 return SQLValue(stringValue); | |
438 } | |
439 | |
440 IDBKey* NativeValueTraits<IDBKey*>::nativeValue(const v8::Local<v8::Value>& valu e, v8::Isolate* isolate, ExceptionState& exceptionState) | |
441 { | |
442 return createIDBKeyFromValue(isolate, value); | |
443 } | |
444 | |
445 IDBKeyRange* NativeValueTraits<IDBKeyRange*>::nativeValue(const v8::Local<v8::Va lue>& value, v8::Isolate* isolate, ExceptionState& exceptionState) | |
jsbell
2015/03/12 17:00:57
It seems like we could do something generic for Sc
| |
446 { | |
447 return V8IDBKeyRange::toImplWithTypeCheck(isolate, value); | |
448 } | |
449 | |
467 } // namespace blink | 450 } // namespace blink |
OLD | NEW |