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