forked from calculatortamer/pluotsorbet-updated
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsshell.js
executable file
·169 lines (143 loc) · 3.65 KB
/
jsshell.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
'use strict';
// Define objects and functions that j2me.js expects
// but are unavailable in the shell environment.
if (typeof console === "undefined") {
var console = {
log: print,
}
}
console.info = function (c) {
putstr(String.fromCharCode(c));
};
console.error = function (c) {
putstr(String.fromCharCode(c));
};
var START_TIME = dateNow();
var performance = {
now: function () {
return dateNow();
}
};
function check() {
}
if (scriptArgs.length !== 1) {
print("error: One main class name must be specified.");
print("usage: jsshell <main class name>");
quit(1);
}
var callbacks = [];
var window = {
setTimeout: function(callback) {
callbacks.push(callback);
},
nextTickBeforeEvents: function(callback) {
callbacks.push(callback);
},
nextTickDuringEvents: function(callback) {
callbacks.push(callback);
},
addEventListener: function() {
},
crypto: {
getRandomValues: function() {
},
},
};
var navigator = {
language: "en-US",
};
function Promise() {
// ...
}
var document = {
documentElement: {
classList: {
add: function() {
},
},
},
querySelector: function() {
return {
addEventListener: function() {
},
};
},
getElementById: function() {
return {
addEventListener: function() {
},
getContext: function() {
return {
save: function() {
},
};
},
getBoundingClientRect: function() {
return { top: 0, left: 0, width: 0, height: 0 };
},
querySelector: function() {
return { style: "" };
},
dispatchEvent: function(event) {
},
style: "",
};
},
addEventListener: function() {
},
};
var Event = function() {
}
var config = {
logConsole: "native",
args: "",
};
var DumbPipe = {
open: function() {
},
};
var profileTimeline = false;
try {
if (profileTimeline) {
load("bld/shumway.js");
}
load("libs/relooper.js", "bld/j2me.js","libs/zipfile.js", "blackBox.js",
"libs/encoding.js", "util.js", "libs/jarstore.js",
"native.js", "string.js", "midp/midp.js", "midp/content.js",
"libs/long.js", "midp/crypto.js", "libs/forge/md5.js", "libs/forge/util.js",
"bld/classes.jar.js");
// load("bld/classes.jar.js");
// load("bld/program.jar.js");
// load("bld/tests.jar.js");
// Define this down here so it overrides the version defined by native.js.
console.print = function (c) {
putstr(String.fromCharCode(c));
};
var dump = putstr;
CLASSES.addSourceDirectory("java/cldc1.1.1");
CLASSES.addSourceDirectory("java/midp");
// CLASSES.addSourceDirectory("bench/scimark2src");
JARStore.addBuiltIn("java/classes.jar", snarf("java/classes.jar", "binary").buffer);
JARStore.addBuiltIn("tests/tests.jar", snarf("tests/tests.jar", "binary").buffer);
JARStore.addBuiltIn("bench/benchmark.jar", snarf("bench/benchmark.jar", "binary").buffer);
//JARStore.addBuiltIn("program.jar", snarf("program.jar", "binary").buffer);
CLASSES.initializeBuiltinClasses();
var start = dateNow();
var jvm = new JVM();
J2ME.writers = J2ME.WriterFlags.None;
start = dateNow();
var runtime = jvm.startIsolate0(scriptArgs[0], config.args);
while (callbacks.length) {
(callbacks.shift())();
}
print("Time: " + (dateNow() - start).toFixed(4) + " ms");
if (profileTimeline) {
J2ME.timeline.createSnapshot().trace(new J2ME.IndentingWriter());
}
// J2ME.interpreterCounter.traceSorted(new J2ME.IndentingWriter());
} catch (x) {
print(x);
print(x.stack);
}