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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 v8::Local<v8::Object> object = v8::Object::New(isolate); | 296 v8::Local<v8::Object> object = v8::Object::New(isolate); |
297 if (!set(isolate, parentValue, keyPathElement, object)) | 297 if (!set(isolate, parentValue, keyPathElement, object)) |
298 return v8Undefined(); | 298 return v8Undefined(); |
299 currentValue = object; | 299 currentValue = object; |
300 } | 300 } |
301 } | 301 } |
302 | 302 |
303 return currentValue; | 303 return currentValue; |
304 } | 304 } |
305 | 305 |
306 static IDBKey* createIDBKeyFromScriptValueAndKeyPathInternal(v8::Isolate* isolat
e, const ScriptValue& value, const String& keyPath, bool allowExperimentalTypes) | 306 static IDBKey* createIDBKeyFromScriptValueAndKeyPathInternal(v8::Isolate* isolat
e, v8::Local<v8::Value> v8Value, const String& keyPath, bool allowExperimentalTy
pes) |
307 { | 307 { |
308 Vector<String> keyPathElements; | 308 Vector<String> keyPathElements; |
309 IDBKeyPathParseError error; | 309 IDBKeyPathParseError error; |
310 IDBParseKeyPath(keyPath, keyPathElements, error); | 310 IDBParseKeyPath(keyPath, keyPathElements, error); |
311 ASSERT(error == IDBKeyPathParseErrorNone); | 311 ASSERT(error == IDBKeyPathParseErrorNone); |
312 ASSERT(isolate->InContext()); | 312 ASSERT(isolate->InContext()); |
313 | 313 |
314 v8::HandleScope handleScope(isolate); | 314 v8::HandleScope handleScope(isolate); |
315 v8::Local<v8::Value> v8Value(value.v8Value()); | |
316 v8::Local<v8::Value> v8Key(getNthValueOnKeyPath(isolate, v8Value, keyPathEle
ments, keyPathElements.size())); | 315 v8::Local<v8::Value> v8Key(getNthValueOnKeyPath(isolate, v8Value, keyPathEle
ments, keyPathElements.size())); |
317 if (v8Key.IsEmpty()) | 316 if (v8Key.IsEmpty()) |
318 return 0; | 317 return 0; |
319 return createIDBKeyFromValue(isolate, v8Key, allowExperimentalTypes); | 318 return createIDBKeyFromValue(isolate, v8Key, allowExperimentalTypes); |
320 } | 319 } |
321 | 320 |
322 static IDBKey* createIDBKeyFromScriptValueAndKeyPathInternal(v8::Isolate* isolat
e, const ScriptValue& value, const IDBKeyPath& keyPath, bool allowExperimentalTy
pes = false) | 321 static IDBKey* createIDBKeyFromScriptValueAndKeyPathInternal(v8::Isolate* isolat
e, v8::Local<v8::Value> value, const IDBKeyPath& keyPath, bool allowExperimental
Types = false) |
323 { | 322 { |
324 ASSERT(!keyPath.isNull()); | 323 ASSERT(!keyPath.isNull()); |
325 v8::HandleScope handleScope(isolate); | 324 v8::HandleScope handleScope(isolate); |
326 if (keyPath.type() == IDBKeyPath::ArrayType) { | 325 if (keyPath.type() == IDBKeyPath::ArrayType) { |
327 IDBKey::KeyArray result; | 326 IDBKey::KeyArray result; |
328 const Vector<String>& array = keyPath.array(); | 327 const Vector<String>& array = keyPath.array(); |
329 for (size_t i = 0; i < array.size(); ++i) { | 328 for (size_t i = 0; i < array.size(); ++i) { |
330 IDBKey* key = createIDBKeyFromScriptValueAndKeyPathInternal(isolate,
value, array[i], allowExperimentalTypes); | 329 IDBKey* key = createIDBKeyFromScriptValueAndKeyPathInternal(isolate,
value, array[i], allowExperimentalTypes); |
331 if (!key) | 330 if (!key) |
332 return 0; | 331 return 0; |
333 result.append(key); | 332 result.append(key); |
334 } | 333 } |
335 return IDBKey::createArray(result); | 334 return IDBKey::createArray(result); |
336 } | 335 } |
337 | 336 |
338 ASSERT(keyPath.type() == IDBKeyPath::StringType); | 337 ASSERT(keyPath.type() == IDBKeyPath::StringType); |
339 return createIDBKeyFromScriptValueAndKeyPathInternal(isolate, value, keyPath
.string(), allowExperimentalTypes); | 338 return createIDBKeyFromScriptValueAndKeyPathInternal(isolate, value, keyPath
.string(), allowExperimentalTypes); |
340 } | 339 } |
341 | 340 |
342 IDBKey* createIDBKeyFromScriptValueAndKeyPath(v8::Isolate* isolate, const Script
Value& value, const IDBKeyPath& keyPath) | |
343 { | |
344 IDB_TRACE("createIDBKeyFromScriptValueAndKeyPath"); | |
345 return createIDBKeyFromScriptValueAndKeyPathInternal(isolate, value, keyPath
); | |
346 } | |
347 | |
348 static v8::Local<v8::Value> deserializeIDBValueBuffer(v8::Isolate* isolate, Shar
edBuffer* buffer, const Vector<blink::WebBlobInfo>* blobInfo) | 341 static v8::Local<v8::Value> deserializeIDBValueBuffer(v8::Isolate* isolate, Shar
edBuffer* buffer, const Vector<blink::WebBlobInfo>* blobInfo) |
349 { | 342 { |
350 ASSERT(isolate->InContext()); | 343 ASSERT(isolate->InContext()); |
351 if (!buffer) | 344 if (!buffer) |
352 return v8::Null(isolate); | 345 return v8::Null(isolate); |
353 | 346 |
354 // FIXME: The extra copy here can be eliminated by allowing SerializedScript
Value to take a raw const char* or const uint8_t*. | 347 // FIXME: The extra copy here can be eliminated by allowing SerializedScript
Value to take a raw const char* or const uint8_t*. |
355 Vector<uint8_t> value; | 348 Vector<uint8_t> value; |
356 value.append(buffer->data(), buffer->size()); | 349 value.append(buffer->data(), buffer->size()); |
357 RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValueFactory
::instance().createFromWireBytes(value); | 350 RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValueFactory
::instance().createFromWireBytes(value); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 if (!stringValue.prepare(exceptionState)) | 426 if (!stringValue.prepare(exceptionState)) |
434 return SQLValue(); | 427 return SQLValue(); |
435 return SQLValue(stringValue); | 428 return SQLValue(stringValue); |
436 } | 429 } |
437 | 430 |
438 IDBKey* NativeValueTraits<IDBKey*>::nativeValue(v8::Isolate* isolate, v8::Local<
v8::Value> value, ExceptionState& exceptionState) | 431 IDBKey* NativeValueTraits<IDBKey*>::nativeValue(v8::Isolate* isolate, v8::Local<
v8::Value> value, ExceptionState& exceptionState) |
439 { | 432 { |
440 return createIDBKeyFromValue(isolate, value); | 433 return createIDBKeyFromValue(isolate, value); |
441 } | 434 } |
442 | 435 |
| 436 IDBKey* NativeValueTraits<IDBKey*>::nativeValue(v8::Isolate* isolate, v8::Local<
v8::Value> value, ExceptionState& exceptionState, const IDBKeyPath& keyPath) |
| 437 { |
| 438 IDB_TRACE("createIDBKeyFromScriptValueAndKeyPath"); |
| 439 return createIDBKeyFromScriptValueAndKeyPathInternal(isolate, value, keyPath
); |
| 440 } |
| 441 |
443 IDBKeyRange* NativeValueTraits<IDBKeyRange*>::nativeValue(v8::Isolate* isolate,
v8::Local<v8::Value> value, ExceptionState& exceptionState) | 442 IDBKeyRange* NativeValueTraits<IDBKeyRange*>::nativeValue(v8::Isolate* isolate,
v8::Local<v8::Value> value, ExceptionState& exceptionState) |
444 { | 443 { |
445 return V8IDBKeyRange::toImplWithTypeCheck(isolate, value); | 444 return V8IDBKeyRange::toImplWithTypeCheck(isolate, value); |
446 } | 445 } |
447 | 446 |
448 #if ENABLE(ASSERT) | 447 #if ENABLE(ASSERT) |
449 void assertPrimaryKeyValidOrInjectable(ScriptState* scriptState, PassRefPtr<Shar
edBuffer> buffer, const Vector<blink::WebBlobInfo>* blobInfo, IDBKey* key, const
IDBKeyPath& keyPath) | 448 void assertPrimaryKeyValidOrInjectable(ScriptState* scriptState, PassRefPtr<Shar
edBuffer> buffer, const Vector<blink::WebBlobInfo>* blobInfo, IDBKey* key, const
IDBKeyPath& keyPath) |
450 { | 449 { |
451 ScriptState::Scope scope(scriptState); | 450 ScriptState::Scope scope(scriptState); |
452 v8::Isolate* isolate = scriptState->isolate(); | 451 v8::Isolate* isolate = scriptState->isolate(); |
453 ScriptValue keyValue = ScriptValue::from(scriptState, key); | 452 ScriptValue keyValue = ScriptValue::from(scriptState, key); |
454 ScriptValue scriptValue(scriptState, deserializeIDBValueBuffer(isolate, buff
er.get(), blobInfo)); | 453 ScriptValue scriptValue(scriptState, deserializeIDBValueBuffer(isolate, buff
er.get(), blobInfo)); |
455 | 454 |
456 // This assertion is about already persisted data, so allow experimental typ
es. | 455 // This assertion is about already persisted data, so allow experimental typ
es. |
457 const bool allowExperimentalTypes = true; | 456 const bool allowExperimentalTypes = true; |
458 IDBKey* expectedKey = createIDBKeyFromScriptValueAndKeyPathInternal(isolate,
scriptValue, keyPath, allowExperimentalTypes); | 457 IDBKey* expectedKey = createIDBKeyFromScriptValueAndKeyPathInternal(isolate,
scriptValue.v8Value(), keyPath, allowExperimentalTypes); |
459 ASSERT(!expectedKey || expectedKey->isEqual(key)); | 458 ASSERT(!expectedKey || expectedKey->isEqual(key)); |
460 | 459 |
461 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa
lue.v8Value(), keyPath); | 460 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa
lue.v8Value(), keyPath); |
462 ASSERT_UNUSED(injected, injected); | 461 ASSERT_UNUSED(injected, injected); |
463 } | 462 } |
464 #endif | 463 #endif |
465 | 464 |
466 } // namespace blink | 465 } // namespace blink |
OLD | NEW |