From d1d09e822cfaf4e2033f8cb151ea001f9fd4e73a Mon Sep 17 00:00:00 2001 From: "sra@google.com" Date: Thu, 19 Apr 2012 21:05:00 +0000 Subject: [PATCH] Constructors for IDBKeyRange Removed static methods on interface and replaced with constructors. This is dom only, html to come later. Review URL: https://chromiumcodereview.appspot.com//10128001 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@6770 260f80e4-7a28-3924-810f-c04153c831b5 --- client/tests/client/client.status | 1 - lib/dom/dom.dart | 29 ++- lib/dom/frog/dom_frog.dart | 179 +++++++++++------- lib/dom/idl/dart/dart.idl | 11 ++ lib/dom/src/dummy_FactoryProviders.dart | 9 + .../src/frog_IDBKeyRangeFactoryProvider.dart | 47 +++++ lib/dom/src/native_FactoryProviders.dart | 17 ++ ...native_FactoryProvidersImplementation.dart | 5 + .../templates/dom/frog/frog_dom.darttemplate | 3 +- .../interface_IDBKeyRange.darttemplate | 18 ++ lib/html/dartium/html_dartium.dart | 47 ----- lib/html/frog/html_frog.dart | 20 -- 12 files changed, 239 insertions(+), 147 deletions(-) create mode 100644 lib/dom/src/frog_IDBKeyRangeFactoryProvider.dart create mode 100644 lib/dom/templates/dom/interface/interface_IDBKeyRange.darttemplate diff --git a/client/tests/client/client.status b/client/tests/client/client.status index ba09088db4c..e6aff540712 100644 --- a/client/tests/client/client.status +++ b/client/tests/client/client.status @@ -28,7 +28,6 @@ html/html_tests: Skip # Issue 2657 # TODO(vsm): Triage DOM tests. dom/DOMIsolatesTest: Fail dom/IndexedDB2Test: Fail # Issue 1883 - IndexedDB methods don't handle maps correctly. -dom/IndexedDB4Test: Fail # IDBKeyRange constructors not implemented. dom/HTMLElementTest: Fail dom/WindowOpenTest: Fail diff --git a/lib/dom/dom.dart b/lib/dom/dom.dart index 6f5b6bf0414..cec2e71d661 100644 --- a/lib/dom/dom.dart +++ b/lib/dom/dom.dart @@ -5192,7 +5192,17 @@ interface IDBKey { // WARNING: Do not edit - generated code. -interface IDBKeyRange { +interface IDBKeyRange default _IDBKeyRangeFactoryProvider { + + IDBKeyRange.only(/*IDBKey*/ value); + + IDBKeyRange.lowerBound(/*IDBKey*/ bound, [bool open]); + + IDBKeyRange.upperBound(/*IDBKey*/ bound, [bool open]); + + IDBKeyRange.bound(/*IDBKey*/ lower, /*IDBKey*/ upper, + [bool lowerOpen, bool upperOpen]); + final /*IDBKey*/ lower; @@ -5201,14 +5211,6 @@ interface IDBKeyRange { final /*IDBKey*/ upper; final bool upperOpen; - - IDBKeyRange bound(/*IDBKey*/ lower, /*IDBKey*/ upper, [bool lowerOpen, bool upperOpen]); - - IDBKeyRange lowerBound(/*IDBKey*/ bound, [bool open]); - - IDBKeyRange only(/*IDBKey*/ value); - - IDBKeyRange upperBound(/*IDBKey*/ bound, [bool open]); } // 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 @@ -12858,6 +12860,15 @@ class _AudioContextFactoryProvider { factory AudioContext() => _dummy(); } +class _IDBKeyRangeFactoryProvider { + + factory IDBKeyRange.only(/*IDBKey*/ value) => _dummy(); + factory IDBKeyRange.lowerBound(/*IDBKey*/ bound, [bool open]) => _dummy(); + factory IDBKeyRange.upperBound(/*IDBKey*/ bound, [bool open]) => _dummy(); + factory IDBKeyRange.bound(/*IDBKey*/ lower, /*IDBKey*/ upper, + [bool lowerOpen, bool upperOpen]) => _dummy(); +} + class _TypedArrayFactoryProvider { factory Float32Array(int length) => _dummy(); diff --git a/lib/dom/frog/dom_frog.dart b/lib/dom/frog/dom_frog.dart index 682d2440428..5be3f4c1695 100644 --- a/lib/dom/frog/dom_frog.dart +++ b/lib/dom/frog/dom_frog.dart @@ -4253,14 +4253,6 @@ class _IDBKeyRangeJs extends _DOMTypeJs implements IDBKeyRange native "*IDBKeyRa final upper; final bool upperOpen; - - _IDBKeyRangeJs bound(lower, upper, [bool lowerOpen = null, bool upperOpen = null]) native; - - _IDBKeyRangeJs lowerBound(bound, [bool open = null]) native; - - _IDBKeyRangeJs only(value) native; - - _IDBKeyRangeJs upperBound(bound, [bool open = null]) native; } class _IDBObjectStoreJs extends _DOMTypeJs implements IDBObjectStore native "*IDBObjectStore" { @@ -17152,7 +17144,17 @@ interface IDBKey { // WARNING: Do not edit - generated code. -interface IDBKeyRange { +interface IDBKeyRange default _IDBKeyRangeFactoryProvider { + + IDBKeyRange.only(/*IDBKey*/ value); + + IDBKeyRange.lowerBound(/*IDBKey*/ bound, [bool open]); + + IDBKeyRange.upperBound(/*IDBKey*/ bound, [bool open]); + + IDBKeyRange.bound(/*IDBKey*/ lower, /*IDBKey*/ upper, + [bool lowerOpen, bool upperOpen]); + final /*IDBKey*/ lower; @@ -17161,14 +17163,6 @@ interface IDBKeyRange { final /*IDBKey*/ upper; final bool upperOpen; - - IDBKeyRange bound(/*IDBKey*/ lower, /*IDBKey*/ upper, [bool lowerOpen, bool upperOpen]); - - IDBKeyRange lowerBound(/*IDBKey*/ bound, [bool open]); - - IDBKeyRange only(/*IDBKey*/ value); - - IDBKeyRange upperBound(/*IDBKey*/ bound, [bool open]); } // 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 @@ -24794,58 +24788,6 @@ interface ReadyState { */ static final String COMPLETE = "complete"; } -// Copyright (c) 2011, 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. - -/** - * The [Collections] class implements static methods useful when - * writing a class that implements [Collection] and the [iterator] - * method. - */ -class _Collections { - static void forEach(Iterable iterable, void f(Object o)) { - for (final e in iterable) { - f(e); - } - } - - static List map(Iterable source, - List destination, - f(o)) { - for (final e in source) { - destination.add(f(e)); - } - return destination; - } - - static bool some(Iterable iterable, bool f(Object o)) { - for (final e in iterable) { - if (f(e)) return true; - } - return false; - } - - static bool every(Iterable iterable, bool f(Object o)) { - for (final e in iterable) { - if (!f(e)) return false; - } - return true; - } - - static List filter(Iterable source, - List destination, - bool f(o)) { - for (final e in source) { - if (f(e)) destination.add(e); - } - return destination; - } - - static bool isEmpty(Iterable iterable) { - return !iterable.iterator().hasNext(); - } -} // 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. @@ -24942,6 +24884,53 @@ class _WebSocketFactoryProvider { // 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. +class _IDBKeyRangeFactoryProvider { + + factory IDBKeyRange.only(/*IDBKey*/ value) => + _only(_class(), _translateKey(value)); + + factory IDBKeyRange.lowerBound(/*IDBKey*/ bound, [bool open = false]) => + _lowerBound(_class(), _translateKey(bound), open); + + factory IDBKeyRange.upperBound(/*IDBKey*/ bound, [bool open = false]) => + _upperBound(_class(), _translateKey(bound), open); + + factory IDBKeyRange.bound(/*IDBKey*/ lower, /*IDBKey*/ upper, + [bool lowerOpen = false, bool upperOpen = false]) => + _bound(_class(), _translateKey(lower), _translateKey(upper), + lowerOpen, upperOpen); + + static var _cachedClass; + + static _class() { + if (_cachedClass != null) return _cachedClass; + return _cachedClass = _uncachedClass(); + } + + static _uncachedClass() native ''' + return window.webkitIDBKeyRange || window.mozIDBKeyRange || + window.msIDBKeyRange || window.IDBKeyRange; + '''; + + static _translateKey(idbkey) => idbkey; // TODO: fixme. + + static _IDBKeyRangeJs _only(cls, value) native + '''return cls.only(value);'''; + + static _IDBKeyRangeJs _lowerBound(cls, bound, open) native + '''return cls.lowerBound(bound, open);'''; + + static _IDBKeyRangeJs _upperBound(cls, bound, open) native + '''return cls.upperBound(bound, open);'''; + + static _IDBKeyRangeJs _bound(cls, lower, upper, lowerOpen, upperOpen) native + '''return cls.bound(lower, upper, lowerOpen, upperOpen);'''; + +} +// 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. + class _TypedArrayFactoryProvider { factory Float32Array(int length) => _F32(length); @@ -25055,6 +25044,58 @@ class _TypedArrayFactoryProvider { // 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. +/** + * The [Collections] class implements static methods useful when + * writing a class that implements [Collection] and the [iterator] + * method. + */ +class _Collections { + static void forEach(Iterable iterable, void f(Object o)) { + for (final e in iterable) { + f(e); + } + } + + static List map(Iterable source, + List destination, + f(o)) { + for (final e in source) { + destination.add(f(e)); + } + return destination; + } + + static bool some(Iterable iterable, bool f(Object o)) { + for (final e in iterable) { + if (f(e)) return true; + } + return false; + } + + static bool every(Iterable iterable, bool f(Object o)) { + for (final e in iterable) { + if (!f(e)) return false; + } + return true; + } + + static List filter(Iterable source, + List destination, + bool f(o)) { + for (final e in source) { + if (f(e)) destination.add(e); + } + return destination; + } + + static bool isEmpty(Iterable iterable) { + return !iterable.iterator().hasNext(); + } +} +// Copyright (c) 2011, 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. + // Iterator for arrays with fixed size. class _FixedSizeListIterator extends _VariableSizeListIterator { _FixedSizeListIterator(List array) diff --git a/lib/dom/idl/dart/dart.idl b/lib/dom/idl/dart/dart.idl index 75c53510e9b..e356caa833e 100644 --- a/lib/dom/idl/dart/dart.idl +++ b/lib/dom/idl/dart/dart.idl @@ -219,6 +219,17 @@ module storage { interface IDBObjectStore { [DartName=getObject] IDBRequest get(in IDBKey key); }; + + interface IDBKeyRange { + [Suppressed] static IDBKeyRange only(in IDBKey value) + raises (IDBDatabaseException); + [Suppressed] static IDBKeyRange lowerBound(in IDBKey bound, in optional boolean open) + raises (IDBDatabaseException); + [Suppressed] static IDBKeyRange upperBound(in IDBKey bound, in optional boolean open) + raises (IDBDatabaseException); + [Suppressed] static IDBKeyRange bound(in IDBKey lower, in IDBKey upper, in optional boolean lowerOpen, optional boolean upperOpen) + raises (IDBDatabaseException); + }; }; module html { diff --git a/lib/dom/src/dummy_FactoryProviders.dart b/lib/dom/src/dummy_FactoryProviders.dart index 2a8a0cb98e4..861b19a07b6 100644 --- a/lib/dom/src/dummy_FactoryProviders.dart +++ b/lib/dom/src/dummy_FactoryProviders.dart @@ -12,6 +12,15 @@ class _AudioContextFactoryProvider { factory AudioContext() => _dummy(); } +class _IDBKeyRangeFactoryProvider { + + factory IDBKeyRange.only(/*IDBKey*/ value) => _dummy(); + factory IDBKeyRange.lowerBound(/*IDBKey*/ bound, [bool open]) => _dummy(); + factory IDBKeyRange.upperBound(/*IDBKey*/ bound, [bool open]) => _dummy(); + factory IDBKeyRange.bound(/*IDBKey*/ lower, /*IDBKey*/ upper, + [bool lowerOpen, bool upperOpen]) => _dummy(); +} + class _TypedArrayFactoryProvider { factory Float32Array(int length) => _dummy(); diff --git a/lib/dom/src/frog_IDBKeyRangeFactoryProvider.dart b/lib/dom/src/frog_IDBKeyRangeFactoryProvider.dart new file mode 100644 index 00000000000..dfe16304c71 --- /dev/null +++ b/lib/dom/src/frog_IDBKeyRangeFactoryProvider.dart @@ -0,0 +1,47 @@ +// 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. + +class _IDBKeyRangeFactoryProvider { + + factory IDBKeyRange.only(/*IDBKey*/ value) => + _only(_class(), _translateKey(value)); + + factory IDBKeyRange.lowerBound(/*IDBKey*/ bound, [bool open = false]) => + _lowerBound(_class(), _translateKey(bound), open); + + factory IDBKeyRange.upperBound(/*IDBKey*/ bound, [bool open = false]) => + _upperBound(_class(), _translateKey(bound), open); + + factory IDBKeyRange.bound(/*IDBKey*/ lower, /*IDBKey*/ upper, + [bool lowerOpen = false, bool upperOpen = false]) => + _bound(_class(), _translateKey(lower), _translateKey(upper), + lowerOpen, upperOpen); + + static var _cachedClass; + + static _class() { + if (_cachedClass != null) return _cachedClass; + return _cachedClass = _uncachedClass(); + } + + static _uncachedClass() native ''' + return window.webkitIDBKeyRange || window.mozIDBKeyRange || + window.msIDBKeyRange || window.IDBKeyRange; + '''; + + static _translateKey(idbkey) => idbkey; // TODO: fixme. + + static _IDBKeyRangeJs _only(cls, value) native + '''return cls.only(value);'''; + + static _IDBKeyRangeJs _lowerBound(cls, bound, open) native + '''return cls.lowerBound(bound, open);'''; + + static _IDBKeyRangeJs _upperBound(cls, bound, open) native + '''return cls.upperBound(bound, open);'''; + + static _IDBKeyRangeJs _bound(cls, lower, upper, lowerOpen, upperOpen) native + '''return cls.bound(lower, upper, lowerOpen, upperOpen);'''; + +} diff --git a/lib/dom/src/native_FactoryProviders.dart b/lib/dom/src/native_FactoryProviders.dart index c82302364e6..74082985a14 100644 --- a/lib/dom/src/native_FactoryProviders.dart +++ b/lib/dom/src/native_FactoryProviders.dart @@ -59,3 +59,20 @@ class _WebKitPointFactoryProvider { class _WebSocketFactoryProvider { factory WebSocket(String url) => FactoryProviderImplementation.createWebSocket(url); } + +class _IDBKeyRangeFactoryProvider { + + factory IDBKeyRange.only(/*IDBKey*/ value) => + FactoryProviderImplementation.IDBKeyRange_only(value); + + factory IDBKeyRange.lowerBound(/*IDBKey*/ bound, [bool open = false]) => + FactoryProviderImplementation.IDBKeyRange_lowerBound(bound, open); + + factory IDBKeyRange.upperBound(/*IDBKey*/ bound, [bool open = false]) => + FactoryProviderImplementation.IDBKeyRange_upperBound(bound, open); + + factory IDBKeyRange.bound(/*IDBKey*/ lower, /*IDBKey*/ upper, + [bool lowerOpen = false, bool upperOpen = false]) => + FactoryProviderImplementation.IDBKeyRange_bound(lower, upper, + lowerOpen, upperOpen); +} diff --git a/lib/dom/src/native_FactoryProvidersImplementation.dart b/lib/dom/src/native_FactoryProvidersImplementation.dart index b415c6d1d4a..ae6d168e34b 100644 --- a/lib/dom/src/native_FactoryProvidersImplementation.dart +++ b/lib/dom/src/native_FactoryProvidersImplementation.dart @@ -20,4 +20,9 @@ class FactoryProviderImplementation { static WebKitPoint createWebKitPoint(num x, num y) native "WebKitPoint_constructor_Callback"; static WebSocket createWebSocket(String url) native "WebSocket_constructor_Callback"; + + static IDBKeyRange IDBKeyRange_only(value) native "IDBKeyRange_only_Callback"; + static IDBKeyRange IDBKeyRange_lowerBound(bound, open) "IDBKeyRange_lowerBound_Callback"; + static IDBKeyRange IDBKeyRange_upperBound(bound, open) "IDBKeyRange_upperBound_Callback"; + static IDBKeyRange IDBKeyRange_bound(lower, upper, lowerOpen, upperOpen) native "IDBKeyRange_bound_Callback"; } diff --git a/lib/dom/templates/dom/frog/frog_dom.darttemplate b/lib/dom/templates/dom/frog/frog_dom.darttemplate index 4914e59772b..b90f17b2416 100644 --- a/lib/dom/templates/dom/frog/frog_dom.darttemplate +++ b/lib/dom/templates/dom/frog/frog_dom.darttemplate @@ -12,12 +12,13 @@ $!GENERATED_DART_FILES #source('../src/KeyLocation.dart'); #source('../src/KeyName.dart'); #source('../src/ReadyState.dart'); -#source('../src/_Collections.dart'); #source('../src/frog_DOMImplementation.dart'); #source('../src/frog_DOMType.dart'); #source('../src/frog_DOMTypeJs.dart'); #source('../src/frog_FactoryProviders.dart'); +#source('../src/frog_IDBKeyRangeFactoryProvider.dart'); #source('../src/frog_TypedArrayFactoryProvider.dart'); +#source('../src/_Collections.dart'); #source('../src/_ListIterators.dart'); #source('../src/_Lists.dart'); diff --git a/lib/dom/templates/dom/interface/interface_IDBKeyRange.darttemplate b/lib/dom/templates/dom/interface/interface_IDBKeyRange.darttemplate new file mode 100644 index 00000000000..b88a6d5272d --- /dev/null +++ b/lib/dom/templates/dom/interface/interface_IDBKeyRange.darttemplate @@ -0,0 +1,18 @@ +// 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. + +// WARNING: Do not edit - generated code. + +interface IDBKeyRange$EXTENDS default _IDBKeyRangeFactoryProvider { + + IDBKeyRange.only(/*IDBKey*/ value); + + IDBKeyRange.lowerBound(/*IDBKey*/ bound, [bool open]); + + IDBKeyRange.upperBound(/*IDBKey*/ bound, [bool open]); + + IDBKeyRange.bound(/*IDBKey*/ lower, /*IDBKey*/ upper, + [bool lowerOpen, bool upperOpen]); + +$!MEMBERS} diff --git a/lib/html/dartium/html_dartium.dart b/lib/html/dartium/html_dartium.dart index 4a85d9ce33e..2db035463ca 100644 --- a/lib/html/dartium/html_dartium.dart +++ b/lib/html/dartium/html_dartium.dart @@ -10402,41 +10402,6 @@ class _IDBKeyRangeImpl extends _DOMTypeBase implements IDBKeyRange { Dynamic get upper() => _wrap(_ptr.upper); bool get upperOpen() => _wrap(_ptr.upperOpen); - - IDBKeyRange bound(/*IDBKey*/ lower, /*IDBKey*/ upper, [bool lowerOpen = null, bool upperOpen = null]) { - if (lowerOpen === null) { - if (upperOpen === null) { - return _wrap(_ptr.bound(_unwrap(lower), _unwrap(upper))); - } - } else { - if (upperOpen === null) { - return _wrap(_ptr.bound(_unwrap(lower), _unwrap(upper), _unwrap(lowerOpen))); - } else { - return _wrap(_ptr.bound(_unwrap(lower), _unwrap(upper), _unwrap(lowerOpen), _unwrap(upperOpen))); - } - } - throw "Incorrect number or type of arguments"; - } - - IDBKeyRange lowerBound(/*IDBKey*/ bound, [bool open = null]) { - if (open === null) { - return _wrap(_ptr.lowerBound(_unwrap(bound))); - } else { - return _wrap(_ptr.lowerBound(_unwrap(bound), _unwrap(open))); - } - } - - IDBKeyRange only(/*IDBKey*/ value) { - return _wrap(_ptr.only(_unwrap(value))); - } - - IDBKeyRange upperBound(/*IDBKey*/ bound, [bool open = null]) { - if (open === null) { - return _wrap(_ptr.upperBound(_unwrap(bound))); - } else { - return _wrap(_ptr.upperBound(_unwrap(bound), _unwrap(open))); - } - } } class _IDBObjectStoreImpl extends _DOMTypeBase implements IDBObjectStore { @@ -29814,18 +29779,6 @@ interface IDBKeyRange { /** @domName IDBKeyRange.upperOpen */ final bool upperOpen; - - /** @domName IDBKeyRange.bound */ - IDBKeyRange bound(/*IDBKey*/ lower, /*IDBKey*/ upper, [bool lowerOpen, bool upperOpen]); - - /** @domName IDBKeyRange.lowerBound */ - IDBKeyRange lowerBound(/*IDBKey*/ bound, [bool open]); - - /** @domName IDBKeyRange.only */ - IDBKeyRange only(/*IDBKey*/ value); - - /** @domName IDBKeyRange.upperBound */ - IDBKeyRange upperBound(/*IDBKey*/ bound, [bool open]); } // 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 diff --git a/lib/html/frog/html_frog.dart b/lib/html/frog/html_frog.dart index 187a941e4b4..f8d7217e78c 100644 --- a/lib/html/frog/html_frog.dart +++ b/lib/html/frog/html_frog.dart @@ -7534,14 +7534,6 @@ class _IDBKeyRangeImpl implements IDBKeyRange native "*IDBKeyRange" { final Dynamic upper; final bool upperOpen; - - _IDBKeyRangeImpl bound(lower, upper, [bool lowerOpen = null, bool upperOpen = null]) native; - - _IDBKeyRangeImpl lowerBound(bound, [bool open = null]) native; - - _IDBKeyRangeImpl only(value) native; - - _IDBKeyRangeImpl upperBound(bound, [bool open = null]) native; } class _IDBObjectStoreImpl implements IDBObjectStore native "*IDBObjectStore" { @@ -24333,18 +24325,6 @@ interface IDBKeyRange { /** @domName IDBKeyRange.upperOpen */ final bool upperOpen; - - /** @domName IDBKeyRange.bound */ - IDBKeyRange bound(/*IDBKey*/ lower, /*IDBKey*/ upper, [bool lowerOpen, bool upperOpen]); - - /** @domName IDBKeyRange.lowerBound */ - IDBKeyRange lowerBound(/*IDBKey*/ bound, [bool open]); - - /** @domName IDBKeyRange.only */ - IDBKeyRange only(/*IDBKey*/ value); - - /** @domName IDBKeyRange.upperBound */ - IDBKeyRange upperBound(/*IDBKey*/ bound, [bool open]); } // 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