vm/src/test/java/org/apidesign/vm4brwsr/Instance.java
changeset 772 d382dacfd73f
parent 771 4252bfc396fc
child 773 406faa8bc64f
     1.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/Instance.java	Tue Feb 26 14:55:55 2013 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,140 +0,0 @@
     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.vm4brwsr;
    1.22 -
    1.23 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
    1.24 -
    1.25 -/**
    1.26 - *
    1.27 - * @author Jaroslav Tulach <jtulach@netbeans.org>
    1.28 - */
    1.29 -public class Instance {
    1.30 -    private int in;
    1.31 -    protected short s;
    1.32 -    public double d;
    1.33 -    private float f;
    1.34 -    protected byte b = (byte)31;
    1.35 -    
    1.36 -    private Instance() {
    1.37 -    }
    1.38 -
    1.39 -    public Instance(int i, double d) {
    1.40 -        this.in = i;
    1.41 -        this.d = d;
    1.42 -    }
    1.43 -    public byte getByte() {
    1.44 -        return b;
    1.45 -    }
    1.46 -    
    1.47 -    public void setByte(byte b) {
    1.48 -        this.b = b;
    1.49 -    }
    1.50 -    public static double defaultDblValue() {
    1.51 -        Instance create = new Instance();
    1.52 -        return create.d;
    1.53 -    }
    1.54 -    
    1.55 -    public static byte assignedByteValue() {
    1.56 -        return new Instance().b;
    1.57 -    }
    1.58 -    public static double magicOne() {
    1.59 -        Instance i = new Instance(10, 3.3d);
    1.60 -        i.b = (byte)0x09;
    1.61 -        return (i.in - i.b) * i.d;
    1.62 -    }
    1.63 -    public static int virtualBytes() {
    1.64 -        Instance i = new InstanceSub(7, 2.2d);
    1.65 -        i.setByte((byte)0x0a);
    1.66 -        Instance i2 = new Instance(3, 333.0d);
    1.67 -        i2.setByte((byte)44);
    1.68 -        return i.getByte() + i2.getByte();
    1.69 -    }
    1.70 -    public static float interfaceBytes() {
    1.71 -        GetByte i = new InstanceSub(7, 2.2d);
    1.72 -        return i.getByte();
    1.73 -    }
    1.74 -    public static boolean instanceOf(int sub) {
    1.75 -        Instance i = createInstance(sub);
    1.76 -        return isInstanceSubOf(i);
    1.77 -    }
    1.78 -    public static int castsWork(boolean interfc) {
    1.79 -        Instance i = createInstance(2);
    1.80 -        if (interfc) {
    1.81 -            GetByte b = (GetByte)i;
    1.82 -        } else {
    1.83 -            InstanceSub s = (InstanceSub)i;
    1.84 -        }
    1.85 -        return 5;
    1.86 -    }
    1.87 -    
    1.88 -    private static boolean isInstanceSubOf(Instance instance) {
    1.89 -        return instance instanceof InstanceSub;
    1.90 -    }
    1.91 -    private static Instance createInstance(int type) {
    1.92 -        switch (type) {
    1.93 -            case 0: return null;
    1.94 -            case 1: return new Instance();
    1.95 -            case 2: return new InstanceSub(3, 0);
    1.96 -        }
    1.97 -        throw new IllegalArgumentException();
    1.98 -    }
    1.99 -    private static boolean isNull() {
   1.100 -        return createInstance(2) == null;
   1.101 -    }
   1.102 -    
   1.103 -    @JavaScriptBody(args = "obj", body = "return obj.constructor;")
   1.104 -    static Object constructor(Object obj) {
   1.105 -        return obj;
   1.106 -    }
   1.107 -    
   1.108 -    public static boolean sharedConstructor() {
   1.109 -        class X {
   1.110 -        }
   1.111 -        
   1.112 -        X x1 = new X();
   1.113 -        X x2 = new X();
   1.114 -        
   1.115 -        return constructor(x1) == constructor(x2);
   1.116 -    }
   1.117 -    public static boolean differentConstructor() {
   1.118 -        class X {
   1.119 -        }
   1.120 -        class Y {
   1.121 -        }
   1.122 -        
   1.123 -        X x = new X();
   1.124 -        Y y = new Y();
   1.125 -        
   1.126 -        return constructor(x) == constructor(y);
   1.127 -    }
   1.128 -    @JavaScriptBody(args = {}, body = "return {};")
   1.129 -    private static Object jsObj() {
   1.130 -        return null;
   1.131 -    }
   1.132 -    
   1.133 -    public static boolean iofObject() {
   1.134 -        return jsObj() instanceof Object;
   1.135 -    }
   1.136 -    
   1.137 -    public static int jscall() {
   1.138 -        return jsgetbytes(new Instance());
   1.139 -    }
   1.140 -    
   1.141 -    @JavaScriptBody(args = { "instance" }, body = "return instance.getByte__B();")
   1.142 -    private static native int jsgetbytes(Instance instance);
   1.143 -}