| Index: sdk/lib/indexed_db/dartium/indexed_db_dartium.dart
|
| diff --git a/sdk/lib/indexed_db/dartium/indexed_db_dartium.dart b/sdk/lib/indexed_db/dartium/indexed_db_dartium.dart
|
| index 184fb005c826110dd5a18e5f246873253adb6776..4ee252564be840961196663444624bda0f5683a7 100644
|
| --- a/sdk/lib/indexed_db/dartium/indexed_db_dartium.dart
|
| +++ b/sdk/lib/indexed_db/dartium/indexed_db_dartium.dart
|
| @@ -65,7 +65,7 @@ class Cursor extends NativeFieldWrapperClass1 {
|
| @DocsEditable
|
| void advance(int count) native "IDBCursor_advance_Callback";
|
|
|
| - void continueFunction([Object key]) {
|
| + void next([Object key]) {
|
| if (?key) {
|
| _continue_1(key);
|
| return;
|
| @@ -250,6 +250,41 @@ class IdbFactory extends NativeFieldWrapperClass1 {
|
| return true;
|
| }
|
|
|
| + @DomName('IDBFactory.open')
|
| + Future<Database> open(String name,
|
| + {int version, void onUpgradeNeeded(VersionChangeEvent)}) {
|
| + try {
|
| + var request;
|
| + if (version != null) {
|
| + request = $dom_open(name, version);
|
| + } else {
|
| + request = $dom_open(name);
|
| + }
|
| +
|
| + if (onUpgradeNeeded != null) {
|
| + request.onUpgradeNeeded.listen(onUpgradeNeeded);
|
| + }
|
| + return _completeRequest(request, new Completer<Database>());
|
| + } catch (e) {
|
| + return new Future.immediateError(e);
|
| + }
|
| + }
|
| +
|
| + @DomName('IDBFactory.open')
|
| + Future<IdbFactory> deleteDatabase(String name,
|
| + {void onBlocked(Event)}) {
|
| + try {
|
| + var request = $dom_deleteDatabase(name);
|
| +
|
| + if (onBlocked != null) {
|
| + request.onBlocked.listen(onBlocked);
|
| + }
|
| + _completeRequest(request, new Completer<Database>());
|
| + } catch (e) {
|
| + return new Future.immediateError(e);
|
| + }
|
| + }
|
| +
|
| IdbFactory.internal();
|
|
|
| @DomName('IDBFactory.cmp')
|
| @@ -258,9 +293,9 @@ class IdbFactory extends NativeFieldWrapperClass1 {
|
|
|
| @DomName('IDBFactory.deleteDatabase')
|
| @DocsEditable
|
| - VersionChangeRequest deleteDatabase(String name) native "IDBFactory_deleteDatabase_Callback";
|
| + VersionChangeRequest $dom_deleteDatabase(String name) native "IDBFactory_deleteDatabase_Callback";
|
|
|
| - OpenDBRequest open(String name, [int version]) {
|
| + OpenDBRequest $dom_open(String name, [int version]) {
|
| if (?version) {
|
| return _open_1(name, version);
|
| }
|
| @@ -280,6 +315,21 @@ class IdbFactory extends NativeFieldWrapperClass1 {
|
| Request webkitGetDatabaseNames() native "IDBFactory_webkitGetDatabaseNames_Callback";
|
|
|
| }
|
| +
|
| +
|
| +/**
|
| + * Ties a request to a completer, so the completer is completed when it succeeds
|
| + * and errors out when the request errors.
|
| + */
|
| +Future _completeRequest(Request request, Completer completer) {
|
| + request.onSuccess.listen((e) {
|
| + completer.complete(request.result);
|
| + });
|
| + request.onError.listen((e) {
|
| + completer.completeError(e);
|
| + });
|
| + return completer.future;
|
| +}
|
| // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
| // for details. All rights reserved. Use of this source code is governed by a
|
| // BSD-style license that can be found in the LICENSE file.
|
| @@ -556,12 +606,70 @@ class KeyRange extends NativeFieldWrapperClass1 {
|
| // for details. All rights reserved. Use of this source code is governed by a
|
| // BSD-style license that can be found in the LICENSE file.
|
|
|
| -// WARNING: Do not edit - generated code.
|
| -
|
|
|
| -@DocsEditable
|
| @DomName('IDBObjectStore')
|
| class ObjectStore extends NativeFieldWrapperClass1 {
|
| +
|
| + @DomName('IDBObjectStore.put')
|
| + Future<Object> put(value, [key]) {
|
| + try {
|
| + var request;
|
| + if (key != null) {
|
| + request = $dom_put(value, key);
|
| + } else {
|
| + request = $dom_put(value);
|
| + }
|
| + return _completeRequest(request, new Completer<Object>());
|
| + } catch (e) {
|
| + return new Future.immediateError(e);
|
| + }
|
| + }
|
| +
|
| + @DomName('IDBObjectStore.getObject')
|
| + Future<Object> getObject(key) {
|
| + try {
|
| + var request = $dom_getObject(key);
|
| +
|
| + return _completeRequest(request, new Completer<Object>());
|
| + } catch (e) {
|
| + return new Future.immediateError(e);
|
| + }
|
| + }
|
| +
|
| + /**
|
| + * Creates a stream of cursors over the records in this object store.
|
| + *
|
| + * The stream must be manually advanced by calling [cursor.next] after
|
| + * each item or by specifying autoAdvance to be true.
|
| + *
|
| + * Asynchronous operations which are not related to the current transaction
|
| + * will cause the transaction to automatically be committed- all processing
|
| + * must be done synchronously unless they are additional async requests to
|
| + * the current transaction.
|
| + */
|
| + @DomName('IDBObjectStore.openCursor')
|
| + Stream<Cursor> openCursor({key, KeyRange range, String direction,
|
| + bool autoAdvance}) {
|
| + var key_OR_range = null;
|
| + if (key != null) {
|
| + if (range != null) {
|
| + throw new ArgumentError('Cannot specify both key and range.');
|
| + }
|
| + key_OR_range = key;
|
| + } else {
|
| + key_OR_range = range;
|
| + }
|
| +
|
| + // TODO: try/catch this and return a stream with an immediate error.
|
| + var request;
|
| + if (direction == null) {
|
| + request = $dom_openCursor(key_OR_range);
|
| + } else {
|
| + request = $dom_openCursor(key_OR_range, direction);
|
| + }
|
| + return _cursorStreamFromResult(request, autoAdvance);
|
| + }
|
| +
|
| ObjectStore.internal();
|
|
|
| @DomName('IDBObjectStore.autoIncrement')
|
| @@ -668,7 +776,7 @@ class ObjectStore extends NativeFieldWrapperClass1 {
|
| @DocsEditable
|
| void deleteIndex(String name) native "IDBObjectStore_deleteIndex_Callback";
|
|
|
| - Request getObject(key) {
|
| + Request $dom_getObject(key) {
|
| if ((key is KeyRange || key == null)) {
|
| return _get_1(key);
|
| }
|
| @@ -690,7 +798,7 @@ class ObjectStore extends NativeFieldWrapperClass1 {
|
| @DocsEditable
|
| Index index(String name) native "IDBObjectStore_index_Callback";
|
|
|
| - Request openCursor([key_OR_range, String direction]) {
|
| + Request $dom_openCursor([key_OR_range, String direction]) {
|
| if (!?key_OR_range && !?direction) {
|
| return _openCursor_1();
|
| }
|
| @@ -729,7 +837,7 @@ class ObjectStore extends NativeFieldWrapperClass1 {
|
| @DocsEditable
|
| Request _openCursor_5(key_OR_range, direction) native "IDBObjectStore__openCursor_5_Callback";
|
|
|
| - Request put(Object value, [Object key]) {
|
| + Request $dom_put(Object value, [Object key]) {
|
| if (?key) {
|
| return _put_1(value, key);
|
| }
|
| @@ -744,6 +852,31 @@ class ObjectStore extends NativeFieldWrapperClass1 {
|
| @DocsEditable
|
| Request _put_2(value) native "IDBObjectStore__put_2_Callback";
|
|
|
| +
|
| + /**
|
| + * Helper for iterating over cursors in a request.
|
| + */
|
| + static Stream<Cursor> _cursorStreamFromResult(Request request,
|
| + bool autoAdvance) {
|
| + var controller = new StreamController<Cursor>();
|
| +
|
| + request.onError.listen((e) {
|
| + controller.signalError(e);
|
| + });
|
| +
|
| + request.onSuccess.listen((e) {
|
| + Cursor cursor = request.result;
|
| + if (cursor == null) {
|
| + controller.close();
|
| + } else {
|
| + controller.add(cursor);
|
| + if (autoAdvance == true) {
|
| + cursor.next();
|
| + }
|
| + }
|
| + });
|
| + return controller.stream;
|
| + }
|
| }
|
| // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
| // for details. All rights reserved. Use of this source code is governed by a
|
|
|