Scott, we already talked about this, but here's the patch for public review.
The basic goal is to surface the native length, sort, push, and shift operators for JsArrays... I know you mentioned that IE6's push may be slower than indexed extension, and thus a candidate for deferred binding, but I wanted to get a basic implementation in first. There should be only checkstyle changes from what we discussed (though that obviously doesn't help the rest GWTC). I also added some checkstyle fixes to JavaScriptObject, introduced by my c5082. --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---
Index: user/src/com/google/gwt/core/client/JsArrayString.java =================================================================== --- user/src/com/google/gwt/core/client/JsArrayString.java (revision 5095) +++ user/src/com/google/gwt/core/client/JsArrayString.java (working copy) @@ -1,12 +1,12 @@ /* * Copyright 2008 Google Inc. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -17,24 +17,24 @@ /** * A simple wrapper around a homogeneous native array of string values. - * + * * This class may not be directly instantiated, and can only be returned from a * native method. For example, - * + * * <code> * native JsArrayString getNativeArray() /*-{ * return ['foo', 'bar', 'baz']; * }-* /; * </code> */ -public class JsArrayString extends JavaScriptObject { +public class JsArrayString extends JsArrayBase { protected JsArrayString() { } /** * Gets the value at a given index. - * + * * @param index the index to be retrieved * @return the value at the given index, or <code>null</code> if none exists */ @@ -43,24 +43,31 @@ }-*/; /** - * Gets the length of the array. - * - * @return the array length + * call underlying push method. */ - public final native int length() /*-{ - return this.length; + public final native void push(String value) /*-{ + this.push(value); }-*/; /** * Sets the value value at a given index. - * + * * If the index is out of bounds, the value will still be set. The array's * length will be updated to encompass the bounds implied by the added value. - * + * * @param index the index to be set * @param value the value to be stored */ public final native void set(int index, String value) /*-{ this[index] = value; }-*/; + + /** + * Shifts the first value off the array. + * @return the shifted value + */ + public final native String shift() /*-{ + return this.shift(); + }-*/; + } Index: user/src/com/google/gwt/core/client/JsArrayBase.java =================================================================== --- user/src/com/google/gwt/core/client/JsArrayBase.java (revision 0) +++ user/src/com/google/gwt/core/client/JsArrayBase.java (revision 0) @@ -0,0 +1,41 @@ +/* + * Copyright 2008 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.core.client; + +/** + * Common methods for JsArray... classes. + */ +public class JsArrayBase extends JavaScriptObject { + + protected JsArrayBase() { + } + + /** + * Gets the length of the array. + * + * @return the array length + */ + public final native int length() /*-{ + return this.length; + }-*/; + + /** + * direct mapping to underlying sort method. + */ + public final native void sort(JavaScriptObject sortFunc) /*-{ + this.sort(sortFunc); + }-*/; +} Index: user/src/com/google/gwt/core/client/JsArray.java =================================================================== --- user/src/com/google/gwt/core/client/JsArray.java (revision 5095) +++ user/src/com/google/gwt/core/client/JsArray.java (working copy) @@ -1,12 +1,12 @@ /* * Copyright 2008 Google Inc. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -18,10 +18,10 @@ /** * A simple wrapper around a homogeneous native array of * {...@link JavaScriptObject} values. - * + * * This class may not be directly instantiated, and can only be returned from a * native method. For example, - * + * * <code> * native JsArray<JavaScriptObject> getNativeArray() /*-{ * return [ @@ -31,17 +31,17 @@ * ]; * }-* /; * </code> - * + * * @param <T> the concrete type of object contained in this array */ -public class JsArray<T extends JavaScriptObject> extends JavaScriptObject { +public class JsArray<T extends JavaScriptObject> extends JsArrayBase { protected JsArray() { } /** * Gets the object at a given index. - * + * * @param index the index to be retrieved * @return the object at the given index, or <code>null</code> if none * exists @@ -51,24 +51,31 @@ }-*/; /** - * Gets the length of the array. - * - * @return the array length + * call underlying push method. */ - public final native int length() /*-{ - return this.length; + public final native void push(T value) /*-{ + this.push(value); }-*/; /** * Sets the object value at a given index. - * + * * If the index is out of bounds, the value will still be set. The array's * length will be updated to encompass the bounds implied by the added object. - * + * * @param index the index to be set * @param value the object to be stored */ public final native void set(int index, T value) /*-{ this[index] = value; }-*/; + + /** + * Shifts the first value off the array. + * @return the shifted value + */ + public final native T shift() /*-{ + return this.shift(); + }-*/; + } Index: user/src/com/google/gwt/core/client/JsArrayBoolean.java =================================================================== --- user/src/com/google/gwt/core/client/JsArrayBoolean.java (revision 5095) +++ user/src/com/google/gwt/core/client/JsArrayBoolean.java (working copy) @@ -1,12 +1,12 @@ /* * Copyright 2008 Google Inc. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -17,28 +17,28 @@ /** * A simple wrapper around a homogeneous native array of boolean values. - * + * * This class may not be directly instantiated, and can only be returned from a * native method. For example, - * + * * <code> * native JsArrayBoolean getNativeArray() /*-{ * return [true, false, true]; * }-* /; * </code> */ -public class JsArrayBoolean extends JavaScriptObject { +public class JsArrayBoolean extends JsArrayBase { protected JsArrayBoolean() { } /** * Gets the value at a given index. - * + * * If an undefined or non-boolean value exists at the given index, a * type-conversion error will occur in hosted mode and unpredictable behavior * may occur in web mode. - * + * * @param index the index to be retrieved * @return the value at the given index */ @@ -47,24 +47,31 @@ }-*/; /** - * Gets the length of the array. - * - * @return the array length + * call underlying push method. */ - public final native int length() /*-{ - return this.length; + public final native void push(boolean value) /*-{ + this.push(value); }-*/; /** * Sets the value value at a given index. - * + * * If the index is out of bounds, the value will still be set. The array's * length will be updated to encompass the bounds implied by the added value. - * + * * @param index the index to be set * @param value the value to be stored */ public final native void set(int index, boolean value) /*-{ this[index] = value; }-*/; + + /** + * Shifts the first value off the array. + * @return the shifted value + */ + public final native boolean shift() /*-{ + return this.shift(); + }-*/; + } Index: user/src/com/google/gwt/core/client/JsArrayNumber.java =================================================================== --- user/src/com/google/gwt/core/client/JsArrayNumber.java (revision 5095) +++ user/src/com/google/gwt/core/client/JsArrayNumber.java (working copy) @@ -1,12 +1,12 @@ /* * Copyright 2008 Google Inc. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -17,31 +17,31 @@ /** * A simple wrapper around a homogeneous native array of numeric values. - * + * * All native JavaScript numeric values are implicitly double-precision, so only * double values may be set and retrieved. - * + * * This class may not be directly instantiated, and can only be returned from a * native method. For example, - * + * * <code> * native JsArrayNumber getNativeArray() /*-{ * return [1.1, 2.2, 3.3]; * }-* /; * </code> */ -public class JsArrayNumber extends JavaScriptObject { +public class JsArrayNumber extends JsArrayBase { protected JsArrayNumber() { } /** * Gets the value at a given index. - * + * * If an undefined or non-numeric value exists at the given index, a * type-conversion error will occur in hosted mode and unpredictable behavior * may occur in web mode. - * + * * @param index the index to be retrieved * @return the value at the given index */ @@ -50,24 +50,31 @@ }-*/; /** - * Gets the length of the array. - * - * @return the array length + * call underlying push method. */ - public final native int length() /*-{ - return this.length; + public final native void push(double value) /*-{ + this.push(value); }-*/; /** * Sets the value value at a given index. - * + * * If the index is out of bounds, the value will still be set. The array's * length will be updated to encompass the bounds implied by the added value. - * + * * @param index the index to be set * @param value the value to be stored */ public final native void set(int index, double value) /*-{ this[index] = value; }-*/; + + /** + * Shifts the first value off the array. + * @return the shifted value + */ + public final native double shift() /*-{ + return this.shift(); + }-*/; + } Index: user/src/com/google/gwt/core/client/JsArrayInteger.java =================================================================== --- user/src/com/google/gwt/core/client/JsArrayInteger.java (revision 5095) +++ user/src/com/google/gwt/core/client/JsArrayInteger.java (working copy) @@ -1,12 +1,12 @@ /* * Copyright 2008 Google Inc. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -17,29 +17,29 @@ /** * A simple wrapper around a homogeneous native array of integer values. - * + * * This class may not be directly instantiated, and can only be returned from a * native method. For example, - * + * * <code> * native JsArrayInteger getNativeArray() /*-{ * return [1, 2, 3]; * }-* /; * </code> */ -public class JsArrayInteger extends JavaScriptObject { +public class JsArrayInteger extends JsArrayBase { protected JsArrayInteger() { } /** * Gets the value at a given index. - * + * * If no value exists at the given index, a type-conversion error will occur * in hosted mode and unpredictable behavior may occur in web mode. If the * numeric value returned is non-integral, it will cause a warning in hosted * mode, and may affect the results of mathematical expressions. - * + * * @param index the index to be retrieved * @return the value at the given index */ @@ -48,24 +48,31 @@ }-*/; /** - * Gets the length of the array. - * - * @return the array length + * call underlying push method. */ - public final native int length() /*-{ - return this.length; + public final native void push(int value) /*-{ + this.push(value); }-*/; /** * Sets the value value at a given index. - * + * * If the index is out of bounds, the value will still be set. The array's * length will be updated to encompass the bounds implied by the added value. - * + * * @param index the index to be set * @param value the value to be stored */ public final native void set(int index, int value) /*-{ this[index] = value; }-*/; + + /** + * Shifts the first value off the array. + * @return the shifted value + */ + public final native int shift() /*-{ + return this.shift(); + }-*/; + } Index: user/src/com/google/gwt/core/client/JavaScriptObject.java =================================================================== --- user/src/com/google/gwt/core/client/JavaScriptObject.java (revision 5095) +++ user/src/com/google/gwt/core/client/JavaScriptObject.java (working copy) @@ -28,13 +28,6 @@ public class JavaScriptObject { /** - * Call the toSource() on the JSO - */ - public native String toSource() /*-{ - this.toSource ? this.toSource() : "NO SOURCE"; - }-*/; - - /** * Returns a new array. */ public static native JavaScriptObject createArray() /*-{ @@ -99,6 +92,13 @@ } /** + * Call the toSource() on the JSO. + */ + public native String toSource() /*-{ + this.toSource ? this.toSource() : "NO SOURCE"; + }-*/; + + /** * catch-all toString in lieu of a better mechanism. * Basic assumption here is that this code is for debugging only! */