rt/emul/compacttest/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/HtmlAnnotations.java
changeset 1723 3a1f262311cf
parent 1635 deef1427bbe7
child 1787 ea12a3bb4b33
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/rt/emul/compacttest/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/HtmlAnnotations.java	Wed Nov 19 19:32:00 2014 +0100
     1.3 @@ -0,0 +1,89 @@
     1.4 +/**
     1.5 + * Back 2 Browser Bytecode Translator
     1.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     1.7 + *
     1.8 + * This program is free software: you can redistribute it and/or modify
     1.9 + * it under the terms of the GNU General Public License as published by
    1.10 + * the Free Software Foundation, version 2 of the License.
    1.11 + *
    1.12 + * This program is distributed in the hope that it will be useful,
    1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.15 + * GNU General Public License for more details.
    1.16 + *
    1.17 + * You should have received a copy of the GNU General Public License
    1.18 + * along with this program. Look for COPYING file in the top folder.
    1.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    1.20 + */
    1.21 +package org.apidesign.bck2brwsr.vmtest.impl;
    1.22 +
    1.23 +import net.java.html.js.JavaScriptBody;
    1.24 +import net.java.html.js.JavaScriptResource;
    1.25 +
    1.26 +/**
    1.27 + *
    1.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    1.29 + */
    1.30 +@JavaScriptResource("htmlannotations.js")
    1.31 +public class HtmlAnnotations {
    1.32 +    private Object callback;
    1.33 +    
    1.34 +    
    1.35 +    @JavaScriptBody(args = {}, body = "return 42;")
    1.36 +    public static int fourtyTwo() {
    1.37 +        return -1;
    1.38 +    }
    1.39 +    
    1.40 +    @JavaScriptBody(args = { "x", "y" }, body = "return mul(x, y);")
    1.41 +    public static native int useExternalMul(int x, int y);
    1.42 +    
    1.43 +    public static int callback() {
    1.44 +        final int[] arr = { 0 };
    1.45 +        callback(new Runnable() {
    1.46 +            @Override
    1.47 +            public void run() {
    1.48 +                arr[0]++;
    1.49 +            }
    1.50 +        });
    1.51 +        return arr[0];
    1.52 +    }
    1.53 +    
    1.54 +    @JavaScriptBody(args = { "r" }, javacall=true, body = "r.@java.lang.Runnable::run()()")
    1.55 +    private static native void callback(Runnable r);
    1.56 +
    1.57 +    @JavaScriptBody(args = {  }, javacall = true, body = "return @org.apidesign.bck2brwsr.vmtest.impl.HtmlAnnotations::callback()();")
    1.58 +    public static native int staticCallback();
    1.59 +
    1.60 +    @JavaScriptBody(args = {  }, wait4js = false, body = "/* do nothing */")
    1.61 +    public static native void empty();
    1.62 +    
    1.63 +    
    1.64 +    protected long chooseLong(boolean takeFirst, boolean takeSecond, long first, long second) {
    1.65 +        long l = 0;
    1.66 +        if (takeFirst) l += first;
    1.67 +        if (takeSecond) l += second;
    1.68 +        return l;
    1.69 +    }
    1.70 +    
    1.71 +    protected void onError(Object obj) throws Exception {
    1.72 +        callback = obj;
    1.73 +    }
    1.74 +    
    1.75 +    Object getError() {
    1.76 +        return callback;
    1.77 +    }
    1.78 +    
    1.79 +    public static Object create() {
    1.80 +        return new HtmlAnnotations();
    1.81 +    }
    1.82 +    @JavaScriptBody(args = { "impl", "a", "b" }, javacall = true, body = 
    1.83 +        "return impl.@org.apidesign.bck2brwsr.vmtest.impl.HtmlAnnotations::chooseLong(ZZJJ)(true, false, a, b);"
    1.84 +    )
    1.85 +    public static native long first(Object impl, long a, long b);
    1.86 +    
    1.87 +    @JavaScriptBody(args = { "impl", "d" }, javacall = true, body = 
    1.88 +        "impl.@org.apidesign.bck2brwsr.vmtest.impl.HtmlAnnotations::onError(Ljava/lang/Object;)(d);" +
    1.89 +        "return impl.@org.apidesign.bck2brwsr.vmtest.impl.HtmlAnnotations::getError()();"
    1.90 +    )
    1.91 +    public static native Double onError(Object impl, Double d);
    1.92 +}