Merge pull request #26 from marco-c/fileconnection_natives

Implement some FileConnection natives
This commit is contained in:
Andreas Gal 2014-08-05 11:30:16 -07:00
Родитель f144ff9889 efa1e39bab
Коммит af1ab5d0c2
3 изменённых файлов: 117 добавлений и 3 удалений

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

@ -7,6 +7,11 @@ var fs = (function() {
return "."; return ".";
} }
if (index == path.length-1) {
path = path.substring(0, index);
index = path.lastIndexOf("/");
}
while (index >= 0 && path[index] == "/") { while (index >= 0 && path[index] == "/") {
--index; --index;
} }
@ -19,11 +24,24 @@ var fs = (function() {
} }
function basename(path) { 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) { function init(cb) {
asyncStorage.setItem("/", [], cb); asyncStorage.getItem("/", function(data) {
if (data) {
cb();
} else {
asyncStorage.setItem("/", [], cb);
}
});
} }
var openedFiles = []; var openedFiles = [];

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

@ -55,4 +55,10 @@ function run(className, args) {
// To launch the MIDP demo: ?main=com/sun/midp/main/MIDletSuiteLoader&midletClassName=HelloCommandMIDlet // 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 // 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) {
run(urlParams.main || "RunTests", urlParams.args);
});
});
});

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

@ -536,3 +536,93 @@ Native["com/nokia/mid/ui/gestures/GestureInteractiveZone.isSupported.(I)Z"] = fu
var gestureEventIdentity = stack.pop(); var gestureEventIdentity = stack.pop();
stack.push(0); stack.push(0);
} }
Native["com/ibm/oti/connection/file/Connection.isValidFilenameImpl.([B)Z"] = function(ctx, stack) {
var byteArray = stack.pop(), _this = stack.pop();
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.push2(Long.fromNumber(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.listImpl.([B[BZ)[[B"] = function(ctx, stack) {
// TODO: FILTER
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);
}
fs.list(path, function(files) {
var pathsArray = CLASSES.newArray("[B", files.length);
for (var i = 0; i < files.length; i++) {
var curPath = path + files[i];
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();
});
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;
}