Merge pull request #457 from marco-c/port_other_natives

Port other natives to Native.create
This commit is contained in:
Myk Melez 2014-10-16 11:25:13 -07:00
Родитель 8b550d3a82 139c038dff
Коммит 108c398cc2
6 изменённых файлов: 467 добавлений и 610 удалений

Просмотреть файл

@ -26,37 +26,32 @@ Native["com/sun/midp/rms/RecordStoreUtil.exists.(Ljava/lang/String;Ljava/lang/St
throw VM.Pause;
}
Native["com/sun/midp/rms/RecordStoreUtil.deleteFile.(Ljava/lang/String;Ljava/lang/String;I)V"] = function(ctx, stack) {
var ext = stack.pop(), name = util.fromJavaString(stack.pop()), filenameBase = util.fromJavaString(stack.pop());
var path = RECORD_STORE_BASE + "/" + filenameBase + "/" + name + "." + ext;
Native.create("com/sun/midp/rms/RecordStoreUtil.deleteFile.(Ljava/lang/String;Ljava/lang/String;I)V",
function(ctx, filenameBase, name, ext) {
var path = RECORD_STORE_BASE + "/" + util.fromJavaString(filenameBase) + "/" + util.fromJavaString(name) + "." + ext;
fs.remove(path, function(removed) {
ctx.resume();
});
throw VM.Pause;
}
Native["com/sun/midp/rms/RecordStoreFile.spaceAvailableNewRecordStore0.(Ljava/lang/String;I)I"] = function(ctx, stack) {
var storageId = stack.pop(), filenameBase = util.fromJavaString(stack.pop());
});
Native.create("com/sun/midp/rms/RecordStoreFile.spaceAvailableNewRecordStore0.(Ljava/lang/String;I)I", function(ctx, filenameBase, storageId) {
// Pretend there is 50MiB available. Our implementation is backed
// by IndexedDB, which has no actual limit beyond space available on device,
// which I don't think we can determine. But this should be sufficient
// to convince the MIDlet to use the API as needed.
stack.push(50 * 1024 * 1024);
}
Native["com/sun/midp/rms/RecordStoreFile.spaceAvailableRecordStore.(ILjava/lang/String;I)I"] = function(ctx, stack) {
var storageId = stack.pop(), filenameBase = util.fromJavaString(stack.pop()), handle = stack.pop();
return 50 * 1024 * 1024;
});
Native.create("com/sun/midp/rms/RecordStoreFile.spaceAvailableRecordStore.(ILjava/lang/String;I)I", function(ctx, handle, filenameBase, storageId) {
// Pretend there is 50MiB available. Our implementation is backed
// by IndexedDB, which has no actual limit beyond space available on device,
// which I don't think we can determine. But this should be sufficient
// to convince the MIDlet to use the API as needed.
stack.push(50 * 1024 * 1024);
}
return 50 * 1024 * 1024;
});
Native["com/sun/midp/rms/RecordStoreFile.openRecordStoreFile.(Ljava/lang/String;Ljava/lang/String;I)I"] = function(ctx, stack) {
var ext = stack.pop(), name = util.fromJavaString(stack.pop()), filenameBase = util.fromJavaString(stack.pop()), _this = stack.pop();
@ -100,70 +95,61 @@ Native["com/sun/midp/rms/RecordStoreFile.openRecordStoreFile.(Ljava/lang/String;
throw VM.Pause;
}
Native["com/sun/midp/rms/RecordStoreFile.setPosition.(II)V"] = function(ctx, stack) {
var pos = stack.pop(), handle = stack.pop();
Native.create("com/sun/midp/rms/RecordStoreFile.setPosition.(II)V", function(ctx, handle, pos) {
fs.setpos(handle, pos);
}
Native["com/sun/midp/rms/RecordStoreFile.readBytes.(I[BII)I"] = function(ctx, stack) {
var numBytes = stack.pop(), offset = stack.pop(), buf = stack.pop(), handle = stack.pop();
});
Native.create("com/sun/midp/rms/RecordStoreFile.readBytes.(I[BII)I", function(ctx, handle, buf, offset, numBytes) {
var from = fs.getpos(handle);
var to = from + numBytes;
var readBytes = fs.read(handle, from, to);
if (readBytes.byteLength <= 0) {
ctx.raiseExceptionAndYield("java/io/IOException", "handle invalid or segment indices out of bounds");
throw new JavaException("java/io/IOException", "handle invalid or segment indices out of bounds");
}
var subBuffer = buf.subarray(offset, offset + readBytes.byteLength);
for (var i = 0; i < readBytes.byteLength; i++) {
subBuffer[i] = readBytes[i];
}
stack.push(readBytes.byteLength);
}
return readBytes.byteLength;
});
Native["com/sun/midp/rms/RecordStoreFile.writeBytes.(I[BII)V"] = function(ctx, stack) {
var numBytes = stack.pop(), offset = stack.pop(), buf = stack.pop(), handle = stack.pop();
Native.create("com/sun/midp/rms/RecordStoreFile.writeBytes.(I[BII)V", function(ctx, handle, buf, offset, numBytes) {
fs.write(handle, buf.subarray(offset, offset + numBytes));
}
});
Native["com/sun/midp/rms/RecordStoreFile.commitWrite.(I)V"] = function(ctx, stack) {
var handle = stack.pop();
Native.create("com/sun/midp/rms/RecordStoreFile.commitWrite.(I)V", function(ctx, handle) {
fs.flush(handle, function() {
ctx.resume();
});
throw VM.Pause;
}
Native["com/sun/midp/rms/RecordStoreFile.closeFile.(I)V"] = function(ctx, stack) {
var handle = stack.pop();
});
Native.create("com/sun/midp/rms/RecordStoreFile.closeFile.(I)V", function(ctx, handle) {
fs.flush(handle, function() {
fs.close(handle);
ctx.resume();
});
throw VM.Pause;
}
Native["com/sun/midp/rms/RecordStoreFile.truncateFile.(II)V"] = function(ctx, stack) {
var size = stack.pop(), handle = stack.pop();
});
Native.create("com/sun/midp/rms/RecordStoreFile.truncateFile.(II)V", function(ctx, handle, size) {
fs.flush(handle, function() {
fs.ftruncate(handle, size);
ctx.resume();
});
throw VM.Pause;
}
});
MIDP.RecordStoreCache = [];
Native["com/sun/midp/rms/RecordStoreSharedDBHeader.getLookupId0.(ILjava/lang/String;I)I"] = function(ctx, stack) {
var headerDataSize = stack.pop(), storeName = util.fromJavaString(stack.pop()), suiteId = stack.pop();
Native.create("com/sun/midp/rms/RecordStoreSharedDBHeader.getLookupId0.(ILjava/lang/String;I)I",
function(ctx, suiteId, jStoreName, headerDataSize) {
var storeName = util.fromJavaString(jStoreName);
var sharedHeader =
MIDP.RecordStoreCache.filter(function(v) { return (v && v.suiteId == suiteId && v.storeName == storeName); })[0];
@ -182,19 +168,17 @@ Native["com/sun/midp/rms/RecordStoreSharedDBHeader.getLookupId0.(ILjava/lang/Str
}
++sharedHeader.refCount;
stack.push(sharedHeader.lookupId);
}
Native["com/sun/midp/rms/RecordStoreSharedDBHeader.shareCachedData0.(I[BI)I"] = function(ctx, stack) {
var headerDataSize = stack.pop(), headerData = stack.pop(), lookupId = stack.pop();
return sharedHeader.lookupId;
});
Native.create("com/sun/midp/rms/RecordStoreSharedDBHeader.shareCachedData0.(I[BI)I", function(ctx, lookupId, headerData, headerDataSize) {
var sharedHeader = MIDP.RecordStoreCache[lookupId];
if (!sharedHeader) {
ctx.raiseExceptionAndYield("java/lang/IllegalStateException", "invalid header lookup ID");
throw new JavaException("java/lang/IllegalStateException", "invalid header lookup ID");
}
if (!headerData) {
ctx.raiseExceptionAndYield("java/lang/IllegalArgumentException", "header data is null");
throw new JavaException("java/lang/IllegalArgumentException", "header data is null");
}
var size = headerDataSize;
@ -204,19 +188,18 @@ Native["com/sun/midp/rms/RecordStoreSharedDBHeader.shareCachedData0.(I[BI)I"] =
sharedHeader.headerData = headerData.buffer.slice(0, size);
++sharedHeader.headerVersion;
stack.push(sharedHeader.headerVersion);
}
Native["com/sun/midp/rms/RecordStoreSharedDBHeader.updateCachedData0.(I[BII)I"] = function(ctx, stack) {
var headerVersion = stack.pop(), headerDataSize = stack.pop(), headerData = stack.pop(), lookupId = stack.pop();
return sharedHeader.headerVersion;
});
Native.create("com/sun/midp/rms/RecordStoreSharedDBHeader.updateCachedData0.(I[BII)I",
function(ctx, lookupId, headerData, headerDataSize, headerVersion) {
var sharedHeader = MIDP.RecordStoreCache[lookupId];
if (!sharedHeader) {
ctx.raiseExceptionAndYield("java/lang/IllegalStateException", "invalid header lookup ID");
throw new JavaException("java/lang/IllegalStateException", "invalid header lookup ID");
}
if (!headerData) {
ctx.raiseExceptionAndYield("java/lang/IllegalArgumentException", "header data is null");
throw new JavaException("java/lang/IllegalArgumentException", "header data is null");
}
if (sharedHeader.headerVersion > headerVersion && sharedHeader.headerData) {
@ -227,26 +210,22 @@ Native["com/sun/midp/rms/RecordStoreSharedDBHeader.updateCachedData0.(I[BII)I"]
for (var i = 0; i < size; i++) {
headerData[i] = sharedHeader.headerData[i];
}
stack.push(sharedHeader.headerVersion);
} else {
stack.push(headerVersion);
return sharedHeader.headerVersion;
}
}
Native["com/sun/midp/rms/RecordStoreSharedDBHeader.getHeaderRefCount0.(I)I"] = function(ctx, stack) {
var lookupId = stack.pop();
return headerVersion;
});
Native.create("com/sun/midp/rms/RecordStoreSharedDBHeader.getHeaderRefCount0.(I)I", function(ctx, lookupId) {
var sharedHeader = MIDP.RecordStoreCache[lookupId];
if (!sharedHeader) {
ctx.raiseExceptionAndYield("java/lang/IllegalStateException", "invalid header lookup ID");
throw new JavaException("java/lang/IllegalStateException", "invalid header lookup ID");
}
stack.push(sharedHeader.refCount);
}
Native["com/sun/midp/rms/RecordStoreSharedDBHeader.cleanup0.()V"] = function(ctx, stack) {
var _this = stack.pop();
return sharedHeader.refCount;
});
Native.create("com/sun/midp/rms/RecordStoreSharedDBHeader.cleanup0.()V", function(ctx) {
for (var i = 0; i < MIDP.RecordStoreCache.length; i++) {
if (MIDP.RecordStoreCache[i] == null) {
continue;
@ -257,69 +236,63 @@ Native["com/sun/midp/rms/RecordStoreSharedDBHeader.cleanup0.()V"] = function(ctx
MIDP.RecordStoreCache[i] = null;
}
}
}
});
// In the reference implementation, finalize is identical to cleanup0.
Native["com/sun/midp/rms/RecordStoreSharedDBHeader.finalize.()V"] =
Native["com/sun/midp/rms/RecordStoreSharedDBHeader.cleanup0.()V"];
Native["com/sun/midp/rms/RecordStoreRegistry.getRecordStoreListeners.(ILjava/lang/String;)[I"] = function(ctx, stack) {
var storeName = util.fromJavaString(stack.pop()), suiteId = stack.pop();
stack.push(null);
Native.create("com/sun/midp/rms/RecordStoreRegistry.getRecordStoreListeners.(ILjava/lang/String;)[I",
function(ctx, suiteId, storeName) {
console.warn("RecordStoreRegistry.getRecordStoreListeners.(IL...String;)[I not implemented (" +
suiteId + ", " + storeName + ")");
}
suiteId + ", " + util.fromJavaString(storeName) + ")");
return null;
});
Native["com/sun/midp/rms/RecordStoreRegistry.sendRecordStoreChangeEvent.(ILjava/lang/String;II)V"] = function(ctx, stack) {
var recordId = stack.pop(), changeType = stack.pop(), storeName = util.fromJavaString(stack.pop()), suiteId = stack.pop();
Native.create("com/sun/midp/rms/RecordStoreRegistry.sendRecordStoreChangeEvent.(ILjava/lang/String;II)V",
function(ctx, suiteId, storeName, changeType, recordId) {
console.warn("RecordStoreRegistry.sendRecordStoreChangeEvent.(IL...String;II)V not implemented (" +
suiteId + ", " + storeName + ", " + changeType + ", " + recordId + ")");
}
suiteId + ", " + util.fromJavaString(storeName) + ", " + changeType + ", " + recordId + ")");
});
Native["com/sun/midp/rms/RecordStoreRegistry.startRecordStoreListening.(ILjava/lang/String;)V"] = function(ctx, stack) {
var storeName = util.fromJavaString(stack.pop()), suiteId = stack.pop();
Native.create("com/sun/midp/rms/RecordStoreRegistry.startRecordStoreListening.(ILjava/lang/String;)V",
function(ctx, suiteId, storeName) {
console.warn("RecordStoreRegistry.startRecordStoreListening.(IL...String;)V not implemented (" +
suiteId + ", " + storeName + ")");
}
suiteId + ", " + util.fromJavaString(storeName) + ")");
});
Native["com/sun/midp/rms/RecordStoreRegistry.stopRecordStoreListening.(ILjava/lang/String;)V"] = function(ctx, stack) {
var storeName = util.fromJavaString(stack.pop()), suiteId = stack.pop();
Native.create("com/sun/midp/rms/RecordStoreRegistry.stopRecordStoreListening.(ILjava/lang/String;)V",
function(ctx, suiteId, storeName) {
console.warn("RecordStoreRegistry.stopRecordStoreListening.(IL...String;)V not implemented (" +
suiteId + ", " + storeName + ")");
}
suiteId + ", " + util.fromJavaString(storeName) + ")");
});
Native["com/sun/midp/rms/RecordStoreRegistry.stopAllRecordStoreListeners.(I)V"] = function(ctx, stack) {
var taskId = stack.pop();
Native.create("com/sun/midp/rms/RecordStoreRegistry.stopAllRecordStoreListeners.(I)V", function(ctx, taskId) {
console.warn("RecordStoreRegistry.stopAllRecordStoreListeners.(I)V not implemented (" + taskId + ")");
}
Native["com/ibm/oti/connection/file/Connection.isValidFilenameImpl.([B)Z"] = function(ctx, stack) {
var path = stack.pop(), _this = stack.pop();
});
Native.create("com/ibm/oti/connection/file/Connection.isValidFilenameImpl.([B)Z", function(ctx, path) {
var invalid = ['<', '>', ':', '"', '/', '\\', '|', '*', '?'].map(function(char) {
return char.charCodeAt(0);
});
for (var i = 0; i < path.length; i++) {
if (path[i] <= 31 || invalid.indexOf(path[i]) != -1) {
stack.push(0);
return;
return false;
}
}
stack.push(1);
}
return true;
});
Native["com/ibm/oti/connection/file/Connection.availableSizeImpl.([B)J"] = function(ctx, stack) {
var path = util.decodeUtf8(stack.pop()), _this = stack.pop();
Native.create("com/ibm/oti/connection/file/Connection.availableSizeImpl.([B)J", function(ctx, path) {
// Pretend there is 1 GB available
stack.push2(Long.fromNumber(1024 * 1024 * 1024));
}
return Long.fromNumber(1024 * 1024 * 1024);
});
Native["com/ibm/oti/connection/file/Connection.setHiddenImpl.([BZ)V"] = function(ctx, stack) {
var value = stack.pop(), path = util.decodeUtf8(stack.pop()), _this = stack.pop();
console.warn("Connection.setHiddenImpl.([BZ)V not implemented (" + path + ")");
}
Native.create("com/ibm/oti/connection/file/Connection.setHiddenImpl.([BZ)V", function(ctx, path, value) {
console.warn("Connection.setHiddenImpl.([BZ)V not implemented (" + util.decodeUtf8(path) + ")");
});
Native["com/ibm/oti/connection/file/Connection.existsImpl.([B)Z"] = function(ctx, stack) {
var path = util.decodeUtf8(stack.pop()), _this = stack.pop();
@ -467,17 +440,15 @@ Native["com/ibm/oti/connection/file/Connection.deleteDirImpl.([B)Z"] = function(
throw VM.Pause;
}
Native["com/ibm/oti/connection/file/Connection.isReadOnlyImpl.([B)Z"] = function(ctx, stack) {
var path = util.decodeUtf8(stack.pop()), _this = stack.pop();
stack.push(0);
console.warn("Connection.isReadOnlyImpl.([B)Z not implemented (" + path + ")");
}
Native.create("com/ibm/oti/connection/file/Connection.isReadOnlyImpl.([B)Z", function(ctx, path) {
console.warn("Connection.isReadOnlyImpl.([B)Z not implemented (" + util.decodeUtf8(path) + ")");
return false;
});
Native["com/ibm/oti/connection/file/Connection.isWriteOnlyImpl.([B)Z"] = function(ctx, stack) {
var path = util.decodeUtf8(stack.pop()), _this = stack.pop();
stack.push(0);
console.warn("Connection.isWriteOnlyImpl.([B)Z not implemented (" + path + ")");
}
Native.create("com/ibm/oti/connection/file/Connection.isWriteOnlyImpl.([B)Z", function(ctx, path) {
console.warn("Connection.isWriteOnlyImpl.([B)Z not implemented (" + util.decodeUtf8(path) + ")");
return false;
});
Native["com/ibm/oti/connection/file/Connection.lastModifiedImpl.([B)J"] = function(ctx, stack) {
var path = util.decodeUtf8(stack.pop()), _this = stack.pop();
@ -494,9 +465,8 @@ Native["com/ibm/oti/connection/file/Connection.lastModifiedImpl.([B)J"] = functi
throw VM.Pause;
}
Native["com/ibm/oti/connection/file/Connection.renameImpl.([B[B)V"] = function(ctx, stack) {
var newPath = util.decodeUtf8(stack.pop()), oldPath = util.decodeUtf8(stack.pop()), _this = stack.pop();
fs.rename(oldPath, newPath, function(renamed) {
Native.create("com/ibm/oti/connection/file/Connection.renameImpl.([B[B)V", function(ctx, oldPath, newPath) {
fs.rename(util.decodeUtf8(oldPath), util.decodeUtf8(newPath), function(renamed) {
if (!renamed) {
ctx.raiseException("java/io/IOException", "Rename failed");
}
@ -504,19 +474,15 @@ Native["com/ibm/oti/connection/file/Connection.renameImpl.([B[B)V"] = function(c
ctx.resume();
});
throw VM.Pause;
}
});
Native["com/ibm/oti/connection/file/Connection.truncateImpl.([BJ)V"] = function(ctx, stack) {
var newLength = stack.pop2().toNumber(), path = util.decodeUtf8(stack.pop()), _this = stack.pop();
// IBM's implementation returns different error numbers, we don't care
fs.open(path, function(fd) {
Native.create("com/ibm/oti/connection/file/Connection.truncateImpl.([BJ)V", function(ctx, path, newLength, _) {
fs.open(util.decodeUtf8(path), function(fd) {
if (fd == -1) {
ctx.raiseException("java/io/IOException", "truncate failed");
ctx.resume();
} else {
fs.ftruncate(fd, newLength);
fs.ftruncate(fd, newLength.toNumber());
fs.flush(fd, function() {
fs.close(fd);
ctx.resume();
@ -525,7 +491,7 @@ Native["com/ibm/oti/connection/file/Connection.truncateImpl.([BJ)V"] = function(
});
throw VM.Pause;
}
});
Native["com/ibm/oti/connection/file/FCInputStream.openImpl.([B)I"] = function(ctx, stack) {
var path = util.decodeUtf8(stack.pop()), _this = stack.pop();
@ -538,65 +504,53 @@ Native["com/ibm/oti/connection/file/FCInputStream.openImpl.([B)I"] = function(ct
throw VM.Pause;
}
Native["com/ibm/oti/connection/file/FCInputStream.availableImpl.(I)I"] = function(ctx, stack) {
var fd = stack.pop(), _this = stack.pop();
stack.push(fs.getsize(fd) - fs.getpos(fd));
}
Native["com/ibm/oti/connection/file/FCInputStream.skipImpl.(JI)J"] = function(ctx, stack) {
var fd = stack.pop(), count = stack.pop2(), _this = stack.pop();
Native.create("com/ibm/oti/connection/file/FCInputStream.availableImpl.(I)I", function(ctx, fd) {
return fs.getsize(fd) - fs.getpos(fd);
});
Native.create("com/ibm/oti/connection/file/FCInputStream.skipImpl.(JI)J", function(ctx, count, _, fd) {
var curpos = fs.getpos(fd);
var size = fs.getsize(fd);
if (curpos + count.toNumber() > size) {
fs.setpos(fd, size);
stack.push2(Long.fromNumber(size - curpos));
} else {
fs.setpos(fd, curpos + count.toNumber());
stack.push2(count);
return Long.fromNumber(size - curpos);
}
}
Native["com/ibm/oti/connection/file/FCInputStream.readImpl.([BIII)I"] = function(ctx, stack) {
var fd = stack.pop(), count = stack.pop(), offset = stack.pop(), buffer = stack.pop(), _this = stack.pop();
fs.setpos(fd, curpos + count.toNumber());
return count;
});
Native.create("com/ibm/oti/connection/file/FCInputStream.readImpl.([BIII)I", function(ctx, buffer, offset, count, fd) {
if (offset < 0 || count < 0 || offset > buffer.byteLength || (buffer.byteLength - offset) < count) {
ctx.raiseExceptionAndYield("java/lang/IndexOutOfBoundsException");
throw new JavaException("java/lang/IndexOutOfBoundsException");
}
if (buffer.byteLength == 0 || count == 0) {
stack.push(0);
return;
return 0;
}
var curpos = fs.getpos(fd);
var data = fs.read(fd, curpos, curpos + count);
buffer.set(data, offset);
stack.push((data.byteLength > 0) ? data.byteLength : -1);
}
Native["com/ibm/oti/connection/file/FCInputStream.readByteImpl.(I)I"] = function(ctx, stack) {
var fd = stack.pop(), _this = stack.pop();
return (data.byteLength > 0) ? data.byteLength : -1;
});
Native.create("com/ibm/oti/connection/file/FCInputStream.readByteImpl.(I)I", function(ctx, fd) {
var curpos = fs.getpos(fd);
var data = fs.read(fd, curpos, curpos+1);
stack.push((data.byteLength > 0) ? data[0] : -1);
}
Native["com/ibm/oti/connection/file/FCInputStream.closeImpl.(I)V"] = function(ctx, stack) {
var fd = stack.pop(), _this = stack.pop();
return (data.byteLength > 0) ? data[0] : -1;
});
Native.create("com/ibm/oti/connection/file/FCInputStream.closeImpl.(I)V", function(ctx, fd) {
if (fd >= 0) {
fs.close(fd);
}
}
Native["com/ibm/oti/connection/file/FCOutputStream.closeImpl.(I)V"] = function(ctx, stack) {
var fd = stack.pop(), _this = stack.pop();
});
Native.create("com/ibm/oti/connection/file/FCOutputStream.closeImpl.(I)V", function(ctx, fd) {
if (fd <= -1) {
return;
}
@ -607,7 +561,7 @@ Native["com/ibm/oti/connection/file/FCOutputStream.closeImpl.(I)V"] = function(c
});
throw VM.Pause;
}
});
Native["com/ibm/oti/connection/file/FCOutputStream.openImpl.([B)I"] = function(ctx, stack) {
var path = util.decodeUtf8(stack.pop()), _this = stack.pop();
@ -673,30 +627,24 @@ Native["com/ibm/oti/connection/file/FCOutputStream.openOffsetImpl.([BJ)I"] = fun
throw VM.Pause;
}
Native["com/ibm/oti/connection/file/FCOutputStream.syncImpl.(I)V"] = function(ctx, stack) {
var fd = stack.pop(), _this = stack.pop();
Native.create("com/ibm/oti/connection/file/FCOutputStream.syncImpl.(I)V", function(ctx, fd) {
fs.flush(fd, function() {
ctx.resume();
});
throw VM.Pause;
}
Native["com/ibm/oti/connection/file/FCOutputStream.writeByteImpl.(II)V"] = function(ctx, stack) {
var fd = stack.pop(), val = stack.pop(), _this = stack.pop();
});
Native.create("com/ibm/oti/connection/file/FCOutputStream.writeByteImpl.(II)V", function(ctx, val, fd) {
var buf = new Uint8Array(1);
buf[0] = val;
fs.write(fd, buf);
}
Native["com/ibm/oti/connection/file/FCOutputStream.writeImpl.([BIII)V"] = function(ctx, stack) {
var fd = stack.pop(), count = stack.pop(), offset = stack.pop(), byteArray = stack.pop(), _this = stack.pop();
});
Native.create("com/ibm/oti/connection/file/FCOutputStream.writeImpl.([BIII)V",
function(ctx, byteArray, offset, count, fd) {
fs.write(fd, byteArray.subarray(offset, offset+count));
}
});
Native["com/sun/midp/io/j2me/storage/RandomAccessStream.open.(Ljava/lang/String;I)I"] = function(ctx, stack) {
var mode = stack.pop(), fileName = util.fromJavaString(stack.pop()), _this = stack.pop();
@ -734,64 +682,55 @@ Native["com/sun/midp/io/j2me/storage/RandomAccessStream.open.(Ljava/lang/String;
throw VM.Pause;
}
Native["com/sun/midp/io/j2me/storage/RandomAccessStream.read.(I[BII)I"] = function(ctx, stack) {
var length = stack.pop(), offset = stack.pop(), buffer = stack.pop(), handle = stack.pop();
Native.create("com/sun/midp/io/j2me/storage/RandomAccessStream.read.(I[BII)I",
function(ctx, handle, buffer, offset, length) {
var from = fs.getpos(handle);
var to = from + length;
var readBytes = fs.read(handle, from, to);
if (readBytes.byteLength <= 0) {
stack.push(-1);
return;
return -1;
}
var subBuffer = buffer.subarray(offset, offset + readBytes.byteLength);
for (var i = 0; i < readBytes.byteLength; i++) {
subBuffer[i] = readBytes[i];
}
stack.push(readBytes.byteLength);
}
return readBytes.byteLength;
});
Native["com/sun/midp/io/j2me/storage/RandomAccessStream.write.(I[BII)V"] = function(ctx, stack) {
var length = stack.pop(), offset = stack.pop(), buffer = stack.pop(), handle = stack.pop();
Native.create("com/sun/midp/io/j2me/storage/RandomAccessStream.write.(I[BII)V",
function(ctx, handle, buffer, offset, length) {
fs.write(handle, buffer.subarray(offset, offset + length));
}
Native["com/sun/midp/io/j2me/storage/RandomAccessStream.commitWrite.(I)V"] = function(ctx, stack) {
var handle = stack.pop();
});
Native.create("com/sun/midp/io/j2me/storage/RandomAccessStream.commitWrite.(I)V", function(ctx, handle) {
fs.flush(handle, function() {
ctx.resume();
});
throw VM.Pause;
}
});
Native["com/sun/midp/io/j2me/storage/RandomAccessStream.position.(II)V"] = function(ctx, stack) {
var position = stack.pop(), handle = stack.pop();
Native.create("com/sun/midp/io/j2me/storage/RandomAccessStream.position.(II)V", function(ctx, handle, position) {
fs.setpos(handle, position);
}
Native["com/sun/midp/io/j2me/storage/RandomAccessStream.sizeOf.(I)I"] = function(ctx, stack) {
var handle = stack.pop();
});
Native.create("com/sun/midp/io/j2me/storage/RandomAccessStream.sizeOf.(I)I", function(ctx, handle) {
var size = fs.getsize(handle);
if (size == -1) {
ctx.raiseExceptionAndYield("java/io/IOException", "RandomAccessStream::sizeOf(" + handle + ") failed");
throw new JavaException("java/io/IOException", "RandomAccessStream::sizeOf(" + handle + ") failed");
}
stack.push(size);
}
Native["com/sun/midp/io/j2me/storage/RandomAccessStream.close.(I)V"] = function(ctx, stack) {
var handle = stack.pop();
return size;
});
Native.create("com/sun/midp/io/j2me/storage/RandomAccessStream.close.(I)V", function(ctx, handle) {
fs.flush(handle, function() {
fs.close(handle);
ctx.resume();
});
throw VM.Pause;
}
});

Просмотреть файл

@ -251,39 +251,21 @@
this.css = style + " " + size + "pt " + face;
});
Native["javax/microedition/lcdui/Font.stringWidth.(Ljava/lang/String;)I"] = function(ctx, stack) {
var str = util.fromJavaString(stack.pop()), _this = stack.pop(),
c = MIDP.Context2D;
withFont(_this, c, str, function(w) {
stack.push(w);
});
}
Native.create("javax/microedition/lcdui/Font.stringWidth.(Ljava/lang/String;)I", function(ctx, str) {
return withFont(this, MIDP.Context2D, util.fromJavaString(str));
});
Native["javax/microedition/lcdui/Font.charWidth.(C)I"] = function(ctx, stack) {
var str = String.fromCharCode(stack.pop()), _this = stack.pop(),
c = MIDP.Context2D;
Native.create("javax/microedition/lcdui/Font.charWidth.(C)I", function(ctx, char) {
return withFont(this, MIDP.Context2D, String.fromCharCode(char));
});
withFont(_this, c, str, function(w) {
stack.push(w);
});
}
Native.create("javax/microedition/lcdui/Font.charsWidth.([CII)I", function(ctx, str, offset, len) {
return withFont(_this, MIDP.Context2D, util.fromJavaChars(str).slice(offset, offset + len));
});
Native["javax/microedition/lcdui/Font.charsWidth.([CII)I"] = function(ctx, stack) {
var len = stack.pop(), offset = stack.pop(), str = util.fromJavaChars(stack.pop()), _this = stack.pop(),
c = MIDP.Context2D;
withFont(_this, c, str.slice(offset, offset + len), function(w) {
stack.push(w);
});
}
Native["javax/microedition/lcdui/Font.substringWidth.(Ljava/lang/String;II)I"] = function(ctx, stack) {
var len = stack.pop(), offset = stack.pop(), str = util.fromJavaString(stack.pop()), _this = stack.pop(),
c = MIDP.Context2D;
withFont(_this, c, str.slice(offset, offset + len), function(w) {
stack.push(w);
});
}
Native.create("javax/microedition/lcdui/Font.substringWidth.(Ljava/lang/String;II)I", function(ctx, str, offset, len) {
return withFont(_this, MIDP.Context2D, util.fromJavaString(str).slice(offset, offset + len));
});
var HCENTER = 1;
var VCENTER = 2;
@ -339,28 +321,27 @@
});
}
function withFont(font, c, str, cb) {
function withFont(font, c, str) {
c.font = font.css;
cb(c.measureText(str).width | 0, c);
return c.measureText(str).width | 0;
}
function withTextAnchor(g, c, anchor, x, y, str, cb) {
withClip(g, c, x, y, function(x, y) {
withFont(g.class.getField("I.currentFont.Ljavax/microedition/lcdui/Font;").get(g), c, str, function(w, c) {
c.textAlign = "left";
c.textBaseline = "top";
if (anchor & RIGHT)
x -= w;
if (anchor & HCENTER)
x -= (w/2)|0;
if (anchor & BOTTOM)
c.textBaseline = "bottom";
if (anchor & VCENTER)
c.textBaseline = "middle";
if (anchor & BASELINE)
c.textBaseline = "alphabetic";
cb(x, y, w);
});
var w = withFont(g.class.getField("I.currentFont.Ljavax/microedition/lcdui/Font;").get(g), c, str);
c.textAlign = "left";
c.textBaseline = "top";
if (anchor & RIGHT)
x -= w;
if (anchor & HCENTER)
x -= (w/2)|0;
if (anchor & BOTTOM)
c.textBaseline = "bottom";
if (anchor & VCENTER)
c.textBaseline = "middle";
if (anchor & BASELINE)
c.textBaseline = "alphabetic";
cb(x, y, w);
});
}

Просмотреть файл

@ -141,8 +141,8 @@ MIDP.messagesTBL = [
["satsa"]
];
Native["com/sun/midp/security/Permissions.getGroupMessages.(Ljava/lang/String;)[Ljava/lang/String;"] = function(ctx, stack) {
var name = util.fromJavaString(stack.pop());
Native.create("com/sun/midp/security/Permissions.getGroupMessages.(Ljava/lang/String;)[Ljava/lang/String;", function(ctx, jName) {
var name = util.fromJavaString(jName);
var list = null;
MIDP.groupTBL.forEach(function(e, n) {
if (e === name) {
@ -153,8 +153,8 @@ Native["com/sun/midp/security/Permissions.getGroupMessages.(Ljava/lang/String;)[
});
}
});
stack.push(list);
}
return list;
});
MIDP.membersTBL = [
["javax.microedition.io.Connector.http",
@ -209,8 +209,8 @@ MIDP.membersTBL = [
["javax.microedition.apdu.sat"],
];
Native["com/sun/midp/security/Permissions.loadGroupPermissions.(Ljava/lang/String;)[Ljava/lang/String;"] = function(ctx, stack) {
var name = util.fromJavaString(stack.pop());
Native.create("com/sun/midp/security/Permissions.loadGroupPermissions.(Ljava/lang/String;)[Ljava/lang/String;", function(ctx, jName) {
var name = util.fromJavaString(jName);
var list = null;
MIDP.groupTBL.forEach(function(e, n) {
if (e === name) {
@ -221,11 +221,10 @@ Native["com/sun/midp/security/Permissions.loadGroupPermissions.(Ljava/lang/Strin
});
}
});
stack.push(list);
}
return list;
});
Native["com/sun/midp/main/CommandState.restoreCommandState.(Lcom/sun/midp/main/CommandState;)V"] = function(ctx, stack) {
var state = stack.pop();
Native.create("com/sun/midp/main/CommandState.restoreCommandState.(Lcom/sun/midp/main/CommandState;)V", function(ctx, state) {
var suiteId = (MIDP.midletClassName === "internal") ? -1 : 1;
state.class.getField("I.suiteId.I").set(state, suiteId);
state.class.getField("I.midletClassName.Ljava/lang/String;").set(state, ctx.newString(MIDP.midletClassName));
@ -233,7 +232,7 @@ Native["com/sun/midp/main/CommandState.restoreCommandState.(Lcom/sun/midp/main/C
state.class.getField("I.arg0.Ljava/lang/String;").set(state, ctx.newString((args.length > 0) ? args[0] : ""));
state.class.getField("I.arg1.Ljava/lang/String;").set(state, ctx.newString((args.length > 1) ? args[1] : ""));
state.class.getField("I.arg2.Ljava/lang/String;").set(state, ctx.newString((args.length > 2) ? args[2] : ""));
}
});
MIDP.domainTBL = [
"manufacturer",
@ -244,13 +243,13 @@ MIDP.domainTBL = [
"maximum,unsecured",
];
Native["com/sun/midp/security/Permissions.loadDomainList.()[Ljava/lang/String;"] = function(ctx, stack) {
Native.create("com/sun/midp/security/Permissions.loadDomainList.()[Ljava/lang/String;", function(ctx) {
var list = ctx.newArray("[Ljava/lang/String;", MIDP.domainTBL.length);
MIDP.domainTBL.forEach(function (e, n) {
list[n] = ctx.newString(e);
});
stack.push(list);
}
return list;
});
MIDP.NEVER = 0;
MIDP.ALLOW = 1;
@ -296,84 +295,79 @@ MIDP.unidentifiedTBL = {
satsa: { max: MIDP.NEVER, default: MIDP.NEVER},
};
Native["com/sun/midp/security/Permissions.getDefaultValue.(Ljava/lang/String;Ljava/lang/String;)B"] = function(ctx, stack) {
var group = util.fromJavaString(stack.pop()), domain = util.fromJavaString(stack.pop());
Native.create("com/sun/midp/security/Permissions.getDefaultValue.(Ljava/lang/String;Ljava/lang/String;)B", function(ctx, domain, group) {
var allow = MIDP.NEVER;
switch (domain) {
switch (util.fromJavaString(domain)) {
case "manufacturer":
case "maximum":
case "operator":
allow = MIDP.ALLOW;
break;
case "identified_third_party":
allow = MIDP.identifiedTBL[group].default;
allow = MIDP.identifiedTBL[util.fromJavaString(group)].default;
break;
case "unidentified_third_party":
allow = MIDP.unidentifiedTBL[group].default;
allow = MIDP.unidentifiedTBL[util.fromJavaString(group)].default;
break;
}
stack.push(allow);
}
return allow;
});
Native["com/sun/midp/security/Permissions.getMaxValue.(Ljava/lang/String;Ljava/lang/String;)B"] = function(ctx, stack) {
var group = util.fromJavaString(stack.pop()), domain = util.fromJavaString(stack.pop());
Native.create("com/sun/midp/security/Permissions.getMaxValue.(Ljava/lang/String;Ljava/lang/String;)B", function(ctx, domain, group) {
var allow = MIDP.NEVER;
switch (domain) {
switch (util.fromJavaString(domain)) {
case "manufacturer":
case "maximum":
case "operator":
allow = MIDP.ALLOW;
break;
case "identified_third_party":
allow = MIDP.identifiedTBL[group].max;
allow = MIDP.identifiedTBL[util.fromJavaString(group)].max;
break;
case "unidentified_third_party":
allow = MIDP.unidentifiedTBL[group].max;
allow = MIDP.unidentifiedTBL[util.fromJavaString(group)].max;
break;
}
stack.push(allow);
}
return allow;
});
Native["com/sun/midp/security/Permissions.loadingFinished.()V"] = function(ctx, stack) {
Native.create("com/sun/midp/security/Permissions.loadingFinished.()V", function(ctx) {
console.warn("Permissions.loadingFinished.()V not implemented");
}
});
Native["com/sun/midp/main/MIDletSuiteUtils.getIsolateId.()I"] = function(ctx, stack) {
stack.push(ctx.runtime.isolate.id);
}
Native.create("com/sun/midp/main/MIDletSuiteUtils.getIsolateId.()I", function(ctx) {
return ctx.runtime.isolate.id;
});
Native["com/sun/midp/main/MIDletSuiteUtils.registerAmsIsolateId.()V"] = function(ctx, stack) {
Native.create("com/sun/midp/main/MIDletSuiteUtils.registerAmsIsolateId.()V", function(ctx) {
MIDP.AMSIsolateId = ctx.runtime.isolate.id;
}
});
Native["com/sun/midp/main/MIDletSuiteUtils.getAmsIsolateId.()I"] = function(ctx, stack) {
stack.push(MIDP.AMSIsolateId);
}
Native.create("com/sun/midp/main/MIDletSuiteUtils.getAmsIsolateId.()I", function(ctx) {
return MIDP.AMSIsolateId;
});
Native["com/sun/midp/main/MIDletSuiteUtils.isAmsIsolate.()Z"] = function(ctx, stack) {
stack.push((MIDP.AMSIsolateId == ctx.runtime.isolate.id) ? 1 : 0);
}
Native.create("com/sun/midp/main/MIDletSuiteUtils.isAmsIsolate.()Z", function(ctx) {
return MIDP.AMSIsolateId == ctx.runtime.isolate.id;
});
Native["com/sun/midp/main/MIDletSuiteUtils.vmBeginStartUp.(I)V"] = function(ctx, stack) {
var midletIsolateId = stack.pop();
Native.create("com/sun/midp/main/MIDletSuiteUtils.vmBeginStartUp.(I)V", function(ctx, midletIsolateId) {
// See DisplayContainer::createDisplayId, called by the LCDUIEnvironment constructor,
// called by CldcMIDletSuiteLoader::createSuiteEnvironment.
// The formula depens on the ID of the isolate that calls createDisplayId, that is
// the same isolate that calls vmBeginStartUp. So this is a good place to calculate
// the display ID.
MIDP.displayId = ((midletIsolateId & 0xff)<<24) | (1 & 0x00ffffff);
}
});
Native["com/sun/midp/main/MIDletSuiteUtils.vmEndStartUp.(I)V"] = function(ctx, stack) {
var midletIsolateId = stack.pop();
}
Native.create("com/sun/midp/main/MIDletSuiteUtils.vmEndStartUp.(I)V", function(ctx, midletIsolateId) {
});
Native["com/sun/midp/main/AppIsolateMIDletSuiteLoader.allocateReservedResources0.()Z"] = function(ctx, stack) {
stack.push(1);
}
Native.create("com/sun/midp/main/AppIsolateMIDletSuiteLoader.allocateReservedResources0.()Z", function(ctx) {
return true;
});
Native["com/sun/midp/main/Configuration.getProperty0.(Ljava/lang/String;)Ljava/lang/String;"] = function(ctx, stack) {
var key = stack.pop();
Native.create("com/sun/midp/main/Configuration.getProperty0.(Ljava/lang/String;)Ljava/lang/String;", function(ctx, key) {
var value;
switch (util.fromJavaString(key)) {
case "com.sun.midp.publickeystore.WebPublicKeyStore":
@ -414,60 +408,58 @@ Native["com/sun/midp/main/Configuration.getProperty0.(Ljava/lang/String;)Ljava/l
value = null;
break;
}
stack.push(value ? ctx.newString(value) : null);
}
return value ? value : null;
});
Native["com/sun/midp/chameleon/skins/resources/LoadedSkinData.beginReadingSkinFile.(Ljava/lang/String;)V"] = function(ctx, stack) {
var fileName = util.fromJavaString(stack.pop());
var data = CLASSES.loadFile(fileName);
Native.create("com/sun/midp/chameleon/skins/resources/LoadedSkinData.beginReadingSkinFile.(Ljava/lang/String;)V", function(ctx, fileName) {
var data = CLASSES.loadFile(util.fromJavaString(fileName));
if (!data)
ctx.raiseExceptionAndYield("java/io/IOException");
throw new JavaException("java/io/IOException");
MIDP.skinFileData = new DataView(data);
MIDP.skinFilePos = 0;
}
});
Native["com/sun/midp/chameleon/skins/resources/LoadedSkinData.readByteArray.(I)[B"] = function(ctx, stack) {
var len = stack.pop();
Native.create("com/sun/midp/chameleon/skins/resources/LoadedSkinData.readByteArray.(I)[B", function(ctx, len) {
if (!MIDP.skinFileData || (MIDP.skinFilePos + len) > MIDP.skinFileData.byteLength)
ctx.raiseExceptionAndYield("java/lang/IllegalStateException");
throw new JavaException("java/lang/IllegalStateException");
var bytes = ctx.newPrimitiveArray("B", len);
for (var n = 0; n < len; ++n) {
bytes[n] = MIDP.skinFileData.getUint8(MIDP.skinFilePos++);
}
stack.push(bytes);
}
return bytes;
});
Native["com/sun/midp/chameleon/skins/resources/LoadedSkinData.readIntArray.()[I"] = function(ctx, stack) {
Native.create("com/sun/midp/chameleon/skins/resources/LoadedSkinData.readIntArray.()[I", function(ctx) {
if (!MIDP.skinFileData || (MIDP.skinFilePos + 4) > MIDP.skinFileData.byteLength)
ctx.raiseExceptionAndYield("java/lang/IllegalStateException");
throw new JavaException("java/lang/IllegalStateException");
var len = MIDP.skinFileData.getInt32(MIDP.skinFilePos, true);
MIDP.skinFilePos += 4;
var ints = ctx.newPrimitiveArray("I", len);
for (var n = 0; n < len; ++n) {
if ((MIDP.skinFilePos + 4) > MIDP.skinFileData.byteLength)
ctx.raiseExceptionAndYield("java/lang/IllegalStateException");
throw new JavaException("java/lang/IllegalStateException");
ints[n] = MIDP.skinFileData.getInt32(MIDP.skinFilePos, true);
MIDP.skinFilePos += 4;
}
stack.push(ints);
}
return ints;
});
MIDP.STRING_ENCODING_USASCII = 0;
MIDP.STRING_ENCODING_UTF8 = 1;
Native["com/sun/midp/chameleon/skins/resources/LoadedSkinData.readStringArray.()[Ljava/lang/String;"] = function(ctx, stack) {
Native.create("com/sun/midp/chameleon/skins/resources/LoadedSkinData.readStringArray.()[Ljava/lang/String;", function(ctx) {
if (!MIDP.skinFileData || (MIDP.skinFilePos + 4) > MIDP.skinFileData.byteLength)
ctx.raiseExceptionAndYield("java/lang/IllegalStateException");
throw new JavaException("java/lang/IllegalStateException");
var len = MIDP.skinFileData.getInt32(MIDP.skinFilePos, true);
MIDP.skinFilePos += 4;
var strings = ctx.newArray("[Ljava/lang/String;", len);
for (var n = 0; n < len; ++n) {
if ((MIDP.skinFilePos + 2) > MIDP.skinFileData.byteLength)
ctx.raiseExceptionAndYield("java/lang/IllegalStateException");
throw new JavaException("java/lang/IllegalStateException");
var strLen = MIDP.skinFileData.getUint8(MIDP.skinFilePos++);
var strEnc = MIDP.skinFileData.getUint8(MIDP.skinFilePos++);
if ((MIDP.skinFilePos + strLen) > MIDP.skinFileData.byteLength)
ctx.raiseExceptionAndYield("java/lang/IllegalStateException");
throw new JavaException("java/lang/IllegalStateException");
var bytes = new Uint8Array(MIDP.skinFileData.buffer).subarray(MIDP.skinFilePos, MIDP.skinFilePos + strLen);
MIDP.skinFilePos += strLen;
var str;
@ -478,60 +470,60 @@ Native["com/sun/midp/chameleon/skins/resources/LoadedSkinData.readStringArray.()
} else if (strEnc === MIDP.STRING_ENCODING_UTF8) {
str = util.decodeUtf8(bytes);
} else {
ctx.raiseExceptionAndYield("java/lang/IllegalStateException");
throw new JavaException("java/lang/IllegalStateException");
}
strings[n] = ctx.newString(str);
}
stack.push(strings);
}
return strings;
});
Native["com/sun/midp/chameleon/skins/resources/LoadedSkinData.finishReadingSkinFile.()I"] = function(ctx, stack) {
Native.create("com/sun/midp/chameleon/skins/resources/LoadedSkinData.finishReadingSkinFile.()I", function(ctx) {
MIDP.skinFileData = null;
MIDP.skinFilePos = 0;
stack.push(0);
}
return 0;
});
MIDP.sharedPool = null;
MIDP.sharedSkinData = null;
Native["com/sun/midp/chameleon/skins/resources/SkinResourcesImpl.shareResourcePool.(Ljava/lang/Object;)V"] = function(ctx, stack) {
MIDP.sharedPool = stack.pop();
}
Native.create("com/sun/midp/chameleon/skins/resources/SkinResourcesImpl.shareResourcePool.(Ljava/lang/Object;)V", function(ctx, pool) {
MIDP.sharedPool = pool;
});
Native["com/sun/midp/chameleon/skins/resources/SkinResourcesImpl.getSharedResourcePool.()Ljava/lang/Object;"] = function(ctx, stack) {
stack.push(MIDP.sharedPool);
}
Native.create("com/sun/midp/chameleon/skins/resources/SkinResourcesImpl.getSharedResourcePool.()Ljava/lang/Object;", function(ctx) {
return MIDP.sharedPool;
});
Native["com/sun/midp/chameleon/skins/resources/SkinResourcesImpl.shareSkinData.(Ljava/lang/Object;)V"] = function(ctx, stack) {
MIDP.sharedSkinData = stack.pop();
}
Native.create("com/sun/midp/chameleon/skins/resources/SkinResourcesImpl.shareSkinData.(Ljava/lang/Object;)V", function(ctx, skinData) {
MIDP.sharedSkinData = skinData;
});
Native["com/sun/midp/chameleon/skins/resources/SkinResourcesImpl.getSharedSkinData.()Ljava/lang/Object;"] = function(ctx, stack) {
stack.push(MIDP.sharedSkinData);
}
Native.create("com/sun/midp/chameleon/skins/resources/SkinResourcesImpl.getSharedSkinData.()Ljava/lang/Object;", function(ctx) {
return MIDP.sharedSkinData;
});
Native["com/sun/midp/chameleon/skins/resources/SkinResourcesImpl.ifLoadAllResources0.()Z"] = function(ctx, stack) {
stack.push(0);
}
Native.create("com/sun/midp/chameleon/skins/resources/SkinResourcesImpl.ifLoadAllResources0.()Z", function(ctx) {
return false;
});
Native["com/sun/midp/util/ResourceHandler.loadRomizedResource0.(Ljava/lang/String;)[B"] = function(ctx, stack) {
var fileName = "assets/0/" + util.fromJavaString(stack.pop()).replace("_", ".").replace("_png", ".png");
Native.create("com/sun/midp/util/ResourceHandler.loadRomizedResource0.(Ljava/lang/String;)[B", function(ctx, file) {
var fileName = "assets/0/" + util.fromJavaString(file).replace("_", ".").replace("_png", ".png");
var data = CLASSES.loadFile(fileName);
if (!data) {
console.error("ResourceHandler::loadRomizedResource0: file " + fileName + " not found");
ctx.raiseExceptionAndYield("java/io/IOException");
throw new JavaException("java/io/IOException");
}
var len = data.byteLength;
var bytes = ctx.newPrimitiveArray("B", len);
var src = new Uint8Array(data);
for (var n = 0; n < bytes.byteLength; ++n)
bytes[n] = src[n];
stack.push(bytes);
}
return bytes;
});
Native["com/sun/midp/chameleon/layers/SoftButtonLayer.isNativeSoftButtonLayerSupported0.()Z"] = function(ctx, stack) {
stack.push(0);
}
Native.create("com/sun/midp/chameleon/layers/SoftButtonLayer.isNativeSoftButtonLayerSupported0.()Z", function(ctx) {
return false;
});
MIDP.Context2D = (function() {
var c = document.getElementById("canvas");
@ -589,63 +581,52 @@ MIDP.Context2D = (function() {
return c.getContext("2d");
})();
Native["com/sun/midp/midletsuite/MIDletSuiteStorage.loadSuitesIcons0.()I"] = function(ctx, stack) {
stack.push(0);
}
Native.create("com/sun/midp/midletsuite/MIDletSuiteStorage.loadSuitesIcons0.()I", function(ctx) {
return 0;
});
Native["com/sun/midp/midletsuite/MIDletSuiteStorage.suiteExists.(I)Z"] = function(ctx, stack) {
var id = stack.pop(), _this = stack.pop();
stack.push(id <= 1 ? 1 : 0);
}
Native.create("com/sun/midp/midletsuite/MIDletSuiteStorage.suiteExists.(I)Z", function(ctx, id) {
return id <= 1;
});
Native["com/sun/midp/midletsuite/MIDletSuiteStorage.suiteIdToString.(I)Ljava/lang/String;"] = function(ctx, stack) {
var id = stack.pop();
stack.push(ctx.newString(id.toString()));
}
Native["com/sun/midp/midletsuite/MIDletSuiteStorage.getMidletSuiteStorageId.(I)I"] = function(ctx, stack) {
var suiteId = stack.pop();
Native.create("com/sun/midp/midletsuite/MIDletSuiteStorage.suiteIdToString.(I)Ljava/lang/String;", function(ctx, id) {
return id.toString();
});
Native.create("com/sun/midp/midletsuite/MIDletSuiteStorage.getMidletSuiteStorageId.(I)I", function(ctx, suiteId) {
// We should be able to use the same storage ID for all MIDlet suites.
stack.push(0); // storageId
}
return 0; // storageId
});
Native["com/sun/midp/midletsuite/MIDletSuiteStorage.getMidletSuiteJarPath.(I)Ljava/lang/String;"] = function(ctx, stack) {
var id = stack.pop(), _this = stack.pop();
stack.push(ctx.newString(""));
}
Native.create("com/sun/midp/midletsuite/MIDletSuiteStorage.getMidletSuiteJarPath.(I)Ljava/lang/String;", function(ctx, id) {
return "";
});
Native["com/sun/midp/midletsuite/MIDletSuiteImpl.lockMIDletSuite.(IZ)V"] = function(ctx, stack) {
var lock = stack.pop(), id = stack.pop();
Native.create("com/sun/midp/midletsuite/MIDletSuiteImpl.lockMIDletSuite.(IZ)V", function(ctx, id, lock) {
console.warn("MIDletSuiteImpl.lockMIDletSuite.(IZ)V not implemented (" + id + ", " + lock + ")");
}
});
Native["com/sun/midp/midletsuite/MIDletSuiteImpl.unlockMIDletSuite.(I)V"] = function(ctx, stack) {
var suiteId = stack.pop();
Native.create("com/sun/midp/midletsuite/MIDletSuiteImpl.unlockMIDletSuite.(I)V", function(ctx, suiteId) {
console.warn("MIDletSuiteImpl.unlockMIDletSuite.(I)V not implemented (" + suiteId + ")");
}
});
Native["com/sun/midp/midletsuite/SuiteSettings.load.()V"] = function(ctx, stack) {
var suiteSettings = stack.pop();
suiteSettings.class.getField("I.pushInterruptSetting.B").set(suiteSettings, 1);
Native.create("com/sun/midp/midletsuite/SuiteSettings.load.()V", function(ctx) {
this.class.getField("I.pushInterruptSetting.B").set(this, 1);
console.warn("com/sun/midp/midletsuite/SuiteSettings.load.()V incomplete");
}
});
Native["com/sun/midp/midletsuite/SuiteSettings.save0.(IBI[B)V"] = function(ctx, stack) {
var permissions = stack.pop(), pushOptions = stack.pop(), pushInterruptSetting = stack.pop(), suiteId = stack.pop(), _this = stack.pop();
Native.create("com/sun/midp/midletsuite/SuiteSettings.save0.(IBI[B)V", function(ctx, suiteId, pushInterruptSetting, pushOptions, permissions) {
console.warn("SuiteSettings.save0.(IBI[B)V not implemented (" +
suiteId + ", " + pushInterruptSetting + ", " + pushOptions + ", " + permissions + ")");
}
});
Native["com/sun/midp/midletsuite/InstallInfo.load.()V"] = function(ctx, stack) {
var _this = stack.pop();
Native.create("com/sun/midp/midletsuite/InstallInfo.load.()V", function(ctx) {
// The MIDlet has to be trusted for opening SSL connections using port 443.
_this.class.getField("I.trusted.Z").set(_this, 1);
this.class.getField("I.trusted.Z").set(this, 1);
console.warn("com/sun/midp/midletsuite/InstallInfo.load.()V incomplete");
}
});
Native["com/sun/midp/midletsuite/SuiteProperties.load.()[Ljava/lang/String;"] = function(ctx, stack) {
var _this = stack.pop();
Native.create("com/sun/midp/midletsuite/SuiteProperties.load.()[Ljava/lang/String;", function(ctx) {
var keys = Object.keys(MIDP.manifest);
var arr = ctx.newArray("[Ljava/lang/String;", keys.length * 2);
var i = 0;
@ -653,21 +634,20 @@ Native["com/sun/midp/midletsuite/SuiteProperties.load.()[Ljava/lang/String;"] =
arr[i++] = ctx.newString(key);
arr[i++] = ctx.newString(MIDP.manifest[key]);
});
stack.push(arr);
}
return arr;
});
Native["javax/microedition/lcdui/SuiteImageCacheImpl.loadAndCreateImmutableImageDataFromCache0.(Ljavax/microedition/lcdui/ImageData;ILjava/lang/String;)Z"] = function(ctx, stack) {
var fileName = util.fromJavaString(stack.pop()), suiteId = stack.pop(), imageData = stack.pop(), _this = stack.pop();
stack.push(0);
Native.create("javax/microedition/lcdui/SuiteImageCacheImpl.loadAndCreateImmutableImageDataFromCache0.(Ljavax/microedition/lcdui/ImageData;ILjava/lang/String;)Z", function(ctx, imageData, suiteId, fileName) {
console.warn("SuiteImageCacheImpl.loadAndCreateImmutableImageDataFromCache0.(L...ImageData;IL...String;)Z " +
"not implemented (" + imageData + ", " + suiteId + ", " + fileName + ")");
}
"not implemented (" + imageData + ", " + suiteId + ", " + util.fromJavaString(fileName) + ")");
return false;
});
MIDP.InterIsolateMutexes = [];
MIDP.LastInterIsolateMutexID = -1;
Native["com/sun/midp/util/isolate/InterIsolateMutex.getID0.(Ljava/lang/String;)I"] = function(ctx, stack) {
var name = util.fromJavaString(stack.pop());
Native.create("com/sun/midp/util/isolate/InterIsolateMutex.getID0.(Ljava/lang/String;)I", function(ctx, jName) {
var name = util.fromJavaString(jName);
var mutex;
for (var i = 0; i < MIDP.InterIsolateMutexes.length; i++) {
@ -686,12 +666,10 @@ Native["com/sun/midp/util/isolate/InterIsolateMutex.getID0.(Ljava/lang/String;)I
MIDP.InterIsolateMutexes.push(mutex);
}
stack.push(mutex.id);
}
Native["com/sun/midp/util/isolate/InterIsolateMutex.lock0.(I)V"] = function(ctx, stack) {
var id = stack.pop();
return mutex.id;
});
Native.create("com/sun/midp/util/isolate/InterIsolateMutex.lock0.(I)V", function(ctx, id) {
var mutex;
for (var i = 0; i < MIDP.InterIsolateMutexes.length; i++) {
if (MIDP.InterIsolateMutexes[i].id == id) {
@ -701,7 +679,7 @@ Native["com/sun/midp/util/isolate/InterIsolateMutex.lock0.(I)V"] = function(ctx,
}
if (!mutex) {
ctx.raiseExceptionAndYield("java/lang/IllegalStateException", "Invalid mutex ID");
throw new JavaException("java/lang/IllegalStateException", "Invalid mutex ID");
}
if (!mutex.locked) {
@ -709,7 +687,7 @@ Native["com/sun/midp/util/isolate/InterIsolateMutex.lock0.(I)V"] = function(ctx,
mutex.holder = ctx.runtime.isolate.id;
} else {
if (mutex.holder == ctx.runtime.isolate.id) {
ctx.raiseExceptionAndYield("java/lang/RuntimeException", "Attempting to lock mutex twice within the same Isolate");
throw new JavaException("java/lang/RuntimeException", "Attempting to lock mutex twice within the same Isolate");
}
mutex.waiting.push(function() {
@ -720,11 +698,9 @@ Native["com/sun/midp/util/isolate/InterIsolateMutex.lock0.(I)V"] = function(ctx,
throw VM.Pause;
}
}
Native["com/sun/midp/util/isolate/InterIsolateMutex.unlock0.(I)V"] = function(ctx, stack) {
var id = stack.pop();
});
Native.create("com/sun/midp/util/isolate/InterIsolateMutex.unlock0.(I)V", function(ctx, id) {
var mutex;
for (var i = 0; i < MIDP.InterIsolateMutexes.length; i++) {
if (MIDP.InterIsolateMutexes[i].id == id) {
@ -734,15 +710,15 @@ Native["com/sun/midp/util/isolate/InterIsolateMutex.unlock0.(I)V"] = function(ct
}
if (!mutex) {
ctx.raiseExceptionAndYield("java/lang/IllegalStateException", "Invalid mutex ID");
throw new JavaException("java/lang/IllegalStateException", "Invalid mutex ID");
}
if (!mutex.locked) {
ctx.raiseExceptionAndYield("java/lang/RuntimeException", "Mutex is not locked");
throw new JavaException("java/lang/RuntimeException", "Mutex is not locked");
}
if (mutex.holder !== ctx.runtime.isolate.id) {
ctx.raiseExceptionAndYield("java/lang/RuntimeException", "Mutex is locked by different Isolate");
throw new JavaException("java/lang/RuntimeException", "Mutex is locked by different Isolate");
}
mutex.locked = false;
@ -751,7 +727,7 @@ Native["com/sun/midp/util/isolate/InterIsolateMutex.unlock0.(I)V"] = function(ct
if (firstWaiting) {
firstWaiting();
}
}
});
// The foreground isolate will get the user events (keypresses, etc.)
MIDP.foregroundIsolateId;
@ -822,22 +798,21 @@ window.addEventListener("keypress", function(ev) {
MIDP.keyPress(ev.which);
});
Native["com/sun/midp/events/EventQueue.getNativeEventQueueHandle.()I"] = function(ctx, stack) {
var _this = stack.pop();
stack.push(0);
}
Native.create("com/sun/midp/events/EventQueue.getNativeEventQueueHandle.()I", function(ctx) {
return 0;
});
Native["com/sun/midp/events/EventQueue.resetNativeEventQueue.()V"] = function(ctx, stack) {
var _this = stack.pop();
Native.create("com/sun/midp/events/EventQueue.resetNativeEventQueue.()V", function(ctx) {
console.warn("EventQueue.resetNativeEventQueue.()V not implemented");
}
});
Native["com/sun/midp/events/EventQueue.sendNativeEventToIsolate.(Lcom/sun/midp/events/NativeEvent;I)V"] = function(ctx, stack) {
var isolateId = stack.pop(), obj = stack.pop(), _this = stack.pop();
Native.create("com/sun/midp/events/EventQueue.sendNativeEventToIsolate.(Lcom/sun/midp/events/NativeEvent;I)V",
function(ctx, obj, isolateId) {
MIDP.sendEvent(obj, isolateId);
}
});
Native["com/sun/midp/events/NativeEventMonitor.waitForNativeEvent.(Lcom/sun/midp/events/NativeEvent;)I"] = function(ctx, stack) {
Native.create("com/sun/midp/events/NativeEventMonitor.waitForNativeEvent.(Lcom/sun/midp/events/NativeEvent;)I",
function(ctx) {
var isolateId = ctx.runtime.isolate.id;
if (!MIDP.nativeEventQueues[isolateId]) {
@ -849,23 +824,20 @@ Native["com/sun/midp/events/NativeEventMonitor.waitForNativeEvent.(Lcom/sun/midp
throw VM.Pause;
}
MIDP.deliverWaitForNativeEventResult(ctx, isolateId);
}
});
Native["com/sun/midp/events/NativeEventMonitor.readNativeEvent.(Lcom/sun/midp/events/NativeEvent;)Z"] = function(ctx, stack) {
var obj = stack.pop();
Native.create("com/sun/midp/events/NativeEventMonitor.readNativeEvent.(Lcom/sun/midp/events/NativeEvent;)Z",
function(ctx, obj) {
if (!MIDP.nativeEventQueues[ctx.runtime.isolate.id].length) {
stack.push(0);
return;
return false;
}
MIDP.copyEvent(obj, ctx.runtime.isolate.id);
stack.push(1);
}
return true;
});
MIDP.localizedStrings = new Map();
Native["com/sun/midp/l10n/LocalizedStringsBase.getContent.(I)Ljava/lang/String;"] = function(ctx, stack) {
var id = stack.pop();
Native.create("com/sun/midp/l10n/LocalizedStringsBase.getContent.(I)Ljava/lang/String;", function(ctx, id) {
var classInfo = CLASSES.getClass("com/sun/midp/i18n/ResourceConstants");
var key;
classInfo.fields.forEach(function(field) {
@ -874,13 +846,13 @@ Native["com/sun/midp/l10n/LocalizedStringsBase.getContent.(I)Ljava/lang/String;"
});
if (!key) {
ctx.raiseExceptionAndYield("java/io/IOException");
throw new JavaException("java/io/IOException");
}
if (MIDP.localizedStrings.size === 0) {
var data = CLASSES.loadFileFromJar("java/classes.jar", "assets/0/en-US.xml");
if (!data)
ctx.raiseExceptionAndYield("java/io/IOException");
throw new JavaException("java/io/IOException");
var text = util.decodeUtf8(data);
var xml = new window.DOMParser().parseFromString(text, "text/xml");
@ -895,45 +867,41 @@ Native["com/sun/midp/l10n/LocalizedStringsBase.getContent.(I)Ljava/lang/String;"
var value = MIDP.localizedStrings.get(key);
if (!value) {
ctx.raiseExceptionAndYield("java/lang/IllegalStateException");
throw new JavaException("java/lang/IllegalStateException");
}
stack.push(ctx.newString(value));
}
return value;
});
Native["javax/microedition/lcdui/Display.drawTrustedIcon0.(IZ)V"] = function(ctx, stack) {
var drawTrusted = stack.pop(), displayId = stack.pop(), _this = stack.pop();
Native.create("javax/microedition/lcdui/Display.drawTrustedIcon0.(IZ)V", function(ctx, displayId, drawTrusted) {
console.warn("Display.drawTrustedIcon0.(IZ)V not implemented (" + displayId + ", " + drawTrusted + ")");
}
});
Native["com/sun/midp/events/EventQueue.sendShutdownEvent.()V"] = function(ctx, stack) {
var _this = stack.pop();
Native.create("com/sun/midp/events/EventQueue.sendShutdownEvent.()V", function(ctx) {
var obj = ctx.newObject(CLASSES.getClass("com/sun/midp/events/NativeEvent"));
obj.class.getField("I.type.I").set(obj, MIDP.EVENT_QUEUE_SHUTDOWN);
MIDP.sendEvent(obj);
}
});
Native["com/sun/midp/main/CommandState.saveCommandState.(Lcom/sun/midp/main/CommandState;)V"] = function(ctx, stack) {
var commandState = stack.pop();
Native.create("com/sun/midp/main/CommandState.saveCommandState.(Lcom/sun/midp/main/CommandState;)V", function(ctx, commandState) {
console.warn("CommandState.saveCommandState.(L...CommandState;)V not implemented (" + commandState + ")");
}
});
Native["com/sun/midp/main/CommandState.exitInternal.(I)V"] = function(ctx, stack) {
console.info("Exit: " + stack.pop());
Native.create("com/sun/midp/main/CommandState.exitInternal.(I)V", function(ctx, exit) {
console.info("Exit: " + exit);
throw VM.Pause;
}
});
Native["com/sun/midp/suspend/SuspendSystem$MIDPSystem.allMidletsKilled.()Z"] = function(ctx, stack) {
var _this = stack.pop();
stack.push(0);
Native.create("com/sun/midp/suspend/SuspendSystem$MIDPSystem.allMidletsKilled.()Z", function(ctx) {
console.warn("SuspendSystem$MIDPSystem.allMidletsKilled.()Z not implemented");
}
return false;
});
Native["com/sun/midp/chameleon/input/InputModeFactory.getInputModeIds.()[I"] = function(ctx, stack) {
Native.create("com/sun/midp/chameleon/input/InputModeFactory.getInputModeIds.()[I", function(ctx) {
var ids = ctx.newPrimitiveArray("I", 1);
ids[0] = 1; // KEYBOARD_INPUT_MODE
stack.push(ids);
}
return ids;
});
/* We don't care about the system keys SELECT,
SOFT_BUTTON1, SOFT_BUTTON2, DEBUG_TRACE1, CLAMSHELL_OPEN, CLAMSHELL_CLOSE,
@ -952,9 +920,9 @@ MIDP.systemKeyMap = {
114: MIDP.SYSTEM_KEY_END, // F3
};
Native["javax/microedition/lcdui/KeyConverter.getSystemKey.(I)I"] = function(ctx, stack) {
stack.push(MIDP.systemKeyMap[stack.pop()] || 0);
}
Native.create("javax/microedition/lcdui/KeyConverter.getSystemKey.(I)I", function(ctx, key) {
return MIDP.systemKeyMap[key] || 0;
});
MIDP.keyMap = {
1: 119, // UP
@ -968,9 +936,9 @@ MIDP.keyMap = {
12: 99, // GAME_D
};
Native["javax/microedition/lcdui/KeyConverter.getKeyCode.(I)I"] = function(ctx, stack) {
stack.push(MIDP.keyMap[stack.pop()] || 0);
}
Native.create("javax/microedition/lcdui/KeyConverter.getKeyCode.(I)I", function(ctx, key) {
return MIDP.keyMap[key] || 0;
});
MIDP.keyNames = {
119: "Up",
@ -984,10 +952,9 @@ MIDP.keyNames = {
99: "Mail",
};
Native["javax/microedition/lcdui/KeyConverter.getKeyName.(I)Ljava/lang/String;"] = function(ctx, stack) {
var keyCode = stack.pop();
stack.push(ctx.newString((keyCode in MIDP.keyNames) ? MIDP.keyNames[keyCode] : String.fromCharCode(keyCode)));
}
Native.create("javax/microedition/lcdui/KeyConverter.getKeyName.(I)Ljava/lang/String;", function(ctx, keyCode) {
return (keyCode in MIDP.keyNames) ? MIDP.keyNames[keyCode] : String.fromCharCode(keyCode);
});
MIDP.gameKeys = {
119: 1, // UP
@ -1001,26 +968,22 @@ MIDP.gameKeys = {
99: 12 // GAME_D
};
Native["javax/microedition/lcdui/KeyConverter.getGameAction.(I)I"] = function(ctx, stack) {
var keyCode = stack.pop();
stack.push(MIDP.gameKeys[keyCode] || 0);
}
Native.create("javax/microedition/lcdui/KeyConverter.getGameAction.(I)I", function(ctx, keyCode) {
return MIDP.gameKeys[keyCode] || 0;
});
Native["javax/microedition/lcdui/game/GameCanvas.setSuppressKeyEvents.(Ljavax/microedition/lcdui/Canvas;Z)V"] = function(ctx, stack) {
var suppressKeyEvents = stack.pop(), canvas = stack.pop(), _this = stack.pop();
Native.create("javax/microedition/lcdui/game/GameCanvas.setSuppressKeyEvents.(Ljavax/microedition/lcdui/Canvas;Z)V", function(ctx, canvas, suppressKeyEvents) {
MIDP.suppressKeyEvents = suppressKeyEvents;
}
});
Native["com/sun/midp/main/MIDletProxyList.resetForegroundInNativeState.()V"] = function(ctx, stack) {
var _this = stack.pop();
Native.create("com/sun/midp/main/MIDletProxyList.resetForegroundInNativeState.()V", function(ctx) {
MIDP.displayId = -1;
}
});
Native["com/sun/midp/main/MIDletProxyList.setForegroundInNativeState.(II)V"] = function(ctx, stack) {
var displayId = stack.pop(), isolateId = stack.pop(), _this = stack.pop();
Native.create("com/sun/midp/main/MIDletProxyList.setForegroundInNativeState.(II)V", function(ctx, isolateId, displayId) {
MIDP.displayId = displayId;
MIDP.foregroundIsolateId = isolateId;
}
});
MIDP.ConnectionRegistry = {
// The lastRegistrationId is in common between alarms and push notifications
@ -1076,10 +1039,8 @@ Native["com/sun/midp/io/j2me/push/ConnectionRegistry.poll0.(J)I"] = function(ctx
throw VM.Pause;
}
Native["com/sun/midp/io/j2me/push/ConnectionRegistry.add0.(Ljava/lang/String;)I"] = function(ctx, stack) {
var connection = util.fromJavaString(stack.pop());
var values = connection.split(',');
Native.create("com/sun/midp/io/j2me/push/ConnectionRegistry.add0.(Ljava/lang/String;)I", function(ctx, connection) {
var values = util.fromJavaString(connection).split(',');
console.warn("ConnectionRegistry.add0.(IL...String;)I isn't completely implemented");
@ -1090,11 +1051,11 @@ Native["com/sun/midp/io/j2me/push/ConnectionRegistry.add0.(Ljava/lang/String;)I"
suiteId: values[3]
});
stack.push(0);
}
return 0;
});
Native["com/sun/midp/io/j2me/push/ConnectionRegistry.addAlarm0.([BJ)J"] = function(ctx, stack) {
var time = stack.pop2().toNumber(), midlet = util.decodeUtf8(stack.pop());
Native.create("com/sun/midp/io/j2me/push/ConnectionRegistry.addAlarm0.([BJ)J", function(ctx, jMidlet, jTime, _) {
var time = jTime.toNumber(), midlet = util.decodeUtf8(jMidlet);
var lastAlarm = 0;
var id = null;
@ -1131,12 +1092,10 @@ Native["com/sun/midp/io/j2me/push/ConnectionRegistry.addAlarm0.([BJ)J"] = functi
}, relativeTime);
}
stack.push2(Long.fromNumber(lastAlarm));
}
Native["com/sun/midp/io/j2me/push/ConnectionRegistry.getMIDlet0.(I[BI)I"] = function(ctx, stack) {
var entrysz = stack.pop(), regentry = stack.pop(), handle = stack.pop();
return Long.fromNumber(lastAlarm);
});
Native.create("com/sun/midp/io/j2me/push/ConnectionRegistry.getMIDlet0.(I[BI)I", function(ctx, handle, regentry, entrysz) {
var reg;
var alarms = MIDP.ConnectionRegistry.alarms;
for (var i = 0; i < alarms.length; i++) {
@ -1155,9 +1114,8 @@ Native["com/sun/midp/io/j2me/push/ConnectionRegistry.getMIDlet0.(I[BI)I"] = func
}
if (!reg) {
console.warn("getMIDlet0 returns -1, this should never happen");
stack.push(-1);
return;
console.error("getMIDlet0 returns -1, this should never happen");
return -1;
}
var str;
@ -1173,61 +1131,52 @@ Native["com/sun/midp/io/j2me/push/ConnectionRegistry.getMIDlet0.(I[BI)I"] = func
}
regentry[str.length] = 0;
stack.push(0);
}
return 0;
});
Native["com/sun/midp/io/j2me/push/ConnectionRegistry.checkInByMidlet0.(ILjava/lang/String;)V"] = function(ctx, stack) {
var className = stack.pop(), suiteId = stack.pop();
Native.create("com/sun/midp/io/j2me/push/ConnectionRegistry.checkInByMidlet0.(ILjava/lang/String;)V", function(ctx, suiteId, className) {
console.warn("ConnectionRegistry.checkInByMidlet0.(IL...String;)V not implemented (" +
suiteId + ", " + className + ")");
}
});
Native["com/sun/midp/io/j2me/push/ConnectionRegistry.checkInByName0.([B)I"] = function(ctx, stack) {
var name = util.decodeUtf8(stack.pop());
Native.create("com/sun/midp/io/j2me/push/ConnectionRegistry.checkInByName0.([B)I", function(ctx, name) {
console.warn("ConnectionRegistry.checkInByName0.([B)V not implemented (" +
name + ")");
stack.push(0);
}
util.decodeUtf8(name) + ")");
return 0;
});
Native["com/nokia/mid/ui/gestures/GestureInteractiveZone.isSupported.(I)Z"] = function(ctx, stack) {
var gestureEventIdentity = stack.pop();
stack.push(0);
Native.create("com/nokia/mid/ui/gestures/GestureInteractiveZone.isSupported.(I)Z", function(ctx, gestureEventIdentity) {
console.warn("GestureInteractiveZone.isSupported.(I)Z not implemented (" + gestureEventIdentity + ")");
}
return false;
});
Native["com/sun/midp/security/SecurityHandler.checkPermission0.(II)Z"] = function(ctx, stack) {
var permission = stack.pop(), suiteId = stack.pop(), _this = stack.pop();
stack.push(1);
}
Native.create("com/sun/midp/security/SecurityHandler.checkPermission0.(II)Z", function(ctx, suiteId, permission) {
return true;
});
Native["com/sun/midp/security/SecurityHandler.checkPermissionStatus0.(II)I"] = function(ctx, stack) {
var permission = stack.pop(), suiteId = stack.pop(), _this = stack.pop();
stack.push(1);
}
Native.create("com/sun/midp/security/SecurityHandler.checkPermissionStatus0.(II)I", function(ctx, suiteId, permission) {
return 1;
});
Native["com/sun/midp/io/NetworkConnectionBase.initializeInternal.()V"] = function(ctx, stack) {
Native.create("com/sun/midp/io/NetworkConnectionBase.initializeInternal.()V", function(ctx) {
console.warn("NetworkConnectionBase.initializeInternal.()V not implemented");
}
});
Native["com/sun/j2me/content/RegistryStore.init.()Z"] = function(ctx, stack) {
var _this = stack.pop();
Native.create("com/sun/j2me/content/RegistryStore.init.()Z", function(ctx) {
console.warn("com/sun/j2me/content/RegistryStore.init.()Z not implemented");
stack.push(1);
}
return true;
});
Native["com/sun/j2me/content/RegistryStore.forSuite0.(I)Ljava/lang/String;"] = function(ctx, stack) {
var suiteID = stack.pop(), _this = stack.pop();
Native.create("com/sun/j2me/content/RegistryStore.forSuite0.(I)Ljava/lang/String;", function(ctx, suiteID) {
console.warn("com/sun/j2me/content/RegistryStore.forSuite0.(I)Ljava/lang/String; not implemented");
stack.push(ctx.newString(""));
}
return "";
});
Native["com/sun/j2me/content/AppProxy.isInSvmMode.()Z"] = function(ctx, stack) {
var _this = stack.pop();
Native.create("com/sun/j2me/content/AppProxy.isInSvmMode.()Z", function(ctx) {
console.warn("com/sun/j2me/content/AppProxy.isInSvmMode.()Z not implemented");
stack.push(0);
}
return false;
});
Native["com/sun/j2me/content/InvocationStore.setCleanup0.(ILjava/lang/String;Z)V"] = function(ctx, stack) {
var cleanup = stack.pop(), className = util.fromJavaString(stack.pop()), suiteID = stack.pop();
Native.create("com/sun/j2me/content/InvocationStore.setCleanup0.(ILjava/lang/String;Z)V", function(ctx, suiteID, className, cleanup) {
console.warn("com/sun/j2me/content/InvocationStore.setCleanup0.(ILjava/lang/String;Z)V not implemented");
}
});

Просмотреть файл

@ -52,44 +52,41 @@ Socket.prototype.close = function() {
this.sender({ type: "close" });
}
Native["com/sun/midp/io/j2me/socket/Protocol.open0.([BI)V"] = function(ctx, stack) {
var port = stack.pop(), ipBytes = stack.pop(), _this = stack.pop();
// console.log("Protocol.open0: " + _this.host + ":" + port);
Native.create("com/sun/midp/io/j2me/socket/Protocol.open0.([BI)V", function(ctx, ipBytes, port) {
this.socket = new Socket(this.host, port);
_this.socket = new Socket(_this.host, port);
this.options = {};
this.options[SOCKET_OPT.DELAY] = 1;
this.options[SOCKET_OPT.LINGER] = 0;
this.options[SOCKET_OPT.KEEPALIVE] = 1;
this.options[SOCKET_OPT.RCVBUF] = 8192;
this.options[SOCKET_OPT.SNDBUF] = 8192;
_this.options = {};
_this.options[SOCKET_OPT.DELAY] = 1;
_this.options[SOCKET_OPT.LINGER] = 0;
_this.options[SOCKET_OPT.KEEPALIVE] = 1;
_this.options[SOCKET_OPT.RCVBUF] = 8192;
_this.options[SOCKET_OPT.SNDBUF] = 8192;
this.data = new Uint8Array();
this.waitingData = null;
_this.data = new Uint8Array();
_this.waitingData = null;
_this.socket.onopen = function() {
this.socket.onopen = function() {
ctx.resume();
}
_this.socket.onerror = function(message) {
this.socket.onerror = function(message) {
ctx.raiseException("java/io/IOException", message.error);
ctx.resume();
}
_this.socket.ondata = function(message) {
var newArray = new Uint8Array(_this.data.byteLength + message.data.length);
newArray.set(_this.data);
newArray.set(message.data, _this.data.byteLength);
_this.data = newArray;
this.socket.ondata = (function(message) {
var newArray = new Uint8Array(this.data.byteLength + message.data.length);
newArray.set(this.data);
newArray.set(message.data, this.data.byteLength);
this.data = newArray;
if (_this.waitingData) {
_this.waitingData();
if (this.waitingData) {
this.waitingData();
}
}
}).bind(this);
throw VM.Pause;
}
});
Native.create("com/sun/midp/io/j2me/socket/Protocol.available0.()I", function(ctx) {
return this.data.byteLength;
@ -160,28 +157,26 @@ Native.create("com/sun/midp/io/j2me/socket/Protocol.setSockOpt0.(II)V", function
Native.create("com/sun/midp/io/j2me/socket/Protocol.getSockOpt0.(I)I", function(ctx, option) {
if (!(option in this.options)) {
ctx.raiseException("java/lang/IllegalArgumentException", "Unsupported socket option");
throw new JavaException("java/lang/IllegalArgumentException", "Unsupported socket option");
}
return this.options[option];
});
Native["com/sun/midp/io/j2me/socket/Protocol.close0.()V"] = function(ctx, stack) {
var _this = stack.pop();
if (_this.socket.isClosed) {
Native.create("com/sun/midp/io/j2me/socket/Protocol.close0.()V", function(ctx) {
if (this.socket.isClosed) {
return;
}
_this.socket.onclose = function() {
_this.socket.onclose = null;
this.socket.onclose = (function() {
this.socket.onclose = null;
ctx.resume();
}
}).bind(this);
_this.socket.close();
this.socket.close();
throw VM.Pause;
}
});
Native.create("com/sun/midp/io/j2me/socket/Protocol.shutdownOutput0.()V", function(ctx) {
// We don't have the ability to close the output stream independently

Просмотреть файл

@ -321,19 +321,18 @@ Override.create("java/lang/String.valueOf.(J)Ljava/lang/String;", function(ctx,
var internedStrings = new Map();
Native["java/lang/String.intern.()Ljava/lang/String;"] = function(ctx, stack) {
var javaString = stack.pop();
var string = util.fromJavaString(javaString);
Native.create("java/lang/String.intern.()Ljava/lang/String;", function(ctx) {
var string = util.fromJavaString(this);
var internedString = internedStrings.get(string);
if (internedString) {
stack.push(internedString);
return internedString;
} else {
internedStrings.set(string, javaString);
stack.push(javaString);
internedStrings.set(string, this);
return this;
}
}
});

Просмотреть файл

@ -1,37 +1,34 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
Native["gnu/testlet/vm/NativeTest.getInt.()I"] = function(ctx, stack) {
stack.push(0xFFFFFFFF);
}
Native.create("gnu/testlet/vm/NativeTest.getInt.()I", function(ctx) {
return 0xFFFFFFFF;
});
Native["gnu/testlet/vm/NativeTest.getLongReturnLong.(J)J"] = function(ctx, stack) {
var val = stack.pop2();
stack.push2(Long.fromNumber(40 + val.toNumber()));
}
Native.create("gnu/testlet/vm/NativeTest.getLongReturnLong.(J)J", function(ctx, val, _) {
return Long.fromNumber(40 + val.toNumber());
});
Native["gnu/testlet/vm/NativeTest.getLongReturnInt.(J)I"] = function(ctx, stack) {
var val = stack.pop2().toNumber();
stack.push(40 + val);
}
Native.create("gnu/testlet/vm/NativeTest.getLongReturnInt.(J)I", function(ctx, val, _) {
return 40 + val.toNumber();
});
Native["gnu/testlet/vm/NativeTest.getIntReturnLong.(I)J"] = function(ctx, stack) {
var val = stack.pop();
stack.push2(Long.fromNumber(40 + val));
}
Native.create("gnu/testlet/vm/NativeTest.getIntReturnLong.(I)J", function(ctx, val) {
return Long.fromNumber(40 + val);
});
Native["gnu/testlet/vm/NativeTest.throwException.()V"] = function(ctx, stack) {
ctx.raiseExceptionAndYield("java/lang/NullPointerException", "An exception");
}
Native.create("gnu/testlet/vm/NativeTest.throwException.()V", function(ctx) {
throw new JavaException("java/lang/NullPointerException", "An exception");
});
Native["gnu/testlet/vm/NativeTest.throwExceptionAfterPause.()V"] = function(ctx, stack) {
Native.create("gnu/testlet/vm/NativeTest.throwExceptionAfterPause.()V", function(ctx) {
setTimeout(function() {
ctx.raiseException("java/lang/NullPointerException", "An exception");
ctx.resume();
}, 100);
throw VM.Pause;
}
});
Native["gnu/testlet/vm/NativeTest.returnAfterPause.()I"] = function(ctx, stack) {
setTimeout(function() {
@ -42,30 +39,27 @@ Native["gnu/testlet/vm/NativeTest.returnAfterPause.()I"] = function(ctx, stack)
throw VM.Pause;
}
Native["gnu/testlet/vm/NativeTest.nonStatic.(I)I"] = function(ctx, stack) {
var val = stack.pop(), _this = stack.pop();
stack.push(val + 40);
}
Native.create("gnu/testlet/vm/NativeTest.nonStatic.(I)I", function(ctx, val) {
return val + 40;
});
Native["gnu/testlet/vm/NativeTest.fromJavaString.(Ljava/lang/String;)I"] = function(ctx, stack) {
var str = util.fromJavaString(stack.pop());
stack.push(str.length);
}
Native.create("gnu/testlet/vm/NativeTest.fromJavaString.(Ljava/lang/String;)I", function(ctx, str) {
return util.fromJavaString(str).length;
});
Native["gnu/testlet/vm/NativeTest.decodeUtf8.([B)I"] = function(ctx, stack) {
var str = util.decodeUtf8(stack.pop());
stack.push(str.length);
}
Native.create("gnu/testlet/vm/NativeTest.decodeUtf8.([B)I", function(ctx, str) {
return util.decodeUtf8(str).length;
});
Native["gnu/testlet/vm/NativeTest.newFunction.()Z"] = function(ctx, stack) {
Native.create("gnu/testlet/vm/NativeTest.newFunction.()Z", function(ctx) {
try {
var fn = new Function("ctx", "stack", "stack.push(1)");
fn(ctx, stack);
var fn = new Function("return true;");
return fn();
} catch(ex) {
console.error(ex);
stack.push(0);
return false;
}
}
});
Native["gnu/testlet/vm/NativeTest.dumbPipe.()Z"] = function(ctx, stack) {
// Ensure we can echo a large amount of data.