зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1379256 - Enable the rest of the recommended ESLint rules for toolkit/components/osfile. r=mossop
MozReview-Commit-ID: F5GmnvS9LpM --HG-- extra : rebase_source : 88e41671790bde3cbd19cde3cd591edb846b74ca
This commit is contained in:
Родитель
7b9493ce4d
Коммит
586eb1af96
|
@ -1,14 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
"rules": {
|
||||
"consistent-return": "off",
|
||||
"no-irregular-whitespace": "off",
|
||||
"no-lone-blocks": "off",
|
||||
"no-redeclare": "off",
|
||||
"no-self-assign": "off",
|
||||
"no-shadow": "off",
|
||||
"no-unused-vars": "off",
|
||||
"object-shorthand": "off",
|
||||
}
|
||||
};
|
|
@ -261,7 +261,7 @@ var Scheduler = this.Scheduler = {
|
|||
/**
|
||||
* Restart the OS.File worker killer timer.
|
||||
*/
|
||||
restartTimer: function(arg) {
|
||||
restartTimer(arg) {
|
||||
this.hasRecentActivity = true;
|
||||
},
|
||||
|
||||
|
@ -275,7 +275,7 @@ var Scheduler = this.Scheduler = {
|
|||
* would not cause leaks. Otherwise, assume that the worker will be shutdown
|
||||
* through some other mean.
|
||||
*/
|
||||
kill: function({shutdown, reset}) {
|
||||
kill({shutdown, reset}) {
|
||||
// Grab the kill queue to make sure that we
|
||||
// cannot be interrupted by another call to `kill`.
|
||||
let killQueue = this._killQueue;
|
||||
|
@ -382,7 +382,7 @@ var Scheduler = this.Scheduler = {
|
|||
* @return {Promise} A promise with the same behavior as
|
||||
* the promise returned by |code|.
|
||||
*/
|
||||
push: function(code) {
|
||||
push(code) {
|
||||
let promise = this.queue.then(code);
|
||||
// By definition, |this.queue| can never reject.
|
||||
this.queue = promise.catch(() => undefined);
|
||||
|
@ -482,7 +482,7 @@ var Scheduler = this.Scheduler = {
|
|||
*
|
||||
* This is only useful on first launch.
|
||||
*/
|
||||
_updateTelemetry: function() {
|
||||
_updateTelemetry() {
|
||||
let worker = this.worker;
|
||||
let workerTimeStamps = worker.workerTimeStamps;
|
||||
if (!workerTimeStamps) {
|
||||
|
@ -1270,10 +1270,10 @@ var DirectoryIterator = function DirectoryIterator(path, options) {
|
|||
this._isClosed = false;
|
||||
};
|
||||
DirectoryIterator.prototype = {
|
||||
iterator: function() {
|
||||
iterator() {
|
||||
return this;
|
||||
},
|
||||
__iterator__: function() {
|
||||
__iterator__() {
|
||||
return this;
|
||||
},
|
||||
|
||||
|
@ -1481,7 +1481,7 @@ this.OS.Path = Path;
|
|||
|
||||
// Returns a resolved promise when all the queued operation have been completed.
|
||||
Object.defineProperty(OS.File, "queue", {
|
||||
get: function() {
|
||||
get() {
|
||||
return Scheduler.queue;
|
||||
}
|
||||
});
|
||||
|
@ -1500,7 +1500,7 @@ var Barriers = {
|
|||
/**
|
||||
* Return the shutdown state of OS.File
|
||||
*/
|
||||
getDetails: function() {
|
||||
getDetails() {
|
||||
let result = {
|
||||
launched: Scheduler.launched,
|
||||
shutdown: Scheduler.shutdown,
|
||||
|
|
|
@ -59,7 +59,7 @@ if (this.Components) {
|
|||
/**
|
||||
* Get a resource from its unique identifier.
|
||||
*/
|
||||
get: function(id) {
|
||||
get(id) {
|
||||
let result = this._map.get(id);
|
||||
if (result == null) {
|
||||
return result;
|
||||
|
@ -69,7 +69,7 @@ if (this.Components) {
|
|||
/**
|
||||
* Remove a resource from its unique identifier.
|
||||
*/
|
||||
remove: function(id) {
|
||||
remove(id) {
|
||||
if (!this._map.has(id)) {
|
||||
throw new Error("Cannot find resource id " + id);
|
||||
}
|
||||
|
@ -84,9 +84,9 @@ if (this.Components) {
|
|||
* @return {*} A unique identifier. For the moment, this is a number,
|
||||
* but this might not remain the case forever.
|
||||
*/
|
||||
add: function(resource, info) {
|
||||
add(resource, info) {
|
||||
let id = this._idgen++;
|
||||
this._map.set(id, {resource: resource, info: info});
|
||||
this._map.set(id, {resource, info});
|
||||
return id;
|
||||
},
|
||||
/**
|
||||
|
@ -154,12 +154,12 @@ if (this.Components) {
|
|||
*/
|
||||
let Agent = {
|
||||
// Update worker's OS.Shared.DEBUG flag message from controller.
|
||||
SET_DEBUG: function(aDEBUG) {
|
||||
SET_DEBUG(aDEBUG) {
|
||||
SharedAll.Config.DEBUG = aDEBUG;
|
||||
},
|
||||
// Return worker's current OS.Shared.DEBUG value to controller.
|
||||
// Note: This is used for testing purposes.
|
||||
GET_DEBUG: function() {
|
||||
GET_DEBUG() {
|
||||
return SharedAll.Config.DEBUG;
|
||||
},
|
||||
/**
|
||||
|
@ -168,7 +168,7 @@ if (this.Components) {
|
|||
* @param {bool} If |true|, kill the worker if this would not cause
|
||||
* leaks.
|
||||
*/
|
||||
Meta_shutdown: function(kill) {
|
||||
Meta_shutdown(kill) {
|
||||
let result = {
|
||||
openedFiles: OpenedFiles.listOpenedResources(),
|
||||
openedDirectoryIterators: OpenedDirectoryIterators.listOpenedResources(),
|
||||
|
@ -269,7 +269,7 @@ if (this.Components) {
|
|||
options
|
||||
);
|
||||
},
|
||||
removeDir: function(path, options) {
|
||||
removeDir(path, options) {
|
||||
return File.removeDir(Type.path.fromMsg(path), options);
|
||||
},
|
||||
new_DirectoryIterator: function new_DirectoryIterator(path, options) {
|
||||
|
|
|
@ -109,7 +109,7 @@ var defineLazyGetter = function defineLazyGetter(object, name, getter) {
|
|||
delete this[name];
|
||||
let value = getter.call(this);
|
||||
Object.defineProperty(object, name, {
|
||||
value: value
|
||||
value
|
||||
});
|
||||
return value;
|
||||
}
|
||||
|
@ -213,10 +213,10 @@ var clone = function(object, refs = []) {
|
|||
let refer = function refer(result, key, object) {
|
||||
Object.defineProperty(result, key, {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
get() {
|
||||
return object[key];
|
||||
},
|
||||
set: function(value) {
|
||||
set(value) {
|
||||
object[key] = value;
|
||||
}
|
||||
});
|
||||
|
@ -301,7 +301,7 @@ Type.prototype = {
|
|||
this);
|
||||
Object.defineProperty(this, "in_ptr",
|
||||
{
|
||||
get: function() {
|
||||
get() {
|
||||
return ptr_t;
|
||||
}
|
||||
});
|
||||
|
@ -319,7 +319,7 @@ Type.prototype = {
|
|||
this);
|
||||
Object.defineProperty(this, "out_ptr",
|
||||
{
|
||||
get: function() {
|
||||
get() {
|
||||
return ptr_t;
|
||||
}
|
||||
});
|
||||
|
@ -341,7 +341,7 @@ Type.prototype = {
|
|||
this);
|
||||
Object.defineProperty(this, "inout_ptr",
|
||||
{
|
||||
get: function() {
|
||||
get() {
|
||||
return ptr_t;
|
||||
}
|
||||
});
|
||||
|
@ -865,7 +865,7 @@ HollowStructure.prototype = {
|
|||
" at offset " + offset +
|
||||
" without exceeding its size of " + this.size);
|
||||
}
|
||||
let field = {name: name, type: type};
|
||||
let field = {name, type};
|
||||
this.offset_to_field_info[offset] = field;
|
||||
},
|
||||
|
||||
|
@ -991,7 +991,7 @@ Library.prototype = Object.freeze({
|
|||
}
|
||||
let error = new Error("Could not open library " + this.name);
|
||||
Object.defineProperty(this, "library", {
|
||||
get: function() {
|
||||
get() {
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
@ -1010,10 +1010,10 @@ Library.prototype = Object.freeze({
|
|||
* @param {Type} returnType The type of values returned by the function.
|
||||
* @param {...Type} argTypes The type of arguments to the function.
|
||||
*/
|
||||
declareLazyFFI: function(object, field, ...args) {
|
||||
declareLazyFFI(object, field, ...args) {
|
||||
let lib = this;
|
||||
Object.defineProperty(object, field, {
|
||||
get: function() {
|
||||
get() {
|
||||
delete this[field];
|
||||
let ffi = declareFFI(lib.library, ...args);
|
||||
if (ffi) {
|
||||
|
@ -1037,10 +1037,10 @@ Library.prototype = Object.freeze({
|
|||
* @param {ctypes.CType} returnType The type of values returned by the function.
|
||||
* @param {...ctypes.CType} argTypes The type of arguments to the function.
|
||||
*/
|
||||
declareLazy: function(object, field, ...args) {
|
||||
declareLazy(object, field, ...args) {
|
||||
let lib = this;
|
||||
Object.defineProperty(object, field, {
|
||||
get: function() {
|
||||
get() {
|
||||
delete this[field];
|
||||
let ffi = lib.library.declare(...args);
|
||||
if (ffi) {
|
||||
|
@ -1067,10 +1067,10 @@ Library.prototype = Object.freeze({
|
|||
* @param {ctypes.CType} returnType The type of values returned by the function.
|
||||
* @param {...ctypes.CType} argTypes The type of arguments to the function.
|
||||
*/
|
||||
declareLazyWithFallback: function(fallbacklibrary, object, field, ...args) {
|
||||
declareLazyWithFallback(fallbacklibrary, object, field, ...args) {
|
||||
let lib = this;
|
||||
Object.defineProperty(object, field, {
|
||||
get: function() {
|
||||
get() {
|
||||
delete this[field];
|
||||
try {
|
||||
let ffi = lib.library.declare(...args);
|
||||
|
@ -1089,7 +1089,7 @@ Library.prototype = Object.freeze({
|
|||
});
|
||||
},
|
||||
|
||||
toString: function() {
|
||||
toString() {
|
||||
return "[Library " + this.name + "]";
|
||||
}
|
||||
});
|
||||
|
@ -1126,7 +1126,6 @@ var declareFFI = function declareFFI(lib, symbol, abi,
|
|||
throw new TypeError("declareFFI expects as third argument an instance of Type");
|
||||
}
|
||||
let signature = [symbol, abi];
|
||||
let argtypes = [];
|
||||
for (let i = 3; i < arguments.length; ++i) {
|
||||
let current = arguments[i];
|
||||
if (!current) {
|
||||
|
@ -1176,7 +1175,7 @@ exports.declareFFI = declareFFI;
|
|||
*/
|
||||
function declareLazyFFI(object, field, ...declareFFIArgs) {
|
||||
Object.defineProperty(object, field, {
|
||||
get: function() {
|
||||
get() {
|
||||
delete this[field];
|
||||
let ffi = declareFFI(...declareFFIArgs);
|
||||
if (ffi) {
|
||||
|
@ -1204,7 +1203,7 @@ exports.declareLazyFFI = declareLazyFFI;
|
|||
*/
|
||||
function declareLazy(object, field, lib, ...declareArgs) {
|
||||
Object.defineProperty(object, field, {
|
||||
get: function() {
|
||||
get() {
|
||||
delete this[field];
|
||||
try {
|
||||
let ffi = lib.declare(...declareArgs);
|
||||
|
@ -1279,31 +1278,31 @@ exports.OSError = OSError;
|
|||
exports.OS = {
|
||||
Constants: exports.Constants,
|
||||
Shared: {
|
||||
LOG: LOG,
|
||||
clone: clone,
|
||||
Type: Type,
|
||||
HollowStructure: HollowStructure,
|
||||
LOG,
|
||||
clone,
|
||||
Type,
|
||||
HollowStructure,
|
||||
Error: OSError,
|
||||
declareFFI: declareFFI,
|
||||
projectValue: projectValue,
|
||||
isTypedArray: isTypedArray,
|
||||
defineLazyGetter: defineLazyGetter
|
||||
declareFFI,
|
||||
projectValue,
|
||||
isTypedArray,
|
||||
defineLazyGetter
|
||||
}
|
||||
};
|
||||
|
||||
Object.defineProperty(exports.OS.Shared, "DEBUG", {
|
||||
get: function() {
|
||||
get() {
|
||||
return Config.DEBUG;
|
||||
},
|
||||
set: function(x) {
|
||||
set(x) {
|
||||
return Config.DEBUG = x;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports.OS.Shared, "TEST", {
|
||||
get: function() {
|
||||
get() {
|
||||
return Config.TEST;
|
||||
},
|
||||
set: function(x) {
|
||||
set(x) {
|
||||
return Config.TEST = x;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -22,7 +22,7 @@ var SharedAll =
|
|||
var Path = require("resource://gre/modules/osfile/ospath.jsm");
|
||||
var Lz4 =
|
||||
require("resource://gre/modules/lz4.js");
|
||||
var LOG = SharedAll.LOG.bind(SharedAll, "Shared front-end");
|
||||
SharedAll.LOG.bind(SharedAll, "Shared front-end");
|
||||
var clone = SharedAll.clone;
|
||||
|
||||
/**
|
||||
|
@ -152,7 +152,7 @@ AbstractFile.openUnique = function openUnique(path, options = {}) {
|
|||
|
||||
try {
|
||||
return {
|
||||
path: path,
|
||||
path,
|
||||
file: OS.File.open(path, mode)
|
||||
};
|
||||
} catch (ex) {
|
||||
|
@ -179,6 +179,7 @@ AbstractFile.openUnique = function openUnique(path, options = {}) {
|
|||
}
|
||||
throw OS.File.Error.exists("could not find an unused file name.", path);
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ if (typeof Components != "undefined") {
|
|||
throw new Error("Please open this module with Component.utils.import or with require()");
|
||||
}
|
||||
|
||||
var LOG = SharedAll.LOG.bind(SharedAll, "Unix", "allthreads");
|
||||
SharedAll.LOG.bind(SharedAll, "Unix", "allthreads");
|
||||
var Const = SharedAll.Constants.libc;
|
||||
|
||||
// Open libc
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
/* eslint-env mozilla/chrome-worker, node */
|
||||
/* global OS */
|
||||
|
||||
// eslint-disable-next-line no-lone-blocks
|
||||
{
|
||||
if (typeof Components != "undefined") {
|
||||
// We do not wish osfile_unix_back.jsm to be used directly as a main thread
|
||||
|
@ -24,7 +25,7 @@
|
|||
require("resource://gre/modules/osfile/osfile_shared_allthreads.jsm");
|
||||
let SysAll =
|
||||
require("resource://gre/modules/osfile/osfile_unix_allthreads.jsm");
|
||||
let LOG = SharedAll.LOG.bind(SharedAll, "Unix", "back");
|
||||
SharedAll.LOG.bind(SharedAll, "Unix", "back");
|
||||
let libc = SysAll.libc;
|
||||
let Const = SharedAll.Constants.libc;
|
||||
|
||||
|
@ -35,19 +36,18 @@
|
|||
*/
|
||||
// FIXME: Both |init| and |aDeclareFFI| are deprecated, we should remove them
|
||||
let init = function init(aDeclareFFI) {
|
||||
let declareFFI;
|
||||
if (aDeclareFFI) {
|
||||
declareFFI = aDeclareFFI.bind(null, libc);
|
||||
aDeclareFFI.bind(null, libc);
|
||||
} else {
|
||||
declareFFI = SysAll.declareFFI;
|
||||
SysAll.declareFFI;
|
||||
}
|
||||
let declareLazyFFI = SharedAll.declareLazyFFI;
|
||||
SharedAll.declareLazyFFI;
|
||||
|
||||
// Initialize types that require additional OS-specific
|
||||
// support - either finalization or matching against
|
||||
// OS-specific constants.
|
||||
let Type = Object.create(SysAll.Type);
|
||||
let SysFile = exports.OS.Unix.File = { Type: Type };
|
||||
let SysFile = exports.OS.Unix.File = { Type };
|
||||
|
||||
/**
|
||||
* A file descriptor.
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
/* eslint-env mozilla/chrome-worker, node */
|
||||
/* global OS */
|
||||
|
||||
// eslint-disable-next-line no-lone-blocks
|
||||
{
|
||||
if (typeof Components != "undefined") {
|
||||
// We do not wish osfile_unix_front.jsm to be used directly as a main thread
|
||||
|
@ -31,7 +32,7 @@
|
|||
let Path = require("resource://gre/modules/osfile/ospath.jsm");
|
||||
let SysAll = require("resource://gre/modules/osfile/osfile_unix_allthreads.jsm");
|
||||
exports.OS.Unix.File._init();
|
||||
let LOG = SharedAll.LOG.bind(SharedAll, "Unix front-end");
|
||||
SharedAll.LOG.bind(SharedAll, "Unix front-end");
|
||||
let Const = SharedAll.Constants.libc;
|
||||
let UnixFile = exports.OS.Unix.File;
|
||||
let Type = UnixFile.Type;
|
||||
|
@ -222,7 +223,7 @@
|
|||
*/
|
||||
if (SharedAll.Constants.Sys.Name != "Android") {
|
||||
File.prototype.setDates = function(accessDate, modificationDate) {
|
||||
let {value, ptr} = datesToTimevals(accessDate, modificationDate);
|
||||
let { /* value, */ ptr} = datesToTimevals(accessDate, modificationDate);
|
||||
throw_on_negative("setDates",
|
||||
UnixFile.futimes(this.fd, ptr),
|
||||
this._path);
|
||||
|
@ -555,7 +556,6 @@
|
|||
// Perform actual copy
|
||||
let total_read = 0;
|
||||
while (true) {
|
||||
let chunk_size = Math.min(nbytes, bufSize);
|
||||
let bytes_just_read = read(pump_buffer, bufSize);
|
||||
if (bytes_just_read == 0) {
|
||||
return total_read;
|
||||
|
@ -646,7 +646,6 @@
|
|||
// copy directories
|
||||
File.copy = function copy(sourcePath, destPath, options = {}) {
|
||||
let source, dest;
|
||||
let result;
|
||||
try {
|
||||
source = File.open(sourcePath);
|
||||
// Need to open the output file with |append:false|, or else |splice|
|
||||
|
@ -657,9 +656,9 @@
|
|||
dest = File.open(destPath, {trunc: true, append: false});
|
||||
}
|
||||
if (options.unixUserland) {
|
||||
result = pump_userland(source, dest, options);
|
||||
pump_userland(source, dest, options);
|
||||
} else {
|
||||
result = pump(source, dest, options);
|
||||
pump(source, dest, options);
|
||||
}
|
||||
} catch (x) {
|
||||
if (dest) {
|
||||
|
@ -1002,7 +1001,7 @@
|
|||
* @throws {OS.File.Error} In case of I/O error.
|
||||
*/
|
||||
File.setDates = function setDates(path, accessDate, modificationDate) {
|
||||
let {value, ptr} = datesToTimevals(accessDate, modificationDate);
|
||||
let {/* value, */ ptr} = datesToTimevals(accessDate, modificationDate);
|
||||
throw_on_negative("setDates",
|
||||
UnixFile.utimes(path, ptr),
|
||||
path);
|
||||
|
@ -1082,10 +1081,10 @@
|
|||
* Get/set the current directory.
|
||||
*/
|
||||
Object.defineProperty(File, "curDir", {
|
||||
set: function(path) {
|
||||
set(path) {
|
||||
this.setCurrentDirectory(path);
|
||||
},
|
||||
get: function() {
|
||||
get() {
|
||||
return this.getCurrentDirectory();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ if (typeof Components != "undefined") {
|
|||
throw new Error("Please open this module with Component.utils.import or with require()");
|
||||
}
|
||||
|
||||
var LOG = SharedAll.LOG.bind(SharedAll, "Win", "allthreads");
|
||||
SharedAll.LOG.bind(SharedAll, "Win", "allthreads");
|
||||
var Const = SharedAll.Constants.Win;
|
||||
|
||||
// Open libc
|
||||
|
@ -85,7 +85,6 @@ libc.declareLazy(Scope, "FormatMessage",
|
|||
*/
|
||||
var OSError = function OSError(operation = "unknown operation",
|
||||
lastError = ctypes.winLastError, path = "") {
|
||||
operation = operation;
|
||||
SharedAll.OSError.call(this, operation, path);
|
||||
this.winLastError = lastError;
|
||||
};
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
/* eslint-env mozilla/chrome-worker, node */
|
||||
/* global OS */
|
||||
|
||||
// eslint-disable-next-line no-lone-blocks
|
||||
{
|
||||
if (typeof Components != "undefined") {
|
||||
// We do not wish osfile_win.jsm to be used directly as a main thread
|
||||
|
@ -40,7 +41,7 @@
|
|||
|
||||
let SharedAll = require("resource://gre/modules/osfile/osfile_shared_allthreads.jsm");
|
||||
let SysAll = require("resource://gre/modules/osfile/osfile_win_allthreads.jsm");
|
||||
let LOG = SharedAll.LOG.bind(SharedAll, "Unix", "back");
|
||||
SharedAll.LOG.bind(SharedAll, "Unix", "back");
|
||||
let libc = SysAll.libc;
|
||||
let advapi32 = new SharedAll.Library("advapi32", "advapi32.dll");
|
||||
let Const = SharedAll.Constants.Win;
|
||||
|
@ -52,19 +53,19 @@
|
|||
*/
|
||||
// FIXME: Both |init| and |aDeclareFFI| are deprecated, we should remove them
|
||||
let init = function init(aDeclareFFI) {
|
||||
let declareFFI;
|
||||
let declareFFI; // eslint-disable-line no-unused-vars
|
||||
if (aDeclareFFI) {
|
||||
declareFFI = aDeclareFFI.bind(null, libc);
|
||||
} else {
|
||||
declareFFI = SysAll.declareFFI;
|
||||
}
|
||||
let declareLazyFFI = SharedAll.declareLazyFFI;
|
||||
let declareLazyFFI = SharedAll.declareLazyFFI; // eslint-disable-line no-unused-vars
|
||||
|
||||
// Initialize types that require additional OS-specific
|
||||
// support - either finalization or matching against
|
||||
// OS-specific constants.
|
||||
let Type = Object.create(SysAll.Type);
|
||||
let SysFile = exports.OS.Win.File = { Type: Type };
|
||||
let SysFile = exports.OS.Win.File = { Type };
|
||||
|
||||
// Initialize types
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
/* eslint-env mozilla/chrome-worker, node */
|
||||
/* global OS */
|
||||
|
||||
// eslint-disable-next-line no-lone-blocks
|
||||
{
|
||||
if (typeof Components != "undefined") {
|
||||
// We do not wish osfile_win_front.jsm to be used directly as a main thread
|
||||
|
@ -1153,10 +1154,10 @@
|
|||
* Get/set the current directory by |curDir|.
|
||||
*/
|
||||
Object.defineProperty(File, "curDir", {
|
||||
set: function(path) {
|
||||
set(path) {
|
||||
this.setCurrentDirectory(path);
|
||||
},
|
||||
get: function() {
|
||||
get() {
|
||||
return this.getCurrentDirectory();
|
||||
}
|
||||
}
|
||||
|
@ -1195,40 +1196,6 @@
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function to sort errors represented as "-1" from successes.
|
||||
*
|
||||
* @param {string=} operation The name of the operation. If unspecified,
|
||||
* the name of the caller function.
|
||||
* @param {number} result The result of the operation that may
|
||||
* represent either an error or a success. If -1, this function raises
|
||||
* an error holding ctypes.winLastError, otherwise it returns |result|.
|
||||
* @param {string=} path The path of the file.
|
||||
*/
|
||||
function throw_on_negative(operation, result, path) {
|
||||
if (result < 0) {
|
||||
throw new File.Error(operation, ctypes.winLastError, path);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function to sort errors represented as |null| from successes.
|
||||
*
|
||||
* @param {string=} operation The name of the operation. If unspecified,
|
||||
* the name of the caller function.
|
||||
* @param {pointer} result The result of the operation that may
|
||||
* represent either an error or a success. If |null|, this function raises
|
||||
* an error holding ctypes.winLastError, otherwise it returns |result|.
|
||||
* @param {string=} path The path of the file.
|
||||
*/
|
||||
function throw_on_null(operation, result, path) {
|
||||
if (result == null || (result.isNull && result.isNull())) {
|
||||
throw new File.Error(operation, ctypes.winLastError, path);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper used by both versions of setPermissions
|
||||
*/
|
||||
|
|
|
@ -407,7 +407,7 @@ var test_debug_test = maketest("debug_test", function debug_test(test) {
|
|||
return (async function() {
|
||||
// Create a console listener.
|
||||
let consoleListener = {
|
||||
observe: function(aMessage) {
|
||||
observe(aMessage) {
|
||||
// Ignore unexpected messages.
|
||||
if (!(aMessage instanceof Components.interfaces.nsIConsoleMessage)) {
|
||||
return;
|
||||
|
@ -420,7 +420,7 @@ var test_debug_test = maketest("debug_test", function debug_test(test) {
|
|||
};
|
||||
toggleDebugTest(true, consoleListener);
|
||||
// Execution of OS.File.exist method will trigger OS.File.LOG several times.
|
||||
let fileExists = await OS.File.exists(EXISTING_FILE);
|
||||
await OS.File.exists(EXISTING_FILE);
|
||||
toggleDebugTest(false, consoleListener);
|
||||
})();
|
||||
});
|
||||
|
|
|
@ -65,7 +65,7 @@ function test_open_non_existing_file() {
|
|||
info("Starting test_open_non_existing");
|
||||
let exn;
|
||||
try {
|
||||
let file = OS.File.open("/I do not exist");
|
||||
OS.File.open("/I do not exist");
|
||||
} catch (x) {
|
||||
exn = x;
|
||||
info("test_open_non_existing_file: Exception detail " + exn);
|
||||
|
|
|
@ -19,12 +19,12 @@ function ok(condition, description) {
|
|||
|
||||
function is(a, b, description) {
|
||||
let outcome = a == b; // Need to decide outcome here, as not everything can be serialized
|
||||
send({kind: "is", outcome: outcome, description: "" + description, a: "" + a, b: "" + b});
|
||||
send({kind: "is", outcome, description: "" + description, a: "" + a, b: "" + b});
|
||||
}
|
||||
|
||||
function isnot(a, b, description) {
|
||||
let outcome = a != b; // Need to decide outcome here, as not everything can be serialized
|
||||
send({kind: "isnot", outcome: outcome, description: "" + description, a: "" + a, b: "" + b});
|
||||
send({kind: "isnot", outcome, description: "" + description, a: "" + a, b: "" + b});
|
||||
}
|
||||
|
||||
function info(description) {
|
||||
|
|
|
@ -118,7 +118,7 @@ function test_read_write() {
|
|||
break;
|
||||
}
|
||||
while (bytes > 0) {
|
||||
let ptr = array.addressOfElement(write_from);
|
||||
array.addressOfElement(write_from);
|
||||
// Note: |write| launches an exception in case of error
|
||||
let written = OS.Unix.File.write(output, array, bytes);
|
||||
isnot(written, -1, "test_read_write: no write error");
|
||||
|
@ -186,10 +186,10 @@ function test_passing_undefined() {
|
|||
let exceptionRaised = false;
|
||||
|
||||
try {
|
||||
let file = OS.Unix.File.open(undefined, OS.Constants.libc.O_RDWR
|
||||
| OS.Constants.libc.O_CREAT
|
||||
| OS.Constants.libc.O_TRUNC,
|
||||
OS.Constants.libc.S_IRWXU);
|
||||
OS.Unix.File.open(undefined, OS.Constants.libc.O_RDWR
|
||||
| OS.Constants.libc.O_CREAT
|
||||
| OS.Constants.libc.O_TRUNC,
|
||||
OS.Constants.libc.S_IRWXU);
|
||||
} catch (e) {
|
||||
if (e instanceof TypeError && e.message.indexOf("open") > -1) {
|
||||
exceptionRaised = true;
|
||||
|
|
|
@ -122,7 +122,7 @@ function test_ReadWrite() {
|
|||
}
|
||||
while (bytes_left.value > 0) {
|
||||
log("test_ReadWrite: writing " + bytes_left.value);
|
||||
let ptr = array.addressOfElement(write_from);
|
||||
array.addressOfElement(write_from);
|
||||
// Note: |WriteFile| launches an exception in case of error
|
||||
result = OS.Win.File.WriteFile(output, array, bytes_left, bytes_written_ptr, null);
|
||||
isnot(result, 0, "test_ReadWrite: write success");
|
||||
|
@ -193,7 +193,7 @@ function test_passing_undefined() {
|
|||
let exceptionRaised = false;
|
||||
|
||||
try {
|
||||
let file = OS.Win.File.CreateFile(
|
||||
OS.Win.File.CreateFile(
|
||||
undefined,
|
||||
OS.Constants.Win.GENERIC_READ,
|
||||
0,
|
||||
|
|
|
@ -36,7 +36,7 @@ add_task(async function test_uncompressed() {
|
|||
for (let i = 0; i < array.byteLength; ++i) {
|
||||
array[i] = i;
|
||||
}
|
||||
let bytes = await OS.File.writeAtomic(path, array); // No compression
|
||||
await OS.File.writeAtomic(path, array); // No compression
|
||||
|
||||
let exn;
|
||||
// Force decompression, reading should fail
|
||||
|
@ -56,7 +56,7 @@ add_task(async function test_no_header() {
|
|||
|
||||
do_print("Writing data with no header");
|
||||
|
||||
let bytes = await OS.File.writeAtomic(path, array); // No compression
|
||||
await OS.File.writeAtomic(path, array); // No compression
|
||||
let exn;
|
||||
// Force decompression, reading should fail
|
||||
try {
|
||||
|
@ -80,7 +80,7 @@ add_task(async function test_invalid_content() {
|
|||
|
||||
do_print("Writing invalid data (with a valid header and only ones after that)");
|
||||
|
||||
let bytes = await OS.File.writeAtomic(path, array); // No compression
|
||||
await OS.File.writeAtomic(path, array); // No compression
|
||||
let exn;
|
||||
// Force decompression, reading should fail
|
||||
try {
|
||||
|
|
|
@ -15,7 +15,7 @@ add_task(async function test_deprecatedCreationDate() {
|
|||
|
||||
let consoleMessagePromise = new Promise(resolve => {
|
||||
let consoleListener = {
|
||||
observe: function(aMessage) {
|
||||
observe(aMessage) {
|
||||
if (aMessage.message.indexOf("Field 'creationDate' is deprecated.") > -1) {
|
||||
do_print("Deprecation message printed");
|
||||
do_check_true(true);
|
||||
|
|
|
@ -59,7 +59,7 @@ add_task(async function duration() {
|
|||
// duration measurement then progressively incremented.
|
||||
outSerializationDuration: null,
|
||||
outExecutionDuration: null,
|
||||
tmpPath: tmpPath
|
||||
tmpPath
|
||||
};
|
||||
await OS.File.writeAtomic(pathDest, contents, writeAtomicOptions);
|
||||
testOptions(writeAtomicOptions, "OS.File.writeAtomic");
|
||||
|
|
|
@ -15,7 +15,7 @@ function run_test() {
|
|||
|
||||
// Create a console listener.
|
||||
let consoleListener = {
|
||||
observe: function(aMessage) {
|
||||
observe(aMessage) {
|
||||
// Ignore unexpected messages.
|
||||
if (!(aMessage instanceof Components.interfaces.nsIConsoleMessage)) {
|
||||
return;
|
||||
|
@ -71,4 +71,3 @@ function run_test() {
|
|||
// Once both messages are observed OS.Shared.DEBUG, and OS.Shared.TEST
|
||||
// are reset to false.
|
||||
}
|
||||
|
||||
|
|
|
@ -62,8 +62,6 @@ async function test_setPosition_failures() {
|
|||
try {
|
||||
let file = await OS.File.open(path, {write: true, append: false});
|
||||
try {
|
||||
let pos = 0;
|
||||
|
||||
// 1. Use an invalid position value
|
||||
try {
|
||||
await file.setPosition(0.5, OS.File.POS_START);
|
||||
|
@ -114,7 +112,7 @@ function run_test() {
|
|||
add_task(test_setPosition.bind(null, 1000, 100, 50));
|
||||
add_task(test_setPosition.bind(null, 1000, -100, -50));
|
||||
|
||||
if (OS.Constants.Win || ctypes.off_t.size >= 8) {
|
||||
if (OS.Constants.Win || ctypes.off_t.size >= 8) {
|
||||
// Now verify stuff still works for large values.
|
||||
// 1. Multiple small seeks, which add up to > MAXINT32
|
||||
add_task(test_setPosition.bind(null, 0x7fffffff, 0x7fffffff, 0));
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
"use strict";
|
||||
|
||||
/* eslint-disable no-lone-blocks */
|
||||
|
||||
Components.utils.import("resource://gre/modules/osfile.jsm");
|
||||
|
||||
/**
|
||||
|
@ -106,7 +108,7 @@ add_task(async function test_proto() {
|
|||
"test_osfile_async_setDates_proto.tmp");
|
||||
await OS.File.writeAtomic(path, new Uint8Array(1));
|
||||
|
||||
try {
|
||||
try {
|
||||
let fd = await OS.File.open(path, {write: true});
|
||||
|
||||
try {
|
||||
|
|
|
@ -62,7 +62,7 @@ add_task(async function test_kill_race() {
|
|||
await OS.File.exists("foo.foo");
|
||||
|
||||
do_print("issuing first request");
|
||||
let firstRequest = OS.File.exists("foo.bar");
|
||||
let firstRequest = OS.File.exists("foo.bar"); // eslint-disable-line no-unused-vars
|
||||
let secondRequest;
|
||||
let secondResolved = false;
|
||||
|
||||
|
|
|
@ -103,7 +103,6 @@ add_task(async function test_non_backupTo_option() {
|
|||
* @result no back up file exists
|
||||
*/
|
||||
add_task(async function test_backupTo_option_without_destination_file() {
|
||||
let DEFAULT_CONTENTS = "default contents" + Math.random();
|
||||
let WRITE_CONTENTS = "abc" + Math.random();
|
||||
let path = Path.join(Constants.Path.tmpDir,
|
||||
"test_backupTo_option_without_destination_file.tmp");
|
||||
|
|
|
@ -16,7 +16,7 @@ add_task(async function check_init() {
|
|||
// after an operation is successful.
|
||||
add_task(async function check_success() {
|
||||
do_print("Attempting to open a file correctly");
|
||||
let openedFile = await OS.File.open(OS.Path.join(do_get_cwd().path, "test_queue.js"));
|
||||
await OS.File.open(OS.Path.join(do_get_cwd().path, "test_queue.js"));
|
||||
do_print("File opened correctly");
|
||||
await OS.File.queue;
|
||||
do_print("Function resolved");
|
||||
|
|
|
@ -86,7 +86,7 @@ add_test_pair(async function read_write_all() {
|
|||
|
||||
let array2 = await OS.File.read(DEST_PATH);
|
||||
do_check_eq(LENGTH, array2.length);
|
||||
for (var i = 0; i < LENGTH; i++)
|
||||
for (var j = 0; j < LENGTH; j++)
|
||||
do_check_eq(array2[i], (i + START) % 256);
|
||||
|
||||
// Cleanup.
|
||||
|
|
Загрузка…
Ссылка в новой задаче