Commit f711430b authored by Numfor Mbiziwo-Tiapo's avatar Numfor Mbiziwo-Tiapo Committed by Commit Bot

Implement putAll and add web platform test

This adds a simple putAll implementation that loops put. A basic web
platform test is added as well.

Change-Id: I8fcc25ffacb64d15855da921eb14f3770df28694
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2274217
Commit-Queue: Daniel Murphy <dmurph@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Reviewed-by: default avatarenne <enne@chromium.org>
Reviewed-by: default avatarOlivier Yiptong <oyiptong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#787815}
parent c46e51b4
......@@ -364,6 +364,22 @@ IDBRequest* IDBObjectStore::put(ScriptState* script_state,
exception_state);
}
HeapVector<Member<IDBRequest>> IDBObjectStore::putAll(
ScriptState* script_state,
const HeapVector<ScriptValue>& values,
ExceptionState& exception_state) {
v8::Isolate* isolate = script_state->GetIsolate();
const ScriptValue& v8_undefined =
ScriptValue(isolate, v8::Undefined(isolate));
HeapVector<Member<IDBRequest>> requests;
for (const auto& value : values) {
IDBRequest* result =
put(script_state, value, v8_undefined, exception_state);
requests.push_back(*result);
}
return requests;
}
IDBRequest* IDBObjectStore::put(ScriptState* script_state,
const ScriptValue& value,
const ScriptValue& key,
......
......@@ -102,6 +102,9 @@ class MODULES_EXPORT IDBObjectStore final : public ScriptWrappable {
const ScriptValue& key,
ExceptionState&);
IDBRequest* put(ScriptState*, const ScriptValue& value, ExceptionState&);
HeapVector<Member<IDBRequest>> putAll(ScriptState*,
const HeapVector<ScriptValue>& values,
ExceptionState&);
IDBRequest* put(ScriptState*,
const ScriptValue& value,
const ScriptValue& key,
......
......@@ -37,6 +37,13 @@
[CallWith=ScriptState, MeasureAs=IndexedDBWrite, NewObject, RaisesException]
IDBRequest put(any value, optional any key);
[
CallWith=ScriptState,
MeasureAs=IndexedDBWrite,
RaisesException,
RuntimeEnabled=IDBPutAll
] sequence<IDBRequest> putAll(sequence<any> values);
[CallWith=ScriptState, MeasureAs=IndexedDBWrite, NewObject, RaisesException]
IDBRequest add(any value, optional any key);
......
......@@ -862,6 +862,10 @@
name: "IDBObserver",
status: "experimental",
},
{
name: "IDBPutAll",
status: "experimental",
},
{
name: "IDBRelaxedDurability",
status: "stable",
......
// META: script=support-promises.js
/**
* This file contains the webplatform tests for the explicit commit() method
* of the IndexedDB transaction API.
*
* @author nums@google.com
*/
promise_test(async testCase => {
const db = await createDatabase(testCase, db => {
const store = createBooksStore(testCase, db);
let values = [
{isbn: 'one', title: 'title1'},
{isbn: 'two', title: 'title2'},
{isbn: 'three', title: 'title3'}
];
const putAllRequests = store.putAll(values);
putAllRequests.forEach(async request => {
await promiseForRequest(testCase, request);
});
});
const txn = db.transaction(['books'], 'readonly');
const objectStore = txn.objectStore('books');
const getRequest1 = objectStore.get('one');
const getRequest2 = objectStore.get('two');
const getRequest3 = objectStore.get('three');
await promiseForTransaction(testCase, txn);
assert_array_equals(
[getRequest1.result.title,
getRequest2.result.title,
getRequest3.result.title],
['title1', 'title2', 'title3'],
'All three retrieved titles should match those that were put.');
db.close();
}, 'Data can be successfully inputted into an object store using putAll.');
\ No newline at end of file
......@@ -731,6 +731,7 @@ interface IDBObjectStore
method openCursor
method openKeyCursor
method put
method putAll
setter name
interface IDBObservation
attribute @@toStringTag
......
......@@ -666,6 +666,7 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] method openCursor
[Worker] method openKeyCursor
[Worker] method put
[Worker] method putAll
[Worker] setter name
[Worker] interface IDBObservation
[Worker] attribute @@toStringTag
......
......@@ -4411,6 +4411,7 @@ interface IDBObjectStore
method openCursor
method openKeyCursor
method put
method putAll
setter name
interface IDBObservation
attribute @@toStringTag
......
......@@ -661,6 +661,7 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] method openCursor
[Worker] method openKeyCursor
[Worker] method put
[Worker] method putAll
[Worker] setter name
[Worker] interface IDBObservation
[Worker] attribute @@toStringTag
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment