From 6fb18e080d025a9d25d7c5cd838137fa045a5f6d Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Mon, 4 Aug 2014 13:35:02 -0700 Subject: [PATCH 1/9] Add some FileConnection natives --- native.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/native.js b/native.js index 1a6e429f..dc83d143 100644 --- a/native.js +++ b/native.js @@ -511,3 +511,11 @@ Native["com/sun/midp/io/j2me/push/ConnectionRegistry.poll0.(J)I"] = function(ctx // Wait for incoming connections throw VM.Pause; } + +Native["com/ibm/oti/connection/file/Connection.isValidFilenameImpl.([B)Z"] = function(ctx, stack) { + var byteArray = stack.pop(), _this = stack.pop; + + console.log(new TextDecoder().decode(byteArray)); + + stack.push(true); +} From 7f548d0968d232f635856fda2b5efae7868cae7d Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Mon, 4 Aug 2014 14:09:27 -0700 Subject: [PATCH 2/9] Add other natives --- native.js | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 101 insertions(+), 2 deletions(-) diff --git a/native.js b/native.js index dc83d143..2da3fb1a 100644 --- a/native.js +++ b/native.js @@ -513,9 +513,108 @@ Native["com/sun/midp/io/j2me/push/ConnectionRegistry.poll0.(J)I"] = function(ctx } Native["com/ibm/oti/connection/file/Connection.isValidFilenameImpl.([B)Z"] = function(ctx, stack) { - var byteArray = stack.pop(), _this = stack.pop; + var byteArray = stack.pop(), _this = stack.pop(); console.log(new TextDecoder().decode(byteArray)); - stack.push(true); + stack.push(1); +} + +Native["com/ibm/oti/connection/file/Connection.existsImpl.([B)Z"] = function(ctx, stack) { + var byteArray = stack.pop(), _this = stack.pop(); + + var path = "/" + new TextDecoder().decode(byteArray); + + fs.exists(path, function(exists) { + stack.push(exists ? 1 : 0); + ctx.resume(); + }); + + throw VM.Pause; +} + +Native["com/ibm/oti/connection/file/Connection.fileSizeImpl.([B)J"] = function(ctx, stack) { + var byteArray = stack.pop(), _this = stack.pop(); + + var path = "/" + new TextDecoder().decode(byteArray); + + fs.size(path, function(size) { + stack.push(size); + ctx.resume(); + }); + + throw VM.Pause; +} + +Native["com/ibm/oti/connection/file/Connection.isDirectoryImpl.([B)Z"] = function(ctx, stack) { + var byteArray = stack.pop(), _this = stack.pop(); + + var path = "/" + new TextDecoder().decode(byteArray); + + fs.list(path, function(files) { + stack.push(files ? 1 : 0); + ctx.resume(); + }); + + throw VM.Pause; +} + +Native["com/ibm/oti/connection/file/Connection.lastModifiedImpl.([B)J"] = function(ctx, stack) { + var byteArray = stack.pop(), _this = stack.pop(); + + stack.push(Long.fromNumber(Date.now())); +} + +Native["com/ibm/oti/connection/file/Connection.listImpl.([B[BZ)[[B"] = function(ctx, stack) { + // todo + + var byteArray = stack.pop(), _this = stack.pop(); + + var path = "/" + new TextDecoder().decode(byteArray); + + fs.list(path, function(files) { + stack.push(files ? 1 : 0); + ctx.resume(); + }); + + throw VM.Pause; +} + +Native["com/ibm/oti/connection/file/Connection.mkdirImpl.([B)I"] = function(ctx, stack) { + var byteArray = stack.pop(), _this = stack.pop(); + + var path = "/" + new TextDecoder().decode(byteArray); + + // IBM's implementation returns different error numbers, we don't care + + fs.mkdir(path, function(created) { + stack.push(created ? 0 : 42); + ctx.resume(); + }); + + throw VM.Pause; +} + +Native["com/ibm/oti/connection/file/Connection.newFileImpl.([B)I"] = function(ctx, stack) { + var byteArray = stack.pop(), _this = stack.pop(); + + var path = "/" + new TextDecoder().decode(byteArray); + + // IBM's implementation returns different error numbers, we don't care + + fs.exists(path, function(exists) { + if (exists) { + fs.truncate(path, function(truncated) { + stack.push(truncated ? 0 : 42); + ctx.resume(); + }); + } else { + fs.create(path, function(created) { + stack.push(created ? 0 : 42); + ctx.resume(); + }); + } + }); + + throw VM.Pause; } From 3af6ea31a8a4534330197a50dc205a36c45b1e32 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Mon, 4 Aug 2014 15:44:04 -0700 Subject: [PATCH 3/9] Add other natives --- native.js | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/native.js b/native.js index 2da3fb1a..982f961f 100644 --- a/native.js +++ b/native.js @@ -618,3 +618,115 @@ Native["com/ibm/oti/connection/file/Connection.newFileImpl.([B)I"] = function(ct throw VM.Pause; } + +Native["com/ibm/oti/connection/file/FCOutputStream.openImpl.([B)I"] = function(ctx, stack) { + var byteArray = stack.pop(), _this = stack.pop(); + + var path = "/" + new TextDecoder().decode(byteArray); + + function open() { + fs.open(path, function(fd) { + stack.push(fd); + _this.pos = 0; + ctx.resume(); + }); + } + + fs.exists(path, function(exists) { + if (exists) { + fs.truncate(path, function(truncated) { + if (truncated) { + open(); + } else { + stack.push(-1); + ctx.resume(); + } + }); + } else { + fs.create(path, function(created) { + if (created) { + open(); + } else { + stack.push(-1); + ctx.resume(); + } + }); + } + }); + + throw VM.Pause; +} + +Native["com/ibm/oti/connection/file/FCOutputStream.openOffsetImpl.([BJ)I"] = function(ctx, stack) { + var byteArray = stack.pop(), offset = stack.pop2(), _this = stack.pop(); + + var path = "/" + new TextDecoder().decode(byteArray); + + function open() { + fs.open(path, function(fd) { + stack.push(fd); + _this.pos = offset.toNumber(); + ctx.resume(); + }); + } + + fs.exists(path, function(exists) { + if (exists) { + open(); + } else { + fs.create(path, function(created) { + if (created) { + open(); + } else { + stack.push(-1); + ctx.resume(); + } + }); + } + }); +} + +Native["com/ibm/oti/connection/file/FCOutputStream.writeImpl.([BIII)V"] = function(ctx, stack) { + var byteArray = stack.pop(), offset = stack.pop(), count: stack.pop(), fd: stack.pop(), _this = stack.pop(); + + var path = "/" + new TextDecoder().decode(byteArray); + + fs.write(fd, new Blob(byteArray).slice(offset, offset+count), _this.pos); + + _this.pos += count; +} + +Native["com/ibm/oti/connection/file/FCOutputStream.writeByteImpl.(II)V"] = function(ctx, stack) { + var val = stack.pop(), _this = stack.pop(); + + var path = "/" + new TextDecoder().decode(byteArray); + + var intBuf = new Uint32Array(1); + intBuf[0] = val; + + var buf = new Uint8Array(intBuf.buffer); + + fs.write(fd, new Blob([buf]).slice(3, 4), _this.pos); + + _this.pos += 1; +} + +Native["com/ibm/oti/connection/file/FCOutputStream.closeImpl.(I)V"] = function(ctx, stack) { + var fd = stack.pop(), _this = stack.pop(); + + var path = "/" + new TextDecoder().decode(byteArray); + + fs.close(fd); +} + +Native["com/ibm/oti/connection/file/FCOutputStream.syncImpl.(I)V"] = function(ctx, stack) { + var fd = stack.pop(), _this = stack.pop(); + + var path = "/" + new TextDecoder().decode(byteArray); + + fs.flush(fd, function() { + ctx.resume(); + }); + + throw VM.Pause; +} From 7d453a1cd60a7468d8b3f3b720b58e8b534f0804 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Tue, 5 Aug 2014 08:48:57 -0700 Subject: [PATCH 4/9] Comment out draft natives --- native.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/native.js b/native.js index 982f961f..599624ba 100644 --- a/native.js +++ b/native.js @@ -514,13 +514,10 @@ Native["com/sun/midp/io/j2me/push/ConnectionRegistry.poll0.(J)I"] = function(ctx Native["com/ibm/oti/connection/file/Connection.isValidFilenameImpl.([B)Z"] = function(ctx, stack) { var byteArray = stack.pop(), _this = stack.pop(); - - console.log(new TextDecoder().decode(byteArray)); - stack.push(1); } -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 byteArray = stack.pop(), _this = stack.pop(); var path = "/" + new TextDecoder().decode(byteArray); @@ -729,4 +726,4 @@ Native["com/ibm/oti/connection/file/FCOutputStream.syncImpl.(I)V"] = function(ct }); throw VM.Pause; -} +}*/ From bb77501fe89f864ffa303c507e910870917dd196 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Tue, 5 Aug 2014 09:40:32 -0700 Subject: [PATCH 5/9] Implement other natives --- libs/fs.js | 22 ++++++++++++++++++++-- main.js | 9 ++++++++- native.js | 38 ++++++++++++++++++++++++++++++-------- 3 files changed, 58 insertions(+), 11 deletions(-) diff --git a/libs/fs.js b/libs/fs.js index 50b3af99..df0928ca 100644 --- a/libs/fs.js +++ b/libs/fs.js @@ -7,6 +7,11 @@ var fs = (function() { return "."; } + if (index == path.length-1) { + path = path.substring(0, index); + index = path.lastIndexOf("/"); + } + while (index >= 0 && path[index] == "/") { --index; } @@ -19,11 +24,24 @@ var fs = (function() { } function basename(path) { - return path.slice(path.lastIndexOf("/") + 1); + var index = path.lastIndexOf("/"); + + if (index == path.length-1) { + path = path.substring(0, index); + index = path.lastIndexOf("/"); + } + + return path.slice(index + 1); } function init(cb) { - asyncStorage.setItem("/", [], cb); + asyncStorage.getItem("/", function(data) { + if (data) { + cb(); + } else { + asyncStorage.setItem("/", [], cb); + } + }); } var openedFiles = []; diff --git a/main.js b/main.js index 9d50cd31..11edab72 100644 --- a/main.js +++ b/main.js @@ -55,4 +55,11 @@ function run(className, args) { // To launch the MIDP demo: ?main=com/sun/midp/main/MIDletSuiteLoader&midletClassName=HelloCommandMIDlet // To launch a JAR file: ?main=com/sun/midp/main/MIDletSuiteLoader&args=app.jar -run(urlParams.main || "RunTests", urlParams.args); +//asyncStorage.clear(function() { + fs.init(function() { + fs.mkdir("/tmp", function(created) { + console.log(created + " created /tmp"); + run(urlParams.main || "RunTests", urlParams.args); + }); + }); +//}); diff --git a/native.js b/native.js index a9f460b9..27104379 100644 --- a/native.js +++ b/native.js @@ -517,7 +517,7 @@ Native["com/ibm/oti/connection/file/Connection.isValidFilenameImpl.([B)Z"] = fun stack.push(1); } -/*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 byteArray = stack.pop(), _this = stack.pop(); var path = "/" + new TextDecoder().decode(byteArray); @@ -530,7 +530,7 @@ Native["com/ibm/oti/connection/file/Connection.isValidFilenameImpl.([B)Z"] = fun throw VM.Pause; } -Native["com/ibm/oti/connection/file/Connection.fileSizeImpl.([B)J"] = function(ctx, stack) { +/*Native["com/ibm/oti/connection/file/Connection.fileSizeImpl.([B)J"] = function(ctx, stack) { var byteArray = stack.pop(), _this = stack.pop(); var path = "/" + new TextDecoder().decode(byteArray); @@ -541,7 +541,7 @@ Native["com/ibm/oti/connection/file/Connection.fileSizeImpl.([B)J"] = function(c }); throw VM.Pause; -} +}*/ Native["com/ibm/oti/connection/file/Connection.isDirectoryImpl.([B)Z"] = function(ctx, stack) { var byteArray = stack.pop(), _this = stack.pop(); @@ -549,6 +549,7 @@ Native["com/ibm/oti/connection/file/Connection.isDirectoryImpl.([B)Z"] = functio var path = "/" + new TextDecoder().decode(byteArray); fs.list(path, function(files) { + console.log((files ? 1 : 0) + " isdir " + path); stack.push(files ? 1 : 0); ctx.resume(); }); @@ -556,21 +557,41 @@ Native["com/ibm/oti/connection/file/Connection.isDirectoryImpl.([B)Z"] = functio throw VM.Pause; } -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 byteArray = stack.pop(), _this = stack.pop(); stack.push(Long.fromNumber(Date.now())); -} +}*/ Native["com/ibm/oti/connection/file/Connection.listImpl.([B[BZ)[[B"] = function(ctx, stack) { // todo - var byteArray = stack.pop(), _this = stack.pop(); + var includeHidden = stack.pop(), filterArray = stack.pop(), byteArray = stack.pop(), _this = stack.pop(); var path = "/" + new TextDecoder().decode(byteArray); + var filter = ""; + if (filterArray) { + filter = new TextDecoder().decode(filterArray); + } + + console.log("FILTER: " + filter); + fs.list(path, function(files) { - stack.push(files ? 1 : 0); + console.log("list " + path); + var pathsArray = CLASSES.newArray("[B", files.length); + for (var i = 0; i < files.length; i++) { + var curPath = path + files[i]; + console.log("list[i] " + curPath); + var bytesCurPath = new TextEncoder.encode(curPath); + var pathArray = CLASSES.newPrimitiveArray("B", bytesCurPath.byteLength); + for (var j = 0; j < bytesCurPath.byteLength; j++) { + pathArray[j] = bytesCurPath[j]; + } + pathsArray[i] = pathArray; + } + + stack.push(pathsArray); ctx.resume(); }); @@ -585,6 +606,7 @@ Native["com/ibm/oti/connection/file/Connection.mkdirImpl.([B)I"] = function(ctx, // IBM's implementation returns different error numbers, we don't care fs.mkdir(path, function(created) { + console.log(created + " created " + path); stack.push(created ? 0 : 42); ctx.resume(); }); @@ -592,7 +614,7 @@ Native["com/ibm/oti/connection/file/Connection.mkdirImpl.([B)I"] = function(ctx, throw VM.Pause; } -Native["com/ibm/oti/connection/file/Connection.newFileImpl.([B)I"] = function(ctx, stack) { +/*Native["com/ibm/oti/connection/file/Connection.newFileImpl.([B)I"] = function(ctx, stack) { var byteArray = stack.pop(), _this = stack.pop(); var path = "/" + new TextDecoder().decode(byteArray); From ae1a68db9fc3d260a442aa8c6109fcf691d6ef91 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Tue, 5 Aug 2014 10:03:38 -0700 Subject: [PATCH 6/9] Add native --- main.js | 4 +- native.js | 134 ++++-------------------------------------------------- 2 files changed, 10 insertions(+), 128 deletions(-) diff --git a/main.js b/main.js index 11edab72..75a5e639 100644 --- a/main.js +++ b/main.js @@ -55,11 +55,11 @@ function run(className, args) { // To launch the MIDP demo: ?main=com/sun/midp/main/MIDletSuiteLoader&midletClassName=HelloCommandMIDlet // To launch a JAR file: ?main=com/sun/midp/main/MIDletSuiteLoader&args=app.jar -//asyncStorage.clear(function() { +asyncStorage.clear(function() { fs.init(function() { fs.mkdir("/tmp", function(created) { console.log(created + " created /tmp"); run(urlParams.main || "RunTests", urlParams.args); }); }); -//}); +}); diff --git a/native.js b/native.js index 13c379e9..eaabbac2 100644 --- a/native.js +++ b/native.js @@ -546,18 +546,19 @@ Native["com/ibm/oti/connection/file/Connection.existsImpl.([B)Z"] = function(ctx throw VM.Pause; } -/*Native["com/ibm/oti/connection/file/Connection.fileSizeImpl.([B)J"] = function(ctx, stack) { +Native["com/ibm/oti/connection/file/Connection.fileSizeImpl.([B)J"] = function(ctx, stack) { var byteArray = stack.pop(), _this = stack.pop(); var path = "/" + new TextDecoder().decode(byteArray); fs.size(path, function(size) { + console.log(size + " size " + path); stack.push(size); ctx.resume(); }); throw VM.Pause; -}*/ +} Native["com/ibm/oti/connection/file/Connection.isDirectoryImpl.([B)Z"] = function(ctx, stack) { var byteArray = stack.pop(), _this = stack.pop(); @@ -573,14 +574,8 @@ Native["com/ibm/oti/connection/file/Connection.isDirectoryImpl.([B)Z"] = functio throw VM.Pause; } -/*Native["com/ibm/oti/connection/file/Connection.lastModifiedImpl.([B)J"] = function(ctx, stack) { - var byteArray = stack.pop(), _this = stack.pop(); - - stack.push(Long.fromNumber(Date.now())); -}*/ - Native["com/ibm/oti/connection/file/Connection.listImpl.([B[BZ)[[B"] = function(ctx, stack) { - // todo + // TODO: FILTER var includeHidden = stack.pop(), filterArray = stack.pop(), byteArray = stack.pop(), _this = stack.pop(); @@ -591,14 +586,10 @@ Native["com/ibm/oti/connection/file/Connection.listImpl.([B[BZ)[[B"] = function( filter = new TextDecoder().decode(filterArray); } - console.log("FILTER: " + filter); - fs.list(path, function(files) { - console.log("list " + path); var pathsArray = CLASSES.newArray("[B", files.length); for (var i = 0; i < files.length; i++) { var curPath = path + files[i]; - console.log("list[i] " + curPath); var bytesCurPath = new TextEncoder.encode(curPath); var pathArray = CLASSES.newPrimitiveArray("B", bytesCurPath.byteLength); for (var j = 0; j < bytesCurPath.byteLength; j++) { @@ -630,7 +621,7 @@ Native["com/ibm/oti/connection/file/Connection.mkdirImpl.([B)I"] = function(ctx, throw VM.Pause; } -/*Native["com/ibm/oti/connection/file/Connection.newFileImpl.([B)I"] = function(ctx, stack) { +Native["com/ibm/oti/connection/file/Connection.newFileImpl.([B)I"] = function(ctx, stack) { var byteArray = stack.pop(), _this = stack.pop(); var path = "/" + new TextDecoder().decode(byteArray); @@ -638,13 +629,16 @@ Native["com/ibm/oti/connection/file/Connection.mkdirImpl.([B)I"] = function(ctx, // IBM's implementation returns different error numbers, we don't care fs.exists(path, function(exists) { + console.log(exists + " exists " + path); if (exists) { fs.truncate(path, function(truncated) { + console.log(truncated + " truncated " + path); stack.push(truncated ? 0 : 42); ctx.resume(); }); } else { fs.create(path, function(created) { + console.log(created + " created " + path); stack.push(created ? 0 : 42); ctx.resume(); }); @@ -653,115 +647,3 @@ Native["com/ibm/oti/connection/file/Connection.mkdirImpl.([B)I"] = function(ctx, throw VM.Pause; } - -Native["com/ibm/oti/connection/file/FCOutputStream.openImpl.([B)I"] = function(ctx, stack) { - var byteArray = stack.pop(), _this = stack.pop(); - - var path = "/" + new TextDecoder().decode(byteArray); - - function open() { - fs.open(path, function(fd) { - stack.push(fd); - _this.pos = 0; - ctx.resume(); - }); - } - - fs.exists(path, function(exists) { - if (exists) { - fs.truncate(path, function(truncated) { - if (truncated) { - open(); - } else { - stack.push(-1); - ctx.resume(); - } - }); - } else { - fs.create(path, function(created) { - if (created) { - open(); - } else { - stack.push(-1); - ctx.resume(); - } - }); - } - }); - - throw VM.Pause; -} - -Native["com/ibm/oti/connection/file/FCOutputStream.openOffsetImpl.([BJ)I"] = function(ctx, stack) { - var byteArray = stack.pop(), offset = stack.pop2(), _this = stack.pop(); - - var path = "/" + new TextDecoder().decode(byteArray); - - function open() { - fs.open(path, function(fd) { - stack.push(fd); - _this.pos = offset.toNumber(); - ctx.resume(); - }); - } - - fs.exists(path, function(exists) { - if (exists) { - open(); - } else { - fs.create(path, function(created) { - if (created) { - open(); - } else { - stack.push(-1); - ctx.resume(); - } - }); - } - }); -} - -Native["com/ibm/oti/connection/file/FCOutputStream.writeImpl.([BIII)V"] = function(ctx, stack) { - var byteArray = stack.pop(), offset = stack.pop(), count: stack.pop(), fd: stack.pop(), _this = stack.pop(); - - var path = "/" + new TextDecoder().decode(byteArray); - - fs.write(fd, new Blob(byteArray).slice(offset, offset+count), _this.pos); - - _this.pos += count; -} - -Native["com/ibm/oti/connection/file/FCOutputStream.writeByteImpl.(II)V"] = function(ctx, stack) { - var val = stack.pop(), _this = stack.pop(); - - var path = "/" + new TextDecoder().decode(byteArray); - - var intBuf = new Uint32Array(1); - intBuf[0] = val; - - var buf = new Uint8Array(intBuf.buffer); - - fs.write(fd, new Blob([buf]).slice(3, 4), _this.pos); - - _this.pos += 1; -} - -Native["com/ibm/oti/connection/file/FCOutputStream.closeImpl.(I)V"] = function(ctx, stack) { - var fd = stack.pop(), _this = stack.pop(); - - var path = "/" + new TextDecoder().decode(byteArray); - - fs.close(fd); -} - -Native["com/ibm/oti/connection/file/FCOutputStream.syncImpl.(I)V"] = function(ctx, stack) { - var fd = stack.pop(), _this = stack.pop(); - - var path = "/" + new TextDecoder().decode(byteArray); - - fs.flush(fd, function() { - ctx.resume(); - }); - - throw VM.Pause; -}*/ From 021b692887ceab859de9633ccbe06a11b4b4f0b7 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Tue, 5 Aug 2014 10:05:59 -0700 Subject: [PATCH 7/9] Remove WIP natives and logging statements --- main.js | 1 - native.js | 30 ------------------------------ 2 files changed, 31 deletions(-) diff --git a/main.js b/main.js index 75a5e639..81d444d8 100644 --- a/main.js +++ b/main.js @@ -58,7 +58,6 @@ function run(className, args) { asyncStorage.clear(function() { fs.init(function() { fs.mkdir("/tmp", function(created) { - console.log(created + " created /tmp"); run(urlParams.main || "RunTests", urlParams.args); }); }); diff --git a/native.js b/native.js index eaabbac2..2a04fb08 100644 --- a/native.js +++ b/native.js @@ -552,7 +552,6 @@ Native["com/ibm/oti/connection/file/Connection.fileSizeImpl.([B)J"] = function(c var path = "/" + new TextDecoder().decode(byteArray); fs.size(path, function(size) { - console.log(size + " size " + path); stack.push(size); ctx.resume(); }); @@ -566,7 +565,6 @@ Native["com/ibm/oti/connection/file/Connection.isDirectoryImpl.([B)Z"] = functio var path = "/" + new TextDecoder().decode(byteArray); fs.list(path, function(files) { - console.log((files ? 1 : 0) + " isdir " + path); stack.push(files ? 1 : 0); ctx.resume(); }); @@ -613,37 +611,9 @@ Native["com/ibm/oti/connection/file/Connection.mkdirImpl.([B)I"] = function(ctx, // IBM's implementation returns different error numbers, we don't care fs.mkdir(path, function(created) { - console.log(created + " created " + path); stack.push(created ? 0 : 42); ctx.resume(); }); throw VM.Pause; } - -Native["com/ibm/oti/connection/file/Connection.newFileImpl.([B)I"] = function(ctx, stack) { - var byteArray = stack.pop(), _this = stack.pop(); - - var path = "/" + new TextDecoder().decode(byteArray); - - // IBM's implementation returns different error numbers, we don't care - - fs.exists(path, function(exists) { - console.log(exists + " exists " + path); - if (exists) { - fs.truncate(path, function(truncated) { - console.log(truncated + " truncated " + path); - stack.push(truncated ? 0 : 42); - ctx.resume(); - }); - } else { - fs.create(path, function(created) { - console.log(created + " created " + path); - stack.push(created ? 0 : 42); - ctx.resume(); - }); - } - }); - - throw VM.Pause; -} From ad232b717a043ffe1b8d506d17fa665bb468fa7f Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Tue, 5 Aug 2014 10:17:56 -0700 Subject: [PATCH 8/9] Use push2 in fileSizeImpl --- native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native.js b/native.js index 64810eda..bfb3ca10 100644 --- a/native.js +++ b/native.js @@ -561,7 +561,7 @@ Native["com/ibm/oti/connection/file/Connection.fileSizeImpl.([B)J"] = function(c var path = "/" + new TextDecoder().decode(byteArray); fs.size(path, function(size) { - stack.push(size); + stack.push2(size); ctx.resume(); }); From a20330612a8c31dfe93f1c05f160da23247d2fca Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Tue, 5 Aug 2014 10:31:20 -0700 Subject: [PATCH 9/9] Use Long.fromNumber for the file size --- native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native.js b/native.js index bfb3ca10..d4f3531d 100644 --- a/native.js +++ b/native.js @@ -561,7 +561,7 @@ Native["com/ibm/oti/connection/file/Connection.fileSizeImpl.([B)J"] = function(c var path = "/" + new TextDecoder().decode(byteArray); fs.size(path, function(size) { - stack.push2(size); + stack.push2(Long.fromNumber(size)); ctx.resume(); });