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

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
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 try {
257 var request;
258 if (version != null) {
259 request = $dom_open(name, version);
260 } else {
261 request = $dom_open(name);
262 }
263
264 if (onUpgradeNeeded != null) {
265 request.onUpgradeNeeded.listen(onUpgradeNeeded);
266 }
267 return _completeRequest(request, new Completer<Database>());
268 } catch (e) {
269 return new Future.immediateError(e);
270 }
271 }
272
273 @DomName('IDBFactory.open')
274 Future<IdbFactory> deleteDatabase(String name,
275 {void onBlocked(Event)}) {
276 try {
277 var request = $dom_deleteDatabase(name);
278
279 if (onBlocked != null) {
280 request.onBlocked.listen(onBlocked);
281 }
282 _completeRequest(request, new Completer<Database>());
283 } catch (e) {
284 return new Future.immediateError(e);
285 }
286 }
287
253 IdbFactory.internal(); 288 IdbFactory.internal();
254 289
255 @DomName('IDBFactory.cmp') 290 @DomName('IDBFactory.cmp')
256 @DocsEditable 291 @DocsEditable
257 int cmp(Object first, Object second) native "IDBFactory_cmp_Callback"; 292 int cmp(Object first, Object second) native "IDBFactory_cmp_Callback";
258 293
259 @DomName('IDBFactory.deleteDatabase') 294 @DomName('IDBFactory.deleteDatabase')
260 @DocsEditable 295 @DocsEditable
261 VersionChangeRequest deleteDatabase(String name) native "IDBFactory_deleteData base_Callback"; 296 VersionChangeRequest $dom_deleteDatabase(String name) native "IDBFactory_delet eDatabase_Callback";
262 297
263 OpenDBRequest open(String name, [int version]) { 298 OpenDBRequest $dom_open(String name, [int version]) {
264 if (?version) { 299 if (?version) {
265 return _open_1(name, version); 300 return _open_1(name, version);
266 } 301 }
267 return _open_2(name); 302 return _open_2(name);
268 } 303 }
269 304
270 @DomName('IDBFactory._open_1') 305 @DomName('IDBFactory._open_1')
271 @DocsEditable 306 @DocsEditable
272 OpenDBRequest _open_1(name, version) native "IDBFactory__open_1_Callback"; 307 OpenDBRequest _open_1(name, version) native "IDBFactory__open_1_Callback";
273 308
274 @DomName('IDBFactory._open_2') 309 @DomName('IDBFactory._open_2')
275 @DocsEditable 310 @DocsEditable
276 OpenDBRequest _open_2(name) native "IDBFactory__open_2_Callback"; 311 OpenDBRequest _open_2(name) native "IDBFactory__open_2_Callback";
277 312
278 @DomName('IDBFactory.webkitGetDatabaseNames') 313 @DomName('IDBFactory.webkitGetDatabaseNames')
279 @DocsEditable 314 @DocsEditable
280 Request webkitGetDatabaseNames() native "IDBFactory_webkitGetDatabaseNames_Cal lback"; 315 Request webkitGetDatabaseNames() native "IDBFactory_webkitGetDatabaseNames_Cal lback";
281 316
282 } 317 }
318
319
320 /**
321 * Ties a request to a completer, so the completer is completed when it succeeds
322 * and errors out when the request errors.
323 */
324 Future _completeRequest(Request request, Completer completer) {
325 request.onSuccess.listen((e) {
326 completer.complete(request.result);
327 });
328 request.onError.listen((e) {
329 completer.completeError(e);
330 });
331 return completer.future;
332 }
283 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 333 // 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 334 // 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. 335 // BSD-style license that can be found in the LICENSE file.
286 336
287 // WARNING: Do not edit - generated code. 337 // WARNING: Do not edit - generated code.
288 338
289 339
290 @DocsEditable 340 @DocsEditable
291 @DomName('IDBIndex') 341 @DomName('IDBIndex')
292 class Index extends NativeFieldWrapperClass1 { 342 class Index extends NativeFieldWrapperClass1 {
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 599
550 @DomName('IDBKeyRange._upperBound_2') 600 @DomName('IDBKeyRange._upperBound_2')
551 @DocsEditable 601 @DocsEditable
552 static KeyRange _upperBound_2(bound) native "IDBKeyRange__upperBound_2_Callbac k"; 602 static KeyRange _upperBound_2(bound) native "IDBKeyRange__upperBound_2_Callbac k";
553 603
554 } 604 }
555 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 605 // 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 606 // 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. 607 // BSD-style license that can be found in the LICENSE file.
558 608
559 // WARNING: Do not edit - generated code.
560 609
561
562 @DocsEditable
563 @DomName('IDBObjectStore') 610 @DomName('IDBObjectStore')
564 class ObjectStore extends NativeFieldWrapperClass1 { 611 class ObjectStore extends NativeFieldWrapperClass1 {
612
613 @DomName('IDBObjectStore.put')
614 Future<Object> put(value, [key]) {
615 try {
616 var request;
617 if (key != null) {
618 request = $dom_put(value, key);
619 } else {
620 request = $dom_put(value);
621 }
622 return _completeRequest(request, new Completer<Object>());
623 } catch (e) {
624 return new Future.immediateError(e);
625 }
626 }
627
628 @DomName('IDBObjectStore.getObject')
629 Future<Object> getObject(key) {
630 try {
631 var request = $dom_getObject(key);
632
633 return _completeRequest(request, new Completer<Object>());
634 } catch (e) {
635 return new Future.immediateError(e);
636 }
637 }
638
639 /**
640 * Creates a stream of cursors over the records in this object store.
641 *
642 * The stream must be manually advanced by calling [cursor.next] after
643 * each item or by specifying autoAdvance to be true.
644 *
645 * Asynchronous operations which are not related to the current transaction
646 * will cause the transaction to automatically be committed- all processing
647 * must be done synchronously unless they are additional async requests to
648 * the current transaction.
649 */
650 @DomName('IDBObjectStore.openCursor')
651 Stream<Cursor> openCursor({key, KeyRange range, String direction,
652 bool autoAdvance}) {
653 var key_OR_range = null;
654 if (key != null) {
655 if (range != null) {
656 throw new ArgumentError('Cannot specify both key and range.');
657 }
658 key_OR_range = key;
659 } else {
660 key_OR_range = range;
661 }
662
663 // TODO: try/catch this and return a stream with an immediate error.
664 var request;
665 if (direction == null) {
666 request = $dom_openCursor(key_OR_range);
667 } else {
668 request = $dom_openCursor(key_OR_range, direction);
669 }
670 return _cursorStreamFromResult(request, autoAdvance);
671 }
672
565 ObjectStore.internal(); 673 ObjectStore.internal();
566 674
567 @DomName('IDBObjectStore.autoIncrement') 675 @DomName('IDBObjectStore.autoIncrement')
568 @DocsEditable 676 @DocsEditable
569 bool get autoIncrement native "IDBObjectStore_autoIncrement_Getter"; 677 bool get autoIncrement native "IDBObjectStore_autoIncrement_Getter";
570 678
571 @DomName('IDBObjectStore.indexNames') 679 @DomName('IDBObjectStore.indexNames')
572 @DocsEditable 680 @DocsEditable
573 List<String> get indexNames native "IDBObjectStore_indexNames_Getter"; 681 List<String> get indexNames native "IDBObjectStore_indexNames_Getter";
574 682
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 Request _delete_1(key_OR_keyRange) native "IDBObjectStore__delete_1_Callback"; 769 Request _delete_1(key_OR_keyRange) native "IDBObjectStore__delete_1_Callback";
662 770
663 @DomName('IDBObjectStore._delete_2') 771 @DomName('IDBObjectStore._delete_2')
664 @DocsEditable 772 @DocsEditable
665 Request _delete_2(key_OR_keyRange) native "IDBObjectStore__delete_2_Callback"; 773 Request _delete_2(key_OR_keyRange) native "IDBObjectStore__delete_2_Callback";
666 774
667 @DomName('IDBObjectStore.deleteIndex') 775 @DomName('IDBObjectStore.deleteIndex')
668 @DocsEditable 776 @DocsEditable
669 void deleteIndex(String name) native "IDBObjectStore_deleteIndex_Callback"; 777 void deleteIndex(String name) native "IDBObjectStore_deleteIndex_Callback";
670 778
671 Request getObject(key) { 779 Request $dom_getObject(key) {
672 if ((key is KeyRange || key == null)) { 780 if ((key is KeyRange || key == null)) {
673 return _get_1(key); 781 return _get_1(key);
674 } 782 }
675 if (?key) { 783 if (?key) {
676 return _get_2(key); 784 return _get_2(key);
677 } 785 }
678 throw new ArgumentError("Incorrect number or type of arguments"); 786 throw new ArgumentError("Incorrect number or type of arguments");
679 } 787 }
680 788
681 @DomName('IDBObjectStore._get_1') 789 @DomName('IDBObjectStore._get_1')
682 @DocsEditable 790 @DocsEditable
683 Request _get_1(key) native "IDBObjectStore__get_1_Callback"; 791 Request _get_1(key) native "IDBObjectStore__get_1_Callback";
684 792
685 @DomName('IDBObjectStore._get_2') 793 @DomName('IDBObjectStore._get_2')
686 @DocsEditable 794 @DocsEditable
687 Request _get_2(key) native "IDBObjectStore__get_2_Callback"; 795 Request _get_2(key) native "IDBObjectStore__get_2_Callback";
688 796
689 @DomName('IDBObjectStore.index') 797 @DomName('IDBObjectStore.index')
690 @DocsEditable 798 @DocsEditable
691 Index index(String name) native "IDBObjectStore_index_Callback"; 799 Index index(String name) native "IDBObjectStore_index_Callback";
692 800
693 Request openCursor([key_OR_range, String direction]) { 801 Request $dom_openCursor([key_OR_range, String direction]) {
694 if (!?key_OR_range && !?direction) { 802 if (!?key_OR_range && !?direction) {
695 return _openCursor_1(); 803 return _openCursor_1();
696 } 804 }
697 if ((key_OR_range is KeyRange || key_OR_range == null) && !?direction) { 805 if ((key_OR_range is KeyRange || key_OR_range == null) && !?direction) {
698 return _openCursor_2(key_OR_range); 806 return _openCursor_2(key_OR_range);
699 } 807 }
700 if ((key_OR_range is KeyRange || key_OR_range == null) && (direction is Stri ng || direction == null)) { 808 if ((key_OR_range is KeyRange || key_OR_range == null) && (direction is Stri ng || direction == null)) {
701 return _openCursor_3(key_OR_range, direction); 809 return _openCursor_3(key_OR_range, direction);
702 } 810 }
703 if (?key_OR_range && !?direction) { 811 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"; 830 Request _openCursor_3(key_OR_range, direction) native "IDBObjectStore__openCur sor_3_Callback";
723 831
724 @DomName('IDBObjectStore._openCursor_4') 832 @DomName('IDBObjectStore._openCursor_4')
725 @DocsEditable 833 @DocsEditable
726 Request _openCursor_4(key_OR_range) native "IDBObjectStore__openCursor_4_Callb ack"; 834 Request _openCursor_4(key_OR_range) native "IDBObjectStore__openCursor_4_Callb ack";
727 835
728 @DomName('IDBObjectStore._openCursor_5') 836 @DomName('IDBObjectStore._openCursor_5')
729 @DocsEditable 837 @DocsEditable
730 Request _openCursor_5(key_OR_range, direction) native "IDBObjectStore__openCur sor_5_Callback"; 838 Request _openCursor_5(key_OR_range, direction) native "IDBObjectStore__openCur sor_5_Callback";
731 839
732 Request put(Object value, [Object key]) { 840 Request $dom_put(Object value, [Object key]) {
733 if (?key) { 841 if (?key) {
734 return _put_1(value, key); 842 return _put_1(value, key);
735 } 843 }
736 return _put_2(value); 844 return _put_2(value);
737 } 845 }
738 846
739 @DomName('IDBObjectStore._put_1') 847 @DomName('IDBObjectStore._put_1')
740 @DocsEditable 848 @DocsEditable
741 Request _put_1(value, key) native "IDBObjectStore__put_1_Callback"; 849 Request _put_1(value, key) native "IDBObjectStore__put_1_Callback";
742 850
743 @DomName('IDBObjectStore._put_2') 851 @DomName('IDBObjectStore._put_2')
744 @DocsEditable 852 @DocsEditable
745 Request _put_2(value) native "IDBObjectStore__put_2_Callback"; 853 Request _put_2(value) native "IDBObjectStore__put_2_Callback";
746 854
855
856 /**
857 * Helper for iterating over cursors in a request.
858 */
859 static Stream<Cursor> _cursorStreamFromResult(Request request,
860 bool autoAdvance) {
861 var controller = new StreamController<Cursor>();
862
863 request.onError.listen((e) {
864 controller.signalError(e);
865 });
866
867 request.onSuccess.listen((e) {
868 Cursor cursor = request.result;
869 if (cursor == null) {
870 controller.close();
871 } else {
872 controller.add(cursor);
873 if (autoAdvance == true) {
874 cursor.next();
875 }
876 }
877 });
878 return controller.stream;
879 }
747 } 880 }
748 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 881 // 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 882 // 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. 883 // BSD-style license that can be found in the LICENSE file.
751 884
752 // WARNING: Do not edit - generated code. 885 // WARNING: Do not edit - generated code.
753 886
754 887
755 @DocsEditable 888 @DocsEditable
756 @DomName('IDBOpenDBRequest') 889 @DomName('IDBOpenDBRequest')
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 1186
1054 // WARNING: Do not edit - generated code. 1187 // WARNING: Do not edit - generated code.
1055 1188
1056 1189
1057 @DocsEditable 1190 @DocsEditable
1058 @DomName('IDBAny') 1191 @DomName('IDBAny')
1059 class _Any extends NativeFieldWrapperClass1 { 1192 class _Any extends NativeFieldWrapperClass1 {
1060 _Any.internal(); 1193 _Any.internal();
1061 1194
1062 } 1195 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698