Chromium Code Reviews| 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 indexed_db; | 5 part of indexed_db; |
| 6 | 6 |
| 7 /// @domName $DOMNAME | 7 /// @domName $DOMNAME |
| 8 class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { | 8 class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { |
| 9 | 9 |
| 10 Transaction transaction(storeName_OR_storeNames, String mode) { | 10 Transaction transaction(storeName_OR_storeNames, String mode) { |
| 11 if (mode != 'readonly' && mode != 'readwrite') { | 11 if (mode != 'readonly' && mode != 'readwrite') { |
| 12 throw new ArgumentError(mode); | 12 throw new ArgumentError(mode); |
| 13 } | 13 } |
| 14 | 14 |
| 15 // TODO(sra): Ensure storeName_OR_storeNames is a string or List<String>, | 15 // TODO(sra): Ensure storeName_OR_storeNames is a string or List<String>, |
| 16 // and copy to JavaScript array if necessary. | 16 // and copy to JavaScript array if necessary. |
| 17 | 17 |
| 18 if (_transaction_fn != null) { | 18 if (_transaction_fn != null) { |
|
sra1
2012/12/18 00:56:52
remove
Emily Fortuna
2012/12/18 18:57:47
Done.
| |
| 19 return _transaction_fn(this, storeName_OR_storeNames, mode); | 19 return _transaction_fn(this, storeName_OR_storeNames, mode); |
| 20 } | 20 } |
| 21 | 21 |
| 22 // Try and create a transaction with a string mode. Browsers that expect a | 22 // Try and create a transaction with a string mode. Browsers that expect a |
| 23 // numeric mode tend to convert the string into a number. This fails | 23 // numeric mode tend to convert the string into a number. This fails |
| 24 // silently, resulting in zero ('readonly'). | 24 // silently, resulting in zero ('readonly'). |
| 25 var txn = _transaction(storeName_OR_storeNames, mode); | 25 var txn = _transaction(storeName_OR_storeNames, mode); |
| 26 if (_hasNumericMode(txn)) { | 26 _transaction_fn = _transaction_string_mode; |
|
sra1
2012/12/18 00:56:52
Since this is the only remaining version of the fu
Emily Fortuna
2012/12/18 18:57:47
Done.
| |
| 27 _transaction_fn = _transaction_numeric_mode; | |
| 28 txn = _transaction_fn(this, storeName_OR_storeNames, mode); | |
| 29 } else { | |
| 30 _transaction_fn = _transaction_string_mode; | |
| 31 } | |
| 32 return txn; | 27 return txn; |
| 33 } | 28 } |
| 34 | 29 |
| 35 static Transaction _transaction_string_mode($CLASSNAME db, stores, mode) { | 30 static Transaction _transaction_string_mode($CLASSNAME db, stores, mode) { |
|
sra1
2012/12/18 00:56:52
remove
Emily Fortuna
2012/12/18 18:57:47
Done.
| |
| 36 return db._transaction(stores, mode); | 31 return db._transaction(stores, mode); |
| 37 } | 32 } |
| 38 | 33 |
| 39 static Transaction _transaction_numeric_mode($CLASSNAME db, stores, mode) { | |
| 40 int intMode; | |
| 41 if (mode == 'readonly') intMode = Transaction.READ_ONLY; | |
| 42 if (mode == 'readwrite') intMode = Transaction.READ_WRITE; | |
| 43 return db._transaction(stores, intMode); | |
| 44 } | |
| 45 | |
| 46 @JSName('transaction') | 34 @JSName('transaction') |
| 47 Transaction _transaction(stores, mode) native; | 35 Transaction _transaction(stores, mode) native; |
| 48 | 36 |
| 49 static bool _hasNumericMode(txn) => | 37 static bool _hasNumericMode(txn) => |
|
sra1
2012/12/18 00:56:52
remove
Emily Fortuna
2012/12/18 18:57:47
Done.
| |
| 50 JS('bool', 'typeof(#.mode) === "number"', txn); | 38 JS('bool', 'typeof(#.mode) === "number"', txn); |
| 51 | 39 |
| 52 $!MEMBERS} | 40 $!MEMBERS} |
| 53 | 41 |
| 54 // TODO(sra): This should be a static member of IDBTransaction but dart2js | 42 // TODO(sra): This should be a static member of IDBTransaction but dart2js |
| 55 // can't handle that. Move it back after dart2js is completely done. | 43 // can't handle that. Move it back after dart2js is completely done. |
| 56 var _transaction_fn; // Assigned one of the static methods. | 44 var _transaction_fn; // Assigned one of the static methods. |
|
sra1
2012/12/18 00:56:52
remove
Emily Fortuna
2012/12/18 18:57:47
Done.
| |
| OLD | NEW |