rt/vm/src/test/java/org/apidesign/vm4brwsr/LibUse.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 10 Jun 2016 06:27:01 +0200
branchLibraries
changeset 1972 a83ae75ebf89
parent 1971 de609e0cdab5
child 1974 a5fc49f9ef40
permissions -rw-r--r--
Recognizes and invokes direct library constructor
jaroslav@1965
     1
/**
jaroslav@1965
     2
 * Back 2 Browser Bytecode Translator
jaroslav@1965
     3
 * Copyright (C) 2012-2015 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@1965
     4
 *
jaroslav@1965
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@1965
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@1965
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@1965
     8
 *
jaroslav@1965
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@1965
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@1965
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@1965
    12
 * GNU General Public License for more details.
jaroslav@1965
    13
 *
jaroslav@1965
    14
 * You should have received a copy of the GNU General Public License
jaroslav@1965
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@1965
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@1965
    17
 */
jaroslav@1965
    18
package org.apidesign.vm4brwsr;
jaroslav@1965
    19
jaroslav@1972
    20
import net.java.html.lib.Date;
jaroslav@1971
    21
import static net.java.html.lib.Exports.NaN;
jaroslav@1966
    22
import static net.java.html.lib.Exports.eval;
jaroslav@1971
    23
import static net.java.html.lib.Exports.isNaN;
jaroslav@1970
    24
import static net.java.html.lib.Exports.parseInt;
jaroslav@1966
    25
import net.java.html.lib.Objs;
jaroslav@1965
    26
jaroslav@1965
    27
public class LibUse {
jaroslav@1965
    28
    public static int fourtyTwo() {
jaroslav@1966
    29
        Number n = (Number) eval("6 * 7");
jaroslav@1965
    30
        return n.intValue();
jaroslav@1965
    31
    }
jaroslav@1966
    32
jaroslav@1968
    33
    public static String hiProperty(String set) {
jaroslav@1966
    34
        final Object obj = eval("var x = {}; x.x = 'Hi'; x");
jaroslav@1966
    35
        if (obj == null) {
jaroslav@1966
    36
            throw new IllegalStateException("Some Value returned " + obj);
jaroslav@1966
    37
        }
jaroslav@1966
    38
        if (!(obj instanceof Objs)) {
jaroslav@1966
    39
            throw new IllegalStateException("The result is Objs: " + obj.getClass());
jaroslav@1966
    40
        }
jaroslav@1966
    41
        Objs js = (Objs) obj;
jaroslav@1968
    42
        if (set != null) {
jaroslav@1968
    43
            js.$set("x", set);
jaroslav@1968
    44
        }
jaroslav@1966
    45
        return (String) js.$get("x");
jaroslav@1966
    46
    }
jaroslav@1970
    47
jaroslav@1970
    48
    public static double parse(String str) throws Exception {
jaroslav@1970
    49
        return parseInt(str);
jaroslav@1970
    50
    }
jaroslav@1970
    51
jaroslav@1970
    52
    public static double parse(String str, int radix) throws Exception {
jaroslav@1970
    53
        return parseInt(str, radix);
jaroslav@1970
    54
    }
jaroslav@1970
    55
jaroslav@1971
    56
    public boolean checkNaN() throws Exception {
jaroslav@1971
    57
        double nan = NaN;
jaroslav@1971
    58
        return isNaN(nan);
jaroslav@1971
    59
    }
jaroslav@1971
    60
jaroslav@1972
    61
    public double dateOperation() throws Exception {
jaroslav@1972
    62
        Date eleven = new Date(2016, 1, 10);
jaroslav@1972
    63
        return eleven.getFullYear() + eleven.getMonth();
jaroslav@1972
    64
    }
jaroslav@1972
    65
jaroslav@1965
    66
}