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

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

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

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

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

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

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