String is like a primitive type. Keep its signature.
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(int sub) {
72 Instance i = createInstance(sub);
73 return isInstanceSubOf(i);
75 public static int castsWork(boolean interfc) {
76 Instance i = createInstance(2);
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(int type) {
91 case 1: return new Instance();
92 case 2: return new InstanceSub(3, 0);
94 throw new IllegalArgumentException();
96 private static boolean isNull() {
97 return createInstance(2) == null;
100 @JavaScriptBody(args = "obj", body = "return obj.constructor;")
101 static Object constructor(Object obj) {
105 public static boolean sharedConstructor() {
112 return constructor(x1) == constructor(x2);
114 public static boolean differentConstructor() {
123 return constructor(x) == constructor(y);
125 @JavaScriptBody(args = {}, body = "return {};")
126 private static Object jsObj() {
130 public static boolean iofObject() {
131 return jsObj() instanceof Object;
134 public static int jscall() {
135 return jsgetbytes(new Instance());
138 public static int noInstOfExposed() {
139 return countInstOf(10);
142 public static String props() {
143 return list(new Object());
146 @JavaScriptBody(args = "o", body = "var s = ''; for (var p in {}) { s += p; }; return s;")
147 private static native String list(Object o);
149 @JavaScriptBody(args = "o", body = "var i = 0; for (p in o) { if (p.toString().indexOf('instOf') >= 0) i++; } return i;")
150 private static native int countInstOf(Object o);
152 @JavaScriptBody(args = { "instance" }, body = "return instance.getByte__B();")
153 private static native int jsgetbytes(Instance instance);
155 int sum(int i, int i0) {