2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.vm4brwsr;
20 import org.apidesign.bck2brwsr.core.JavaScriptBody;
24 * @author Jaroslav Tulach <jtulach@netbeans.org>
26 public class Instance {
31 protected byte b = (byte)31;
36 public Instance(int i, double d) {
40 public byte getByte() {
44 public void setByte(byte b) {
47 public static double defaultDblValue() {
48 Instance create = new Instance();
52 public static byte assignedByteValue() {
53 return new Instance().b;
55 public static double magicOne() {
56 Instance i = new Instance(10, 3.3d);
58 return (i.in - i.b) * i.d;
60 public static int virtualBytes() {
61 Instance i = new InstanceSub(7, 2.2d);
62 i.setByte((byte)0x0a);
63 Instance i2 = new Instance(3, 333.0d);
65 return i.getByte() + i2.getByte();
67 public static float interfaceBytes() {
68 GetByte i = new InstanceSub(7, 2.2d);
71 public static boolean instanceOf(boolean sub) {
72 Instance i = createInstance(sub);
73 return isInstanceSubOf(i);
75 public static int castsWork(boolean interfc) {
76 Instance i = createInstance(true);
78 GetByte b = (GetByte)i;
80 InstanceSub s = (InstanceSub)i;
85 private static boolean isInstanceSubOf(Instance instance) {
86 return instance instanceof InstanceSub;
88 private static Instance createInstance(boolean sub) {
89 return sub ? new InstanceSub(3, 0) : new Instance();
91 private static boolean isNull() {
92 return createInstance(true) == null;
95 @JavaScriptBody(args = "obj", body = "return obj.constructor;")
96 static Object constructor(Object obj) {
100 public static boolean sharedConstructor() {
107 return constructor(x1) == constructor(x2);
109 public static boolean differentConstructor() {
118 return constructor(x) == constructor(y);
120 @JavaScriptBody(args = {}, body = "return {};")
121 private static Object jsObj() {
125 public static boolean iofObject() {
126 return jsObj() instanceof Object;
129 public static int jscall() {
130 return jsgetbytes(new Instance());
133 @JavaScriptBody(args = { "instance" }, body = "return instance.getByte__B();")
134 private static native int jsgetbytes(Instance instance);