pluotsorbet/override.js

101 строка
3.4 KiB
JavaScript
Исходник Обычный вид История

/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
2015-01-21 00:11:49 +03:00
'use strict';
var Override = {};
2014-12-19 00:03:59 +03:00
function asyncImpl(returnKind, promise) {
var ctx = $.ctx;
promise.then(function(res) {
if (returnKind === "J" || returnKind === "D") {
ctx.current().stack.push2(res);
} else if (returnKind !== "V") {
ctx.current().stack.push(res);
} else {
// void, do nothing
}
ctx.execute();
2014-12-19 00:03:59 +03:00
}, function(exception) {
var syntheticMethod = new MethodInfo({
name: "RaiseExceptionSynthetic",
signature: "()V",
isStatic: true,
2015-01-21 10:02:38 +03:00
classInfo: J2ME.ClassInfo.createFromObject({
className: {value: "java/lang/Object"},
vmc: {value: {}},
vfc: {value: {}},
constant_pool: {value: [
2014-12-19 00:03:59 +03:00
null
]}
}),
code: new Uint8Array([
2014-12-19 00:03:59 +03:00
0x2a, // aload_0
0xbf // athrow
])
});
2015-01-16 12:45:59 +03:00
var callee = Frame.create(syntheticMethod, [exception], 0);
ctx.frames.push(callee);
ctx.execute();
});
2015-01-11 12:02:23 +03:00
$.pause("Async");
}
2014-12-19 00:03:59 +03:00
Override["com/ibm/oti/connection/file/Connection.decode.(Ljava/lang/String;)Ljava/lang/String;"] = function(string) {
2015-01-30 12:08:51 +03:00
return J2ME.newString(decodeURIComponent(J2ME.fromJavaString(string)));
2014-12-19 00:03:59 +03:00
};
2014-12-19 00:03:59 +03:00
Override["com/ibm/oti/connection/file/Connection.encode.(Ljava/lang/String;)Ljava/lang/String;"] = function(string) {
2015-01-30 12:08:51 +03:00
return J2ME.newString(J2ME.fromJavaString(string).replace(/[^a-zA-Z0-9-_\.!~\*\\'()/:]/g, encodeURIComponent));
2014-12-19 00:03:59 +03:00
};
// The following Permissions methods are overriden to avoid expensive calls to
// DomainPolicy.loadValues. This has the added benefit that we avoid many other
// computations.
2014-12-19 00:03:59 +03:00
Override["com/sun/midp/security/Permissions.forDomain.(Ljava/lang/String;)[[B"] = function(name) {
// NUMBER_OF_PERMISSIONS = PermissionsStrings.PERMISSION_STRINGS.length + 2
2014-10-01 06:29:25 +04:00
// The 2 is the two hardcoded MIPS and AMS permissions.
var NUMBER_OF_PERMISSIONS = 61;
var ALLOW = 1;
2014-11-27 05:35:12 +03:00
var maximums = J2ME.newByteArray(NUMBER_OF_PERMISSIONS);
var defaults = J2ME.newByteArray(NUMBER_OF_PERMISSIONS);
for (var i = 0; i < NUMBER_OF_PERMISSIONS; i++) {
maximums[i] = defaults[i] = ALLOW;
}
var permissions = J2ME.newArray(J2ME.PrimitiveArrayClassInfo.B.klass, 2);
permissions[0] = maximums;
permissions[1] = defaults;
return permissions;
2014-12-19 00:03:59 +03:00
};
// Always return true to make Java think the MIDlet domain is trusted.
2014-12-19 00:03:59 +03:00
Override["com/sun/midp/security/Permissions.isTrusted.(Ljava/lang/String;)Z"] = function(name) {
return 1;
};
// Returns the ID of the permission. The callers will use this ID to check the
// permission in the permissions array returned by Permissions::forDomain.
2014-12-19 00:03:59 +03:00
Override["com/sun/midp/security/Permissions.getId.(Ljava/lang/String;)I"] = function(name) {
return 0;
2014-12-19 00:03:59 +03:00
};
// The Java code that uses this method doesn't actually use the return value, but
// passes it to Permissions.getId. So we can return anything.
2014-12-19 00:03:59 +03:00
Override["com/sun/midp/security/Permissions.getName.(I)Ljava/lang/String;"] = function(id) {
2014-12-23 23:17:16 +03:00
return J2ME.newString("com.sun.midp");
2014-12-19 00:03:59 +03:00
};
2015-01-06 17:46:05 +03:00
Override["com/sun/cldc/i18n/uclc/DefaultCaseConverter.toLowerCase.(C)C"] = function(char) {
2015-01-06 17:46:05 +03:00
return String.fromCharCode(char).toLowerCase().charCodeAt(0);
};
2015-01-06 17:46:05 +03:00
Override["com/sun/cldc/i18n/uclc/DefaultCaseConverter.toUpperCase.(C)C"] = function(char) {
2015-01-06 17:46:05 +03:00
return String.fromCharCode(char).toUpperCase().charCodeAt(0);
};