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)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS
{ | 7 $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS
{ |
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 | |
13 return true; | |
14 $else | |
15 return JS('bool', | 12 return JS('bool', |
16 '!!(window.indexedDB || ' | 13 '!!(window.indexedDB || ' |
17 'window.webkitIndexedDB || ' | 14 'window.webkitIndexedDB || ' |
18 'window.mozIndexedDB)'); | 15 'window.mozIndexedDB)'); |
19 $endif | |
20 } | 16 } |
21 | 17 |
22 @DomName('IDBFactory.open') | 18 @DomName('IDBFactory.open') |
23 Future<Database> open(String name, | 19 Future<Database> open(String name, |
24 {int version, void onUpgradeNeeded(VersionChangeEvent), | 20 {int version, void onUpgradeNeeded(VersionChangeEvent), |
25 void onBlocked(Event)}) { | 21 void onBlocked(Event)}) { |
26 if ((version == null) != (onUpgradeNeeded == null)) { | 22 if ((version == null) != (onUpgradeNeeded == null)) { |
27 return new Future.error(new ArgumentError( | 23 return new Future.error(new ArgumentError( |
28 'version and onUpgradeNeeded must be specified together')); | 24 'version and onUpgradeNeeded must be specified together')); |
29 } | 25 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 return _completeRequest(request); | 73 return _completeRequest(request); |
78 } catch (e, stacktrace) { | 74 } catch (e, stacktrace) { |
79 return new Future.error(e, stacktrace); | 75 return new Future.error(e, stacktrace); |
80 } | 76 } |
81 } | 77 } |
82 | 78 |
83 /** | 79 /** |
84 * Checks to see if getDatabaseNames is supported by the current platform. | 80 * Checks to see if getDatabaseNames is supported by the current platform. |
85 */ | 81 */ |
86 bool get supportsDatabaseNames { | 82 bool get supportsDatabaseNames { |
87 $if DART2JS | |
88 return supported && JS('bool', | 83 return supported && JS('bool', |
89 '!!(#.getDatabaseNames || #.webkitGetDatabaseNames)', this, this); | 84 '!!(#.getDatabaseNames || #.webkitGetDatabaseNames)', this, this); |
90 $else | |
91 return true; | |
92 $endif | |
93 } | 85 } |
94 | 86 |
95 $!MEMBERS | 87 $!MEMBERS |
96 } | 88 } |
97 | 89 |
98 | 90 |
99 /** | 91 /** |
100 * Ties a request to a completer, so the completer is completed when it succeeds | 92 * Ties a request to a completer, so the completer is completed when it succeeds |
101 * and errors out when the request errors. | 93 * and errors out when the request errors. |
102 */ | 94 */ |
103 Future/*<T>*/ _completeRequest/*<T>*/(Request request) { | 95 Future/*<T>*/ _completeRequest/*<T>*/(Request request) { |
104 var completer = new Completer/*<T>*/.sync(); | 96 var completer = new Completer/*<T>*/.sync(); |
105 // TODO: make sure that completer.complete is synchronous as transactions | 97 // TODO: make sure that completer.complete is synchronous as transactions |
106 // may be committed if the result is not processed immediately. | 98 // may be committed if the result is not processed immediately. |
107 request.onSuccess.listen((e) { | 99 request.onSuccess.listen((e) { |
108 var result = _cast/*<T>*/(request.result); | 100 var result = _cast/*<T>*/(request.result); |
109 completer.complete(result); | 101 completer.complete(result); |
110 }); | 102 }); |
111 request.onError.listen(completer.completeError); | 103 request.onError.listen(completer.completeError); |
112 return completer.future; | 104 return completer.future; |
113 } | 105 } |
OLD | NEW |