| 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> v8Value, const IDBKeyPath& keyPath, bool allowExperiment
alTypes = 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,
v8Value, 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, v8Value, keyPa
th.string(), allowExperimentalTypes); |
| 340 } | |
| 341 | |
| 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 } | 339 } |
| 347 | 340 |
| 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; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 if (value.IsEmpty() || value->IsNull()) | 421 if (value.IsEmpty() || value->IsNull()) |
| 429 return SQLValue(); | 422 return SQLValue(); |
| 430 if (value->IsNumber()) | 423 if (value->IsNumber()) |
| 431 return SQLValue(value->NumberValue()); | 424 return SQLValue(value->NumberValue()); |
| 432 V8StringResource<> stringValue(value); | 425 V8StringResource<> stringValue(value); |
| 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::Local<v8::Value> value, v8::
Isolate* isolate, ExceptionState& exceptionState) | 431 IDBKey* NativeValueTraits<IDBKey*>::nativeValue(v8::Local<v8::Value> value, v8::
Isolate* isolate, ExceptionState& exceptionState, const IDBKeyPath& keyPath) |
| 439 { | 432 { |
| 440 return createIDBKeyFromValue(isolate, value); | 433 if (keyPath.isNull()) |
| 434 return createIDBKeyFromValue(isolate, value); |
| 435 IDB_TRACE("createIDBKeyFromScriptValueAndKeyPath)"); |
| 436 return createIDBKeyFromScriptValueAndKeyPathInternal(isolate, value, keyPath
); |
| 441 } | 437 } |
| 442 | 438 |
| 443 IDBKeyRange* NativeValueTraits<IDBKeyRange*>::nativeValue(v8::Local<v8::Value> v
alue, v8::Isolate* isolate, ExceptionState& exceptionState) | 439 IDBKeyRange* NativeValueTraits<IDBKeyRange*>::nativeValue(v8::Local<v8::Value> v
alue, v8::Isolate* isolate, ExceptionState& exceptionState) |
| 444 { | 440 { |
| 445 return V8IDBKeyRange::toImplWithTypeCheck(isolate, value); | 441 return V8IDBKeyRange::toImplWithTypeCheck(isolate, value); |
| 446 } | 442 } |
| 447 | 443 |
| 448 #if ENABLE(ASSERT) | 444 #if ENABLE(ASSERT) |
| 449 void assertPrimaryKeyValidOrInjectable(ScriptState* scriptState, PassRefPtr<Shar
edBuffer> buffer, const Vector<blink::WebBlobInfo>* blobInfo, IDBKey* key, const
IDBKeyPath& keyPath) | 445 void assertPrimaryKeyValidOrInjectable(ScriptState* scriptState, PassRefPtr<Shar
edBuffer> buffer, const Vector<blink::WebBlobInfo>* blobInfo, IDBKey* key, const
IDBKeyPath& keyPath) |
| 450 { | 446 { |
| 451 ScriptState::Scope scope(scriptState); | 447 ScriptState::Scope scope(scriptState); |
| 452 v8::Isolate* isolate = scriptState->isolate(); | 448 v8::Isolate* isolate = scriptState->isolate(); |
| 453 ScriptValue keyValue = ScriptValue::from(scriptState, key); | 449 ScriptValue keyValue = ScriptValue::from(scriptState, key); |
| 454 ScriptValue scriptValue(scriptState, deserializeIDBValueBuffer(isolate, buff
er.get(), blobInfo)); | 450 ScriptValue scriptValue(scriptState, deserializeIDBValueBuffer(isolate, buff
er.get(), blobInfo)); |
| 455 | 451 |
| 456 // This assertion is about already persisted data, so allow experimental typ
es. | 452 // This assertion is about already persisted data, so allow experimental typ
es. |
| 457 const bool allowExperimentalTypes = true; | 453 const bool allowExperimentalTypes = true; |
| 458 IDBKey* expectedKey = createIDBKeyFromScriptValueAndKeyPathInternal(isolate,
scriptValue, keyPath, allowExperimentalTypes); | 454 IDBKey* expectedKey = createIDBKeyFromScriptValueAndKeyPathInternal(isolate,
scriptValue.v8Value(), keyPath, allowExperimentalTypes); |
| 459 ASSERT(!expectedKey || expectedKey->isEqual(key)); | 455 ASSERT(!expectedKey || expectedKey->isEqual(key)); |
| 460 | 456 |
| 461 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa
lue.v8Value(), keyPath); | 457 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa
lue.v8Value(), keyPath); |
| 462 ASSERT_UNUSED(injected, injected); | 458 ASSERT_UNUSED(injected, injected); |
| 463 } | 459 } |
| 464 #endif | 460 #endif |
| 465 | 461 |
| 466 } // namespace blink | 462 } // namespace blink |
| OLD | NEW |