| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 const IDBValue*); | 59 const IDBValue*); |
| 60 static v8::Local<v8::Value> deserializeIDBValue( | 60 static v8::Local<v8::Value> deserializeIDBValue( |
| 61 v8::Isolate*, | 61 v8::Isolate*, |
| 62 v8::Local<v8::Object> creationContext, | 62 v8::Local<v8::Object> creationContext, |
| 63 const IDBValue*); | 63 const IDBValue*); |
| 64 static v8::Local<v8::Value> deserializeIDBValueArray( | 64 static v8::Local<v8::Value> deserializeIDBValueArray( |
| 65 v8::Isolate*, | 65 v8::Isolate*, |
| 66 v8::Local<v8::Object> creationContext, | 66 v8::Local<v8::Object> creationContext, |
| 67 const Vector<RefPtr<IDBValue>>*); | 67 const Vector<RefPtr<IDBValue>>*); |
| 68 | 68 |
| 69 v8::Local<v8::Value> toV8(const IDBKeyPath& value, | 69 v8::Local<v8::Value> ToV8(const IDBKeyPath& value, |
| 70 v8::Local<v8::Object> creationContext, | 70 v8::Local<v8::Object> creationContext, |
| 71 v8::Isolate* isolate) { | 71 v8::Isolate* isolate) { |
| 72 switch (value.getType()) { | 72 switch (value.getType()) { |
| 73 case IDBKeyPath::NullType: | 73 case IDBKeyPath::NullType: |
| 74 return v8::Null(isolate); | 74 return v8::Null(isolate); |
| 75 case IDBKeyPath::StringType: | 75 case IDBKeyPath::StringType: |
| 76 return v8String(isolate, value.string()); | 76 return v8String(isolate, value.string()); |
| 77 case IDBKeyPath::ArrayType: | 77 case IDBKeyPath::ArrayType: |
| 78 return toV8(value.array(), creationContext, isolate); | 78 return ToV8(value.array(), creationContext, isolate); |
| 79 } | 79 } |
| 80 ASSERT_NOT_REACHED(); | 80 ASSERT_NOT_REACHED(); |
| 81 return v8::Undefined(isolate); | 81 return v8::Undefined(isolate); |
| 82 } | 82 } |
| 83 | 83 |
| 84 v8::Local<v8::Value> toV8(const IDBKey* key, | 84 v8::Local<v8::Value> ToV8(const IDBKey* key, |
| 85 v8::Local<v8::Object> creationContext, | 85 v8::Local<v8::Object> creationContext, |
| 86 v8::Isolate* isolate) { | 86 v8::Isolate* isolate) { |
| 87 if (!key) { | 87 if (!key) { |
| 88 // The IndexedDB spec requires that absent keys appear as attribute | 88 // The IndexedDB spec requires that absent keys appear as attribute |
| 89 // values as undefined, rather than the more typical (for DOM) null. | 89 // values as undefined, rather than the more typical (for DOM) null. |
| 90 // This appears on the |upper| and |lower| attributes of IDBKeyRange. | 90 // This appears on the |upper| and |lower| attributes of IDBKeyRange. |
| 91 // Spec: http://www.w3.org/TR/IndexedDB/#idl-def-IDBKeyRange | 91 // Spec: http://www.w3.org/TR/IndexedDB/#idl-def-IDBKeyRange |
| 92 return v8Undefined(); | 92 return v8Undefined(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 95 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 96 | 96 |
| 97 switch (key->getType()) { | 97 switch (key->getType()) { |
| 98 case IDBKey::InvalidType: | 98 case IDBKey::InvalidType: |
| 99 case IDBKey::MinType: | 99 case IDBKey::MinType: |
| 100 ASSERT_NOT_REACHED(); | 100 ASSERT_NOT_REACHED(); |
| 101 return v8Undefined(); | 101 return v8Undefined(); |
| 102 case IDBKey::NumberType: | 102 case IDBKey::NumberType: |
| 103 return v8::Number::New(isolate, key->number()); | 103 return v8::Number::New(isolate, key->number()); |
| 104 case IDBKey::StringType: | 104 case IDBKey::StringType: |
| 105 return v8String(isolate, key->string()); | 105 return v8String(isolate, key->string()); |
| 106 case IDBKey::BinaryType: | 106 case IDBKey::BinaryType: |
| 107 // Experimental feature: binary keys | 107 // Experimental feature: binary keys |
| 108 // https://w3c.github.io/IndexedDB/#steps-to-convert-a-key-to-a-value | 108 // https://w3c.github.io/IndexedDB/#steps-to-convert-a-key-to-a-value |
| 109 return toV8(DOMArrayBuffer::create(reinterpret_cast<const unsigned char*>( | 109 return ToV8(DOMArrayBuffer::create(reinterpret_cast<const unsigned char*>( |
| 110 key->binary()->data()), | 110 key->binary()->data()), |
| 111 key->binary()->size()), | 111 key->binary()->size()), |
| 112 creationContext, isolate); | 112 creationContext, isolate); |
| 113 case IDBKey::DateType: | 113 case IDBKey::DateType: |
| 114 return v8::Date::New(context, key->date()).ToLocalChecked(); | 114 return v8::Date::New(context, key->date()).ToLocalChecked(); |
| 115 case IDBKey::ArrayType: { | 115 case IDBKey::ArrayType: { |
| 116 v8::Local<v8::Array> array = v8::Array::New(isolate, key->array().size()); | 116 v8::Local<v8::Array> array = v8::Array::New(isolate, key->array().size()); |
| 117 for (size_t i = 0; i < key->array().size(); ++i) { | 117 for (size_t i = 0; i < key->array().size(); ++i) { |
| 118 v8::Local<v8::Value> value = | 118 v8::Local<v8::Value> value = |
| 119 toV8(key->array()[i].get(), creationContext, isolate); | 119 ToV8(key->array()[i].get(), creationContext, isolate); |
| 120 if (value.IsEmpty()) | 120 if (value.IsEmpty()) |
| 121 value = v8::Undefined(isolate); | 121 value = v8::Undefined(isolate); |
| 122 if (!v8CallBoolean(array->CreateDataProperty(context, i, value))) | 122 if (!v8CallBoolean(array->CreateDataProperty(context, i, value))) |
| 123 return v8Undefined(); | 123 return v8Undefined(); |
| 124 } | 124 } |
| 125 return array; | 125 return array; |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 | 128 |
| 129 ASSERT_NOT_REACHED(); | 129 ASSERT_NOT_REACHED(); |
| 130 return v8Undefined(); | 130 return v8Undefined(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 // IDBAny is a variant type used to hold the values produced by the |result| | 133 // IDBAny is a variant type used to hold the values produced by the |result| |
| 134 // attribute of IDBRequest and (as a convenience) the |source| attribute of | 134 // attribute of IDBRequest and (as a convenience) the |source| attribute of |
| 135 // IDBRequest and IDBCursor. | 135 // IDBRequest and IDBCursor. |
| 136 // TODO(jsbell): Replace the use of IDBAny for |source| attributes (which are | 136 // TODO(jsbell): Replace the use of IDBAny for |source| attributes (which are |
| 137 // ScriptWrappable types) using unions per IDL. | 137 // ScriptWrappable types) using unions per IDL. |
| 138 v8::Local<v8::Value> toV8(const IDBAny* impl, | 138 v8::Local<v8::Value> ToV8(const IDBAny* impl, |
| 139 v8::Local<v8::Object> creationContext, | 139 v8::Local<v8::Object> creationContext, |
| 140 v8::Isolate* isolate) { | 140 v8::Isolate* isolate) { |
| 141 if (!impl) | 141 if (!impl) |
| 142 return v8::Null(isolate); | 142 return v8::Null(isolate); |
| 143 | 143 |
| 144 switch (impl->getType()) { | 144 switch (impl->getType()) { |
| 145 case IDBAny::UndefinedType: | 145 case IDBAny::UndefinedType: |
| 146 return v8::Undefined(isolate); | 146 return v8::Undefined(isolate); |
| 147 case IDBAny::NullType: | 147 case IDBAny::NullType: |
| 148 return v8::Null(isolate); | 148 return v8::Null(isolate); |
| 149 case IDBAny::DOMStringListType: | 149 case IDBAny::DOMStringListType: |
| 150 return toV8(impl->domStringList(), creationContext, isolate); | 150 return ToV8(impl->domStringList(), creationContext, isolate); |
| 151 case IDBAny::IDBCursorType: | 151 case IDBAny::IDBCursorType: |
| 152 return toV8(impl->idbCursor(), creationContext, isolate); | 152 return ToV8(impl->idbCursor(), creationContext, isolate); |
| 153 case IDBAny::IDBCursorWithValueType: | 153 case IDBAny::IDBCursorWithValueType: |
| 154 return toV8(impl->idbCursorWithValue(), creationContext, isolate); | 154 return ToV8(impl->idbCursorWithValue(), creationContext, isolate); |
| 155 case IDBAny::IDBDatabaseType: | 155 case IDBAny::IDBDatabaseType: |
| 156 return toV8(impl->idbDatabase(), creationContext, isolate); | 156 return ToV8(impl->idbDatabase(), creationContext, isolate); |
| 157 case IDBAny::IDBIndexType: | 157 case IDBAny::IDBIndexType: |
| 158 return toV8(impl->idbIndex(), creationContext, isolate); | 158 return ToV8(impl->idbIndex(), creationContext, isolate); |
| 159 case IDBAny::IDBObjectStoreType: | 159 case IDBAny::IDBObjectStoreType: |
| 160 return toV8(impl->idbObjectStore(), creationContext, isolate); | 160 return ToV8(impl->idbObjectStore(), creationContext, isolate); |
| 161 case IDBAny::IDBValueType: | 161 case IDBAny::IDBValueType: |
| 162 return deserializeIDBValue(isolate, creationContext, impl->value()); | 162 return deserializeIDBValue(isolate, creationContext, impl->value()); |
| 163 case IDBAny::IDBValueArrayType: | 163 case IDBAny::IDBValueArrayType: |
| 164 return deserializeIDBValueArray(isolate, creationContext, impl->values()); | 164 return deserializeIDBValueArray(isolate, creationContext, impl->values()); |
| 165 case IDBAny::IntegerType: | 165 case IDBAny::IntegerType: |
| 166 return v8::Number::New(isolate, impl->integer()); | 166 return v8::Number::New(isolate, impl->integer()); |
| 167 case IDBAny::KeyType: | 167 case IDBAny::KeyType: |
| 168 return toV8(impl->key(), creationContext, isolate); | 168 return ToV8(impl->key(), creationContext, isolate); |
| 169 } | 169 } |
| 170 | 170 |
| 171 ASSERT_NOT_REACHED(); | 171 ASSERT_NOT_REACHED(); |
| 172 return v8::Undefined(isolate); | 172 return v8::Undefined(isolate); |
| 173 } | 173 } |
| 174 | 174 |
| 175 static const size_t maximumDepth = 2000; | 175 static const size_t maximumDepth = 2000; |
| 176 | 176 |
| 177 static IDBKey* createIDBKeyFromValue(v8::Isolate* isolate, | 177 static IDBKey* createIDBKeyFromValue(v8::Isolate* isolate, |
| 178 v8::Local<v8::Value> value, | 178 v8::Local<v8::Value> value, |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 v8::Isolate* isolate, | 405 v8::Isolate* isolate, |
| 406 v8::Local<v8::Object> creationContext, | 406 v8::Local<v8::Object> creationContext, |
| 407 const IDBValue* value) { | 407 const IDBValue* value) { |
| 408 ASSERT(isolate->InContext()); | 408 ASSERT(isolate->InContext()); |
| 409 if (!value || value->isNull()) | 409 if (!value || value->isNull()) |
| 410 return v8::Null(isolate); | 410 return v8::Null(isolate); |
| 411 | 411 |
| 412 v8::Local<v8::Value> v8Value = deserializeIDBValueData(isolate, value); | 412 v8::Local<v8::Value> v8Value = deserializeIDBValueData(isolate, value); |
| 413 if (value->primaryKey()) { | 413 if (value->primaryKey()) { |
| 414 v8::Local<v8::Value> key = | 414 v8::Local<v8::Value> key = |
| 415 toV8(value->primaryKey(), creationContext, isolate); | 415 ToV8(value->primaryKey(), creationContext, isolate); |
| 416 if (key.IsEmpty()) | 416 if (key.IsEmpty()) |
| 417 return v8::Local<v8::Value>(); | 417 return v8::Local<v8::Value>(); |
| 418 bool injected = | 418 bool injected = |
| 419 injectV8KeyIntoV8Value(isolate, key, v8Value, value->keyPath()); | 419 injectV8KeyIntoV8Value(isolate, key, v8Value, value->keyPath()); |
| 420 DCHECK(injected); | 420 DCHECK(injected); |
| 421 } | 421 } |
| 422 | 422 |
| 423 return v8Value; | 423 return v8Value; |
| 424 } | 424 } |
| 425 | 425 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 if (expectedKey && expectedKey->isEqual(value->primaryKey())) | 617 if (expectedKey && expectedKey->isEqual(value->primaryKey())) |
| 618 return; | 618 return; |
| 619 | 619 |
| 620 bool injected = injectV8KeyIntoV8Value( | 620 bool injected = injectV8KeyIntoV8Value( |
| 621 isolate, keyValue.v8Value(), scriptValue.v8Value(), value->keyPath()); | 621 isolate, keyValue.v8Value(), scriptValue.v8Value(), value->keyPath()); |
| 622 DCHECK(injected); | 622 DCHECK(injected); |
| 623 } | 623 } |
| 624 #endif | 624 #endif |
| 625 | 625 |
| 626 } // namespace blink | 626 } // namespace blink |
| OLD | NEW |