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 RefPtr<DOMArrayBuffer> buffer = DOMArrayBuffer::createOrNull(reinter pret_cast<const unsigned char*>(key->binary()->data()), key->binary()->size()); | |
| 103 if (!buffer) { | |
| 104 isolate->ThrowException(v8::Exception::RangeError(v8::String::Ne wFromUtf8(isolate, "Out of memory. Failed to allocate ArrayBuffer."))); | |
|
jsbell
2015/10/16 22:12:24
This is going to be weird behavior! The scenario w
jsbell
2015/10/16 22:16:26
Hrm, I'm an idiot... this *also* applies to *value
Justin Novosad
2015/10/19 16:42:52
For this initial CL, I want to stay clear of anyth
| |
| 105 return v8Undefined(); | |
| 106 } | |
| 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 if (!buffer) { | |
|
jsbell
2015/10/16 22:12:24
The usage here is that script has passed a view in
Justin Novosad
2015/10/19 16:42:52
Acknowledged.
| |
| 197 exceptionState.throwRangeError("Out of Momory."); | |
|
binji
2015/10/16 22:12:39
sp: memory
Justin Novosad
2015/10/19 16:42:52
Acknowledged.
| |
| 198 return nullptr; | |
| 199 } | |
| 200 if (buffer->isNeutered()) { | |
| 189 exceptionState.throwTypeError("The viewed ArrayBuffer is neutere d."); | 201 exceptionState.throwTypeError("The viewed ArrayBuffer is neutere d."); |
| 190 return nullptr; | 202 return nullptr; |
| 191 } | 203 } |
| 192 const char* start = static_cast<const char*>(view->baseAddress()); | 204 const char* start = static_cast<const char*>(view->baseAddress()); |
| 193 size_t length = view->byteLength(); | 205 size_t length = view->byteLength(); |
| 194 return IDBKey::createBinary(SharedBuffer::create(start, length)); | 206 return IDBKey::createBinary(SharedBuffer::create(start, length)); |
| 195 } | 207 } |
| 196 } | 208 } |
| 197 if (value->IsArray()) { | 209 if (value->IsArray()) { |
| 198 v8::Local<v8::Array> array = value.As<v8::Array>(); | 210 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()); | 523 ASSERT(!exceptionState.hadException()); |
| 512 if (expectedKey && expectedKey->isEqual(value->primaryKey())) | 524 if (expectedKey && expectedKey->isEqual(value->primaryKey())) |
| 513 return; | 525 return; |
| 514 | 526 |
| 515 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa lue.v8Value(), value->keyPath()); | 527 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa lue.v8Value(), value->keyPath()); |
| 516 ASSERT_UNUSED(injected, injected); | 528 ASSERT_UNUSED(injected, injected); |
| 517 } | 529 } |
| 518 #endif | 530 #endif |
| 519 | 531 |
| 520 } // namespace blink | 532 } // namespace blink |
| OLD | NEW |