Files
sdk/tools/dom/templates/html/impl/impl_IDBFactory.darttemplate
T
Terry Lucas ef6273cba0 Dart Web Libraries re-generated based on Chrome 63 WebIDLs.
This is a migration of 13 Chrome release about 1.5 years of Chrome releases.
Update PYTHON scripts for cleaner and easier rolling.

Here's a doc on the changes that might affect Dart users:
https://docs.google.com/document/d/1Kj0nk3SueO3JKub8im7z3znu9j5oiI7vf49ejZrMxuE/edit#

Change-Id: I768fbd09b04fe6884af36ac102d5813f67bae426
Reviewed-on: https://dart-review.googlesource.com/24501
Commit-Queue: Terry Lucas <terry@google.com>
Reviewed-by: Terry Lucas <terry@google.com>
2018-03-18 09:41:04 +00:00

94 lines
2.8 KiB
Plaintext

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
part of $LIBRARYNAME;
$(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS {
/**
* Checks to see if Indexed DB is supported on the current platform.
*/
static bool get supported {
return JS('bool',
'!!(window.indexedDB || '
'window.webkitIndexedDB || '
'window.mozIndexedDB)');
}
@DomName('IDBFactory.open')
Future<Database> open(String name,
{int version, void onUpgradeNeeded(VersionChangeEvent event),
void onBlocked(Event event)}) {
if ((version == null) != (onUpgradeNeeded == null)) {
return new Future.error(new ArgumentError(
'version and onUpgradeNeeded must be specified together'));
}
try {
var request;
if (version != null) {
request = _open(name, version);
} else {
request = _open(name);
}
if (onUpgradeNeeded != null) {
request.onUpgradeNeeded.listen(onUpgradeNeeded);
}
if (onBlocked != null) {
request.onBlocked.listen(onBlocked);
}
return _completeRequest(request);
} catch (e, stacktrace) {
return new Future.error(e, stacktrace);
}
}
@DomName('IDBFactory.deleteDatabase')
Future<IdbFactory> deleteDatabase(String name,
{void onBlocked(Event e)}) {
try {
var request = _deleteDatabase(name);
if (onBlocked != null) {
request.onBlocked.listen(onBlocked);
}
var completer = new Completer<IdbFactory>.sync();
request.onSuccess.listen((e) {
completer.complete(this);
});
request.onError.listen(completer.completeError);
return completer.future;
} catch (e, stacktrace) {
return new Future.error(e, stacktrace);
}
}
/**
* Checks to see if getDatabaseNames is supported by the current platform.
* TODO(terry): Should be able to always return false?
*/
bool get supportsDatabaseNames {
return supported && JS('bool',
'!!(#.getDatabaseNames || #.webkitGetDatabaseNames)', this, this);
}
$!MEMBERS
}
/**
* Ties a request to a completer, so the completer is completed when it succeeds
* and errors out when the request errors.
*/
Future<T> _completeRequest<T>(Request request) {
var completer = new Completer<T>.sync();
// TODO: make sure that completer.complete is synchronous as transactions
// may be committed if the result is not processed immediately.
request.onSuccess.listen((e) {
T result = request.result;
completer.complete(result);
});
request.onError.listen(completer.completeError);
return completer.future;
}