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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 #include "modules/indexeddb/IDBKeyRange.h" | 46 #include "modules/indexeddb/IDBKeyRange.h" |
47 #include "modules/indexeddb/IDBTracing.h" | 47 #include "modules/indexeddb/IDBTracing.h" |
48 #include "platform/SharedBuffer.h" | 48 #include "platform/SharedBuffer.h" |
49 #include "wtf/ArrayBufferView.h" | 49 #include "wtf/ArrayBufferView.h" |
50 #include "wtf/MathExtras.h" | 50 #include "wtf/MathExtras.h" |
51 #include "wtf/Uint8Array.h" | 51 #include "wtf/Uint8Array.h" |
52 #include "wtf/Vector.h" | 52 #include "wtf/Vector.h" |
53 | 53 |
54 namespace WebCore { | 54 namespace WebCore { |
55 | 55 |
56 static v8::Handle<v8::Value> deserializeIDBValueBuffer(v8::Isolate*, SharedBuffe
r*); | 56 static v8::Handle<v8::Value> deserializeIDBValueBuffer(v8::Isolate*, SharedBuffe
r*, const Vector<blink::WebBlobInfo>*); |
57 | 57 |
58 static v8::Handle<v8::Value> toV8(const IDBKeyPath& value, v8::Handle<v8::Object
> creationContext, v8::Isolate* isolate) | 58 static v8::Handle<v8::Value> toV8(const IDBKeyPath& value, v8::Handle<v8::Object
> creationContext, v8::Isolate* isolate) |
59 { | 59 { |
60 switch (value.type()) { | 60 switch (value.type()) { |
61 case IDBKeyPath::NullType: | 61 case IDBKeyPath::NullType: |
62 return v8::Null(isolate); | 62 return v8::Null(isolate); |
63 case IDBKeyPath::StringType: | 63 case IDBKeyPath::StringType: |
64 return v8String(isolate, value.string()); | 64 return v8String(isolate, value.string()); |
65 case IDBKeyPath::ArrayType: | 65 case IDBKeyPath::ArrayType: |
66 RefPtr<DOMStringList> keyPaths = DOMStringList::create(); | 66 RefPtr<DOMStringList> keyPaths = DOMStringList::create(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 } | 136 } |
137 case IDBAny::IDBDatabaseType: | 137 case IDBAny::IDBDatabaseType: |
138 return toV8(impl->idbDatabase(), creationContext, isolate); | 138 return toV8(impl->idbDatabase(), creationContext, isolate); |
139 case IDBAny::IDBIndexType: | 139 case IDBAny::IDBIndexType: |
140 return toV8(impl->idbIndex(), creationContext, isolate); | 140 return toV8(impl->idbIndex(), creationContext, isolate); |
141 case IDBAny::IDBObjectStoreType: | 141 case IDBAny::IDBObjectStoreType: |
142 return toV8(impl->idbObjectStore(), creationContext, isolate); | 142 return toV8(impl->idbObjectStore(), creationContext, isolate); |
143 case IDBAny::IDBTransactionType: | 143 case IDBAny::IDBTransactionType: |
144 return toV8(impl->idbTransaction(), creationContext, isolate); | 144 return toV8(impl->idbTransaction(), creationContext, isolate); |
145 case IDBAny::BufferType: | 145 case IDBAny::BufferType: |
146 return deserializeIDBValueBuffer(isolate, impl->buffer()); | 146 return deserializeIDBValueBuffer(isolate, impl->buffer(), impl->blobInfo
()); |
147 case IDBAny::StringType: | 147 case IDBAny::StringType: |
148 return v8String(isolate, impl->string()); | 148 return v8String(isolate, impl->string()); |
149 case IDBAny::IntegerType: | 149 case IDBAny::IntegerType: |
150 return v8::Number::New(isolate, impl->integer()); | 150 return v8::Number::New(isolate, impl->integer()); |
151 case IDBAny::KeyType: | 151 case IDBAny::KeyType: |
152 return toV8(impl->key(), creationContext, isolate); | 152 return toV8(impl->key(), creationContext, isolate); |
153 case IDBAny::KeyPathType: | 153 case IDBAny::KeyPathType: |
154 return toV8(impl->keyPath(), creationContext, isolate); | 154 return toV8(impl->keyPath(), creationContext, isolate); |
155 case IDBAny::BufferKeyAndKeyPathType: { | 155 case IDBAny::BufferKeyAndKeyPathType: { |
156 v8::Handle<v8::Value> value = deserializeIDBValueBuffer(isolate, impl->b
uffer()); | 156 v8::Handle<v8::Value> value = deserializeIDBValueBuffer(isolate, impl->b
uffer(), impl->blobInfo()); |
157 v8::Handle<v8::Value> key = toV8(impl->key(), creationContext, isolate); | 157 v8::Handle<v8::Value> key = toV8(impl->key(), creationContext, isolate); |
158 bool injected = injectV8KeyIntoV8Value(isolate, key, value, impl->keyPat
h()); | 158 bool injected = injectV8KeyIntoV8Value(isolate, key, value, impl->keyPat
h()); |
159 ASSERT_UNUSED(injected, injected); | 159 ASSERT_UNUSED(injected, injected); |
160 return value; | 160 return value; |
161 } | 161 } |
162 } | 162 } |
163 | 163 |
164 ASSERT_NOT_REACHED(); | 164 ASSERT_NOT_REACHED(); |
165 return v8::Undefined(isolate); | 165 return v8::Undefined(isolate); |
166 } | 166 } |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 ASSERT(keyPath.type() == IDBKeyPath::StringType); | 340 ASSERT(keyPath.type() == IDBKeyPath::StringType); |
341 return createIDBKeyFromScriptValueAndKeyPathInternal(isolate, value, keyPath
.string(), allowExperimentalTypes); | 341 return createIDBKeyFromScriptValueAndKeyPathInternal(isolate, value, keyPath
.string(), allowExperimentalTypes); |
342 } | 342 } |
343 | 343 |
344 PassRefPtr<IDBKey> createIDBKeyFromScriptValueAndKeyPath(v8::Isolate* isolate, c
onst ScriptValue& value, const IDBKeyPath& keyPath) | 344 PassRefPtr<IDBKey> createIDBKeyFromScriptValueAndKeyPath(v8::Isolate* isolate, c
onst ScriptValue& value, const IDBKeyPath& keyPath) |
345 { | 345 { |
346 IDB_TRACE("createIDBKeyFromScriptValueAndKeyPath"); | 346 IDB_TRACE("createIDBKeyFromScriptValueAndKeyPath"); |
347 return createIDBKeyFromScriptValueAndKeyPathInternal(isolate, value, keyPath
); | 347 return createIDBKeyFromScriptValueAndKeyPathInternal(isolate, value, keyPath
); |
348 } | 348 } |
349 | 349 |
350 static v8::Handle<v8::Value> deserializeIDBValueBuffer(v8::Isolate* isolate, Sha
redBuffer* buffer) | 350 static v8::Handle<v8::Value> deserializeIDBValueBuffer(v8::Isolate* isolate, Sha
redBuffer* buffer, const Vector<blink::WebBlobInfo>* blobInfo) |
351 { | 351 { |
352 ASSERT(isolate->InContext()); | 352 ASSERT(isolate->InContext()); |
353 if (!buffer) | 353 if (!buffer) |
354 return v8::Null(isolate); | 354 return v8::Null(isolate); |
355 | 355 |
356 // FIXME: The extra copy here can be eliminated by allowing SerializedScript
Value to take a raw const char* or const uint8_t*. | 356 // FIXME: The extra copy here can be eliminated by allowing SerializedScript
Value to take a raw const char* or const uint8_t*. |
357 Vector<uint8_t> value; | 357 Vector<uint8_t> value; |
358 value.append(buffer->data(), buffer->size()); | 358 value.append(buffer->data(), buffer->size()); |
359 RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValue::creat
eFromWireBytes(value); | 359 RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValue::creat
eFromWireBytes(value); |
360 return serializedValue->deserialize(isolate, 0, 0); | 360 return serializedValue->deserialize(isolate, 0, blobInfo); |
361 } | 361 } |
362 | 362 |
363 bool injectV8KeyIntoV8Value(v8::Isolate* isolate, v8::Handle<v8::Value> key, v8:
:Handle<v8::Value> value, const IDBKeyPath& keyPath) | 363 bool injectV8KeyIntoV8Value(v8::Isolate* isolate, v8::Handle<v8::Value> key, v8:
:Handle<v8::Value> value, const IDBKeyPath& keyPath) |
364 { | 364 { |
365 IDB_TRACE("injectIDBV8KeyIntoV8Value"); | 365 IDB_TRACE("injectIDBV8KeyIntoV8Value"); |
366 ASSERT(isolate->InContext()); | 366 ASSERT(isolate->InContext()); |
367 | 367 |
368 ASSERT(keyPath.type() == IDBKeyPath::StringType); | 368 ASSERT(keyPath.type() == IDBKeyPath::StringType); |
369 Vector<String> keyPathElements; | 369 Vector<String> keyPathElements; |
370 IDBKeyPathParseError error; | 370 IDBKeyPathParseError error; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 } | 426 } |
427 | 427 |
428 PassRefPtr<IDBKeyRange> scriptValueToIDBKeyRange(v8::Isolate* isolate, const Scr
iptValue& scriptValue) | 428 PassRefPtr<IDBKeyRange> scriptValueToIDBKeyRange(v8::Isolate* isolate, const Scr
iptValue& scriptValue) |
429 { | 429 { |
430 v8::HandleScope handleScope(isolate); | 430 v8::HandleScope handleScope(isolate); |
431 v8::Handle<v8::Value> value(scriptValue.v8Value()); | 431 v8::Handle<v8::Value> value(scriptValue.v8Value()); |
432 return V8IDBKeyRange::toNativeWithTypeCheck(isolate, value); | 432 return V8IDBKeyRange::toNativeWithTypeCheck(isolate, value); |
433 } | 433 } |
434 | 434 |
435 #ifndef NDEBUG | 435 #ifndef NDEBUG |
436 void assertPrimaryKeyValidOrInjectable(NewScriptState* scriptState, PassRefPtr<S
haredBuffer> buffer, PassRefPtr<IDBKey> prpKey, const IDBKeyPath& keyPath) | 436 void assertPrimaryKeyValidOrInjectable(NewScriptState* scriptState, PassRefPtr<S
haredBuffer> buffer, const Vector<blink::WebBlobInfo>* blobInfo, PassRefPtr<IDBK
ey> prpKey, const IDBKeyPath& keyPath) |
437 { | 437 { |
438 RefPtr<IDBKey> key(prpKey); | 438 RefPtr<IDBKey> key(prpKey); |
439 | 439 |
440 NewScriptState::Scope scope(scriptState); | 440 NewScriptState::Scope scope(scriptState); |
441 v8::Isolate* isolate = scriptState->isolate(); | 441 v8::Isolate* isolate = scriptState->isolate(); |
442 ScriptValue keyValue = idbKeyToScriptValue(scriptState, key); | 442 ScriptValue keyValue = idbKeyToScriptValue(scriptState, key); |
443 ScriptValue scriptValue(deserializeIDBValueBuffer(isolate, buffer.get()), is
olate); | 443 ScriptValue scriptValue(deserializeIDBValueBuffer(isolate, buffer.get(), blo
bInfo), isolate); |
444 | 444 |
445 // This assertion is about already persisted data, so allow experimental typ
es. | 445 // This assertion is about already persisted data, so allow experimental typ
es. |
446 const bool allowExperimentalTypes = true; | 446 const bool allowExperimentalTypes = true; |
447 RefPtr<IDBKey> expectedKey = createIDBKeyFromScriptValueAndKeyPathInternal(i
solate, scriptValue, keyPath, allowExperimentalTypes); | 447 RefPtr<IDBKey> expectedKey = createIDBKeyFromScriptValueAndKeyPathInternal(i
solate, scriptValue, keyPath, allowExperimentalTypes); |
448 ASSERT(!expectedKey || expectedKey->isEqual(key.get())); | 448 ASSERT(!expectedKey || expectedKey->isEqual(key.get())); |
449 | 449 |
450 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa
lue.v8Value(), keyPath); | 450 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa
lue.v8Value(), keyPath); |
451 ASSERT_UNUSED(injected, injected); | 451 ASSERT_UNUSED(injected, injected); |
452 } | 452 } |
453 #endif | 453 #endif |
454 | 454 |
455 } // namespace WebCore | 455 } // namespace WebCore |
OLD | NEW |