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

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

Issue 12313015: Dartifying remainder of Index DB 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
« no previous file with comments | « no previous file | 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 124
125 /// May modify original. If so, action is idempotent. 125 /// May modify original. If so, action is idempotent.
126 _convertNativeToDart_IDBAny(object) { 126 _convertNativeToDart_IDBAny(object) {
127 return convertNativeToDart_AcceptStructuredClone(object, mustCopy: false); 127 return convertNativeToDart_AcceptStructuredClone(object, mustCopy: false);
128 } 128 }
129 129
130 130
131 const String _idbKey = '=List|=Object|num|String'; // TODO(sra): Add DateTime. 131 const String _idbKey = '=List|=Object|num|String'; // TODO(sra): Add DateTime.
132 const _annotation_Creates_IDBKey = const Creates(_idbKey); 132 const _annotation_Creates_IDBKey = const Creates(_idbKey);
133 const _annotation_Returns_IDBKey = const Returns(_idbKey); 133 const _annotation_Returns_IDBKey = const Returns(_idbKey);
134 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 134 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
135 // for details. All rights reserved. Use of this source code is governed by a 135 // for details. All rights reserved. Use of this source code is governed by a
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 @DocsEditable
140 @DomName('IDBCursor') 139 @DomName('IDBCursor')
141 class Cursor native "*IDBCursor" { 140 class Cursor native "*IDBCursor" {
141 @DomName('IDBCursor.delete')
142 Future delete() {
143 try {
144 return _completeRequest($dom_delete());
145 } catch (e, stacktrace) {
146 return new Future.immediateError(e, stacktrace);
147 }
148 }
142 149
150 @DomName('IDBCursor.value')
151 Future update(value) {
152 try {
153 return _completeRequest($dom_update(value));
154 } catch (e, stacktrace) {
155 return new Future.immediateError(e, stacktrace);
156 }
157 }
158
159
143 @DomName('IDBCursor.direction') 160 @DomName('IDBCursor.direction')
144 @DocsEditable 161 @DocsEditable
145 final String direction; 162 final String direction;
146 163
147 @DomName('IDBCursor.key') 164 @DomName('IDBCursor.key')
148 @DocsEditable 165 @DocsEditable
149 @_annotation_Creates_IDBKey 166 @_annotation_Creates_IDBKey
150 @_annotation_Returns_IDBKey 167 @_annotation_Returns_IDBKey
151 final Object key; 168 final Object key;
152 169
153 @DomName('IDBCursor.primaryKey') 170 @DomName('IDBCursor.primaryKey')
154 @DocsEditable 171 @DocsEditable
155 final Object primaryKey; 172 final Object primaryKey;
156 173
157 @DomName('IDBCursor.source') 174 @DomName('IDBCursor.source')
158 @DocsEditable 175 @DocsEditable
159 final dynamic source; 176 final dynamic source;
160 177
161 @DomName('IDBCursor.advance') 178 @DomName('IDBCursor.advance')
162 @DocsEditable 179 @DocsEditable
163 void advance(int count) native; 180 void advance(int count) native;
164 181
165 @JSName('continue') 182 @JSName('continue')
166 @DomName('IDBCursor.continue') 183 @DomName('IDBCursor.continue')
167 @DocsEditable 184 @DocsEditable
168 void next([Object key]) native; 185 void next([Object key]) native;
169 186
187 @JSName('delete')
170 @DomName('IDBCursor.delete') 188 @DomName('IDBCursor.delete')
171 @DocsEditable 189 @DocsEditable
172 Request delete() native; 190 Request $dom_delete() native;
173 191
174 @DomName('IDBCursor.update') 192 @DomName('IDBCursor.update')
175 @DocsEditable 193 @DocsEditable
176 Request update(/*any*/ value) { 194 Request $dom_update(/*any*/ value) {
177 var value_1 = convertDartToNative_SerializedScriptValue(value); 195 var value_1 = convertDartToNative_SerializedScriptValue(value);
178 return _update_1(value_1); 196 return _$dom_update_1(value_1);
179 } 197 }
180 @JSName('update') 198 @JSName('update')
181 @DomName('IDBCursor.update') 199 @DomName('IDBCursor.update')
182 @DocsEditable 200 @DocsEditable
183 Request _update_1(value) native; 201 Request _$dom_update_1(value) native;
202
184 } 203 }
185 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 204 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
186 // for details. All rights reserved. Use of this source code is governed by a 205 // for details. All rights reserved. Use of this source code is governed by a
187 // BSD-style license that can be found in the LICENSE file. 206 // BSD-style license that can be found in the LICENSE file.
188 207
189 208
190 @DocsEditable 209 @DocsEditable
191 @DomName('IDBCursorWithValue') 210 @DomName('IDBCursorWithValue')
192 class CursorWithValue extends Cursor native "*IDBCursorWithValue" { 211 class CursorWithValue extends Cursor native "*IDBCursorWithValue" {
193 212
194 dynamic get value => _convertNativeToDart_IDBAny(this._value); 213 dynamic get value => _convertNativeToDart_IDBAny(this._value);
195 @JSName('value') 214 @JSName('value')
196 @DomName('IDBCursorWithValue.value') 215 @DomName('IDBCursorWithValue.value')
197 @DocsEditable 216 @DocsEditable
198 @annotation_Creates_SerializedScriptValue 217 @annotation_Creates_SerializedScriptValue
199 @annotation_Returns_SerializedScriptValue 218 @annotation_Returns_SerializedScriptValue
200 final dynamic _value; 219 final dynamic _value;
201 } 220 }
202 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 221 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
203 // for details. All rights reserved. Use of this source code is governed by a 222 // for details. All rights reserved. Use of this source code is governed by a
204 // BSD-style license that can be found in the LICENSE file. 223 // BSD-style license that can be found in the LICENSE file.
205 224
206 225
226 @DocsEditable
207 @DomName('IDBDatabase') 227 @DomName('IDBDatabase')
208 @SupportedBrowser(SupportedBrowser.CHROME) 228 @SupportedBrowser(SupportedBrowser.CHROME)
209 @SupportedBrowser(SupportedBrowser.FIREFOX, '15') 229 @SupportedBrowser(SupportedBrowser.FIREFOX, '15')
210 @SupportedBrowser(SupportedBrowser.IE, '10') 230 @SupportedBrowser(SupportedBrowser.IE, '10')
211 @Experimental 231 @Experimental
212 class Database extends EventTarget native "*IDBDatabase" { 232 class Database extends EventTarget native "*IDBDatabase" {
233 @DomName('IDBDatabase.createObjectStore')
234 @DocsEditable
235 ObjectStore createObjectStore(String name,
236 {String keyPath, bool autoIncrement}) {
237 var options = {};
238 if (keyPath != null) {
239 options['keyPath'] = keyPath;
240 }
241 if (autoIncrement != null) {
242 options['autoIncrement'] = autoIncrement;
243 }
244
245 return $dom_createObjectStore(name, options);
246 }
213 247
214 Transaction transaction(storeName_OR_storeNames, String mode) { 248 Transaction transaction(storeName_OR_storeNames, String mode) {
215 if (mode != 'readonly' && mode != 'readwrite') { 249 if (mode != 'readonly' && mode != 'readwrite') {
216 throw new ArgumentError(mode); 250 throw new ArgumentError(mode);
217 } 251 }
218 252
219 // TODO(sra): Ensure storeName_OR_storeNames is a string or List<String>, 253 // TODO(sra): Ensure storeName_OR_storeNames is a string or List<String>,
220 // and copy to JavaScript array if necessary. 254 // and copy to JavaScript array if necessary.
221 255
222 // Try and create a transaction with a string mode. Browsers that expect a 256 // Try and create a transaction with a string mode. Browsers that expect a
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 @DomName('IDBDatabase.addEventListener') 293 @DomName('IDBDatabase.addEventListener')
260 @DocsEditable 294 @DocsEditable
261 void $dom_addEventListener(String type, EventListener listener, [bool useCaptu re]) native; 295 void $dom_addEventListener(String type, EventListener listener, [bool useCaptu re]) native;
262 296
263 @DomName('IDBDatabase.close') 297 @DomName('IDBDatabase.close')
264 @DocsEditable 298 @DocsEditable
265 void close() native; 299 void close() native;
266 300
267 @DomName('IDBDatabase.createObjectStore') 301 @DomName('IDBDatabase.createObjectStore')
268 @DocsEditable 302 @DocsEditable
269 ObjectStore createObjectStore(String name, [Map options]) { 303 ObjectStore $dom_createObjectStore(String name, [Map options]) {
270 if (?options) { 304 if (?options) {
271 var options_1 = convertDartToNative_Dictionary(options); 305 var options_1 = convertDartToNative_Dictionary(options);
272 return _createObjectStore_1(name, options_1); 306 return _$dom_createObjectStore_1(name, options_1);
273 } 307 }
274 return _createObjectStore_2(name); 308 return _$dom_createObjectStore_2(name);
275 } 309 }
276 @JSName('createObjectStore') 310 @JSName('createObjectStore')
277 @DomName('IDBDatabase.createObjectStore') 311 @DomName('IDBDatabase.createObjectStore')
278 @DocsEditable 312 @DocsEditable
279 ObjectStore _createObjectStore_1(name, options) native; 313 ObjectStore _$dom_createObjectStore_1(name, options) native;
280 @JSName('createObjectStore') 314 @JSName('createObjectStore')
281 @DomName('IDBDatabase.createObjectStore') 315 @DomName('IDBDatabase.createObjectStore')
282 @DocsEditable 316 @DocsEditable
283 ObjectStore _createObjectStore_2(name) native; 317 ObjectStore _$dom_createObjectStore_2(name) native;
284 318
285 @DomName('IDBDatabase.deleteObjectStore') 319 @DomName('IDBDatabase.deleteObjectStore')
286 @DocsEditable 320 @DocsEditable
287 void deleteObjectStore(String name) native; 321 void deleteObjectStore(String name) native;
288 322
289 @DomName('IDBDatabase.dispatchEvent') 323 @DomName('IDBDatabase.dispatchEvent')
290 @DocsEditable 324 @DocsEditable
291 bool dispatchEvent(Event evt) native; 325 bool dispatchEvent(Event evt) native;
292 326
293 @JSName('removeEventListener') 327 @JSName('removeEventListener')
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 398
365 if (onBlocked != null) { 399 if (onBlocked != null) {
366 request.onBlocked.listen(onBlocked); 400 request.onBlocked.listen(onBlocked);
367 } 401 }
368 return _completeRequest(request); 402 return _completeRequest(request);
369 } catch (e, stacktrace) { 403 } catch (e, stacktrace) {
370 return new Future.immediateError(e, stacktrace); 404 return new Future.immediateError(e, stacktrace);
371 } 405 }
372 } 406 }
373 407
408 @DomName('IDBFactory.getDatabaseNames')
409 @SupportedBrowser(SupportedBrowser.CHROME)
410 @Experimental
411 Future<List<String>> getDatabaseNames() {
412 try {
413 var request = $dom_webkitGetDatabaseNames();
414
415 return _completeRequest(request);
416 } catch (e, stacktrace) {
417 return new Future.immediateError(e, stacktrace);
418 }
419 }
420
421 /**
422 * Checks to see if getDatabaseNames is supported by the current platform.
423 */
424 bool get supportsDatabaseNames {
425 return JS('bool', '!!(#.getDatabaseNames || #.webkitGetDatabaseNames)',
426 this, this);
427 }
428
374 429
375 @DomName('IDBFactory.cmp') 430 @DomName('IDBFactory.cmp')
376 @DocsEditable 431 @DocsEditable
377 int cmp(Object first, Object second) native; 432 int cmp(Object first, Object second) native;
378 433
379 @JSName('deleteDatabase') 434 @JSName('deleteDatabase')
380 @DomName('IDBFactory.deleteDatabase') 435 @DomName('IDBFactory.deleteDatabase')
381 @DocsEditable 436 @DocsEditable
382 OpenDBRequest $dom_deleteDatabase(String name) native; 437 OpenDBRequest $dom_deleteDatabase(String name) native;
383 438
384 @JSName('open') 439 @JSName('open')
385 @DomName('IDBFactory.open') 440 @DomName('IDBFactory.open')
386 @DocsEditable 441 @DocsEditable
387 @Returns('Request') 442 @Returns('Request')
388 @Creates('Request') 443 @Creates('Request')
389 @Creates('Database') 444 @Creates('Database')
390 OpenDBRequest $dom_open(String name, [int version]) native; 445 OpenDBRequest $dom_open(String name, [int version]) native;
391 446
392 @JSName('webkitGetDatabaseNames') 447 @JSName('webkitGetDatabaseNames')
393 @DomName('IDBFactory.webkitGetDatabaseNames') 448 @DomName('IDBFactory.webkitGetDatabaseNames')
394 @DocsEditable 449 @DocsEditable
395 @SupportedBrowser(SupportedBrowser.CHROME) 450 @SupportedBrowser(SupportedBrowser.CHROME)
396 @SupportedBrowser(SupportedBrowser.SAFARI) 451 @SupportedBrowser(SupportedBrowser.SAFARI)
397 @Experimental 452 @Experimental
398 Request getDatabaseNames() native; 453 @Returns('Request')
454 @Creates('Request')
455 @Creates('DomStringList')
456 Request $dom_webkitGetDatabaseNames() native;
399 457
400 } 458 }
401 459
402 460
403 /** 461 /**
404 * Ties a request to a completer, so the completer is completed when it succeeds 462 * Ties a request to a completer, so the completer is completed when it succeeds
405 * and errors out when the request errors. 463 * and errors out when the request errors.
406 */ 464 */
407 Future _completeRequest(Request request) { 465 Future _completeRequest(Request request) {
408 var completer = new Completer(); 466 var completer = new Completer();
409 // TODO: make sure that completer.complete is synchronous as transactions 467 // TODO: make sure that completer.complete is synchronous as transactions
410 // may be committed if the result is not processed immediately. 468 // may be committed if the result is not processed immediately.
411 request.onSuccess.listen((e) { 469 request.onSuccess.listen((e) {
412 completer.complete(request.result); 470 completer.complete(request.result);
413 }); 471 });
414 request.onError.listen((e) { 472 request.onError.listen((e) {
415 completer.completeError(e); 473 completer.completeError(e);
416 }); 474 });
417 return completer.future; 475 return completer.future;
418 } 476 }
419 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 477 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
420 // for details. All rights reserved. Use of this source code is governed by a 478 // for details. All rights reserved. Use of this source code is governed by a
421 // BSD-style license that can be found in the LICENSE file. 479 // BSD-style license that can be found in the LICENSE file.
422 480
423 481
424 @DocsEditable
425 @DomName('IDBIndex') 482 @DomName('IDBIndex')
426 class Index native "*IDBIndex" { 483 class Index native "*IDBIndex" {
484 @DomName('IDBIndex.count')
485 Future<int> count([key_OR_range]) {
486 try {
487 var request;
488 if (key_OR_range != null) {
489 request = $dom_count(key_OR_range);
490 } else {
491 request = $dom_count();
492 }
493 return _completeRequest(request);
494 } catch (e, stacktrace) {
495 return new Future.immediateError(e, stacktrace);
496 }
497 }
427 498
499 @DomName('IDBIndex.get')
500 Future get(key) {
501 try {
502 var request = $dom_get(key);
503
504 return _completeRequest(request);
505 } catch (e, stacktrace) {
506 return new Future.immediateError(e, stacktrace);
507 }
508 }
509
510 @DomName('IDBIndex.getKey')
511 Future getKey(key) {
512 try {
513 var request = $dom_getKey(key);
514
515 return _completeRequest(request);
516 } catch (e, stacktrace) {
517 return new Future.immediateError(e, stacktrace);
518 }
519 }
520
521 /**
522 * Creates a stream of cursors over the records in this object store.
523 *
524 * See also:
525 *
526 * * [ObjectStore.openCursor]
527 */
528 Stream<CursorWithValue> openCursor({key, KeyRange range, String direction,
529 bool autoAdvance}) {
530 var key_OR_range = null;
531 if (key != null) {
532 if (range != null) {
533 throw new ArgumentError('Cannot specify both key and range.');
534 }
535 key_OR_range = key;
536 } else {
537 key_OR_range = range;
538 }
539 var request;
540 if (direction == null) {
541 request = $dom_openCursor(key_OR_range);
542 } else {
543 request = $dom_openCursor(key_OR_range, direction);
544 }
545 return ObjectStore._cursorStreamFromResult(request, autoAdvance);
546 }
547
548 /**
549 * Creates a stream of cursors over the records in this object store.
550 *
551 * See also:
552 *
553 * * [ObjectStore.openCursor]
554 */
555 Stream<Cursor> openKeyCursor({key, KeyRange range, String direction,
556 bool autoAdvance}) {
557 var key_OR_range = null;
558 if (key != null) {
559 if (range != null) {
560 throw new ArgumentError('Cannot specify both key and range.');
561 }
562 key_OR_range = key;
563 } else {
564 key_OR_range = range;
565 }
566 var request;
567 if (direction == null) {
568 request = $dom_openKeyCursor(key_OR_range);
569 } else {
570 request = $dom_openKeyCursor(key_OR_range, direction);
571 }
572 return ObjectStore._cursorStreamFromResult(request, autoAdvance);
573 }
574
575
428 @DomName('IDBIndex.keyPath') 576 @DomName('IDBIndex.keyPath')
429 @DocsEditable 577 @DocsEditable
430 final dynamic keyPath; 578 final dynamic keyPath;
431 579
432 @DomName('IDBIndex.multiEntry') 580 @DomName('IDBIndex.multiEntry')
433 @DocsEditable 581 @DocsEditable
434 final bool multiEntry; 582 final bool multiEntry;
435 583
436 @DomName('IDBIndex.name') 584 @DomName('IDBIndex.name')
437 @DocsEditable 585 @DocsEditable
438 final String name; 586 final String name;
439 587
440 @DomName('IDBIndex.objectStore') 588 @DomName('IDBIndex.objectStore')
441 @DocsEditable 589 @DocsEditable
442 final ObjectStore objectStore; 590 final ObjectStore objectStore;
443 591
444 @DomName('IDBIndex.unique') 592 @DomName('IDBIndex.unique')
445 @DocsEditable 593 @DocsEditable
446 final bool unique; 594 final bool unique;
447 595
596 @JSName('count')
448 @DomName('IDBIndex.count') 597 @DomName('IDBIndex.count')
449 @DocsEditable 598 @DocsEditable
450 Request count([key_OR_range]) native; 599 Request $dom_count([key_OR_range]) native;
451 600
601 @JSName('get')
452 @DomName('IDBIndex.get') 602 @DomName('IDBIndex.get')
453 @DocsEditable 603 @DocsEditable
454 @Returns('Request') 604 @Returns('Request')
455 @Creates('Request') 605 @Creates('Request')
456 @annotation_Creates_SerializedScriptValue 606 @annotation_Creates_SerializedScriptValue
457 Request get(key) native; 607 Request $dom_get(key) native;
458 608
609 @JSName('getKey')
459 @DomName('IDBIndex.getKey') 610 @DomName('IDBIndex.getKey')
460 @DocsEditable 611 @DocsEditable
461 @Returns('Request') 612 @Returns('Request')
462 @Creates('Request') 613 @Creates('Request')
463 @annotation_Creates_SerializedScriptValue 614 @annotation_Creates_SerializedScriptValue
464 @Creates('ObjectStore') 615 @Creates('ObjectStore')
465 Request getKey(key) native; 616 Request $dom_getKey(key) native;
466 617
618 @JSName('openCursor')
467 @DomName('IDBIndex.openCursor') 619 @DomName('IDBIndex.openCursor')
468 @DocsEditable 620 @DocsEditable
469 @Returns('Request') 621 @Returns('Request')
470 @Creates('Request') 622 @Creates('Request')
471 @Creates('Cursor') 623 @Creates('Cursor')
472 Request openCursor([key_OR_range, String direction]) native; 624 Request $dom_openCursor([key_OR_range, String direction]) native;
473 625
626 @JSName('openKeyCursor')
474 @DomName('IDBIndex.openKeyCursor') 627 @DomName('IDBIndex.openKeyCursor')
475 @DocsEditable 628 @DocsEditable
476 @Returns('Request') 629 @Returns('Request')
477 @Creates('Request') 630 @Creates('Request')
478 @Creates('Cursor') 631 @Creates('Cursor')
479 Request openKeyCursor([key_OR_range, String direction]) native; 632 Request $dom_openKeyCursor([key_OR_range, String direction]) native;
633
480 } 634 }
481 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 635 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
482 // for details. All rights reserved. Use of this source code is governed by a 636 // for details. All rights reserved. Use of this source code is governed by a
483 // BSD-style license that can be found in the LICENSE file. 637 // BSD-style license that can be found in the LICENSE file.
484 638
485 639
486 @DomName('IDBKeyRange') 640 @DomName('IDBKeyRange')
487 class KeyRange native "*IDBKeyRange" { 641 class KeyRange native "*IDBKeyRange" {
488 @DomName('IDBKeyRange.only') 642 @DomName('IDBKeyRange.only')
489 factory KeyRange.only(/*Key*/ value) => 643 factory KeyRange.only(/*Key*/ value) =>
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 696
543 } 697 }
544 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 698 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
545 // for details. All rights reserved. Use of this source code is governed by a 699 // for details. All rights reserved. Use of this source code is governed by a
546 // BSD-style license that can be found in the LICENSE file. 700 // BSD-style license that can be found in the LICENSE file.
547 701
548 702
549 @DomName('IDBObjectStore') 703 @DomName('IDBObjectStore')
550 class ObjectStore native "*IDBObjectStore" { 704 class ObjectStore native "*IDBObjectStore" {
551 705
706 @DomName('IDBObjectStore.add')
707 Future add(value, [key]) {
708 try {
709 var request;
710 if (key != null) {
711 request = $dom_add(value, key);
712 } else {
713 request = $dom_add(value);
714 }
715 return _completeRequest(request);
716 } catch (e, stacktrace) {
717 return new Future.immediateError(e, stacktrace);
718 }
719 }
720
721 @DomName('IDBObjectStore.clear')
722 Future clear() {
723 try {
724 return _completeRequest($dom_clear());
725 } catch (e, stacktrace) {
726 return new Future.immediateError(e, stacktrace);
727 }
728 }
729
730 @DomName('IDBObjectStore.delete')
731 Future delete(key_OR_keyRange){
732 try {
733 return _completeRequest($dom_delete(key_OR_keyRange));
734 } catch (e, stacktrace) {
735 return new Future.immediateError(e, stacktrace);
736 }
737 }
738
739 @DomName('IDBObjectStore.count')
740 Future<int> count([key_OR_range]) {
741 try {
742 var request;
743 if (key_OR_range != null) {
744 request = $dom_count(key_OR_range);
745 } else {
746 request = $dom_count();
747 }
748 return _completeRequest(request);
749 } catch (e, stacktrace) {
750 return new Future.immediateError(e, stacktrace);
751 }
752 }
753
552 @DomName('IDBObjectStore.put') 754 @DomName('IDBObjectStore.put')
553 Future put(value, [key]) { 755 Future put(value, [key]) {
554 try { 756 try {
555 var request; 757 var request;
556 if (key != null) { 758 if (key != null) {
557 request = $dom_put(value, key); 759 request = $dom_put(value, key);
558 } else { 760 } else {
559 request = $dom_put(value); 761 request = $dom_put(value);
560 } 762 }
561 return _completeRequest(request); 763 return _completeRequest(request);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 // TODO: try/catch this and return a stream with an immediate error. 814 // TODO: try/catch this and return a stream with an immediate error.
613 var request; 815 var request;
614 if (direction == null) { 816 if (direction == null) {
615 request = $dom_openCursor(key_OR_range); 817 request = $dom_openCursor(key_OR_range);
616 } else { 818 } else {
617 request = $dom_openCursor(key_OR_range, direction); 819 request = $dom_openCursor(key_OR_range, direction);
618 } 820 }
619 return _cursorStreamFromResult(request, autoAdvance); 821 return _cursorStreamFromResult(request, autoAdvance);
620 } 822 }
621 823
824 @DomName('IDBObjectStore.createIndex')
825 Index createIndex(String name, keyPath, {bool unique, bool multiEntry}) {
826 var options = {};
827 if (unique != null) {
828 options['unique'] = unique;
829 }
830 if (multiEntry != null) {
831 options['multiEntry'] = multiEntry;
832 }
833
834 return $dom_createIndex(name, keyPath, options);
835 }
836
622 837
623 @DomName('IDBObjectStore.autoIncrement') 838 @DomName('IDBObjectStore.autoIncrement')
624 @DocsEditable 839 @DocsEditable
625 final bool autoIncrement; 840 final bool autoIncrement;
626 841
627 @DomName('IDBObjectStore.indexNames') 842 @DomName('IDBObjectStore.indexNames')
628 @DocsEditable 843 @DocsEditable
629 @Returns('DomStringList') 844 @Returns('DomStringList')
630 @Creates('DomStringList') 845 @Creates('DomStringList')
631 final List<String> indexNames; 846 final List<String> indexNames;
632 847
633 @DomName('IDBObjectStore.keyPath') 848 @DomName('IDBObjectStore.keyPath')
634 @DocsEditable 849 @DocsEditable
635 final dynamic keyPath; 850 final dynamic keyPath;
636 851
637 @DomName('IDBObjectStore.name') 852 @DomName('IDBObjectStore.name')
638 @DocsEditable 853 @DocsEditable
639 final String name; 854 final String name;
640 855
641 @DomName('IDBObjectStore.transaction') 856 @DomName('IDBObjectStore.transaction')
642 @DocsEditable 857 @DocsEditable
643 final Transaction transaction; 858 final Transaction transaction;
644 859
645 @DomName('IDBObjectStore.add') 860 @DomName('IDBObjectStore.add')
646 @DocsEditable 861 @DocsEditable
647 @Returns('Request') 862 @Returns('Request')
648 @Creates('Request') 863 @Creates('Request')
649 @_annotation_Creates_IDBKey 864 @_annotation_Creates_IDBKey
650 Request add(/*any*/ value, [/*any*/ key]) { 865 Request $dom_add(/*any*/ value, [/*any*/ key]) {
651 if (?key) { 866 if (?key) {
652 var value_1 = convertDartToNative_SerializedScriptValue(value); 867 var value_1 = convertDartToNative_SerializedScriptValue(value);
653 var key_2 = convertDartToNative_SerializedScriptValue(key); 868 var key_2 = convertDartToNative_SerializedScriptValue(key);
654 return _add_1(value_1, key_2); 869 return _$dom_add_1(value_1, key_2);
655 } 870 }
656 var value_3 = convertDartToNative_SerializedScriptValue(value); 871 var value_3 = convertDartToNative_SerializedScriptValue(value);
657 return _add_2(value_3); 872 return _$dom_add_2(value_3);
658 } 873 }
659 @JSName('add') 874 @JSName('add')
660 @DomName('IDBObjectStore.add') 875 @DomName('IDBObjectStore.add')
661 @DocsEditable 876 @DocsEditable
662 @Returns('Request') 877 @Returns('Request')
663 @Creates('Request') 878 @Creates('Request')
664 @_annotation_Creates_IDBKey 879 @_annotation_Creates_IDBKey
665 Request _add_1(value, key) native; 880 Request _$dom_add_1(value, key) native;
666 @JSName('add') 881 @JSName('add')
667 @DomName('IDBObjectStore.add') 882 @DomName('IDBObjectStore.add')
668 @DocsEditable 883 @DocsEditable
669 @Returns('Request') 884 @Returns('Request')
670 @Creates('Request') 885 @Creates('Request')
671 @_annotation_Creates_IDBKey 886 @_annotation_Creates_IDBKey
672 Request _add_2(value) native; 887 Request _$dom_add_2(value) native;
673 888
889 @JSName('clear')
674 @DomName('IDBObjectStore.clear') 890 @DomName('IDBObjectStore.clear')
675 @DocsEditable 891 @DocsEditable
676 Request clear() native; 892 Request $dom_clear() native;
677 893
894 @JSName('count')
678 @DomName('IDBObjectStore.count') 895 @DomName('IDBObjectStore.count')
679 @DocsEditable 896 @DocsEditable
680 Request count([key_OR_range]) native; 897 Request $dom_count([key_OR_range]) native;
681 898
682 @DomName('IDBObjectStore.createIndex') 899 @DomName('IDBObjectStore.createIndex')
683 @DocsEditable 900 @DocsEditable
684 Index createIndex(String name, keyPath, [Map options]) { 901 Index $dom_createIndex(String name, keyPath, [Map options]) {
685 if ((keyPath is List<String> || keyPath == null) && !?options) { 902 if ((keyPath is List<String> || keyPath == null) && !?options) {
686 List keyPath_1 = convertDartToNative_StringArray(keyPath); 903 List keyPath_1 = convertDartToNative_StringArray(keyPath);
687 return _createIndex_1(name, keyPath_1); 904 return _$dom_createIndex_1(name, keyPath_1);
688 } 905 }
689 if ((keyPath is List<String> || keyPath == null)) { 906 if ((keyPath is List<String> || keyPath == null)) {
690 List keyPath_2 = convertDartToNative_StringArray(keyPath); 907 List keyPath_2 = convertDartToNative_StringArray(keyPath);
691 var options_3 = convertDartToNative_Dictionary(options); 908 var options_3 = convertDartToNative_Dictionary(options);
692 return _createIndex_2(name, keyPath_2, options_3); 909 return _$dom_createIndex_2(name, keyPath_2, options_3);
693 } 910 }
694 if ((keyPath is String || keyPath == null) && !?options) { 911 if ((keyPath is String || keyPath == null) && !?options) {
695 return _createIndex_3(name, keyPath); 912 return _$dom_createIndex_3(name, keyPath);
696 } 913 }
697 if ((keyPath is String || keyPath == null)) { 914 if ((keyPath is String || keyPath == null)) {
698 var options_4 = convertDartToNative_Dictionary(options); 915 var options_4 = convertDartToNative_Dictionary(options);
699 return _createIndex_4(name, keyPath, options_4); 916 return _$dom_createIndex_4(name, keyPath, options_4);
700 } 917 }
701 throw new ArgumentError("Incorrect number or type of arguments"); 918 throw new ArgumentError("Incorrect number or type of arguments");
702 } 919 }
703 @JSName('createIndex') 920 @JSName('createIndex')
704 @DomName('IDBObjectStore.createIndex') 921 @DomName('IDBObjectStore.createIndex')
705 @DocsEditable 922 @DocsEditable
706 Index _createIndex_1(name, List keyPath) native; 923 Index _$dom_createIndex_1(name, List keyPath) native;
707 @JSName('createIndex') 924 @JSName('createIndex')
708 @DomName('IDBObjectStore.createIndex') 925 @DomName('IDBObjectStore.createIndex')
709 @DocsEditable 926 @DocsEditable
710 Index _createIndex_2(name, List keyPath, options) native; 927 Index _$dom_createIndex_2(name, List keyPath, options) native;
711 @JSName('createIndex') 928 @JSName('createIndex')
712 @DomName('IDBObjectStore.createIndex') 929 @DomName('IDBObjectStore.createIndex')
713 @DocsEditable 930 @DocsEditable
714 Index _createIndex_3(name, String keyPath) native; 931 Index _$dom_createIndex_3(name, String keyPath) native;
715 @JSName('createIndex') 932 @JSName('createIndex')
716 @DomName('IDBObjectStore.createIndex') 933 @DomName('IDBObjectStore.createIndex')
717 @DocsEditable 934 @DocsEditable
718 Index _createIndex_4(name, String keyPath, options) native; 935 Index _$dom_createIndex_4(name, String keyPath, options) native;
719 936
937 @JSName('delete')
720 @DomName('IDBObjectStore.delete') 938 @DomName('IDBObjectStore.delete')
721 @DocsEditable 939 @DocsEditable
722 Request delete(key_OR_keyRange) native; 940 Request $dom_delete(key_OR_keyRange) native;
723 941
724 @DomName('IDBObjectStore.deleteIndex') 942 @DomName('IDBObjectStore.deleteIndex')
725 @DocsEditable 943 @DocsEditable
726 void deleteIndex(String name) native; 944 void deleteIndex(String name) native;
727 945
728 @JSName('get') 946 @JSName('get')
729 @DomName('IDBObjectStore.get') 947 @DomName('IDBObjectStore.get')
730 @DocsEditable 948 @DocsEditable
731 @Returns('Request') 949 @Returns('Request')
732 @Creates('Request') 950 @Creates('Request')
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 } 1238 }
1021 // 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
1022 // 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
1023 // BSD-style license that can be found in the LICENSE file. 1241 // BSD-style license that can be found in the LICENSE file.
1024 1242
1025 1243
1026 @DocsEditable 1244 @DocsEditable
1027 @DomName('IDBAny') 1245 @DomName('IDBAny')
1028 class _IDBAny native "*IDBAny" { 1246 class _IDBAny native "*IDBAny" {
1029 } 1247 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/indexed_db/dartium/indexed_db_dartium.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698