window
object in the browser.
* @return global object.
*/
- @JSExpression(params = "obj", expr = "window")
+ @JSBody(params = {}, script = "return window;")
public static native JSObject getGlobal();
@InjectedBy(JSNativeGenerator.class)
@@ -148,136 +148,136 @@ public final class JS {
return result;
}
- public static JSArrayIndicates that method is to have native JavaScript implementation, which can be written as a - * single JavaScript expression. - * Method only can take and return primitive values and {@link JSObject}s. - * JSExpression script can't call Java methods, but you can pass callbacks wrapped into {@link JSFunctor}. - * Note that unless method is static, it must belong to class that implements {@link JSObject}. - * If applied to non-native method, original Java body will be overwritten by JavaScript.
- * - *Use this annotation instead of JSBody when possible, since this can increase performance and - * reduce generated JavaScript size.
- * - * @author Alexey Andreev - */ -public @interface JSExpression { - /** - *How method parameters are named inside JavaScript implementation.
- */ - String[] params(); - - /** - *JavaScript expression.
- */ - String expr(); -} diff --git a/teavm-jso/src/main/java/org/teavm/jso/JSNumber.java b/teavm-jso/src/main/java/org/teavm/jso/JSNumber.java index 6f5fde8c0..8638d876e 100644 --- a/teavm-jso/src/main/java/org/teavm/jso/JSNumber.java +++ b/teavm-jso/src/main/java/org/teavm/jso/JSNumber.java @@ -27,49 +27,59 @@ public abstract class JSNumber implements JSObject { return doubleValue(this); } - @JSExpression(params = "number", expr = "number") + @JSBody(params = "number", script = "return number;") private static native double doubleValue(JSNumber number); public final int intValue() { return intValue(this); } - @JSExpression(params = "number", expr = "number") + @JSBody(params = "number", script = "return number;") private static native int intValue(JSNumber number); + public final char charValue() { + return charValue(this); + } + + @JSBody(params = "number", script = "return number;") + private static native char charValue(JSNumber number); + public final byte byteValue() { return byteValue(this); } - @JSExpression(params = "number", expr = "number") + @JSBody(params = "number", script = "return number;") private static native byte byteValue(JSNumber number); public final short shortValue() { return shortValue(this); } - @JSExpression(params = "number", expr = "number") + @JSBody(params = "number", script = "return number;") private static native short shortValue(JSNumber number); public final float floatValue() { return floatValue(this); } - @JSExpression(params = "number", expr = "number") + @JSBody(params = "number", script = "return number;") private static native float floatValue(JSNumber number); - @JSExpression(params = "value", expr = "value") + @JSBody(params = "value", script = "return value;") public static native JSNumber valueOf(byte value); - @JSExpression(params = "value", expr = "value") + @JSBody(params = "value", script = "return value;") public static native JSNumber valueOf(short value); - @JSExpression(params = "value", expr = "value") + @JSBody(params = "value", script = "return value;") public static native JSNumber valueOf(int value); - @JSExpression(params = "value", expr = "value") + @JSBody(params = "value", script = "return value;") + public static native JSNumber valueOf(char value); + + @JSBody(params = "value", script = "return value;") public static native JSNumber valueOf(float value); - @JSExpression(params = "value", expr = "value") + @JSBody(params = "value", script = "return value;") public static native JSNumber valueOf(double value); } diff --git a/teavm-jso/src/main/java/org/teavm/jso/JSObject.java b/teavm-jso/src/main/java/org/teavm/jso/JSObject.java index a27ed8774..906de29c6 100644 --- a/teavm-jso/src/main/java/org/teavm/jso/JSObject.java +++ b/teavm-jso/src/main/java/org/teavm/jso/JSObject.java @@ -20,6 +20,4 @@ package org.teavm.jso; * @author Alexey Andreev */ public interface JSObject { - @Override - String toString(); } diff --git a/teavm-jso/src/main/java/org/teavm/jso/JSString.java b/teavm-jso/src/main/java/org/teavm/jso/JSString.java new file mode 100644 index 000000000..195a9d617 --- /dev/null +++ b/teavm-jso/src/main/java/org/teavm/jso/JSString.java @@ -0,0 +1,71 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * 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 org.teavm.jso; + +/** + * + * @author Alexey Andreev + */ +public abstract class JSString implements JSObject { + private JSString() { + } + + public final String stringValue() { + return stringValue(this); + } + + @JSBody(params = "str", script = "return str;") + private static native String stringValue(JSString str); + + @JSBody(params = "str", script = "return str;") + public static native JSString valueOf(String str); + + @JSBody(params = "code", script = "return String.fromCharCode(code)") + public static native JSString fromCharCode(int code); + + @JSProperty + public abstract int getLength(); + + public abstract JSString charAt(int index); + + public abstract int charCodeAt(int index); + + public abstract JSString concat(JSString a); + + public abstract JSString concat(JSString a, JSString b); + + public abstract JSString concat(JSString a, JSString b, JSString c); + + public abstract int indexOf(JSString a); + + public abstract int lastIndexOf(JSString a); + + public abstract JSString slice(int beginSlice); + + public abstract JSString slice(int beginSlice, int endSlice); + + public abstract JSString[] split(JSString separator); + + public abstract JSString[] split(JSString separator, int limit); + + public abstract JSString substr(int start); + + public abstract JSString substr(int start, int length); + + public abstract JSString substring(int start); + + public abstract JSString substring(int start, int end); +}