pluotsorbet/jsshell.js

126 строки
2.6 KiB
JavaScript
Исходник Обычный вид История

/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
'use strict';
2015-01-30 02:02:57 +03:00
if (typeof console === "undefined") {
var console = {
log: print
}
}
console.print = function (c) {
putstr(String.fromCharCode(c));
};
2015-01-19 06:54:01 +03:00
2014-11-18 12:03:00 +03:00
function check() {
}
if (scriptArgs.length !== 1) {
print("error: One main class name must be specified.");
print("usage: jsshell <main class name>");
quit(1);
}
2015-01-19 06:54:01 +03:00
var callbacks = [];
var window = {
setZeroTimeout: function(callback) {
2015-01-19 06:54:01 +03:00
callbacks.push(callback);
},
addEventListener: function() {
},
crypto: {
getRandomValues: function() {
},
},
};
var navigator = {
language: "en-US",
};
2014-12-20 01:36:06 +03:00
function Promise() {
// ...
}
var document = {
documentElement: {
classList: {
add: function() {
},
},
},
querySelector: function() {
return {
addEventListener: function() {
},
};
},
getElementById: function() {
return {
addEventListener: function() {
},
getContext: function() {
},
2014-11-18 03:25:34 +03:00
getBoundingClientRect: function() {
return { top: 0, left: 0, width: 0, height: 0 };
}
};
},
2014-11-18 03:25:34 +03:00
addEventListener: function() {
},
};
var config = {
logConsole: "native",
args: "",
};
try {
2015-01-30 02:02:57 +03:00
load("libs/relooper.js", "build/j2me.js","libs/zipfile.js", "blackBox.js",
"libs/encoding.js", "util.js",
"instrument.js",
2014-12-01 22:35:09 +03:00
"override.js", "native.js", "tests/override.js",
2015-01-19 06:54:01 +03:00
"string.js", "midp/midp.js",
2014-12-20 01:36:06 +03:00
"libs/long.js", "midp/crypto.js", "libs/forge/md5.js", "libs/forge/util.js");
2015-01-19 06:54:01 +03:00
// load("build/classes.jar.js");
// load("build/program.jar.js");
2015-01-30 02:02:57 +03:00
// load("build/tests.jar.js");
var dump = putstr;
CLASSES.addSourceDirectory("java/cldc1.1.1");
CLASSES.addSourceDirectory("java/midp");
2015-01-19 06:54:01 +03:00
// CLASSES.addSourceDirectory("bench/scimark2src");
2014-11-26 12:21:11 +03:00
CLASSES.addPath("java/classes.jar", snarf("java/classes.jar", "binary").buffer);
CLASSES.addPath("tests/tests.jar", snarf("tests/tests.jar", "binary").buffer);
2015-01-19 06:54:01 +03:00
//CLASSES.addPath("program.jar", snarf("program.jar", "binary").buffer);
2014-11-26 12:21:11 +03:00
CLASSES.initializeBuiltinClasses();
2014-11-26 12:21:11 +03:00
var start = dateNow();
var jvm = new JVM();
2015-01-30 02:02:57 +03:00
J2ME.writers = J2ME.WriterFlags.JIT;
2014-12-20 01:36:06 +03:00
print("INITIALIZATION TIME: " + (dateNow() - start));
start = dateNow();
var runtime = jvm.startIsolate0(scriptArgs[0], config.args);
2015-01-19 06:54:01 +03:00
while (callbacks.length) {
(callbacks.shift())();
}
print("RUNNING TIME: " + (dateNow() - start));
2014-12-12 03:04:20 +03:00
// J2ME.interpreterCounter.traceSorted(new J2ME.IndentingWriter());
} catch (x) {
print(x);
print(x.stack);
}