Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 @DocsEditable | 157 @DocsEditable |
| 158 final dynamic source; | 158 final dynamic source; |
| 159 | 159 |
| 160 @DomName('IDBCursor.advance') | 160 @DomName('IDBCursor.advance') |
| 161 @DocsEditable | 161 @DocsEditable |
| 162 void advance(int count) native; | 162 void advance(int count) native; |
| 163 | 163 |
| 164 @JSName('continue') | 164 @JSName('continue') |
| 165 @DomName('IDBCursor.continue') | 165 @DomName('IDBCursor.continue') |
| 166 @DocsEditable | 166 @DocsEditable |
| 167 void continueFunction([Object key]) native; | 167 void next([Object key]) native; |
| 168 | 168 |
| 169 @DomName('IDBCursor.delete') | 169 @DomName('IDBCursor.delete') |
| 170 @DocsEditable | 170 @DocsEditable |
| 171 Request delete() native; | 171 Request delete() native; |
| 172 | 172 |
| 173 Request update(/*any*/ value) { | 173 Request update(/*any*/ value) { |
| 174 var value_1 = convertDartToNative_SerializedScriptValue(value); | 174 var value_1 = convertDartToNative_SerializedScriptValue(value); |
| 175 return _update_1(value_1); | 175 return _update_1(value_1); |
| 176 } | 176 } |
| 177 @JSName('update') | 177 @JSName('update') |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 /** | 336 /** |
| 337 * Checks to see if Indexed DB is supported on the current platform. | 337 * Checks to see if Indexed DB is supported on the current platform. |
| 338 */ | 338 */ |
| 339 static bool get supported { | 339 static bool get supported { |
| 340 return JS('bool', | 340 return JS('bool', |
| 341 '!!(window.indexedDB || ' | 341 '!!(window.indexedDB || ' |
| 342 'window.webkitIndexedDB || ' | 342 'window.webkitIndexedDB || ' |
| 343 'window.mozIndexedDB)'); | 343 'window.mozIndexedDB)'); |
| 344 } | 344 } |
| 345 | 345 |
| 346 @DomName('IDBFactory.open') | |
| 347 Future<Database> open(String name, | |
| 348 {int version, void onUpgradeNeeded(VersionChangeEvent)}) { | |
|
nweiz
2013/02/05 02:03:19
It's probably worthwhile to add some code that thr
blois
2013/02/05 03:02:42
True- my initial reading was that it was only for
| |
| 349 try { | |
| 350 var request; | |
| 351 if (version != null) { | |
| 352 request = $dom_open(name, version); | |
| 353 } else { | |
| 354 request = $dom_open(name); | |
| 355 } | |
| 356 | |
| 357 if (onUpgradeNeeded != null) { | |
| 358 request.onUpgradeNeeded.listen(onUpgradeNeeded); | |
| 359 } | |
| 360 return _completeRequest(request, new Completer<Database>()); | |
| 361 } catch (e) { | |
| 362 return new Future.immediateError(e); | |
|
nweiz
2013/02/05 02:03:19
Catch and report the stack trace.
blois
2013/02/05 03:02:42
Done.
| |
| 363 } | |
| 364 } | |
| 365 | |
| 366 @DomName('IDBFactory.open') | |
| 367 Future<IdbFactory> deleteDatabase(String name, | |
| 368 {void onBlocked(Event)}) { | |
| 369 try { | |
| 370 var request = $dom_deleteDatabase(name); | |
| 371 | |
| 372 if (onBlocked != null) { | |
| 373 request.onBlocked.listen(onBlocked); | |
| 374 } | |
| 375 _completeRequest(request, new Completer<Database>()); | |
| 376 } catch (e) { | |
| 377 return new Future.immediateError(e); | |
| 378 } | |
| 379 } | |
| 380 | |
| 346 | 381 |
| 347 @DomName('IDBFactory.cmp') | 382 @DomName('IDBFactory.cmp') |
| 348 @DocsEditable | 383 @DocsEditable |
| 349 int cmp(Object first, Object second) native; | 384 int cmp(Object first, Object second) native; |
| 350 | 385 |
| 386 @JSName('deleteDatabase') | |
| 351 @DomName('IDBFactory.deleteDatabase') | 387 @DomName('IDBFactory.deleteDatabase') |
| 352 @DocsEditable | 388 @DocsEditable |
| 353 VersionChangeRequest deleteDatabase(String name) native; | 389 VersionChangeRequest $dom_deleteDatabase(String name) native; |
| 354 | 390 |
| 391 @JSName('open') | |
| 355 @DomName('IDBFactory.open') | 392 @DomName('IDBFactory.open') |
| 356 @DocsEditable | 393 @DocsEditable |
| 357 @Returns('Request') | 394 @Returns('Request') |
| 358 @Creates('Request') | 395 @Creates('Request') |
| 359 @Creates('Database') | 396 @Creates('Database') |
| 360 OpenDBRequest open(String name, [int version]) native; | 397 OpenDBRequest $dom_open(String name, [int version]) native; |
| 361 | 398 |
| 362 @DomName('IDBFactory.webkitGetDatabaseNames') | 399 @DomName('IDBFactory.webkitGetDatabaseNames') |
| 363 @DocsEditable | 400 @DocsEditable |
| 364 Request webkitGetDatabaseNames() native; | 401 Request webkitGetDatabaseNames() native; |
| 365 | 402 |
| 366 } | 403 } |
| 404 | |
| 405 | |
| 406 /** | |
| 407 * Ties a request to a completer, so the completer is completed when it succeeds | |
| 408 * and errors out when the request errors. | |
| 409 */ | |
| 410 Future _completeRequest(Request request, Completer completer) { | |
|
nweiz
2013/02/05 02:03:19
Why does this take an external completer? It seems
blois
2013/02/05 03:02:42
I made it take one so it would be typed properly.
nweiz
2013/02/05 03:05:39
Trying to get Futures typed correctly is a losing
| |
| 411 request.onSuccess.listen((e) { | |
| 412 completer.complete(request.result); | |
| 413 }); | |
| 414 request.onError.listen((e) { | |
| 415 completer.completeError(e); | |
| 416 }); | |
| 417 return completer.future; | |
| 418 } | |
| 367 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 419 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 368 // for details. All rights reserved. Use of this source code is governed by a | 420 // for details. All rights reserved. Use of this source code is governed by a |
| 369 // BSD-style license that can be found in the LICENSE file. | 421 // BSD-style license that can be found in the LICENSE file. |
| 370 | 422 |
| 371 | 423 |
| 372 @DocsEditable | 424 @DocsEditable |
| 373 @DomName('IDBIndex') | 425 @DomName('IDBIndex') |
| 374 class Index native "*IDBIndex" { | 426 class Index native "*IDBIndex" { |
| 375 | 427 |
| 376 @DomName('IDBIndex.keyPath') | 428 @DomName('IDBIndex.keyPath') |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 487 @DomName('IDBKeyRange.upperBound') | 539 @DomName('IDBKeyRange.upperBound') |
| 488 @DocsEditable | 540 @DocsEditable |
| 489 static KeyRange upperBound_(Object bound, [bool open]) native; | 541 static KeyRange upperBound_(Object bound, [bool open]) native; |
| 490 | 542 |
| 491 } | 543 } |
| 492 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 544 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 493 // for details. All rights reserved. Use of this source code is governed by a | 545 // for details. All rights reserved. Use of this source code is governed by a |
| 494 // BSD-style license that can be found in the LICENSE file. | 546 // BSD-style license that can be found in the LICENSE file. |
| 495 | 547 |
| 496 | 548 |
| 497 @DocsEditable | |
| 498 @DomName('IDBObjectStore') | 549 @DomName('IDBObjectStore') |
| 499 class ObjectStore native "*IDBObjectStore" { | 550 class ObjectStore native "*IDBObjectStore" { |
| 500 | 551 |
| 552 @DomName('IDBObjectStore.put') | |
| 553 Future<Object> put(value, [key]) { | |
|
nweiz
2013/02/05 02:03:19
Why "Future<Object>" rather than just "Future"?
blois
2013/02/05 03:02:42
Removed, but it was a preference to be explicit as
| |
| 554 try { | |
| 555 var request; | |
| 556 if (key != null) { | |
| 557 request = $dom_put(value, key); | |
| 558 } else { | |
| 559 request = $dom_put(value); | |
| 560 } | |
| 561 return _completeRequest(request, new Completer<Object>()); | |
| 562 } catch (e) { | |
| 563 return new Future.immediateError(e); | |
| 564 } | |
| 565 } | |
| 566 | |
| 567 @DomName('IDBObjectStore.getObject') | |
| 568 Future<Object> getObject(key) { | |
| 569 try { | |
| 570 var request = $dom_getObject(key); | |
| 571 | |
| 572 return _completeRequest(request, new Completer<Object>()); | |
| 573 } catch (e) { | |
| 574 return new Future.immediateError(e); | |
| 575 } | |
| 576 } | |
| 577 | |
| 578 /** | |
| 579 * Creates a stream of cursors over the records in this object store. | |
| 580 * | |
| 581 * The stream must be manually advanced by calling [cursor.next] after | |
| 582 * each item or by specifying autoAdvance to be true. | |
| 583 * | |
| 584 * Asynchronous operations which are not related to the current transaction | |
| 585 * will cause the transaction to automatically be committed- all processing | |
|
nweiz
2013/02/05 02:03:19
Nit: "committed- all" -> "comitted--all"
| |
| 586 * must be done synchronously unless they are additional async requests to | |
| 587 * the current transaction. | |
|
nweiz
2013/02/05 02:03:19
I would make this warning more urgent and scary, m
blois
2013/02/05 03:02:42
Done.
| |
| 588 */ | |
| 589 @DomName('IDBObjectStore.openCursor') | |
| 590 Stream<Cursor> openCursor({key, KeyRange range, String direction, | |
| 591 bool autoAdvance}) { | |
| 592 var key_OR_range = null; | |
| 593 if (key != null) { | |
| 594 if (range != null) { | |
| 595 throw new ArgumentError('Cannot specify both key and range.'); | |
| 596 } | |
| 597 key_OR_range = key; | |
| 598 } else { | |
| 599 key_OR_range = range; | |
| 600 } | |
| 601 | |
| 602 // TODO: try/catch this and return a stream with an immediate error. | |
| 603 var request; | |
| 604 if (direction == null) { | |
| 605 request = $dom_openCursor(key_OR_range); | |
| 606 } else { | |
| 607 request = $dom_openCursor(key_OR_range, direction); | |
| 608 } | |
| 609 return _cursorStreamFromResult(request, autoAdvance); | |
| 610 } | |
| 611 | |
| 612 | |
| 501 @DomName('IDBObjectStore.autoIncrement') | 613 @DomName('IDBObjectStore.autoIncrement') |
| 502 @DocsEditable | 614 @DocsEditable |
| 503 final bool autoIncrement; | 615 final bool autoIncrement; |
| 504 | 616 |
| 505 @DomName('IDBObjectStore.indexNames') | 617 @DomName('IDBObjectStore.indexNames') |
| 506 @DocsEditable | 618 @DocsEditable |
| 507 @Returns('DomStringList') | 619 @Returns('DomStringList') |
| 508 @Creates('DomStringList') | 620 @Creates('DomStringList') |
| 509 final List<String> indexNames; | 621 final List<String> indexNames; |
| 510 | 622 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 593 @DomName('IDBObjectStore.deleteIndex') | 705 @DomName('IDBObjectStore.deleteIndex') |
| 594 @DocsEditable | 706 @DocsEditable |
| 595 void deleteIndex(String name) native; | 707 void deleteIndex(String name) native; |
| 596 | 708 |
| 597 @JSName('get') | 709 @JSName('get') |
| 598 @DomName('IDBObjectStore.get') | 710 @DomName('IDBObjectStore.get') |
| 599 @DocsEditable | 711 @DocsEditable |
| 600 @Returns('Request') | 712 @Returns('Request') |
| 601 @Creates('Request') | 713 @Creates('Request') |
| 602 @annotation_Creates_SerializedScriptValue | 714 @annotation_Creates_SerializedScriptValue |
| 603 Request getObject(key) native; | 715 Request $dom_getObject(key) native; |
| 604 | 716 |
| 605 @DomName('IDBObjectStore.index') | 717 @DomName('IDBObjectStore.index') |
| 606 @DocsEditable | 718 @DocsEditable |
| 607 Index index(String name) native; | 719 Index index(String name) native; |
| 608 | 720 |
| 721 @JSName('openCursor') | |
| 609 @DomName('IDBObjectStore.openCursor') | 722 @DomName('IDBObjectStore.openCursor') |
| 610 @DocsEditable | 723 @DocsEditable |
| 611 @Returns('Request') | 724 @Returns('Request') |
| 612 @Creates('Request') | 725 @Creates('Request') |
| 613 @Creates('Cursor') | 726 @Creates('Cursor') |
| 614 Request openCursor([key_OR_range, String direction]) native; | 727 Request $dom_openCursor([key_OR_range, String direction]) native; |
| 615 | 728 |
| 616 Request put(/*any*/ value, [/*any*/ key]) { | 729 Request $dom_put(/*any*/ value, [/*any*/ key]) { |
| 617 if (?key) { | 730 if (?key) { |
| 618 var value_1 = convertDartToNative_SerializedScriptValue(value); | 731 var value_1 = convertDartToNative_SerializedScriptValue(value); |
| 619 var key_2 = convertDartToNative_SerializedScriptValue(key); | 732 var key_2 = convertDartToNative_SerializedScriptValue(key); |
| 620 return _put_1(value_1, key_2); | 733 return _$dom_put_1(value_1, key_2); |
| 621 } | 734 } |
| 622 var value_3 = convertDartToNative_SerializedScriptValue(value); | 735 var value_3 = convertDartToNative_SerializedScriptValue(value); |
| 623 return _put_2(value_3); | 736 return _$dom_put_2(value_3); |
| 624 } | 737 } |
| 625 @JSName('put') | 738 @JSName('put') |
| 626 @DomName('IDBObjectStore.put') | 739 @DomName('IDBObjectStore.put') |
| 627 @DocsEditable | 740 @DocsEditable |
| 628 @Returns('Request') | 741 @Returns('Request') |
| 629 @Creates('Request') | 742 @Creates('Request') |
| 630 @_annotation_Creates_IDBKey | 743 @_annotation_Creates_IDBKey |
| 631 Request _put_1(value, key) native; | 744 Request _$dom_put_1(value, key) native; |
| 632 @JSName('put') | 745 @JSName('put') |
| 633 @DomName('IDBObjectStore.put') | 746 @DomName('IDBObjectStore.put') |
| 634 @DocsEditable | 747 @DocsEditable |
| 635 @Returns('Request') | 748 @Returns('Request') |
| 636 @Creates('Request') | 749 @Creates('Request') |
| 637 @_annotation_Creates_IDBKey | 750 @_annotation_Creates_IDBKey |
| 638 Request _put_2(value) native; | 751 Request _$dom_put_2(value) native; |
| 752 | |
| 753 | |
| 754 /** | |
| 755 * Helper for iterating over cursors in a request. | |
| 756 */ | |
| 757 static Stream<Cursor> _cursorStreamFromResult(Request request, | |
| 758 bool autoAdvance) { | |
| 759 var controller = new StreamController<Cursor>(); | |
|
nweiz
2013/02/05 02:03:19
Add a TODO to use an explicitly synchronous contro
blois
2013/02/05 03:02:42
Done.
| |
| 760 | |
| 761 request.onError.listen((e) { | |
| 762 controller.signalError(e); | |
|
nweiz
2013/02/05 02:03:19
Add a TODO here to include a stack trace once issu
blois
2013/02/05 03:02:42
Done.
| |
| 763 }); | |
| 764 | |
| 765 request.onSuccess.listen((e) { | |
| 766 Cursor cursor = request.result; | |
| 767 if (cursor == null) { | |
| 768 controller.close(); | |
| 769 } else { | |
| 770 controller.add(cursor); | |
| 771 if (autoAdvance == true) { | |
| 772 cursor.next(); | |
| 773 } | |
| 774 } | |
| 775 }); | |
| 776 return controller.stream; | |
| 777 } | |
| 639 } | 778 } |
| 640 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 779 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 641 // for details. All rights reserved. Use of this source code is governed by a | 780 // for details. All rights reserved. Use of this source code is governed by a |
| 642 // BSD-style license that can be found in the LICENSE file. | 781 // BSD-style license that can be found in the LICENSE file. |
| 643 | 782 |
| 644 | 783 |
| 645 @DocsEditable | 784 @DocsEditable |
| 646 @DomName('IDBOpenDBRequest') | 785 @DomName('IDBOpenDBRequest') |
| 647 class OpenDBRequest extends Request implements EventTarget native "*IDBOpenDBReq uest" { | 786 class OpenDBRequest extends Request implements EventTarget native "*IDBOpenDBReq uest" { |
| 648 | 787 |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 925 } | 1064 } |
| 926 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1065 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 927 // for details. All rights reserved. Use of this source code is governed by a | 1066 // for details. All rights reserved. Use of this source code is governed by a |
| 928 // BSD-style license that can be found in the LICENSE file. | 1067 // BSD-style license that can be found in the LICENSE file. |
| 929 | 1068 |
| 930 | 1069 |
| 931 @DocsEditable | 1070 @DocsEditable |
| 932 @DomName('IDBAny') | 1071 @DomName('IDBAny') |
| 933 class _Any native "*IDBAny" { | 1072 class _Any native "*IDBAny" { |
| 934 } | 1073 } |
| OLD | NEW |