Skip to content

Commit

Permalink
Port some midp/midp.js natives to Native.create
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-c committed Oct 14, 2014
1 parent 1dfb9a0 commit bc59269
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions midp/midp.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,21 @@ var MIDP = {

MIDP.manifest = {};

Native["com/sun/midp/jarutil/JarReader.readJarEntry0.(Ljava/lang/String;Ljava/lang/String;)[B"] = function(ctx, stack) {
var entryName = util.fromJavaString(stack.pop()), jar = util.fromJavaString(stack.pop());
var bytes = CLASSES.loadFileFromJar(jar, entryName);
Native.create("com/sun/midp/jarutil/JarReader.readJarEntry0.(Ljava/lang/String;Ljava/lang/String;)[B", function(ctx, jar, entryName) {
var bytes = CLASSES.loadFileFromJar(util.fromJavaString(jar), util.fromJavaString(entryName));
if (!bytes)
ctx.raiseExceptionAndYield("java/io/IOException");
throw new JavaException("java/io/IOException");
var length = bytes.byteLength;
var data = new Uint8Array(bytes);
var array = ctx.newPrimitiveArray("B", length);
for (var n = 0; n < length; ++n)
array[n] = data[n];
stack.push(array);
}
return array;
}, { static: true });

Native["com/sun/midp/log/LoggingBase.report.(IILjava/lang/String;)V"] = function(ctx, stack) {
var message = stack.pop(), channelID = stack.pop(), severity = stack.pop();
Native.create("com/sun/midp/log/LoggingBase.report.(IILjava/lang/String;)V", function(ctx, severity, channelID, message) {
console.info(util.fromJavaString(message));
}
}, { static: true });

MIDP.groupTBL = [
"net_access",
Expand All @@ -45,13 +43,13 @@ MIDP.groupTBL = [
"satsa"
];

Native["com/sun/midp/security/Permissions.loadGroupList.()[Ljava/lang/String;"] = function(ctx, stack) {
Native.create("com/sun/midp/security/Permissions.loadGroupList.()[Ljava/lang/String;", function(ctx) {
var list = ctx.newArray("[Ljava/lang/String;", MIDP.groupTBL.length);
MIDP.groupTBL.forEach(function (e, n) {
list[n] = ctx.newString(e);
});
stack.push(list);
}
return list;
}, { static: true });

MIDP.messagesTBL = [
["Airtime",
Expand Down

0 comments on commit bc59269

Please sign in to comment.