jaroslav@106
|
1 |
/**
|
jaroslav@106
|
2 |
* Back 2 Browser Bytecode Translator
|
jaroslav@106
|
3 |
* Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
|
jaroslav@106
|
4 |
*
|
jaroslav@106
|
5 |
* This program is free software: you can redistribute it and/or modify
|
jaroslav@106
|
6 |
* it under the terms of the GNU General Public License as published by
|
jaroslav@106
|
7 |
* the Free Software Foundation, version 2 of the License.
|
jaroslav@106
|
8 |
*
|
jaroslav@106
|
9 |
* This program is distributed in the hope that it will be useful,
|
jaroslav@106
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
jaroslav@106
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
jaroslav@106
|
12 |
* GNU General Public License for more details.
|
jaroslav@106
|
13 |
*
|
jaroslav@106
|
14 |
* You should have received a copy of the GNU General Public License
|
jaroslav@106
|
15 |
* along with this program. Look for COPYING file in the top folder.
|
jaroslav@106
|
16 |
* If not, see http://opensource.org/licenses/GPL-2.0.
|
jaroslav@106
|
17 |
*/
|
jaroslav@22
|
18 |
package org.apidesign.vm4brwsr;
|
jaroslav@0
|
19 |
|
jaroslav@137
|
20 |
import java.io.File;
|
jaroslav@137
|
21 |
import java.io.FileWriter;
|
jaroslav@0
|
22 |
import java.io.IOException;
|
jaroslav@298
|
23 |
import java.io.InputStream;
|
jaroslav@298
|
24 |
import java.net.URL;
|
jaroslav@298
|
25 |
import java.util.Enumeration;
|
jaroslav@0
|
26 |
import javax.script.Invocable;
|
jaroslav@0
|
27 |
import javax.script.ScriptEngine;
|
jaroslav@0
|
28 |
import javax.script.ScriptEngineManager;
|
jaroslav@0
|
29 |
import javax.script.ScriptException;
|
jaroslav@0
|
30 |
import static org.testng.Assert.*;
|
jaroslav@103
|
31 |
import org.testng.annotations.BeforeClass;
|
jaroslav@0
|
32 |
import org.testng.annotations.Test;
|
jaroslav@0
|
33 |
|
jaroslav@0
|
34 |
/** Checks the basic behavior of the translator.
|
jaroslav@0
|
35 |
*
|
jaroslav@0
|
36 |
* @author Jaroslav Tulach <jtulach@netbeans.org>
|
jaroslav@0
|
37 |
*/
|
jaroslav@0
|
38 |
public class StaticMethodTest {
|
jaroslav@0
|
39 |
@Test public void threePlusFour() throws Exception {
|
jaroslav@2
|
40 |
assertExec(
|
jaroslav@2
|
41 |
"Should be seven",
|
jaroslav@248
|
42 |
StaticMethod.class, "sum__III",
|
jaroslav@2
|
43 |
Double.valueOf(7),
|
jaroslav@2
|
44 |
3, 4
|
jaroslav@2
|
45 |
);
|
jaroslav@0
|
46 |
}
|
jaroslav@0
|
47 |
|
jaroslav@173
|
48 |
@Test public void checkReallyInitializedValues() throws Exception {
|
jaroslav@173
|
49 |
assertExec(
|
jaroslav@173
|
50 |
"Return true",
|
jaroslav@248
|
51 |
StaticMethod.class, "isNull__Z",
|
jaroslav@173
|
52 |
Double.valueOf(1)
|
jaroslav@173
|
53 |
);
|
jaroslav@173
|
54 |
}
|
jaroslav@173
|
55 |
|
jaroslav@1
|
56 |
@Test public void powerOfThree() throws Exception {
|
jaroslav@2
|
57 |
assertExec(
|
jaroslav@2
|
58 |
"Should be nine",
|
jaroslav@248
|
59 |
StaticMethod.class, "power__FF",
|
jaroslav@2
|
60 |
Double.valueOf(9),
|
jaroslav@2
|
61 |
3.0f
|
jaroslav@2
|
62 |
);
|
jaroslav@1
|
63 |
}
|
jaroslav@1
|
64 |
|
jaroslav@48
|
65 |
@Test public void minusOne() throws Exception {
|
jaroslav@48
|
66 |
assertExec(
|
jaroslav@48
|
67 |
"Should be minus one",
|
jaroslav@248
|
68 |
StaticMethod.class, "minusOne__I",
|
jaroslav@48
|
69 |
Double.valueOf(-1)
|
jaroslav@48
|
70 |
);
|
jaroslav@48
|
71 |
}
|
jaroslav@48
|
72 |
|
jaroslav@2
|
73 |
@Test public void doubleWithoutLong() throws Exception {
|
jaroslav@2
|
74 |
assertExec(
|
jaroslav@2
|
75 |
"Should be two",
|
jaroslav@248
|
76 |
StaticMethod.class, "minus__DDJ",
|
jaroslav@2
|
77 |
Double.valueOf(2),
|
jaroslav@2
|
78 |
3.0d, 1l
|
jaroslav@2
|
79 |
);
|
jaroslav@2
|
80 |
}
|
jaroslav@600
|
81 |
|
jaroslav@600
|
82 |
@Test public void rintNegativeUp() throws Exception {
|
jaroslav@600
|
83 |
final double cnts = -453904.634;
|
jaroslav@600
|
84 |
assertExec(
|
jaroslav@600
|
85 |
"Should round up to end with 5",
|
jaroslav@600
|
86 |
Math.class, "rint__DD",
|
jaroslav@600
|
87 |
-453905.0, cnts
|
jaroslav@600
|
88 |
);
|
jaroslav@600
|
89 |
}
|
jaroslav@600
|
90 |
|
jaroslav@600
|
91 |
@Test public void rintNegativeDown() throws Exception {
|
jaroslav@600
|
92 |
final double cnts = -453904.434;
|
jaroslav@600
|
93 |
assertExec(
|
jaroslav@600
|
94 |
"Should round up to end with 4",
|
jaroslav@600
|
95 |
Math.class, "rint__DD",
|
jaroslav@600
|
96 |
-453904.0, cnts
|
jaroslav@600
|
97 |
);
|
jaroslav@600
|
98 |
}
|
jaroslav@600
|
99 |
|
jaroslav@600
|
100 |
@Test public void rintPositiveUp() throws Exception {
|
jaroslav@600
|
101 |
final double cnts = 453904.634;
|
jaroslav@600
|
102 |
assertExec(
|
jaroslav@600
|
103 |
"Should round up to end with 5",
|
jaroslav@600
|
104 |
Math.class, "rint__DD",
|
jaroslav@600
|
105 |
453905.0, cnts
|
jaroslav@600
|
106 |
);
|
jaroslav@600
|
107 |
}
|
jaroslav@600
|
108 |
@Test public void rintPositiveDown() throws Exception {
|
jaroslav@600
|
109 |
final double cnts = 453904.434;
|
jaroslav@600
|
110 |
assertExec(
|
jaroslav@600
|
111 |
"Should round up to end with 4",
|
jaroslav@600
|
112 |
Math.class, "rint__DD",
|
jaroslav@600
|
113 |
453904.0, cnts
|
jaroslav@600
|
114 |
);
|
jaroslav@600
|
115 |
}
|
jaroslav@600
|
116 |
@Test public void rintOneHalf() throws Exception {
|
jaroslav@600
|
117 |
final double cnts = 1.5;
|
jaroslav@600
|
118 |
assertExec(
|
jaroslav@600
|
119 |
"Should round up to end with 2",
|
jaroslav@600
|
120 |
Math.class, "rint__DD",
|
jaroslav@600
|
121 |
2.0, cnts
|
jaroslav@600
|
122 |
);
|
jaroslav@600
|
123 |
}
|
jaroslav@600
|
124 |
@Test public void rintNegativeOneHalf() throws Exception {
|
jaroslav@600
|
125 |
final double cnts = -1.5;
|
jaroslav@600
|
126 |
assertExec(
|
jaroslav@600
|
127 |
"Should round up to end with 2",
|
jaroslav@600
|
128 |
Math.class, "rint__DD",
|
jaroslav@600
|
129 |
-2.0, cnts
|
jaroslav@600
|
130 |
);
|
jaroslav@600
|
131 |
}
|
jaroslav@600
|
132 |
@Test public void rintTwoAndHalf() throws Exception {
|
jaroslav@600
|
133 |
final double cnts = 2.5;
|
jaroslav@600
|
134 |
assertExec(
|
jaroslav@600
|
135 |
"Should round up to end with 2",
|
jaroslav@600
|
136 |
Math.class, "rint__DD",
|
jaroslav@600
|
137 |
2.0, cnts
|
jaroslav@600
|
138 |
);
|
jaroslav@600
|
139 |
}
|
jaroslav@600
|
140 |
@Test public void rintNegativeTwoOneHalf() throws Exception {
|
jaroslav@600
|
141 |
final double cnts = -2.5;
|
jaroslav@600
|
142 |
assertExec(
|
jaroslav@600
|
143 |
"Should round up to end with 2",
|
jaroslav@600
|
144 |
Math.class, "rint__DD",
|
jaroslav@600
|
145 |
-2.0, cnts
|
jaroslav@600
|
146 |
);
|
jaroslav@600
|
147 |
}
|
jaroslav@3
|
148 |
|
jaroslav@605
|
149 |
@Test public void ieeeReminder1() throws Exception {
|
jaroslav@605
|
150 |
assertExec(
|
jaroslav@605
|
151 |
"Same result 1",
|
jaroslav@605
|
152 |
Math.class, "IEEEremainder__DDD",
|
jaroslav@605
|
153 |
Math.IEEEremainder(10.0, 4.5), 10.0, 4.5
|
jaroslav@605
|
154 |
);
|
jaroslav@605
|
155 |
}
|
jaroslav@605
|
156 |
|
jaroslav@605
|
157 |
@Test public void ieeeReminder2() throws Exception {
|
jaroslav@605
|
158 |
assertExec(
|
jaroslav@605
|
159 |
"Same result 1",
|
jaroslav@605
|
160 |
Math.class, "IEEEremainder__DDD",
|
jaroslav@605
|
161 |
Math.IEEEremainder(Integer.MAX_VALUE, -4.5), Integer.MAX_VALUE, -4.5
|
jaroslav@605
|
162 |
);
|
jaroslav@605
|
163 |
}
|
jaroslav@605
|
164 |
|
jaroslav@3
|
165 |
@Test public void divAndRound() throws Exception {
|
jaroslav@3
|
166 |
assertExec(
|
jaroslav@3
|
167 |
"Should be rounded to one",
|
jaroslav@248
|
168 |
StaticMethod.class, "div__IBD",
|
jaroslav@3
|
169 |
Double.valueOf(1),
|
jaroslav@3
|
170 |
3, 3.75
|
jaroslav@3
|
171 |
);
|
jaroslav@3
|
172 |
}
|
jaroslav@3
|
173 |
@Test public void mixedMethodFourParams() throws Exception {
|
jaroslav@3
|
174 |
assertExec(
|
jaroslav@3
|
175 |
"Should be two",
|
jaroslav@248
|
176 |
StaticMethod.class, "mix__IIJBD",
|
jaroslav@3
|
177 |
Double.valueOf(20),
|
jaroslav@3
|
178 |
2, 10l, 5, 2.0
|
jaroslav@3
|
179 |
);
|
jaroslav@3
|
180 |
}
|
jaroslav@4
|
181 |
@Test public void factRec() throws Exception {
|
jaroslav@4
|
182 |
assertExec(
|
jaroslav@4
|
183 |
"Factorial of 5 is 120",
|
jaroslav@248
|
184 |
StaticMethod.class, "factRec__JI",
|
jaroslav@4
|
185 |
Double.valueOf(120),
|
jaroslav@4
|
186 |
5
|
jaroslav@4
|
187 |
);
|
jaroslav@4
|
188 |
}
|
jaroslav@5
|
189 |
@Test public void factIter() throws Exception {
|
jaroslav@5
|
190 |
assertExec(
|
jaroslav@5
|
191 |
"Factorial of 5 is 120",
|
jaroslav@248
|
192 |
StaticMethod.class, "factIter__JI",
|
jaroslav@5
|
193 |
Double.valueOf(120),
|
jaroslav@5
|
194 |
5
|
jaroslav@5
|
195 |
);
|
jaroslav@5
|
196 |
}
|
jaroslav@2
|
197 |
|
jaroslav@6
|
198 |
@Test public void xor() throws Exception {
|
jaroslav@6
|
199 |
assertExec(
|
jaroslav@6
|
200 |
"Xor is 4",
|
jaroslav@248
|
201 |
StaticMethod.class, "xor__JIJ",
|
jaroslav@6
|
202 |
Double.valueOf(4),
|
jaroslav@6
|
203 |
7,
|
jaroslav@6
|
204 |
3
|
jaroslav@6
|
205 |
);
|
jaroslav@6
|
206 |
}
|
jaroslav@6
|
207 |
|
jaroslav@7
|
208 |
@Test public void or() throws Exception {
|
jaroslav@7
|
209 |
assertExec(
|
jaroslav@7
|
210 |
"Or will be 7",
|
jaroslav@248
|
211 |
StaticMethod.class, "orOrAnd__JZII",
|
jaroslav@7
|
212 |
Double.valueOf(7),
|
jaroslav@7
|
213 |
true,
|
jaroslav@7
|
214 |
4,
|
jaroslav@7
|
215 |
3
|
jaroslav@7
|
216 |
);
|
jaroslav@7
|
217 |
}
|
jaroslav@46
|
218 |
@Test public void nullCheck() throws Exception {
|
jaroslav@46
|
219 |
assertExec(
|
jaroslav@46
|
220 |
"Returns nothing",
|
jaroslav@248
|
221 |
StaticMethod.class, "none__Ljava_lang_Object_2II",
|
jaroslav@46
|
222 |
null, 1, 3
|
jaroslav@46
|
223 |
);
|
jaroslav@46
|
224 |
}
|
jaroslav@7
|
225 |
@Test public void and() throws Exception {
|
jaroslav@7
|
226 |
assertExec(
|
jaroslav@7
|
227 |
"And will be 3",
|
jaroslav@248
|
228 |
StaticMethod.class, "orOrAnd__JZII",
|
jaroslav@7
|
229 |
Double.valueOf(3),
|
jaroslav@7
|
230 |
false,
|
jaroslav@7
|
231 |
7,
|
jaroslav@7
|
232 |
3
|
jaroslav@7
|
233 |
);
|
jaroslav@7
|
234 |
}
|
jaroslav@9
|
235 |
@Test public void inc4() throws Exception {
|
jaroslav@9
|
236 |
assertExec(
|
jaroslav@9
|
237 |
"It will be 4",
|
jaroslav@248
|
238 |
StaticMethod.class, "inc4__I",
|
jaroslav@9
|
239 |
Double.valueOf(4)
|
jaroslav@9
|
240 |
);
|
jaroslav@9
|
241 |
}
|
jaroslav@7
|
242 |
|
jaroslav@93
|
243 |
@Test public void shiftLeftInJava() throws Exception {
|
jaroslav@93
|
244 |
int res = StaticMethod.shiftLeft(1, 8);
|
jaroslav@93
|
245 |
assertEquals(res, 256);
|
jaroslav@93
|
246 |
}
|
jaroslav@93
|
247 |
|
jaroslav@93
|
248 |
@Test public void shiftLeftInJS() throws Exception {
|
jaroslav@93
|
249 |
assertExec(
|
jaroslav@93
|
250 |
"Setting 9th bit",
|
jaroslav@248
|
251 |
StaticMethod.class, "shiftLeft__III",
|
jaroslav@93
|
252 |
Double.valueOf(256),
|
jaroslav@93
|
253 |
1, 8
|
jaroslav@93
|
254 |
);
|
jaroslav@93
|
255 |
}
|
jaroslav@93
|
256 |
|
jaroslav@93
|
257 |
@Test public void shiftRightInJava() throws Exception {
|
jaroslav@93
|
258 |
int res = StaticMethod.shiftArithmRight(-8, 3, true);
|
jaroslav@93
|
259 |
assertEquals(res, -1);
|
jaroslav@93
|
260 |
}
|
jaroslav@93
|
261 |
|
jaroslav@93
|
262 |
@Test public void shiftRightInJS() throws Exception {
|
jaroslav@93
|
263 |
assertExec(
|
jaroslav@93
|
264 |
"Get -1",
|
jaroslav@248
|
265 |
StaticMethod.class, "shiftArithmRight__IIIZ",
|
jaroslav@93
|
266 |
Double.valueOf(-1),
|
jaroslav@93
|
267 |
-8, 3, true
|
jaroslav@93
|
268 |
);
|
jaroslav@93
|
269 |
}
|
jaroslav@93
|
270 |
@Test public void unsignedShiftRightInJava() throws Exception {
|
jaroslav@93
|
271 |
int res = StaticMethod.shiftArithmRight(8, 3, false);
|
jaroslav@93
|
272 |
assertEquals(res, 1);
|
jaroslav@93
|
273 |
}
|
jaroslav@93
|
274 |
|
jaroslav@93
|
275 |
@Test public void unsignedShiftRightInJS() throws Exception {
|
jaroslav@93
|
276 |
assertExec(
|
jaroslav@93
|
277 |
"Get -1",
|
jaroslav@248
|
278 |
StaticMethod.class, "shiftArithmRight__IIIZ",
|
jaroslav@93
|
279 |
Double.valueOf(1),
|
jaroslav@93
|
280 |
8, 3, false
|
jaroslav@93
|
281 |
);
|
jaroslav@93
|
282 |
}
|
jaroslav@93
|
283 |
|
jaroslav@94
|
284 |
@Test public void javaScriptBody() throws Exception {
|
jaroslav@94
|
285 |
assertExec(
|
jaroslav@94
|
286 |
"JavaScript string",
|
jaroslav@248
|
287 |
StaticMethod.class, "i2s__Ljava_lang_String_2II",
|
jaroslav@94
|
288 |
"333",
|
jaroslav@99
|
289 |
330, 3
|
jaroslav@94
|
290 |
);
|
jaroslav@94
|
291 |
}
|
jaroslav@94
|
292 |
|
jaroslav@115
|
293 |
@Test public void switchJarda() throws Exception {
|
jaroslav@115
|
294 |
assertExec(
|
jaroslav@115
|
295 |
"The expected value",
|
jaroslav@248
|
296 |
StaticMethod.class, "swtch__Ljava_lang_String_2I",
|
jaroslav@115
|
297 |
"Jarda",
|
jaroslav@115
|
298 |
0
|
jaroslav@115
|
299 |
);
|
jaroslav@115
|
300 |
}
|
jaroslav@115
|
301 |
|
jaroslav@115
|
302 |
@Test public void switchDarda() throws Exception {
|
jaroslav@115
|
303 |
assertExec(
|
jaroslav@115
|
304 |
"The expected value",
|
jaroslav@248
|
305 |
StaticMethod.class, "swtch__Ljava_lang_String_2I",
|
jaroslav@115
|
306 |
"Darda",
|
jaroslav@115
|
307 |
1
|
jaroslav@115
|
308 |
);
|
jaroslav@115
|
309 |
}
|
jaroslav@115
|
310 |
@Test public void switchParda() throws Exception {
|
jaroslav@115
|
311 |
assertExec(
|
jaroslav@115
|
312 |
"The expected value",
|
jaroslav@248
|
313 |
StaticMethod.class, "swtch2__Ljava_lang_String_2I",
|
jaroslav@115
|
314 |
"Parda",
|
jaroslav@115
|
315 |
22
|
jaroslav@115
|
316 |
);
|
jaroslav@115
|
317 |
}
|
jaroslav@115
|
318 |
@Test public void switchMarda() throws Exception {
|
jaroslav@115
|
319 |
assertExec(
|
jaroslav@115
|
320 |
"The expected value",
|
jaroslav@248
|
321 |
StaticMethod.class, "swtch__Ljava_lang_String_2I",
|
jaroslav@115
|
322 |
"Marda",
|
jaroslav@115
|
323 |
-433
|
jaroslav@115
|
324 |
);
|
jaroslav@115
|
325 |
}
|
jaroslav@115
|
326 |
|
jaroslav@291
|
327 |
@Test public void checkNullCast() throws Exception {
|
jaroslav@291
|
328 |
assertExec("Null can be cast to any type",
|
jaroslav@291
|
329 |
StaticMethod.class, "castNull__Ljava_lang_String_2Z",
|
jaroslav@291
|
330 |
null, true
|
jaroslav@291
|
331 |
);
|
jaroslav@291
|
332 |
}
|
jaroslav@291
|
333 |
|
jaroslav@103
|
334 |
private static CharSequence codeSeq;
|
jaroslav@103
|
335 |
private static Invocable code;
|
jaroslav@103
|
336 |
|
jaroslav@103
|
337 |
@BeforeClass
|
jaroslav@103
|
338 |
public void compileTheCode() throws Exception {
|
jaroslav@103
|
339 |
StringBuilder sb = new StringBuilder();
|
jaroslav@103
|
340 |
code = compileClass(sb, "org/apidesign/vm4brwsr/StaticMethod");
|
jaroslav@103
|
341 |
codeSeq = sb;
|
jaroslav@103
|
342 |
}
|
jaroslav@103
|
343 |
|
jaroslav@103
|
344 |
|
jaroslav@203
|
345 |
private static void assertExec(
|
jaroslav@203
|
346 |
String msg, Class clazz, String method,
|
jaroslav@203
|
347 |
Object expRes, Object... args
|
jaroslav@203
|
348 |
) throws Exception {
|
jaroslav@203
|
349 |
assertExec(code, codeSeq, msg, clazz, method, expRes, args);
|
jaroslav@203
|
350 |
}
|
jaroslav@203
|
351 |
static void assertExec(
|
jaroslav@203
|
352 |
Invocable toRun, CharSequence theCode,
|
jaroslav@203
|
353 |
String msg, Class clazz, String method,
|
jaroslav@203
|
354 |
Object expRes, Object... args
|
jaroslav@203
|
355 |
) throws Exception {
|
Martin@582
|
356 |
Object ret = TestUtils.execCode(toRun, theCode, msg, clazz, method, expRes, args);
|
Martin@582
|
357 |
if (ret == null) {
|
jaroslav@2
|
358 |
return;
|
jaroslav@2
|
359 |
}
|
jaroslav@46
|
360 |
if (expRes != null && expRes.equals(ret)) {
|
jaroslav@2
|
361 |
return;
|
jaroslav@2
|
362 |
}
|
jaroslav@203
|
363 |
assertEquals(ret, expRes, msg + "was: " + ret + "\n" + dumpJS(theCode));
|
jaroslav@2
|
364 |
|
jaroslav@2
|
365 |
}
|
jaroslav@2
|
366 |
|
jaroslav@13
|
367 |
static Invocable compileClass(StringBuilder sb, String... names) throws ScriptException, IOException {
|
jaroslav@201
|
368 |
return compileClass(sb, null, names);
|
jaroslav@201
|
369 |
}
|
jaroslav@201
|
370 |
static Invocable compileClass(
|
jaroslav@201
|
371 |
StringBuilder sb, ScriptEngine[] eng, String... names
|
jaroslav@201
|
372 |
) throws ScriptException, IOException {
|
jaroslav@19
|
373 |
if (sb == null) {
|
jaroslav@19
|
374 |
sb = new StringBuilder();
|
jaroslav@19
|
375 |
}
|
jaroslav@298
|
376 |
Bck2Brwsr.generate(sb, new EmulationResources(), names);
|
jaroslav@0
|
377 |
ScriptEngineManager sem = new ScriptEngineManager();
|
jaroslav@0
|
378 |
ScriptEngine js = sem.getEngineByExtension("js");
|
jaroslav@201
|
379 |
if (eng != null) {
|
jaroslav@201
|
380 |
eng[0] = js;
|
jaroslav@201
|
381 |
}
|
jaroslav@0
|
382 |
try {
|
jaroslav@0
|
383 |
Object res = js.eval(sb.toString());
|
jaroslav@0
|
384 |
assertTrue(js instanceof Invocable, "It is invocable object: " + res);
|
jaroslav@0
|
385 |
return (Invocable)js;
|
jaroslav@137
|
386 |
} catch (Exception ex) {
|
jaroslav@137
|
387 |
if (sb.length() > 2000) {
|
jtulach@190
|
388 |
sb = dumpJS(sb);
|
jaroslav@137
|
389 |
}
|
jaroslav@203
|
390 |
fail("Could not evaluate:\n" + sb, ex);
|
jaroslav@0
|
391 |
return null;
|
jaroslav@0
|
392 |
}
|
jaroslav@0
|
393 |
}
|
jtulach@190
|
394 |
static StringBuilder dumpJS(CharSequence sb) throws IOException {
|
jaroslav@172
|
395 |
File f = File.createTempFile("execution", ".js");
|
jaroslav@172
|
396 |
FileWriter w = new FileWriter(f);
|
jaroslav@172
|
397 |
w.append(sb);
|
jaroslav@172
|
398 |
w.close();
|
jtulach@190
|
399 |
return new StringBuilder(f.getPath());
|
jaroslav@172
|
400 |
}
|
jaroslav@298
|
401 |
private static class EmulationResources implements Bck2Brwsr.Resources {
|
jaroslav@298
|
402 |
@Override
|
jaroslav@298
|
403 |
public InputStream get(String name) throws IOException {
|
jaroslav@298
|
404 |
Enumeration<URL> en = StaticMethodTest.class.getClassLoader().getResources(name);
|
jaroslav@298
|
405 |
URL u = null;
|
jaroslav@298
|
406 |
while (en.hasMoreElements()) {
|
jaroslav@298
|
407 |
u = en.nextElement();
|
jaroslav@298
|
408 |
}
|
jaroslav@298
|
409 |
if (u == null) {
|
jaroslav@298
|
410 |
throw new IOException("Can't find " + name);
|
jaroslav@298
|
411 |
}
|
jaroslav@298
|
412 |
if (u.toExternalForm().contains("rt.jar!")) {
|
jaroslav@298
|
413 |
throw new IOException("No emulation for " + u);
|
jaroslav@298
|
414 |
}
|
jaroslav@298
|
415 |
return u.openStream();
|
jaroslav@298
|
416 |
}
|
jaroslav@298
|
417 |
}
|
jaroslav@0
|
418 |
}
|