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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 switch (key->type()) { | 89 switch (key->type()) { |
90 case IDBKey::InvalidType: | 90 case IDBKey::InvalidType: |
91 case IDBKey::MinType: | 91 case IDBKey::MinType: |
92 ASSERT_NOT_REACHED(); | 92 ASSERT_NOT_REACHED(); |
93 return v8Undefined(); | 93 return v8Undefined(); |
94 case IDBKey::NumberType: | 94 case IDBKey::NumberType: |
95 return v8::Number::New(isolate, key->number()); | 95 return v8::Number::New(isolate, key->number()); |
96 case IDBKey::StringType: | 96 case IDBKey::StringType: |
97 return v8String(isolate, key->string()); | 97 return v8String(isolate, key->string()); |
98 case IDBKey::BinaryType: | 98 case IDBKey::BinaryType: |
99 // Experimental feature: binary keys | 99 { |
100 // https://w3c.github.io/IndexedDB/#steps-to-convert-a-key-to-a-value | 100 // Experimental feature: binary keys |
101 return toV8(DOMArrayBuffer::create(reinterpret_cast<const unsigned char*
>(key->binary()->data()), key->binary()->size()), creationContext, isolate); | 101 // https://w3c.github.io/IndexedDB/#steps-to-convert-a-key-to-a-valu
e |
| 102 |
| 103 // FIXME: Find a more graceful way to handle allocation failures wit
h |
| 104 // createOrNull. It would be possible to throw a RangeError from her
e |
| 105 // but the consequences of such a change need to be studied carefull
y. |
| 106 RefPtr<DOMArrayBuffer> buffer = DOMArrayBuffer::deprecatedCreateOrCr
ash(reinterpret_cast<const unsigned char*>(key->binary()->data()), key->binary()
->size()); |
| 107 return toV8(buffer, creationContext, isolate); |
| 108 } |
102 case IDBKey::DateType: | 109 case IDBKey::DateType: |
103 return v8::Date::New(context, key->date()).ToLocalChecked(); | 110 return v8::Date::New(context, key->date()).ToLocalChecked(); |
104 case IDBKey::ArrayType: | 111 case IDBKey::ArrayType: |
105 { | 112 { |
106 v8::Local<v8::Array> array = v8::Array::New(isolate, key->array().si
ze()); | 113 v8::Local<v8::Array> array = v8::Array::New(isolate, key->array().si
ze()); |
107 for (size_t i = 0; i < key->array().size(); ++i) { | 114 for (size_t i = 0; i < key->array().size(); ++i) { |
108 v8::Local<v8::Value> value = toV8(key->array()[i].get(), creatio
nContext, isolate); | 115 v8::Local<v8::Value> value = toV8(key->array()[i].get(), creatio
nContext, isolate); |
109 if (value.IsEmpty()) | 116 if (value.IsEmpty()) |
110 value = v8::Undefined(isolate); | 117 value = v8::Undefined(isolate); |
111 if (!v8CallBoolean(array->CreateDataProperty(context, i, value))
) | 118 if (!v8CallBoolean(array->CreateDataProperty(context, i, value))
) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 if (buffer->isNeutered()) { | 185 if (buffer->isNeutered()) { |
179 exceptionState.throwTypeError("The ArrayBuffer is neutered."); | 186 exceptionState.throwTypeError("The ArrayBuffer is neutered."); |
180 return nullptr; | 187 return nullptr; |
181 } | 188 } |
182 const char* start = static_cast<const char*>(buffer->data()); | 189 const char* start = static_cast<const char*>(buffer->data()); |
183 size_t length = buffer->byteLength(); | 190 size_t length = buffer->byteLength(); |
184 return IDBKey::createBinary(SharedBuffer::create(start, length)); | 191 return IDBKey::createBinary(SharedBuffer::create(start, length)); |
185 } | 192 } |
186 if (value->IsArrayBufferView()) { | 193 if (value->IsArrayBufferView()) { |
187 DOMArrayBufferView* view = V8ArrayBufferView::toImpl(value.As<v8::Ob
ject>()); | 194 DOMArrayBufferView* view = V8ArrayBufferView::toImpl(value.As<v8::Ob
ject>()); |
188 if (view->buffer()->isNeutered()) { | 195 RefPtr<DOMArrayBuffer> buffer = view->bufferOrNull(); |
| 196 RELEASE_ASSERT(buffer); |
| 197 if (buffer->isNeutered()) { |
189 exceptionState.throwTypeError("The viewed ArrayBuffer is neutere
d."); | 198 exceptionState.throwTypeError("The viewed ArrayBuffer is neutere
d."); |
190 return nullptr; | 199 return nullptr; |
191 } | 200 } |
192 const char* start = static_cast<const char*>(view->baseAddress()); | 201 const char* start = static_cast<const char*>(view->baseAddress()); |
193 size_t length = view->byteLength(); | 202 size_t length = view->byteLength(); |
194 return IDBKey::createBinary(SharedBuffer::create(start, length)); | 203 return IDBKey::createBinary(SharedBuffer::create(start, length)); |
195 } | 204 } |
196 } | 205 } |
197 if (value->IsArray()) { | 206 if (value->IsArray()) { |
198 v8::Local<v8::Array> array = value.As<v8::Array>(); | 207 v8::Local<v8::Array> array = value.As<v8::Array>(); |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 ASSERT(!exceptionState.hadException()); | 520 ASSERT(!exceptionState.hadException()); |
512 if (expectedKey && expectedKey->isEqual(value->primaryKey())) | 521 if (expectedKey && expectedKey->isEqual(value->primaryKey())) |
513 return; | 522 return; |
514 | 523 |
515 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa
lue.v8Value(), value->keyPath()); | 524 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa
lue.v8Value(), value->keyPath()); |
516 ASSERT_UNUSED(injected, injected); | 525 ASSERT_UNUSED(injected, injected); |
517 } | 526 } |
518 #endif | 527 #endif |
519 | 528 |
520 } // namespace blink | 529 } // namespace blink |
OLD | NEW |