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 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(crbug.com/536816): Find a more graceful way to handle alloc ation | |
|
haraken
2015/10/29 16:24:34
Ditto.
| |
| 104 // failures with createOrNull. It would be possible to throw a Range Error | |
| 105 // from here but the consequences of such a change need to be consid ered | |
| 106 // carefully. | |
| 107 RefPtr<DOMArrayBuffer> buffer = DOMArrayBuffer::deprecatedCreateOrCr ash(reinterpret_cast<const unsigned char*>(key->binary()->data()), key->binary() ->size()); | |
| 108 return toV8(buffer, creationContext, isolate); | |
| 109 } | |
| 102 case IDBKey::DateType: | 110 case IDBKey::DateType: |
| 103 return v8::Date::New(context, key->date()).ToLocalChecked(); | 111 return v8::Date::New(context, key->date()).ToLocalChecked(); |
| 104 case IDBKey::ArrayType: | 112 case IDBKey::ArrayType: |
| 105 { | 113 { |
| 106 v8::Local<v8::Array> array = v8::Array::New(isolate, key->array().si ze()); | 114 v8::Local<v8::Array> array = v8::Array::New(isolate, key->array().si ze()); |
| 107 for (size_t i = 0; i < key->array().size(); ++i) { | 115 for (size_t i = 0; i < key->array().size(); ++i) { |
| 108 v8::Local<v8::Value> value = toV8(key->array()[i].get(), creatio nContext, isolate); | 116 v8::Local<v8::Value> value = toV8(key->array()[i].get(), creatio nContext, isolate); |
| 109 if (value.IsEmpty()) | 117 if (value.IsEmpty()) |
| 110 value = v8::Undefined(isolate); | 118 value = v8::Undefined(isolate); |
| 111 if (!v8CallBoolean(array->CreateDataProperty(context, i, value)) ) | 119 if (!v8CallBoolean(array->CreateDataProperty(context, i, value)) ) |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 if (buffer->isNeutered()) { | 186 if (buffer->isNeutered()) { |
| 179 exceptionState.throwTypeError("The ArrayBuffer is neutered."); | 187 exceptionState.throwTypeError("The ArrayBuffer is neutered."); |
| 180 return nullptr; | 188 return nullptr; |
| 181 } | 189 } |
| 182 const char* start = static_cast<const char*>(buffer->data()); | 190 const char* start = static_cast<const char*>(buffer->data()); |
| 183 size_t length = buffer->byteLength(); | 191 size_t length = buffer->byteLength(); |
| 184 return IDBKey::createBinary(SharedBuffer::create(start, length)); | 192 return IDBKey::createBinary(SharedBuffer::create(start, length)); |
| 185 } | 193 } |
| 186 if (value->IsArrayBufferView()) { | 194 if (value->IsArrayBufferView()) { |
| 187 DOMArrayBufferView* view = V8ArrayBufferView::toImpl(value.As<v8::Ob ject>()); | 195 DOMArrayBufferView* view = V8ArrayBufferView::toImpl(value.As<v8::Ob ject>()); |
| 188 if (view->buffer()->isNeutered()) { | 196 RefPtr<DOMArrayBuffer> buffer = view->bufferOrNull(); |
| 197 RELEASE_ASSERT(buffer); // This is essentially an out-of-memory cras h (crbug.com/536816) | |
| 198 if (buffer->isNeutered()) { | |
| 189 exceptionState.throwTypeError("The viewed ArrayBuffer is neutere d."); | 199 exceptionState.throwTypeError("The viewed ArrayBuffer is neutere d."); |
| 190 return nullptr; | 200 return nullptr; |
| 191 } | 201 } |
| 192 const char* start = static_cast<const char*>(view->baseAddress()); | 202 const char* start = static_cast<const char*>(view->baseAddress()); |
| 193 size_t length = view->byteLength(); | 203 size_t length = view->byteLength(); |
| 194 return IDBKey::createBinary(SharedBuffer::create(start, length)); | 204 return IDBKey::createBinary(SharedBuffer::create(start, length)); |
| 195 } | 205 } |
| 196 } | 206 } |
| 197 if (value->IsArray()) { | 207 if (value->IsArray()) { |
| 198 v8::Local<v8::Array> array = value.As<v8::Array>(); | 208 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()); | 521 ASSERT(!exceptionState.hadException()); |
| 512 if (expectedKey && expectedKey->isEqual(value->primaryKey())) | 522 if (expectedKey && expectedKey->isEqual(value->primaryKey())) |
| 513 return; | 523 return; |
| 514 | 524 |
| 515 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa lue.v8Value(), value->keyPath()); | 525 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa lue.v8Value(), value->keyPath()); |
| 516 ASSERT_UNUSED(injected, injected); | 526 ASSERT_UNUSED(injected, injected); |
| 517 } | 527 } |
| 518 #endif | 528 #endif |
| 519 | 529 |
| 520 } // namespace blink | 530 } // namespace blink |
| OLD | NEW |