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

Side by Side Diff: sdk/lib/indexed_db/dart2js/indexed_db_dart2js.dart

Issue 14070010: Refactor Future constructors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added co19 issue number. Created 7 years, 8 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/async/future_impl.dart ('k') | sdk/lib/indexed_db/dartium/indexed_db_dartium.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:_js_helper' show Creates, Returns, JSName, Null; 6 import 'dart:_js_helper' show Creates, Returns, JSName, Null;
7 import 'dart:_foreign_helper' show JS; 7 import 'dart:_foreign_helper' show JS;
8 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 8 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
9 // for details. All rights reserved. Use of this source code is governed by a 9 // for details. All rights reserved. Use of this source code is governed by a
10 // BSD-style license that can be found in the LICENSE file. 10 // BSD-style license that can be found in the LICENSE file.
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // BSD-style license that can be found in the LICENSE file. 136 // BSD-style license that can be found in the LICENSE file.
137 137
138 138
139 @DomName('IDBCursor') 139 @DomName('IDBCursor')
140 class Cursor native "*IDBCursor" { 140 class Cursor native "*IDBCursor" {
141 @DomName('IDBCursor.delete') 141 @DomName('IDBCursor.delete')
142 Future delete() { 142 Future delete() {
143 try { 143 try {
144 return _completeRequest($dom_delete()); 144 return _completeRequest($dom_delete());
145 } catch (e, stacktrace) { 145 } catch (e, stacktrace) {
146 return new Future.immediateError(e, stacktrace); 146 return new Future.error(e, stacktrace);
147 } 147 }
148 } 148 }
149 149
150 @DomName('IDBCursor.value') 150 @DomName('IDBCursor.value')
151 Future update(value) { 151 Future update(value) {
152 try { 152 try {
153 return _completeRequest($dom_update(value)); 153 return _completeRequest($dom_update(value));
154 } catch (e, stacktrace) { 154 } catch (e, stacktrace) {
155 return new Future.immediateError(e, stacktrace); 155 return new Future.error(e, stacktrace);
156 } 156 }
157 } 157 }
158 158
159 159
160 @DomName('IDBCursor.direction') 160 @DomName('IDBCursor.direction')
161 @DocsEditable 161 @DocsEditable
162 final String direction; 162 final String direction;
163 163
164 @DomName('IDBCursor.key') 164 @DomName('IDBCursor.key')
165 @DocsEditable 165 @DocsEditable
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 '!!(window.indexedDB || ' 360 '!!(window.indexedDB || '
361 'window.webkitIndexedDB || ' 361 'window.webkitIndexedDB || '
362 'window.mozIndexedDB)'); 362 'window.mozIndexedDB)');
363 } 363 }
364 364
365 @DomName('IDBFactory.open') 365 @DomName('IDBFactory.open')
366 Future<Database> open(String name, 366 Future<Database> open(String name,
367 {int version, void onUpgradeNeeded(VersionChangeEvent), 367 {int version, void onUpgradeNeeded(VersionChangeEvent),
368 void onBlocked(Event)}) { 368 void onBlocked(Event)}) {
369 if ((version == null) != (onUpgradeNeeded == null)) { 369 if ((version == null) != (onUpgradeNeeded == null)) {
370 return new Future.immediateError(new ArgumentError( 370 return new Future.error(new ArgumentError(
371 'version and onUpgradeNeeded must be specified together')); 371 'version and onUpgradeNeeded must be specified together'));
372 } 372 }
373 try { 373 try {
374 var request; 374 var request;
375 if (version != null) { 375 if (version != null) {
376 request = $dom_open(name, version); 376 request = $dom_open(name, version);
377 } else { 377 } else {
378 request = $dom_open(name); 378 request = $dom_open(name);
379 } 379 }
380 380
381 if (onUpgradeNeeded != null) { 381 if (onUpgradeNeeded != null) {
382 request.onUpgradeNeeded.listen(onUpgradeNeeded); 382 request.onUpgradeNeeded.listen(onUpgradeNeeded);
383 } 383 }
384 if (onBlocked != null) { 384 if (onBlocked != null) {
385 request.onBlocked.listen(onBlocked); 385 request.onBlocked.listen(onBlocked);
386 } 386 }
387 return _completeRequest(request); 387 return _completeRequest(request);
388 } catch (e, stacktrace) { 388 } catch (e, stacktrace) {
389 return new Future.immediateError(e, stacktrace); 389 return new Future.error(e, stacktrace);
390 } 390 }
391 } 391 }
392 392
393 @DomName('IDBFactory.deleteDatabase') 393 @DomName('IDBFactory.deleteDatabase')
394 Future<IdbFactory> deleteDatabase(String name, 394 Future<IdbFactory> deleteDatabase(String name,
395 {void onBlocked(Event)}) { 395 {void onBlocked(Event)}) {
396 try { 396 try {
397 var request = $dom_deleteDatabase(name); 397 var request = $dom_deleteDatabase(name);
398 398
399 if (onBlocked != null) { 399 if (onBlocked != null) {
400 request.onBlocked.listen(onBlocked); 400 request.onBlocked.listen(onBlocked);
401 } 401 }
402 return _completeRequest(request); 402 return _completeRequest(request);
403 } catch (e, stacktrace) { 403 } catch (e, stacktrace) {
404 return new Future.immediateError(e, stacktrace); 404 return new Future.error(e, stacktrace);
405 } 405 }
406 } 406 }
407 407
408 @DomName('IDBFactory.getDatabaseNames') 408 @DomName('IDBFactory.getDatabaseNames')
409 @SupportedBrowser(SupportedBrowser.CHROME) 409 @SupportedBrowser(SupportedBrowser.CHROME)
410 @Experimental 410 @Experimental
411 Future<List<String>> getDatabaseNames() { 411 Future<List<String>> getDatabaseNames() {
412 try { 412 try {
413 var request = $dom_webkitGetDatabaseNames(); 413 var request = $dom_webkitGetDatabaseNames();
414 414
415 return _completeRequest(request); 415 return _completeRequest(request);
416 } catch (e, stacktrace) { 416 } catch (e, stacktrace) {
417 return new Future.immediateError(e, stacktrace); 417 return new Future.error(e, stacktrace);
418 } 418 }
419 } 419 }
420 420
421 /** 421 /**
422 * Checks to see if getDatabaseNames is supported by the current platform. 422 * Checks to see if getDatabaseNames is supported by the current platform.
423 */ 423 */
424 bool get supportsDatabaseNames { 424 bool get supportsDatabaseNames {
425 return supported && JS('bool', 425 return supported && JS('bool',
426 '!!(#.getDatabaseNames || #.webkitGetDatabaseNames)', this, this); 426 '!!(#.getDatabaseNames || #.webkitGetDatabaseNames)', this, this);
427 } 427 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 Future<int> count([key_OR_range]) { 485 Future<int> count([key_OR_range]) {
486 try { 486 try {
487 var request; 487 var request;
488 if (key_OR_range != null) { 488 if (key_OR_range != null) {
489 request = $dom_count(key_OR_range); 489 request = $dom_count(key_OR_range);
490 } else { 490 } else {
491 request = $dom_count(); 491 request = $dom_count();
492 } 492 }
493 return _completeRequest(request); 493 return _completeRequest(request);
494 } catch (e, stacktrace) { 494 } catch (e, stacktrace) {
495 return new Future.immediateError(e, stacktrace); 495 return new Future.error(e, stacktrace);
496 } 496 }
497 } 497 }
498 498
499 @DomName('IDBIndex.get') 499 @DomName('IDBIndex.get')
500 Future get(key) { 500 Future get(key) {
501 try { 501 try {
502 var request = $dom_get(key); 502 var request = $dom_get(key);
503 503
504 return _completeRequest(request); 504 return _completeRequest(request);
505 } catch (e, stacktrace) { 505 } catch (e, stacktrace) {
506 return new Future.immediateError(e, stacktrace); 506 return new Future.error(e, stacktrace);
507 } 507 }
508 } 508 }
509 509
510 @DomName('IDBIndex.getKey') 510 @DomName('IDBIndex.getKey')
511 Future getKey(key) { 511 Future getKey(key) {
512 try { 512 try {
513 var request = $dom_getKey(key); 513 var request = $dom_getKey(key);
514 514
515 return _completeRequest(request); 515 return _completeRequest(request);
516 } catch (e, stacktrace) { 516 } catch (e, stacktrace) {
517 return new Future.immediateError(e, stacktrace); 517 return new Future.error(e, stacktrace);
518 } 518 }
519 } 519 }
520 520
521 /** 521 /**
522 * Creates a stream of cursors over the records in this object store. 522 * Creates a stream of cursors over the records in this object store.
523 * 523 *
524 * See also: 524 * See also:
525 * 525 *
526 * * [ObjectStore.openCursor] 526 * * [ObjectStore.openCursor]
527 */ 527 */
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 Future add(value, [key]) { 707 Future add(value, [key]) {
708 try { 708 try {
709 var request; 709 var request;
710 if (key != null) { 710 if (key != null) {
711 request = $dom_add(value, key); 711 request = $dom_add(value, key);
712 } else { 712 } else {
713 request = $dom_add(value); 713 request = $dom_add(value);
714 } 714 }
715 return _completeRequest(request); 715 return _completeRequest(request);
716 } catch (e, stacktrace) { 716 } catch (e, stacktrace) {
717 return new Future.immediateError(e, stacktrace); 717 return new Future.error(e, stacktrace);
718 } 718 }
719 } 719 }
720 720
721 @DomName('IDBObjectStore.clear') 721 @DomName('IDBObjectStore.clear')
722 Future clear() { 722 Future clear() {
723 try { 723 try {
724 return _completeRequest($dom_clear()); 724 return _completeRequest($dom_clear());
725 } catch (e, stacktrace) { 725 } catch (e, stacktrace) {
726 return new Future.immediateError(e, stacktrace); 726 return new Future.error(e, stacktrace);
727 } 727 }
728 } 728 }
729 729
730 @DomName('IDBObjectStore.delete') 730 @DomName('IDBObjectStore.delete')
731 Future delete(key_OR_keyRange){ 731 Future delete(key_OR_keyRange){
732 try { 732 try {
733 return _completeRequest($dom_delete(key_OR_keyRange)); 733 return _completeRequest($dom_delete(key_OR_keyRange));
734 } catch (e, stacktrace) { 734 } catch (e, stacktrace) {
735 return new Future.immediateError(e, stacktrace); 735 return new Future.error(e, stacktrace);
736 } 736 }
737 } 737 }
738 738
739 @DomName('IDBObjectStore.count') 739 @DomName('IDBObjectStore.count')
740 Future<int> count([key_OR_range]) { 740 Future<int> count([key_OR_range]) {
741 try { 741 try {
742 var request; 742 var request;
743 if (key_OR_range != null) { 743 if (key_OR_range != null) {
744 request = $dom_count(key_OR_range); 744 request = $dom_count(key_OR_range);
745 } else { 745 } else {
746 request = $dom_count(); 746 request = $dom_count();
747 } 747 }
748 return _completeRequest(request); 748 return _completeRequest(request);
749 } catch (e, stacktrace) { 749 } catch (e, stacktrace) {
750 return new Future.immediateError(e, stacktrace); 750 return new Future.error(e, stacktrace);
751 } 751 }
752 } 752 }
753 753
754 @DomName('IDBObjectStore.put') 754 @DomName('IDBObjectStore.put')
755 Future put(value, [key]) { 755 Future put(value, [key]) {
756 try { 756 try {
757 var request; 757 var request;
758 if (key != null) { 758 if (key != null) {
759 request = $dom_put(value, key); 759 request = $dom_put(value, key);
760 } else { 760 } else {
761 request = $dom_put(value); 761 request = $dom_put(value);
762 } 762 }
763 return _completeRequest(request); 763 return _completeRequest(request);
764 } catch (e, stacktrace) { 764 } catch (e, stacktrace) {
765 return new Future.immediateError(e, stacktrace); 765 return new Future.error(e, stacktrace);
766 } 766 }
767 } 767 }
768 768
769 @DomName('IDBObjectStore.get') 769 @DomName('IDBObjectStore.get')
770 Future getObject(key) { 770 Future getObject(key) {
771 try { 771 try {
772 var request = $dom_get(key); 772 var request = $dom_get(key);
773 773
774 return _completeRequest(request); 774 return _completeRequest(request);
775 } catch (e, stacktrace) { 775 } catch (e, stacktrace) {
776 return new Future.immediateError(e, stacktrace); 776 return new Future.error(e, stacktrace);
777 } 777 }
778 } 778 }
779 779
780 /** 780 /**
781 * Creates a stream of cursors over the records in this object store. 781 * Creates a stream of cursors over the records in this object store.
782 * 782 *
783 * **The stream must be manually advanced by calling [Cursor.next] after 783 * **The stream must be manually advanced by calling [Cursor.next] after
784 * each item or by specifying autoAdvance to be true.** 784 * each item or by specifying autoAdvance to be true.**
785 * 785 *
786 * var cursors = objectStore.openCursor().listen( 786 * var cursors = objectStore.openCursor().listen(
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 } 1238 }
1239 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1239 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
1240 // for details. All rights reserved. Use of this source code is governed by a 1240 // for details. All rights reserved. Use of this source code is governed by a
1241 // BSD-style license that can be found in the LICENSE file. 1241 // BSD-style license that can be found in the LICENSE file.
1242 1242
1243 1243
1244 @DocsEditable 1244 @DocsEditable
1245 @DomName('IDBAny') 1245 @DomName('IDBAny')
1246 abstract class _IDBAny native "*IDBAny" { 1246 abstract class _IDBAny native "*IDBAny" {
1247 } 1247 }
OLDNEW
« no previous file with comments | « sdk/lib/async/future_impl.dart ('k') | sdk/lib/indexed_db/dartium/indexed_db_dartium.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698