| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of $LIBRARYNAME; | 5 part of $LIBRARYNAME; |
| 6 | 6 |
| 7 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { | 7 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { |
| 8 /** | 8 /** |
| 9 * Checks to see if Indexed DB is supported on the current platform. | 9 * Checks to see if Indexed DB is supported on the current platform. |
| 10 */ | 10 */ |
| 11 static bool get supported { | 11 static bool get supported { |
| 12 $if DARTIUM | 12 $if DARTIUM |
| 13 return true; | 13 return true; |
| 14 $else | 14 $else |
| 15 return JS('bool', | 15 return JS('bool', |
| 16 '!!(window.indexedDB || ' | 16 '!!(window.indexedDB || ' |
| 17 'window.webkitIndexedDB || ' | 17 'window.webkitIndexedDB || ' |
| 18 'window.mozIndexedDB)'); | 18 'window.mozIndexedDB)'); |
| 19 $endif | 19 $endif |
| 20 } | 20 } |
| 21 | 21 |
| 22 @DomName('IDBFactory.open') |
| 23 Future<Database> open(String name, |
| 24 {int version, void onUpgradeNeeded(VersionChangeEvent)}) { |
| 25 try { |
| 26 var request; |
| 27 if (version != null) { |
| 28 request = $dom_open(name, version); |
| 29 } else { |
| 30 request = $dom_open(name); |
| 31 } |
| 32 |
| 33 if (onUpgradeNeeded != null) { |
| 34 request.onUpgradeNeeded.listen(onUpgradeNeeded); |
| 35 } |
| 36 return _completeRequest(request, new Completer<Database>()); |
| 37 } catch (e) { |
| 38 return new Future.immediateError(e); |
| 39 } |
| 40 } |
| 41 |
| 42 @DomName('IDBFactory.open') |
| 43 Future<IdbFactory> deleteDatabase(String name, |
| 44 {void onBlocked(Event)}) { |
| 45 try { |
| 46 var request = $dom_deleteDatabase(name); |
| 47 |
| 48 if (onBlocked != null) { |
| 49 request.onBlocked.listen(onBlocked); |
| 50 } |
| 51 _completeRequest(request, new Completer<Database>()); |
| 52 } catch (e) { |
| 53 return new Future.immediateError(e); |
| 54 } |
| 55 } |
| 56 |
| 22 $!MEMBERS | 57 $!MEMBERS |
| 23 } | 58 } |
| 59 |
| 60 |
| 61 /** |
| 62 * Ties a request to a completer, so the completer is completed when it succeeds |
| 63 * and errors out when the request errors. |
| 64 */ |
| 65 Future _completeRequest(Request request, Completer completer) { |
| 66 request.onSuccess.listen((e) { |
| 67 completer.complete(request.result); |
| 68 }); |
| 69 request.onError.listen((e) { |
| 70 completer.completeError(e); |
| 71 }); |
| 72 return completer.future; |
| 73 } |
| OLD | NEW |