Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: sdk/lib/indexed_db/dartium/indexed_db_dartium.dart

Issue 12159005: Dartifying some IndexedDB APIs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/indexed_db/dart2js/indexed_db_dart2js.dart ('k') | tests/html/indexeddb_1_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 library dart.dom.indexed_db; 1 library dart.dom.indexed_db;
2 2
3 import 'dart:async'; 3 import 'dart:async';
4 import 'dart:html'; 4 import 'dart:html';
5 import 'dart:html_common'; 5 import 'dart:html_common';
6 import 'dart:nativewrappers'; 6 import 'dart:nativewrappers';
7 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 7 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
8 // for details. All rights reserved. Use of this source code is governed by a 8 // for details. All rights reserved. Use of this source code is governed by a
9 // BSD-style license that can be found in the LICENSE file. 9 // BSD-style license that can be found in the LICENSE file.
10 10
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 Object get primaryKey native "IDBCursor_primaryKey_Getter"; 58 Object get primaryKey native "IDBCursor_primaryKey_Getter";
59 59
60 @DomName('IDBCursor.source') 60 @DomName('IDBCursor.source')
61 @DocsEditable 61 @DocsEditable
62 dynamic get source native "IDBCursor_source_Getter"; 62 dynamic get source native "IDBCursor_source_Getter";
63 63
64 @DomName('IDBCursor.advance') 64 @DomName('IDBCursor.advance')
65 @DocsEditable 65 @DocsEditable
66 void advance(int count) native "IDBCursor_advance_Callback"; 66 void advance(int count) native "IDBCursor_advance_Callback";
67 67
68 void continueFunction([Object key]) { 68 void next([Object key]) {
69 if (?key) { 69 if (?key) {
70 _continue_1(key); 70 _continue_1(key);
71 return; 71 return;
72 } 72 }
73 _continue_2(); 73 _continue_2();
74 return; 74 return;
75 } 75 }
76 76
77 @DomName('IDBCursor._continue_1') 77 @DomName('IDBCursor._continue_1')
78 @DocsEditable 78 @DocsEditable
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 @SupportedBrowser(SupportedBrowser.IE, '10') 243 @SupportedBrowser(SupportedBrowser.IE, '10')
244 @Experimental 244 @Experimental
245 class IdbFactory extends NativeFieldWrapperClass1 { 245 class IdbFactory extends NativeFieldWrapperClass1 {
246 /** 246 /**
247 * Checks to see if Indexed DB is supported on the current platform. 247 * Checks to see if Indexed DB is supported on the current platform.
248 */ 248 */
249 static bool get supported { 249 static bool get supported {
250 return true; 250 return true;
251 } 251 }
252 252
253 @DomName('IDBFactory.open')
254 Future<Database> open(String name,
255 {int version, void onUpgradeNeeded(VersionChangeEvent),
256 void onBlocked(Event)}) {
257 if ((version == null) != (onUpgradeNeeded == null)) {
258 return new Future.immediateError(new ArgumentError(
259 'version and onUpgradeNeeded must be specified together'));
260 }
261 try {
262 var request;
263 if (version != null) {
264 request = $dom_open(name, version);
265 } else {
266 request = $dom_open(name);
267 }
268
269 if (onUpgradeNeeded != null) {
270 request.onUpgradeNeeded.listen(onUpgradeNeeded);
271 }
272 if (onBlocked != null) {
273 request.onBlocked.listen(onBlocked);
274 }
275 return _completeRequest(request);
276 } catch (e, stacktrace) {
277 return new Future.immediateError(e, stacktrace);
278 }
279 }
280
281 @DomName('IDBFactory.open')
282 Future<IdbFactory> deleteDatabase(String name,
283 {void onBlocked(Event)}) {
284 try {
285 var request = $dom_deleteDatabase(name);
286
287 if (onBlocked != null) {
288 request.onBlocked.listen(onBlocked);
289 }
290 return _completeRequest(request);
291 } catch (e, stacktrace) {
292 return new Future.immediateError(e, stacktrace);
293 }
294 }
295
253 IdbFactory.internal(); 296 IdbFactory.internal();
254 297
255 @DomName('IDBFactory.cmp') 298 @DomName('IDBFactory.cmp')
256 @DocsEditable 299 @DocsEditable
257 int cmp(Object first, Object second) native "IDBFactory_cmp_Callback"; 300 int cmp(Object first, Object second) native "IDBFactory_cmp_Callback";
258 301
259 @DomName('IDBFactory.deleteDatabase') 302 @DomName('IDBFactory.deleteDatabase')
260 @DocsEditable 303 @DocsEditable
261 OpenDBRequest deleteDatabase(String name) native "IDBFactory_deleteDatabase_Ca llback"; 304 OpenDBRequest $dom_deleteDatabase(String name) native "IDBFactory_deleteDataba se_Callback";
262 305
263 OpenDBRequest open(String name, [int version]) { 306 OpenDBRequest $dom_open(String name, [int version]) {
264 if (?version) { 307 if (?version) {
265 return _open_1(name, version); 308 return _open_1(name, version);
266 } 309 }
267 return _open_2(name); 310 return _open_2(name);
268 } 311 }
269 312
270 @DomName('IDBFactory._open_1') 313 @DomName('IDBFactory._open_1')
271 @DocsEditable 314 @DocsEditable
272 OpenDBRequest _open_1(name, version) native "IDBFactory__open_1_Callback"; 315 OpenDBRequest _open_1(name, version) native "IDBFactory__open_1_Callback";
273 316
274 @DomName('IDBFactory._open_2') 317 @DomName('IDBFactory._open_2')
275 @DocsEditable 318 @DocsEditable
276 OpenDBRequest _open_2(name) native "IDBFactory__open_2_Callback"; 319 OpenDBRequest _open_2(name) native "IDBFactory__open_2_Callback";
277 320
278 @DomName('IDBFactory.webkitGetDatabaseNames') 321 @DomName('IDBFactory.webkitGetDatabaseNames')
279 @DocsEditable 322 @DocsEditable
280 Request webkitGetDatabaseNames() native "IDBFactory_webkitGetDatabaseNames_Cal lback"; 323 Request webkitGetDatabaseNames() native "IDBFactory_webkitGetDatabaseNames_Cal lback";
281 324
282 } 325 }
326
327
328 /**
329 * Ties a request to a completer, so the completer is completed when it succeeds
330 * and errors out when the request errors.
331 */
332 Future _completeRequest(Request request) {
333 var completer = new Completer();
334 // TODO: make sure that completer.complete is synchronous as transactions
335 // may be committed if the result is not processed immediately.
336 request.onSuccess.listen((e) {
337 completer.complete(request.result);
338 });
339 request.onError.listen((e) {
340 completer.completeError(e);
341 });
342 return completer.future;
343 }
283 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 344 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
284 // for details. All rights reserved. Use of this source code is governed by a 345 // for details. All rights reserved. Use of this source code is governed by a
285 // BSD-style license that can be found in the LICENSE file. 346 // BSD-style license that can be found in the LICENSE file.
286 347
287 // WARNING: Do not edit - generated code. 348 // WARNING: Do not edit - generated code.
288 349
289 350
290 @DocsEditable 351 @DocsEditable
291 @DomName('IDBIndex') 352 @DomName('IDBIndex')
292 class Index extends NativeFieldWrapperClass1 { 353 class Index extends NativeFieldWrapperClass1 {
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 610
550 @DomName('IDBKeyRange._upperBound_2') 611 @DomName('IDBKeyRange._upperBound_2')
551 @DocsEditable 612 @DocsEditable
552 static KeyRange _upperBound_2(bound) native "IDBKeyRange__upperBound_2_Callbac k"; 613 static KeyRange _upperBound_2(bound) native "IDBKeyRange__upperBound_2_Callbac k";
553 614
554 } 615 }
555 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 616 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
556 // for details. All rights reserved. Use of this source code is governed by a 617 // for details. All rights reserved. Use of this source code is governed by a
557 // BSD-style license that can be found in the LICENSE file. 618 // BSD-style license that can be found in the LICENSE file.
558 619
559 // WARNING: Do not edit - generated code.
560 620
561
562 @DocsEditable
563 @DomName('IDBObjectStore') 621 @DomName('IDBObjectStore')
564 class ObjectStore extends NativeFieldWrapperClass1 { 622 class ObjectStore extends NativeFieldWrapperClass1 {
623
624 @DomName('IDBObjectStore.put')
625 Future put(value, [key]) {
626 try {
627 var request;
628 if (key != null) {
629 request = $dom_put(value, key);
630 } else {
631 request = $dom_put(value);
632 }
633 return _completeRequest(request);
634 } catch (e, stacktrace) {
635 return new Future.immediateError(e, stacktrace);
636 }
637 }
638
639 @DomName('IDBObjectStore.getObject')
640 Future getObject(key) {
641 try {
642 var request = $dom_getObject(key);
643
644 return _completeRequest(request);
645 } catch (e, stacktrace) {
646 return new Future.immediateError(e, stacktrace);
647 }
648 }
649
650 /**
651 * Creates a stream of cursors over the records in this object store.
652 *
653 * **The stream must be manually advanced by calling [Cursor.next] after
654 * each item or by specifying autoAdvance to be true.**
655 *
656 * var cursors = objectStore.openCursor().listen(
657 * (cursor) {
658 * // ...some processing with the cursor
659 * cursor.next(); // advance onto the next cursor.
660 * },
661 * onDone: () {
662 * // called when there are no more cursors.
663 * print('all done!');
664 * });
665 *
666 * Asynchronous operations which are not related to the current transaction
667 * will cause the transaction to automatically be committed-- all processing
668 * must be done synchronously unless they are additional async requests to
669 * the current transaction.
670 */
671 @DomName('IDBObjectStore.openCursor')
672 Stream<Cursor> openCursor({key, KeyRange range, String direction,
673 bool autoAdvance}) {
674 var key_OR_range = null;
675 if (key != null) {
676 if (range != null) {
677 throw new ArgumentError('Cannot specify both key and range.');
678 }
679 key_OR_range = key;
680 } else {
681 key_OR_range = range;
682 }
683
684 // TODO: try/catch this and return a stream with an immediate error.
685 var request;
686 if (direction == null) {
687 request = $dom_openCursor(key_OR_range);
688 } else {
689 request = $dom_openCursor(key_OR_range, direction);
690 }
691 return _cursorStreamFromResult(request, autoAdvance);
692 }
693
565 ObjectStore.internal(); 694 ObjectStore.internal();
566 695
567 @DomName('IDBObjectStore.autoIncrement') 696 @DomName('IDBObjectStore.autoIncrement')
568 @DocsEditable 697 @DocsEditable
569 bool get autoIncrement native "IDBObjectStore_autoIncrement_Getter"; 698 bool get autoIncrement native "IDBObjectStore_autoIncrement_Getter";
570 699
571 @DomName('IDBObjectStore.indexNames') 700 @DomName('IDBObjectStore.indexNames')
572 @DocsEditable 701 @DocsEditable
573 List<String> get indexNames native "IDBObjectStore_indexNames_Getter"; 702 List<String> get indexNames native "IDBObjectStore_indexNames_Getter";
574 703
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 Request _delete_1(key_OR_keyRange) native "IDBObjectStore__delete_1_Callback"; 790 Request _delete_1(key_OR_keyRange) native "IDBObjectStore__delete_1_Callback";
662 791
663 @DomName('IDBObjectStore._delete_2') 792 @DomName('IDBObjectStore._delete_2')
664 @DocsEditable 793 @DocsEditable
665 Request _delete_2(key_OR_keyRange) native "IDBObjectStore__delete_2_Callback"; 794 Request _delete_2(key_OR_keyRange) native "IDBObjectStore__delete_2_Callback";
666 795
667 @DomName('IDBObjectStore.deleteIndex') 796 @DomName('IDBObjectStore.deleteIndex')
668 @DocsEditable 797 @DocsEditable
669 void deleteIndex(String name) native "IDBObjectStore_deleteIndex_Callback"; 798 void deleteIndex(String name) native "IDBObjectStore_deleteIndex_Callback";
670 799
671 Request getObject(key) { 800 Request $dom_getObject(key) {
672 if ((key is KeyRange || key == null)) { 801 if ((key is KeyRange || key == null)) {
673 return _get_1(key); 802 return _get_1(key);
674 } 803 }
675 if (?key) { 804 if (?key) {
676 return _get_2(key); 805 return _get_2(key);
677 } 806 }
678 throw new ArgumentError("Incorrect number or type of arguments"); 807 throw new ArgumentError("Incorrect number or type of arguments");
679 } 808 }
680 809
681 @DomName('IDBObjectStore._get_1') 810 @DomName('IDBObjectStore._get_1')
682 @DocsEditable 811 @DocsEditable
683 Request _get_1(key) native "IDBObjectStore__get_1_Callback"; 812 Request _get_1(key) native "IDBObjectStore__get_1_Callback";
684 813
685 @DomName('IDBObjectStore._get_2') 814 @DomName('IDBObjectStore._get_2')
686 @DocsEditable 815 @DocsEditable
687 Request _get_2(key) native "IDBObjectStore__get_2_Callback"; 816 Request _get_2(key) native "IDBObjectStore__get_2_Callback";
688 817
689 @DomName('IDBObjectStore.index') 818 @DomName('IDBObjectStore.index')
690 @DocsEditable 819 @DocsEditable
691 Index index(String name) native "IDBObjectStore_index_Callback"; 820 Index index(String name) native "IDBObjectStore_index_Callback";
692 821
693 Request openCursor([key_OR_range, String direction]) { 822 Request $dom_openCursor([key_OR_range, String direction]) {
694 if (!?key_OR_range && !?direction) { 823 if (!?key_OR_range && !?direction) {
695 return _openCursor_1(); 824 return _openCursor_1();
696 } 825 }
697 if ((key_OR_range is KeyRange || key_OR_range == null) && !?direction) { 826 if ((key_OR_range is KeyRange || key_OR_range == null) && !?direction) {
698 return _openCursor_2(key_OR_range); 827 return _openCursor_2(key_OR_range);
699 } 828 }
700 if ((key_OR_range is KeyRange || key_OR_range == null) && (direction is Stri ng || direction == null)) { 829 if ((key_OR_range is KeyRange || key_OR_range == null) && (direction is Stri ng || direction == null)) {
701 return _openCursor_3(key_OR_range, direction); 830 return _openCursor_3(key_OR_range, direction);
702 } 831 }
703 if (?key_OR_range && !?direction) { 832 if (?key_OR_range && !?direction) {
(...skipping 18 matching lines...) Expand all
722 Request _openCursor_3(key_OR_range, direction) native "IDBObjectStore__openCur sor_3_Callback"; 851 Request _openCursor_3(key_OR_range, direction) native "IDBObjectStore__openCur sor_3_Callback";
723 852
724 @DomName('IDBObjectStore._openCursor_4') 853 @DomName('IDBObjectStore._openCursor_4')
725 @DocsEditable 854 @DocsEditable
726 Request _openCursor_4(key_OR_range) native "IDBObjectStore__openCursor_4_Callb ack"; 855 Request _openCursor_4(key_OR_range) native "IDBObjectStore__openCursor_4_Callb ack";
727 856
728 @DomName('IDBObjectStore._openCursor_5') 857 @DomName('IDBObjectStore._openCursor_5')
729 @DocsEditable 858 @DocsEditable
730 Request _openCursor_5(key_OR_range, direction) native "IDBObjectStore__openCur sor_5_Callback"; 859 Request _openCursor_5(key_OR_range, direction) native "IDBObjectStore__openCur sor_5_Callback";
731 860
732 Request put(Object value, [Object key]) { 861 Request $dom_put(Object value, [Object key]) {
733 if (?key) { 862 if (?key) {
734 return _put_1(value, key); 863 return _put_1(value, key);
735 } 864 }
736 return _put_2(value); 865 return _put_2(value);
737 } 866 }
738 867
739 @DomName('IDBObjectStore._put_1') 868 @DomName('IDBObjectStore._put_1')
740 @DocsEditable 869 @DocsEditable
741 Request _put_1(value, key) native "IDBObjectStore__put_1_Callback"; 870 Request _put_1(value, key) native "IDBObjectStore__put_1_Callback";
742 871
743 @DomName('IDBObjectStore._put_2') 872 @DomName('IDBObjectStore._put_2')
744 @DocsEditable 873 @DocsEditable
745 Request _put_2(value) native "IDBObjectStore__put_2_Callback"; 874 Request _put_2(value) native "IDBObjectStore__put_2_Callback";
746 875
876
877 /**
878 * Helper for iterating over cursors in a request.
879 */
880 static Stream<Cursor> _cursorStreamFromResult(Request request,
881 bool autoAdvance) {
882 // TODO: need to guarantee that the controller provides the values
883 // immediately as waiting until the next tick will cause the transaction to
884 // close.
885 var controller = new StreamController<Cursor>();
886
887 request.onError.listen((e) {
888 //TODO: Report stacktrace once issue 4061 is resolved.
889 controller.signalError(e);
890 });
891
892 request.onSuccess.listen((e) {
893 Cursor cursor = request.result;
894 if (cursor == null) {
895 controller.close();
896 } else {
897 controller.add(cursor);
898 if (autoAdvance == true) {
899 cursor.next();
900 }
901 }
902 });
903 return controller.stream;
904 }
747 } 905 }
748 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 906 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
749 // for details. All rights reserved. Use of this source code is governed by a 907 // for details. All rights reserved. Use of this source code is governed by a
750 // BSD-style license that can be found in the LICENSE file. 908 // BSD-style license that can be found in the LICENSE file.
751 909
752 // WARNING: Do not edit - generated code. 910 // WARNING: Do not edit - generated code.
753 911
754 912
755 @DocsEditable 913 @DocsEditable
756 @DomName('IDBOpenDBRequest') 914 @DomName('IDBOpenDBRequest')
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 class RequestEvents extends Events { 1028 class RequestEvents extends Events {
871 @DocsEditable 1029 @DocsEditable
872 RequestEvents(EventTarget _ptr) : super(_ptr); 1030 RequestEvents(EventTarget _ptr) : super(_ptr);
873 1031
874 @DocsEditable 1032 @DocsEditable
875 EventListenerList get error => this['error']; 1033 EventListenerList get error => this['error'];
876 1034
877 @DocsEditable 1035 @DocsEditable
878 EventListenerList get success => this['success']; 1036 EventListenerList get success => this['success'];
879 } 1037 }
880 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1038 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
881 // for details. All rights reserved. Use of this source code is governed by a 1039 // for details. All rights reserved. Use of this source code is governed by a
882 // BSD-style license that can be found in the LICENSE file. 1040 // BSD-style license that can be found in the LICENSE file.
883 1041
884 // WARNING: Do not edit - generated code.
885 1042
886
887 @DocsEditable
888 @DomName('IDBTransaction') 1043 @DomName('IDBTransaction')
889 class Transaction extends EventTarget { 1044 class Transaction extends EventTarget {
1045
1046 /**
1047 * Provides a Future which will be completed once the transaction has
1048 * completed.
1049 *
1050 * The future will error if an error occurrs on the transaction or if the
1051 * transaction is aborted.
1052 */
1053 Future<Database> get completed {
1054 var completer = new Completer<Database>();
1055
1056 this.onComplete.first.then((_) {
1057 completer.complete(db);
1058 });
1059
1060 this.onError.first.then((e) {
1061 completer.completeError(e);
1062 });
1063
1064 this.onAbort.first.then((e) {
1065 completer.completeError(e);
1066 });
1067
1068 return completer.future;
1069 }
1070
890 Transaction.internal() : super.internal(); 1071 Transaction.internal() : super.internal();
891 1072
892 @DomName('IDBTransaction.abortEvent') 1073 @DomName('IDBTransaction.abortEvent')
893 @DocsEditable 1074 @DocsEditable
894 static const EventStreamProvider<Event> abortEvent = const EventStreamProvider <Event>('abort'); 1075 static const EventStreamProvider<Event> abortEvent = const EventStreamProvider <Event>('abort');
895 1076
896 @DomName('IDBTransaction.completeEvent') 1077 @DomName('IDBTransaction.completeEvent')
897 @DocsEditable 1078 @DocsEditable
898 static const EventStreamProvider<Event> completeEvent = const EventStreamProvi der<Event>('complete'); 1079 static const EventStreamProvider<Event> completeEvent = const EventStreamProvi der<Event>('complete');
899 1080
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 1180
1000 // WARNING: Do not edit - generated code. 1181 // WARNING: Do not edit - generated code.
1001 1182
1002 1183
1003 @DocsEditable 1184 @DocsEditable
1004 @DomName('IDBAny') 1185 @DomName('IDBAny')
1005 class _IDBAny extends NativeFieldWrapperClass1 { 1186 class _IDBAny extends NativeFieldWrapperClass1 {
1006 _IDBAny.internal(); 1187 _IDBAny.internal();
1007 1188
1008 } 1189 }
OLDNEW
« no previous file with comments | « sdk/lib/indexed_db/dart2js/indexed_db_dart2js.dart ('k') | tests/html/indexeddb_1_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698