зеркало из https://github.com/mozilla/gecko-dev.git
Bug 767021 - Make error-handling compatible with 'use strict'. r=yoric
This commit is contained in:
Родитель
e105819686
Коммит
749caea84b
|
@ -120,7 +120,7 @@
|
|||
*/
|
||||
read: function read(buffer, nbytes, options) {
|
||||
// |gBytesReadPtr| is a pointer to |gBytesRead|.
|
||||
throw_on_zero(
|
||||
throw_on_zero("read",
|
||||
WinFile.ReadFile(this.fd, buffer, nbytes, gBytesReadPtr, null)
|
||||
);
|
||||
return gBytesRead.value;
|
||||
|
@ -141,7 +141,7 @@
|
|||
*/
|
||||
write: function write(buffer, nbytes, options) {
|
||||
// |gBytesWrittenPtr| is a pointer to |gBytesWritten|.
|
||||
throw_on_zero(
|
||||
throw_on_zero("write",
|
||||
WinFile.WriteFile(this.fd, buffer, nbytes, gBytesWrittenPtr, null)
|
||||
);
|
||||
return gBytesWritten.value;
|
||||
|
@ -177,7 +177,8 @@
|
|||
// OS.File.POS_CURRENT == OS.Constants.Win.FILE_CURRENT
|
||||
// OS.File.POS_END == OS.Constants.Win.FILE_END
|
||||
whence = (whence == undefined)?Const.FILE_BEGIN:whence;
|
||||
return throw_on_negative(WinFile.SetFilePointer(this.fd, pos, null, whence));
|
||||
return throw_on_negative("setPosition",
|
||||
WinFile.SetFilePointer(this.fd, pos, null, whence));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -370,7 +371,8 @@
|
|||
}
|
||||
// Now, perform manual truncation
|
||||
file.setPosition(0, File.POS_START);
|
||||
throw_on_zero(WinFile.SetEndOfFile(file.fd));
|
||||
throw_on_zero("open",
|
||||
WinFile.SetEndOfFile(file.fd));
|
||||
return file;
|
||||
};
|
||||
|
||||
|
@ -381,7 +383,8 @@
|
|||
* @throws {OS.File.Error} In case of I/O error.
|
||||
*/
|
||||
File.remove = function remove(path) {
|
||||
throw_on_zero(WinFile.DeleteFile(path));
|
||||
throw_on_zero("remove",
|
||||
WinFile.DeleteFile(path));
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -409,7 +412,7 @@
|
|||
*/
|
||||
File.copy = function copy(sourcePath, destPath, options) {
|
||||
options = options || noOptions;
|
||||
throw_on_zero(
|
||||
throw_on_zero("copy",
|
||||
WinFile.CopyFile(sourcePath, destPath, options.noOverwrite || false)
|
||||
);
|
||||
};
|
||||
|
@ -445,7 +448,7 @@
|
|||
} else {
|
||||
flags = Const.MOVEFILE_COPY_ALLOWED | Const.MOVEFILE_REPLACE_EXISTING;
|
||||
}
|
||||
throw_on_zero(
|
||||
throw_on_zero("move",
|
||||
WinFile.MoveFileEx(sourcePath, destPath, flags)
|
||||
);
|
||||
};
|
||||
|
@ -455,7 +458,8 @@
|
|||
*/
|
||||
Object.defineProperty(File, "curDir", {
|
||||
set: function(path) {
|
||||
WinFile.SetCurrentDirectory(path);
|
||||
throw_on_zero("set curDir",
|
||||
WinFile.SetCurrentDirectory(path));
|
||||
},
|
||||
get: function() {
|
||||
// This function is more complicated than one could hope.
|
||||
|
@ -474,11 +478,11 @@
|
|||
let buffer_size = 4096;
|
||||
while (true) {
|
||||
let array = new (ctypes.ArrayType(ctypes.jschar, buffer_size))();
|
||||
let expected_size = throw_on_zero(
|
||||
let expected_size = throw_on_zero("get curDir",
|
||||
WinFile.GetCurrentDirectory(buffer_size, array)
|
||||
);
|
||||
if (expected_size <= buffer_size) {
|
||||
return array;
|
||||
return array.readString();
|
||||
}
|
||||
// At this point, we are in a case in which our buffer was not
|
||||
// large enough to hold the name of the current directory.
|
||||
|
@ -499,20 +503,26 @@
|
|||
}
|
||||
return new File(maybe);
|
||||
}
|
||||
function throw_on_zero(result, operation) {
|
||||
function throw_on_zero(operation, result) {
|
||||
if (result == 0) {
|
||||
operation = operation || throw_on_zero.caller.name;
|
||||
throw new File.Error(operation);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function throw_on_negative(result, operation) {
|
||||
function throw_on_negative(operation, result) {
|
||||
if (result < 0) {
|
||||
operation = operation || throw_on_negative.caller.name;
|
||||
throw new File.Error(operation);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function throw_on_null(operation, result) {
|
||||
if (result == null || (result.isNull && result.isNull())) {
|
||||
throw new File.Error(operation);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Constants
|
||||
|
|
Загрузка…
Ссылка в новой задаче