2014-07-06 12:29:36 +04:00
|
|
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2014-08-08 02:18:03 +04:00
|
|
|
function load(file, responseType, cb) {
|
2014-07-06 12:29:36 +04:00
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
xhr.open("GET", file, true);
|
2014-08-08 02:18:03 +04:00
|
|
|
xhr.responseType = responseType;
|
2014-07-06 12:29:36 +04:00
|
|
|
xhr.onload = function () {
|
|
|
|
cb(xhr.response);
|
|
|
|
}
|
|
|
|
xhr.send(null);
|
|
|
|
}
|
|
|
|
|
2014-09-24 02:16:09 +04:00
|
|
|
// To launch the unit tests: ?main=RunTests
|
|
|
|
// To launch the MIDP demo: ?main=com/sun/midp/main/MIDletSuiteLoader&midletClassName=HelloCommandMIDlet
|
|
|
|
// To launch a JAR file: ?main=com/sun/midp/main/MIDletSuiteLoader&args=app.jar
|
2014-08-21 01:31:05 +04:00
|
|
|
|
2014-09-24 02:16:09 +04:00
|
|
|
var jvm = new JVM();
|
2014-08-02 03:53:44 +04:00
|
|
|
|
2014-09-24 02:16:09 +04:00
|
|
|
var main = urlParams.main || "com/sun/midp/main/MIDletSuiteLoader";
|
|
|
|
MIDP.midletClassName = urlParams.midletClassName ? urlParams.midletClassName.replace(/\//g, '.') : "RunTests";
|
2014-08-02 03:53:44 +04:00
|
|
|
|
2014-09-24 02:16:09 +04:00
|
|
|
var jars = ["java/classes.jar", "tests/tests.jar"];
|
|
|
|
if (urlParams.jars) {
|
|
|
|
jars = jars.concat(urlParams.jars.split(":"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (urlParams.pushConn && urlParams.pushMidlet) {
|
|
|
|
MIDP.pushRegistrations.push({
|
|
|
|
connection: urlParams.pushConn,
|
|
|
|
midlet: urlParams.pushMidlet,
|
|
|
|
filter: "*",
|
|
|
|
suiteId: "1",
|
|
|
|
id: ++MIDP.lastRegistrationId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-09-24 02:28:40 +04:00
|
|
|
var initSteps = new Set();
|
2014-09-24 02:16:09 +04:00
|
|
|
|
2014-09-24 02:28:40 +04:00
|
|
|
function executeNextBatch(completedStep) {
|
|
|
|
initSteps.delete(completedStep);
|
2014-09-24 02:16:09 +04:00
|
|
|
|
2014-09-24 02:28:40 +04:00
|
|
|
initSteps.forEach(function(initStep) {
|
|
|
|
initStep.dependencyResolved(completedStep)
|
2014-09-24 02:16:09 +04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-09-24 02:28:40 +04:00
|
|
|
var InitStep = function(func, deps) {
|
2014-09-24 02:16:09 +04:00
|
|
|
this.func = func;
|
2014-09-24 02:28:40 +04:00
|
|
|
this.deps = deps;
|
|
|
|
this.depsResolved = 0;
|
2014-09-24 02:16:09 +04:00
|
|
|
|
2014-09-24 02:28:40 +04:00
|
|
|
initSteps.add(this);
|
2014-09-24 02:16:09 +04:00
|
|
|
}
|
|
|
|
|
2014-09-24 02:28:40 +04:00
|
|
|
InitStep.prototype.execute = function() {
|
2014-09-24 02:16:09 +04:00
|
|
|
this.func(executeNextBatch.bind(null, this));
|
|
|
|
}
|
|
|
|
|
2014-09-24 02:28:40 +04:00
|
|
|
InitStep.prototype.addDependency = function(dependency) {
|
|
|
|
this.deps.add(dependency)
|
|
|
|
}
|
|
|
|
|
|
|
|
InitStep.prototype.dependencyResolved = function(dependency) {
|
|
|
|
if (this.deps.size === 0 ||
|
|
|
|
(this.deps.has(dependency) && ++this.depsResolved === this.deps.size)) {
|
2014-09-24 02:16:09 +04:00
|
|
|
this.execute();
|
2014-08-28 22:22:43 +04:00
|
|
|
}
|
2014-09-24 02:16:09 +04:00
|
|
|
}
|
|
|
|
|
2014-09-24 02:28:40 +04:00
|
|
|
var initFS = new InitStep(function(callback) {
|
2014-09-24 02:16:09 +04:00
|
|
|
fs.init(callback);
|
|
|
|
}, new Set());
|
2014-08-28 22:22:43 +04:00
|
|
|
|
2014-09-24 02:28:40 +04:00
|
|
|
var mkdirPersistent = new InitStep(function(callback) {
|
2014-09-24 02:16:09 +04:00
|
|
|
fs.mkdir("/Persistent", callback);
|
|
|
|
}, new Set([ initFS ]));
|
|
|
|
|
2014-09-24 02:28:40 +04:00
|
|
|
var createKeystore = new InitStep(function(callback) {
|
2014-08-28 22:22:43 +04:00
|
|
|
fs.exists("/_main.ks", function(exists) {
|
|
|
|
if (exists) {
|
2014-09-24 02:16:09 +04:00
|
|
|
callback();
|
2014-08-28 22:22:43 +04:00
|
|
|
} else {
|
2014-08-29 00:37:09 +04:00
|
|
|
load("certs/_main.ks", "blob", function(data) {
|
2014-08-28 22:22:43 +04:00
|
|
|
fs.create("/_main.ks", data, function() {
|
2014-09-24 02:16:09 +04:00
|
|
|
callback();
|
2014-08-28 22:22:43 +04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2014-08-26 21:57:42 +04:00
|
|
|
});
|
2014-09-24 02:16:09 +04:00
|
|
|
}, new Set([ initFS ]));
|
|
|
|
|
2014-09-24 02:28:40 +04:00
|
|
|
var startJVM = new InitStep(function(callback) {
|
2014-09-24 02:16:09 +04:00
|
|
|
jvm.initializeBuiltinClasses();
|
|
|
|
jvm.startIsolate0(main, urlParams.args);
|
|
|
|
}, new Set([ mkdirPersistent, createKeystore ]));
|
|
|
|
|
|
|
|
jars.forEach(function(jar) {
|
2014-09-24 02:28:40 +04:00
|
|
|
startJVM.addDependency(new InitStep(function(callback) {
|
2014-09-24 02:16:09 +04:00
|
|
|
load(jar, "arraybuffer", function(data) {
|
|
|
|
jvm.addPath(jar, data);
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
}, new Set()));
|
|
|
|
});
|
2014-07-16 03:14:48 +04:00
|
|
|
|
2014-09-24 02:16:09 +04:00
|
|
|
if (MIDP.midletClassName == "RunTests") {
|
2014-09-24 02:28:40 +04:00
|
|
|
startJVM.addDependency(new InitStep(function(callback) {
|
2014-09-24 02:16:09 +04:00
|
|
|
var element = document.createElement('script');
|
|
|
|
element.setAttribute("type", "text/javascript");
|
|
|
|
element.setAttribute("src", "tests/native.js");
|
|
|
|
document.getElementsByTagName("head")[0].appendChild(element);
|
2014-08-03 02:56:56 +04:00
|
|
|
|
2014-09-24 02:16:09 +04:00
|
|
|
var testContactsScript = document.createElement('script');
|
|
|
|
testContactsScript.setAttribute("type", "text/javascript");
|
|
|
|
testContactsScript.setAttribute("src", "tests/contacts.js");
|
|
|
|
document.getElementsByTagName("head")[0].appendChild(testContactsScript);
|
2014-09-03 05:04:13 +04:00
|
|
|
|
2014-09-24 02:16:09 +04:00
|
|
|
testContactsScript.onload = callback;
|
|
|
|
}, new Set()));
|
|
|
|
}
|
2014-09-16 20:56:07 +04:00
|
|
|
|
2014-09-24 02:16:09 +04:00
|
|
|
if (urlParams.jad) {
|
2014-09-24 02:28:40 +04:00
|
|
|
startJVM.addDependency(new InitStep(function(callback) {
|
2014-09-24 02:16:09 +04:00
|
|
|
load(urlParams.jad, "text", function(data) {
|
|
|
|
data
|
|
|
|
.replace(/\r\n|\r/g, "\n")
|
|
|
|
.replace(/\n /g, "")
|
|
|
|
.split("\n")
|
|
|
|
.forEach(function(entry) {
|
|
|
|
if (entry) {
|
|
|
|
var keyval = entry.split(':');
|
|
|
|
MIDP.manifest[keyval[0]] = keyval[1].trim();
|
|
|
|
}
|
|
|
|
});
|
2014-09-20 00:25:03 +04:00
|
|
|
|
2014-09-24 02:16:09 +04:00
|
|
|
callback();
|
|
|
|
});
|
|
|
|
}, new Set()));
|
|
|
|
}
|
|
|
|
|
|
|
|
executeNextBatch();
|
2014-08-06 04:49:51 +04:00
|
|
|
|
2014-09-22 12:05:03 +04:00
|
|
|
function getIsOff(button) {
|
|
|
|
return button.textContent.contains("OFF");
|
|
|
|
}
|
2014-08-21 20:47:08 +04:00
|
|
|
function toggle(button) {
|
2014-09-22 12:05:03 +04:00
|
|
|
var isOff = getIsOff(button);
|
2014-08-21 20:47:08 +04:00
|
|
|
button.textContent = button.textContent.replace(isOff ? "OFF" : "ON", isOff ? "ON" : "OFF");
|
|
|
|
}
|
|
|
|
|
2014-08-06 04:49:51 +04:00
|
|
|
window.onload = function() {
|
|
|
|
document.getElementById("clearstorage").onclick = function() {
|
|
|
|
asyncStorage.clear();
|
|
|
|
};
|
2014-08-09 00:27:00 +04:00
|
|
|
document.getElementById("trace").onclick = function() {
|
|
|
|
VM.DEBUG = !VM.DEBUG;
|
2014-08-21 20:47:08 +04:00
|
|
|
toggle(this);
|
2014-08-09 00:27:00 +04:00
|
|
|
};
|
2014-08-21 20:46:07 +04:00
|
|
|
document.getElementById("printAllExceptions").onclick = function() {
|
|
|
|
VM.DEBUG_PRINT_ALL_EXCEPTIONS = !VM.DEBUG_PRINT_ALL_EXCEPTIONS;
|
2014-08-21 20:47:08 +04:00
|
|
|
toggle(this);
|
2014-08-09 00:27:00 +04:00
|
|
|
};
|
2014-09-22 12:05:03 +04:00
|
|
|
document.getElementById("profile").onclick = function() {
|
|
|
|
if (getIsOff(this)) {
|
|
|
|
Instrument.startProfile();
|
|
|
|
} else {
|
|
|
|
Instrument.stopProfile();
|
|
|
|
}
|
|
|
|
toggle(this);
|
2014-09-21 02:13:26 +04:00
|
|
|
};
|
2014-09-22 12:05:03 +04:00
|
|
|
if (Instrument.profiling) {
|
2014-09-22 12:09:20 +04:00
|
|
|
toggle(document.getElementById("profile"));
|
2014-09-22 12:05:03 +04:00
|
|
|
}
|
2014-08-06 04:49:51 +04:00
|
|
|
};
|
2014-09-22 12:05:03 +04:00
|
|
|
|
|
|
|
if (urlParams.profile && !/no|0/.test(urlParams.profile)) {
|
|
|
|
Instrument.startProfile();
|
|
|
|
}
|