--- a/toolkit/components/osfile/.eslintrc.js
+++ b/toolkit/components/osfile/.eslintrc.js
@@ -1,32 +1,15 @@
"use strict";
module.exports = {
"rules": {
- "brace-style": "off",
- "comma-spacing": "off",
"consistent-return": "off",
- "eol-last": "off",
- "func-call-spacing": "off",
- "key-spacing": "off",
- "keyword-spacing": "off",
- "no-else-return": "off",
- "no-extra-semi": "off",
"no-irregular-whitespace": "off",
"no-lone-blocks": "off",
- "no-lonely-if": "off",
- "no-multi-spaces": "off",
"no-redeclare": "off",
"no-self-assign": "off",
"no-shadow": "off",
- "no-trailing-spaces": "off",
"no-undef": "off",
- "no-unsafe-negation": "off",
"no-unused-vars": "off",
- "no-useless-return": "off",
"object-shorthand": "off",
- "quotes": "off",
- "space-before-function-paren": "off",
- "space-infix-ops": "off",
- "spaced-comment": "off",
}
};
--- a/toolkit/components/osfile/modules/osfile_async_front.jsm
+++ b/toolkit/components/osfile/modules/osfile_async_front.jsm
@@ -63,17 +63,17 @@ Cu.import("resource://gre/modules/AsyncS
var Native = Cu.import("resource://gre/modules/osfile/osfile_native.jsm", {});
// It's possible for osfile.jsm to get imported before the profile is
// set up. In this case, some path constants aren't yet available.
// Here, we make them lazy loaders.
function lazyPathGetter(constProp, dirKey) {
- return function () {
+ return function() {
let path;
try {
path = Services.dirsvc.get(dirKey, Ci.nsIFile).path;
delete SharedAll.Constants.Path[constProp];
SharedAll.Constants.Path[constProp] = path;
} catch (ex) {
// Ignore errors if the value still isn't available. Hopefully
// the next access will return it.
@@ -431,17 +431,17 @@ var Scheduler = this.Scheduler = {
Scheduler.Debugging.latestReceived = null;
Scheduler.Debugging.latestSent = [Date.now(), method, summarizeObject(args)];
// Don't kill the worker just yet
Scheduler.restartTimer();
// The last object inside the args may be an options object.
let options = null;
- if (args && args.length >= 1 && typeof args[args.length-1] === "object") {
+ if (args && args.length >= 1 && typeof args[args.length - 1] === "object") {
options = args[args.length - 1];
}
let reply;
try {
try {
Scheduler.Debugging.messagesSent++;
Scheduler.Debugging.latestSent = Scheduler.Debugging.latestSent.slice(0, 2);
@@ -507,17 +507,17 @@ const PREF_OSFILE_LOG_REDIRECT = "toolki
* Returns a value read or, in case of an error, oldPref or false.
*
* @param bool oldPref
* An optional value that the DEBUG flag was set to previously.
*/
function readDebugPref(prefName, oldPref = false) {
// If neither pref nor oldPref were set, default it to false.
return Services.prefs.getBoolPref(prefName, oldPref);
-};
+}
/**
* Listen to PREF_OSFILE_LOG changes and update gShouldLog flag
* appropriately.
*/
Services.prefs.addObserver(PREF_OSFILE_LOG,
function prefObserver(aSubject, aTopic, aData) {
SharedAll.Config.DEBUG = readDebugPref(PREF_OSFILE_LOG, SharedAll.Config.DEBUG);
@@ -677,17 +677,17 @@ File.prototype = {
// Preserve reference to option |outExecutionDuration|, |outSerializationDuration|, if it is passed.
options = clone(options, ["outExecutionDuration", "outSerializationDuration"]);
options.bytes = buffer.byteLength;
}
return Scheduler.post("File_prototype_write",
[this._fdmsg,
Type.void_t.in_ptr.toMsg(buffer),
options],
- buffer/*Ensure that |buffer| is not gc-ed*/);
+ buffer/* Ensure that |buffer| is not gc-ed*/);
},
/**
* Read bytes from this file to a new buffer.
*
* @param {number=} bytes If unspecified, read all the remaining bytes from
* this file. If specified, read |bytes| bytes, or less if the file does not
* contain that many bytes.
@@ -1185,20 +1185,20 @@ File.exists = function exists(path) {
*/
File.writeAtomic = function writeAtomic(path, buffer, options = {}) {
// Copy |options| to avoid modifying the original object but preserve the
// reference to |outExecutionDuration|, |outSerializationDuration| option if it is passed.
options = clone(options, ["outExecutionDuration", "outSerializationDuration"]);
// As options.tmpPath is a path, we need to encode it as |Type.path| message
if ("tmpPath" in options) {
options.tmpPath = Type.path.toMsg(options.tmpPath);
- };
+ }
if (isTypedArray(buffer) && (!("bytes" in options))) {
options.bytes = buffer.byteLength;
- };
+ }
let refObj = {};
TelemetryStopwatch.start("OSFILE_WRITEATOMIC_JANK_MS", refObj);
let promise = Scheduler.post("writeAtomic",
[Type.path.toMsg(path),
Type.void_t.in_ptr.toMsg(buffer),
options], [options, buffer, path]);
TelemetryStopwatch.finish("OSFILE_WRITEATOMIC_JANK_MS", refObj);
return promise;
@@ -1265,20 +1265,20 @@ var DirectoryIterator = function Directo
*/
this.__itmsg = Scheduler.post(
"new_DirectoryIterator", [Type.path.toMsg(path), options],
path
);
this._isClosed = false;
};
DirectoryIterator.prototype = {
- iterator: function () {
+ iterator: function() {
return this;
},
- __iterator__: function () {
+ __iterator__: function() {
return this;
},
// Once close() is called, _itmsg should reject with a
// StopIteration. However, we don't want to create the promise until
// it's needed because it might never be used. In that case, we
// would get a warning on the console.
get _itmsg() {
--- a/toolkit/components/osfile/modules/osfile_async_worker.js
+++ b/toolkit/components/osfile/modules/osfile_async_worker.js
@@ -80,17 +80,17 @@ if (this.Components) {
* @param {*} resource A resource.
* @param {*=} info Optional information. For debugging purposes.
*
* @return {*} A unique identifier. For the moment, this is a number,
* but this might not remain the case forever.
*/
add: function(resource, info) {
let id = this._idgen++;
- this._map.set(id, {resource:resource, info:info});
+ this._map.set(id, {resource: resource, info: info});
return id;
},
/**
* Return a list of all open resources i.e. the ones still present in
* ResourceTracker's _map.
*/
listOpenedResources: function listOpenedResources() {
return Array.from(this._map, ([id, resource]) => resource.info.path);
--- a/toolkit/components/osfile/modules/osfile_shared_allthreads.jsm
+++ b/toolkit/components/osfile/modules/osfile_shared_allthreads.jsm
@@ -62,46 +62,46 @@ var EXPORTED_SYMBOLS = [
"normalizeBufferArgs",
"projectValue",
"isArrayBuffer",
"isTypedArray",
"defineLazyGetter",
"OS" // Warning: this exported symbol will disappear
];
-////////////////////// Configuration of OS.File
+// //////////////////// Configuration of OS.File
var Config = {
/**
* If |true|, calls to |LOG| are shown. Otherwise, they are hidden.
*
* This configuration option is controlled by preference "toolkit.osfile.log".
*/
DEBUG: false,
/**
* TEST
*/
TEST: false
};
exports.Config = Config;
-////////////////////// OS Constants
+// //////////////////// OS Constants
if (typeof Components != "undefined") {
// On the main thread, OS.Constants is defined by a xpcom
// component. On other threads, it is available automatically
Cu.import("resource://gre/modules/ctypes.jsm");
Cc["@mozilla.org/net/osfileconstantsservice;1"].
getService(Ci.nsIOSFileConstantsService).init();
}
exports.Constants = OS.Constants;
-///////////////////// Utilities
+// /////////////////// Utilities
// Define a lazy getter for a property
var defineLazyGetter = function defineLazyGetter(object, name, getter) {
Object.defineProperty(object, name, {
configurable: true,
get: function lazy() {
delete this[name];
let value = getter.call(this);
@@ -110,17 +110,17 @@ var defineLazyGetter = function defineLa
});
return value;
}
});
};
exports.defineLazyGetter = defineLazyGetter;
-///////////////////// Logging
+// /////////////////// Logging
/**
* The default implementation of the logger.
*
* The choice of logger can be overridden with Config.TEST.
*/
var gLogger;
if (typeof window != "undefined" && window.console && console.log) {
@@ -151,31 +151,31 @@ var stringifyArg = function stringifyArg
* implementation of |toString| is to check whether it returns
* '[object Object]'. Unfortunately, we cannot simply compare |arg.toString|
* and |Object.prototype.toString| as |arg| typically comes from another
* compartment.
*/
if (argToString === "[object Object]") {
return JSON.stringify(arg, function(key, value) {
if (isTypedArray(value)) {
- return "["+ value.constructor.name + " " + value.byteOffset + " " + value.byteLength + "]";
+ return "[" + value.constructor.name + " " + value.byteOffset + " " + value.byteLength + "]";
}
if (isArrayBuffer(arg)) {
return "[" + value.constructor.name + " " + value.byteLength + "]";
}
return value;
});
- } else {
+ }
return argToString;
- }
+
}
return arg;
};
-var LOG = function (...args) {
+var LOG = function(...args) {
if (!Config.DEBUG) {
// If logging is deactivated, don't log
return;
}
let logFunc = gLogger;
if (Config.TEST && typeof Components != "undefined") {
// If _TESTING_LOGGING is set, and if we are on the main thread,
@@ -199,17 +199,17 @@ exports.LOG = LOG;
*
* Note: to reference and not copy specific fields, provide an optional
* |refs| argument containing their names.
*
* @param {JSON} object Options to be cloned.
* @param {Array} refs An optional array of field names to be passed by
* reference instead of copying.
*/
-var clone = function (object, refs = []) {
+var clone = function(object, refs = []) {
let result = {};
// Make a reference between result[key] and object[key].
let refer = function refer(result, key, object) {
Object.defineProperty(result, key, {
enumerable: true,
get: function() {
return object[key];
},
@@ -225,17 +225,17 @@ var clone = function (object, refs = [])
refer(result, k, object);
}
}
return result;
};
exports.clone = clone;
-///////////////////// Abstractions above js-ctypes
+// /////////////////// Abstractions above js-ctypes
/**
* Abstraction above js-ctypes types.
*
* Use values of this type to register FFI functions. In addition to the
* usual features of js-ctypes, values of this type perform the necessary
* transformations to ensure that C errors are handled nicely, to connect
* resources with their finalizer, etc.
@@ -246,17 +246,17 @@ exports.clone = clone;
* @constructor
*/
function Type(name, implementation) {
if (!(typeof name == "string")) {
throw new TypeError("Type expects as first argument a name, got: "
+ name);
}
if (!(implementation instanceof ctypes.CType)) {
- throw new TypeError("Type expects as second argument a ctypes.CType"+
+ throw new TypeError("Type expects as second argument a ctypes.CType" +
", got: " + implementation);
}
Object.defineProperty(this, "name", { value: name });
Object.defineProperty(this, "implementation", { value: implementation });
}
Type.prototype = {
/**
* Serialize a value of |this| |Type| into a format that can
@@ -426,17 +426,17 @@ exports.isArrayBuffer = isArrayBuffer;
* A |Type| of pointers.
*
* @param {string} name The name of this type.
* @param {CType} implementation The type of this pointer.
* @param {Type} targetType The target type.
*/
function PtrType(name, implementation, targetType) {
Type.call(this, name, implementation);
- if (targetType == null || !targetType instanceof Type) {
+ if (targetType == null || !(targetType instanceof Type)) {
throw new TypeError("targetType must be an instance of Type");
}
/**
* The type of values targeted by this pointer type.
*/
Object.defineProperty(this, "targetType", {
value: targetType
});
@@ -529,17 +529,17 @@ var projectValue = function projectValue
if (!("value" in x)) { // Sanity check
throw new TypeError("Number " + x.toSource() + " has no field |value|");
}
return x.value;
};
function projector(type, signed) {
LOG("Determining best projection for", type,
- "(size: ", type.size, ")", signed?"signed":"unsigned");
+ "(size: ", type.size, ")", signed ? "signed" : "unsigned");
if (type instanceof Type) {
type = type.implementation;
}
if (!type.size) {
throw new TypeError("Argument is not a proper C type");
}
// Determine if type is projected to Int64/Uint64
if (type.size == 8 // Usual case
@@ -549,24 +549,24 @@ function projector(type, signed) {
|| type == ctypes.size_t // Special cases
|| type == ctypes.ssize_t
|| type == ctypes.intptr_t
|| type == ctypes.uintptr_t
|| type == ctypes.off_t) {
if (signed) {
LOG("Projected as a large signed integer");
return projectLargeInt;
- } else {
+ }
LOG("Projected as a large unsigned integer");
return projectLargeUInt;
- }
+
}
LOG("Projected as a regular number");
return projectValue;
-};
+}
exports.projectValue = projectValue;
/**
* Get the appropriate type for an unsigned int of the given size.
*
* This function is useful to define types such as |mode_t| whose
* actual width depends on the OS/platform.
*
@@ -640,17 +640,17 @@ Type.voidptr_t =
* |false| otherwise.
*
* @constructor
*/
function IntType(name, implementation, signed) {
Type.call(this, name, implementation);
this.importFromC = projector(implementation, signed);
this.project = this.importFromC;
-};
+}
IntType.prototype = Object.create(Type.prototype);
IntType.prototype.toMsg = function toMsg(value) {
if (typeof value == "number") {
return value;
}
return this.project(value);
};
@@ -857,17 +857,17 @@ HollowStructure.prototype = {
" already has a field at offset " + offset);
}
if (offset + type.size > this.size) {
throw new Error("HollowStructure " + this.name +
" cannot place a value of type " + type +
" at offset " + offset +
" without exceeding its size of " + this.size);
}
- let field = {name: name, type:type};
+ let field = {name: name, type: type};
this.offset_to_field_info[offset] = field;
},
/**
* Create a pseudo-field that will only serve as padding.
*
* @param {number} size The number of bytes in the field.
* @return {Object} An association field-name => field-type,
@@ -955,17 +955,17 @@ exports.HollowStructure = HollowStructur
* represent this library. Used e.g. to try different library names
* on distinct operating systems ("libxul", "XUL", etc.).
*
* @constructor
*/
function Library(name, ...candidates) {
this.name = name;
this._candidates = candidates;
-};
+}
Library.prototype = Object.freeze({
/**
* The native library as a js-ctypes object.
*
* @throws {Error} If none of the candidate libraries could be opened.
*/
get library() {
let library;
@@ -1102,17 +1102,17 @@ exports.Library = Library;
* @param {Type} returnType The type of values returned by the function.
* @param {...Type} argTypes The type of arguments to the function.
*
* @return null if the function could not be defined (generally because
* it does not exist), or a JavaScript wrapper performing the call to C
* and any type conversion required.
*/
var declareFFI = function declareFFI(lib, symbol, abi,
- returnType /*, argTypes ...*/) {
+ returnType /* , argTypes ...*/) {
LOG("Attempting to declare FFI ", symbol);
// We guard agressively, to avoid any late surprise
if (typeof symbol != "string") {
throw new TypeError("declareFFI expects as first argument a string");
}
abi = abi || ctypes.default_abi;
if (Object.prototype.toString.call(abi) != "[object CABI]") {
// Note: This is the only known manner of checking whether an object
@@ -1237,20 +1237,20 @@ function normalizeBufferArgs(candidate,
} else if (candidate.byteLength < bytes) {
throw new TypeError("Buffer is too short. I need at least " +
bytes +
" bytes but I have only " +
candidate.byteLength +
"bytes");
}
return bytes;
-};
+}
exports.normalizeBufferArgs = normalizeBufferArgs;
-///////////////////// OS interactions
+// /////////////////// OS interactions
/**
* An OS error.
*
* This class is provided mostly for type-matching. If you need more
* details about an error, you should use the platform-specific error
* codes provided by subclasses of |OS.Shared.Error|.
*
@@ -1264,17 +1264,17 @@ function OSError(operation, path = "") {
Error.call(this);
this.operation = operation;
this.path = path;
}
OSError.prototype = Object.create(Error.prototype);
exports.OSError = OSError;
-///////////////////// Temporary boilerplate
+// /////////////////// Temporary boilerplate
// Boilerplate, to simplify the transition to require()
// Do not rely upon this symbol, it will disappear with
// bug 883050.
exports.OS = {
Constants: exports.Constants,
Shared: {
LOG: LOG,
clone: clone,
@@ -1301,15 +1301,15 @@ Object.defineProperty(exports.OS.Shared,
return Config.TEST;
},
set: function(x) {
return Config.TEST = x;
}
});
-///////////////////// Permanent boilerplate
+// /////////////////// Permanent boilerplate
if (typeof Components != "undefined") {
this.EXPORTED_SYMBOLS = EXPORTED_SYMBOLS;
for (let symbol of EXPORTED_SYMBOLS) {
this[symbol] = exports[symbol];
}
}
--- a/toolkit/components/osfile/modules/osfile_shared_front.jsm
+++ b/toolkit/components/osfile/modules/osfile_shared_front.jsm
@@ -76,19 +76,19 @@ AbstractFile.prototype = {
let chunkSize = this._read(view, length, options);
if (chunkSize == 0) {
break;
}
pos += chunkSize;
}
if (pos == bytes) {
return buffer;
- } else {
+ }
return buffer.subarray(0, pos);
- }
+
},
/**
* Write bytes from a buffer to this file.
*
* Note that, by default, this function may perform several I/O
* operations to ensure that the buffer is fully written.
*
@@ -127,22 +127,22 @@ AbstractFile.prototype = {
* - {number} maxReadableNumber Used to limit the amount of tries after a failed
* file creation. Default is 20.
*
* @return {Object} contains A file object{file} and the path{path}.
* @throws {OS.File.Error} If the file could not be opened.
*/
AbstractFile.openUnique = function openUnique(path, options = {}) {
let mode = {
- create : true
+ create: true
};
let dirName = Path.dirname(path);
let leafName = Path.basename(path);
- let lastDotCharacter = leafName.lastIndexOf('.');
+ let lastDotCharacter = leafName.lastIndexOf(".");
let fileName = leafName.substring(0, lastDotCharacter != -1 ? lastDotCharacter : leafName.length);
let suffix = (lastDotCharacter != -1 ? leafName.substring(lastDotCharacter) : "");
let uniquePath = "";
let maxAttempts = options.maxAttempts || 99;
let humanReadable = !!options.humanReadable;
const HEX_RADIX = 16;
// We produce HEX numbers between 0 and 2^24 - 1.
const MAX_HEX_NUMBER = 16777215;
--- a/toolkit/components/osfile/modules/osfile_unix_allthreads.jsm
+++ b/toolkit/components/osfile/modules/osfile_unix_allthreads.jsm
@@ -46,18 +46,18 @@ exports.libc = libc;
// Define declareFFI
var declareFFI = SharedAll.declareFFI.bind(null, libc);
exports.declareFFI = declareFFI;
// Define lazy binding
var LazyBindings = {};
libc.declareLazy(LazyBindings, "strerror",
"strerror", ctypes.default_abi,
- /*return*/ ctypes.char.ptr,
- /*errnum*/ ctypes.int);
+ /* return*/ ctypes.char.ptr,
+ /* errnum*/ ctypes.int);
/**
* A File-related error.
*
* To obtain a human-readable error message, use method |toString|.
* To determine the cause of the error, use the various |becauseX|
* getters. To determine the operation that failed, use field
* |operation|.
@@ -83,17 +83,17 @@ var OSError = function OSError(operation
errno = ctypes.errno, path = "") {
SharedAll.OSError.call(this, operation, path);
this.unixErrno = errno;
};
OSError.prototype = Object.create(SharedAll.OSError.prototype);
OSError.prototype.toString = function toString() {
return "Unix error " + this.unixErrno +
" during operation " + this.operation +
- (this.path? " on file " + this.path : "") +
+ (this.path ? " on file " + this.path : "") +
" (" + LazyBindings.strerror(this.unixErrno).readString() + ")";
};
OSError.prototype.toMsg = function toMsg() {
return OSError.toMsg(this);
};
/**
* |true| if the error was raised because a file or directory
@@ -361,15 +361,15 @@ var EXPORTED_SYMBOLS = [
"AbstractInfo",
"AbstractEntry",
"Type",
"POS_START",
"POS_CURRENT",
"POS_END"
];
-//////////// Boilerplate
+// ////////// Boilerplate
if (typeof Components != "undefined") {
this.EXPORTED_SYMBOLS = EXPORTED_SYMBOLS;
for (let symbol of EXPORTED_SYMBOLS) {
this[symbol] = exports[symbol];
}
}
--- a/toolkit/components/osfile/modules/osfile_unix_back.jsm
+++ b/toolkit/components/osfile/modules/osfile_unix_back.jsm
@@ -236,28 +236,26 @@
Type.statvfs = statvfs.getType();
}
// Declare libc functions as functions of |OS.Unix.File|
// Finalizer-related functions
libc.declareLazy(SysFile, "_close",
"close", ctypes.default_abi,
- /*return */ctypes.int,
- /*fd*/ ctypes.int);
+ /* return */ctypes.int, ctypes.int);
SysFile.close = function close(fd) {
// Detach the finalizer and call |_close|.
return fd.dispose();
};
libc.declareLazy(SysFile, "_close_dir",
"closedir", ctypes.default_abi,
- /*return */ctypes.int,
- /*dirp*/ Type.DIR.in_ptr.implementation);
+ /* return */ctypes.int, Type.DIR.in_ptr.implementation);
SysFile.closedir = function closedir(fd) {
// Detach the finalizer and call |_close_dir|.
return fd.dispose();
};
{
// Symbol free() is special.
@@ -268,324 +266,263 @@
// On platforms for which we override free(), nspr defines
// a special library name "a.out" that will resolve to the
// correct implementation free().
// If it turns out we don't have an a.out library or a.out
// doesn't contain free, use the ordinary libc free.
default_lib.declareLazyWithFallback(libc, SysFile, "free",
"free", ctypes.default_abi,
- /*return*/ ctypes.void_t,
- /*ptr*/ ctypes.voidptr_t);
+ /* return*/ ctypes.void_t, ctypes.voidptr_t);
}
// Other functions
- libc.declareLazyFFI(SysFile, "access",
+ libc.declareLazyFFI(SysFile, "access",
"access", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*path*/ Type.path,
- /*mode*/ Type.int);
+ /* return*/ Type.negativeone_or_nothing, Type.path, Type.int);
- libc.declareLazyFFI(SysFile, "chdir",
+ libc.declareLazyFFI(SysFile, "chdir",
"chdir", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*path*/ Type.path);
+ /* return*/ Type.negativeone_or_nothing, Type.path);
- libc.declareLazyFFI(SysFile, "chmod",
+ libc.declareLazyFFI(SysFile, "chmod",
"chmod", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*path*/ Type.path,
- /*mode*/ Type.mode_t);
+ /* return*/ Type.negativeone_or_nothing, Type.path, Type.mode_t);
- libc.declareLazyFFI(SysFile, "chown",
+ libc.declareLazyFFI(SysFile, "chown",
"chown", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*path*/ Type.path,
- /*uid*/ Type.uid_t,
- /*gid*/ Type.gid_t);
+ /* return*/ Type.negativeone_or_nothing, Type.path, Type.uid_t, Type.gid_t);
- libc.declareLazyFFI(SysFile, "copyfile",
+ libc.declareLazyFFI(SysFile, "copyfile",
"copyfile", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*source*/ Type.path,
- /*dest*/ Type.path,
- /*state*/ Type.void_t.in_ptr, // Ignored atm
- /*flags*/ Type.uint32_t);
+ /* return*/ Type.negativeone_or_nothing,
+ /* source*/ Type.path, Type.path, Type.void_t.in_ptr, Type.uint32_t);
- libc.declareLazyFFI(SysFile, "dup",
+ libc.declareLazyFFI(SysFile, "dup",
"dup", ctypes.default_abi,
- /*return*/ Type.negativeone_or_fd,
- /*fd*/ Type.fd);
+ /* return*/ Type.negativeone_or_fd, Type.fd);
if ("OSFILE_SIZEOF_DIR" in Const) {
// On platforms for which |dirfd| is a macro
SysFile.dirfd =
function dirfd(DIRp) {
return Type.DIR.in_ptr.implementation(DIRp).contents.dd_fd;
};
} else {
// On platforms for which |dirfd| is a function
- libc.declareLazyFFI(SysFile, "dirfd",
+ libc.declareLazyFFI(SysFile, "dirfd",
"dirfd", ctypes.default_abi,
- /*return*/ Type.negativeone_or_fd,
- /*dir*/ Type.DIR.in_ptr);
+ /* return*/ Type.negativeone_or_fd, Type.DIR.in_ptr);
}
- libc.declareLazyFFI(SysFile, "chdir",
+ libc.declareLazyFFI(SysFile, "chdir",
"chdir", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*path*/ Type.path);
+ /* return*/ Type.negativeone_or_nothing, Type.path);
- libc.declareLazyFFI(SysFile, "fchdir",
+ libc.declareLazyFFI(SysFile, "fchdir",
"fchdir", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*fd*/ Type.fd);
+ /* return*/ Type.negativeone_or_nothing, Type.fd);
- libc.declareLazyFFI(SysFile, "fchmod",
+ libc.declareLazyFFI(SysFile, "fchmod",
"fchmod", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*fd*/ Type.fd,
- /*mode*/ Type.mode_t);
+ /* return*/ Type.negativeone_or_nothing, Type.fd, Type.mode_t);
- libc.declareLazyFFI(SysFile, "fchown",
+ libc.declareLazyFFI(SysFile, "fchown",
"fchown", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*fd*/ Type.fd,
- /*uid_t*/ Type.uid_t,
- /*gid_t*/ Type.gid_t);
+ /* return*/ Type.negativeone_or_nothing, Type.fd, Type.uid_t, Type.gid_t);
- libc.declareLazyFFI(SysFile, "fsync",
+ libc.declareLazyFFI(SysFile, "fsync",
"fsync", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*fd*/ Type.fd);
+ /* return*/ Type.negativeone_or_nothing, Type.fd);
- libc.declareLazyFFI(SysFile, "getcwd",
+ libc.declareLazyFFI(SysFile, "getcwd",
"getcwd", ctypes.default_abi,
- /*return*/ Type.out_path,
- /*buf*/ Type.out_path,
- /*size*/ Type.size_t);
+ /* return*/ Type.out_path, Type.out_path, Type.size_t);
- libc.declareLazyFFI(SysFile, "getwd",
+ libc.declareLazyFFI(SysFile, "getwd",
"getwd", ctypes.default_abi,
- /*return*/ Type.out_path,
- /*buf*/ Type.out_path);
+ /* return*/ Type.out_path, Type.out_path);
// Two variants of |getwd| which allocate the memory
// dynamically.
// Linux/Android version
- libc.declareLazyFFI(SysFile, "get_current_dir_name",
+ libc.declareLazyFFI(SysFile, "get_current_dir_name",
"get_current_dir_name", ctypes.default_abi,
- /*return*/ Type.out_path.releaseWithLazy(() =>
+ /* return*/ Type.out_path.releaseWithLazy(() =>
SysFile.free
));
// MacOS/BSD version (will return NULL on Linux/Android)
- libc.declareLazyFFI(SysFile, "getwd_auto",
+ libc.declareLazyFFI(SysFile, "getwd_auto",
"getwd", ctypes.default_abi,
- /*return*/ Type.out_path.releaseWithLazy(() =>
+ /* return*/ Type.out_path.releaseWithLazy(() =>
SysFile.free
- ),
- /*buf*/ Type.void_t.out_ptr);
+ ), Type.void_t.out_ptr);
- libc.declareLazyFFI(SysFile, "fdatasync",
+ libc.declareLazyFFI(SysFile, "fdatasync",
"fdatasync", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*fd*/ Type.fd); // Note: MacOS/BSD-specific
+ /* return*/ Type.negativeone_or_nothing, Type.fd); // Note: MacOS/BSD-specific
- libc.declareLazyFFI(SysFile, "ftruncate",
+ libc.declareLazyFFI(SysFile, "ftruncate",
"ftruncate", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*fd*/ Type.fd,
- /*length*/ Type.off_t);
+ /* return*/ Type.negativeone_or_nothing, Type.fd,
+ /* length*/ Type.off_t);
- libc.declareLazyFFI(SysFile, "lchown",
+ libc.declareLazyFFI(SysFile, "lchown",
"lchown", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*path*/ Type.path,
- /*uid_t*/ Type.uid_t,
- /*gid_t*/ Type.gid_t);
+ /* return*/ Type.negativeone_or_nothing, Type.path, Type.uid_t, Type.gid_t);
- libc.declareLazyFFI(SysFile, "link",
+ libc.declareLazyFFI(SysFile, "link",
"link", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*source*/ Type.path,
- /*dest*/ Type.path);
+ /* return*/ Type.negativeone_or_nothing,
+ /* source*/ Type.path, Type.path);
- libc.declareLazyFFI(SysFile, "lseek",
+ libc.declareLazyFFI(SysFile, "lseek",
"lseek", ctypes.default_abi,
- /*return*/ Type.off_t,
- /*fd*/ Type.fd,
- /*offset*/ Type.off_t,
- /*whence*/ Type.int);
-
- libc.declareLazyFFI(SysFile, "mkdir",
- "mkdir", ctypes.default_abi,
- /*return*/ Type.int,
- /*path*/ Type.path,
- /*mode*/ Type.int);
+ /* return*/ Type.off_t, Type.fd,
+ /* offset*/ Type.off_t,
+ /* whence*/ Type.int);
- libc.declareLazyFFI(SysFile, "mkstemp",
- "mkstemp", ctypes.default_abi,
- /*return*/ Type.fd,
- /*template*/ Type.out_path);
+ libc.declareLazyFFI(SysFile, "mkdir",
+ "mkdir", ctypes.default_abi,
+ /* return*/ Type.int,
+ /* path*/ Type.path,
+ /* mode*/ Type.int);
- libc.declareLazyFFI(SysFile, "open",
+ libc.declareLazyFFI(SysFile, "mkstemp",
+ "mkstemp", ctypes.default_abi, Type.fd,
+ /* template*/ Type.out_path);
+
+ libc.declareLazyFFI(SysFile, "open",
"open", ctypes.default_abi,
- /*return*/ Type.negativeone_or_fd,
- /*path*/ Type.path,
- /*oflags*/ Type.int,
- /*mode*/ Type.int);
+ /* return*/ Type.negativeone_or_fd, Type.path,
+ /* oflags*/ Type.int, Type.int);
if (OS.Constants.Sys.Name == "NetBSD") {
- libc.declareLazyFFI(SysFile, "opendir",
+ libc.declareLazyFFI(SysFile, "opendir",
"__opendir30", ctypes.default_abi,
- /*return*/ Type.null_or_DIR_ptr,
- /*path*/ Type.path);
+ /* return*/ Type.null_or_DIR_ptr, Type.path);
} else {
- libc.declareLazyFFI(SysFile, "opendir",
+ libc.declareLazyFFI(SysFile, "opendir",
"opendir", ctypes.default_abi,
- /*return*/ Type.null_or_DIR_ptr,
- /*path*/ Type.path);
+ /* return*/ Type.null_or_DIR_ptr, Type.path);
}
- libc.declareLazyFFI(SysFile, "pread",
+ libc.declareLazyFFI(SysFile, "pread",
"pread", ctypes.default_abi,
- /*return*/ Type.negativeone_or_ssize_t,
- /*fd*/ Type.fd,
- /*buf*/ Type.void_t.out_ptr,
- /*nbytes*/ Type.size_t,
- /*offset*/ Type.off_t);
+ /* return*/ Type.negativeone_or_ssize_t, Type.fd, Type.void_t.out_ptr,
+ /* nbytes*/ Type.size_t,
+ /* offset*/ Type.off_t);
- libc.declareLazyFFI(SysFile, "pwrite",
+ libc.declareLazyFFI(SysFile, "pwrite",
"pwrite", ctypes.default_abi,
- /*return*/ Type.negativeone_or_ssize_t,
- /*fd*/ Type.fd,
- /*buf*/ Type.void_t.in_ptr,
- /*nbytes*/ Type.size_t,
- /*offset*/ Type.off_t);
+ /* return*/ Type.negativeone_or_ssize_t, Type.fd, Type.void_t.in_ptr,
+ /* nbytes*/ Type.size_t,
+ /* offset*/ Type.off_t);
- libc.declareLazyFFI(SysFile, "read",
+ libc.declareLazyFFI(SysFile, "read",
"read", ctypes.default_abi,
- /*return*/Type.negativeone_or_ssize_t,
- /*fd*/ Type.fd,
- /*buf*/ Type.void_t.out_ptr,
- /*nbytes*/Type.size_t);
+ /* return*/Type.negativeone_or_ssize_t, Type.fd, Type.void_t.out_ptr,
+ /* nbytes*/Type.size_t);
- libc.declareLazyFFI(SysFile, "posix_fadvise",
+ libc.declareLazyFFI(SysFile, "posix_fadvise",
"posix_fadvise", ctypes.default_abi,
- /*return*/ Type.int,
- /*fd*/ Type.fd,
- /*offset*/ Type.off_t,
- /*len*/ Type.off_t,
- /*advise*/ Type.int);
+ /* return*/ Type.int, Type.fd,
+ /* offset*/ Type.off_t, Type.off_t,
+ /* advise*/ Type.int);
if (Const._DARWIN_FEATURE_64_BIT_INODE) {
// Special case for MacOS X 10.5+
// Symbol name "readdir" still exists but is used for a
// deprecated function that does not match the
// constants of |Const|.
- libc.declareLazyFFI(SysFile, "readdir",
+ libc.declareLazyFFI(SysFile, "readdir",
"readdir$INODE64", ctypes.default_abi,
- /*return*/ Type.null_or_dirent_ptr,
- /*dir*/ Type.DIR.in_ptr); // For MacOS X
+ /* return*/ Type.null_or_dirent_ptr, Type.DIR.in_ptr); // For MacOS X
} else if (OS.Constants.Sys.Name == "NetBSD") {
- libc.declareLazyFFI(SysFile, "readdir",
+ libc.declareLazyFFI(SysFile, "readdir",
"__readdir30", ctypes.default_abi,
- /*return*/Type.null_or_dirent_ptr,
- /*dir*/ Type.DIR.in_ptr); // Other Unices
+ /* return*/Type.null_or_dirent_ptr, Type.DIR.in_ptr); // Other Unices
} else {
- libc.declareLazyFFI(SysFile, "readdir",
+ libc.declareLazyFFI(SysFile, "readdir",
"readdir", ctypes.default_abi,
- /*return*/Type.null_or_dirent_ptr,
- /*dir*/ Type.DIR.in_ptr); // Other Unices
+ /* return*/Type.null_or_dirent_ptr, Type.DIR.in_ptr); // Other Unices
}
- libc.declareLazyFFI(SysFile, "rename",
+ libc.declareLazyFFI(SysFile, "rename",
"rename", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*old*/ Type.path,
- /*new*/ Type.path);
+ /* return*/ Type.negativeone_or_nothing, Type.path, Type.path);
- libc.declareLazyFFI(SysFile, "rmdir",
+ libc.declareLazyFFI(SysFile, "rmdir",
"rmdir", ctypes.default_abi,
- /*return*/ Type.int,
- /*path*/ Type.path);
+ /* return*/ Type.int, Type.path);
- libc.declareLazyFFI(SysFile, "splice",
+ libc.declareLazyFFI(SysFile, "splice",
"splice", ctypes.default_abi,
- /*return*/ Type.long,
- /*fd_in*/ Type.fd,
- /*off_in*/ Type.off_t.in_ptr,
- /*fd_out*/ Type.fd,
- /*off_out*/Type.off_t.in_ptr,
- /*len*/ Type.size_t,
- /*flags*/ Type.unsigned_int); // Linux/Android-specific
+ /* return*/ Type.long, Type.fd,
+ /* off_in*/ Type.off_t.in_ptr,
+ /* fd_out*/ Type.fd,
+ /* off_out*/Type.off_t.in_ptr, Type.size_t, Type.unsigned_int); // Linux/Android-specific
- libc.declareLazyFFI(SysFile, "statfs",
+ libc.declareLazyFFI(SysFile, "statfs",
"statfs", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*path*/ Type.path,
- /*buf*/ Type.statvfs.out_ptr); // Android,B2G
+ /* return*/ Type.negativeone_or_nothing, Type.path, Type.statvfs.out_ptr); // Android,B2G
- libc.declareLazyFFI(SysFile, "statvfs",
+ libc.declareLazyFFI(SysFile, "statvfs",
"statvfs", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*path*/ Type.path,
- /*buf*/ Type.statvfs.out_ptr); // Other platforms
+ /* return*/ Type.negativeone_or_nothing, Type.path, Type.statvfs.out_ptr); // Other platforms
- libc.declareLazyFFI(SysFile, "symlink",
+ libc.declareLazyFFI(SysFile, "symlink",
"symlink", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*source*/ Type.path,
- /*dest*/ Type.path);
+ /* return*/ Type.negativeone_or_nothing,
+ /* source*/ Type.path, Type.path);
- libc.declareLazyFFI(SysFile, "truncate",
+ libc.declareLazyFFI(SysFile, "truncate",
"truncate", ctypes.default_abi,
- /*return*/Type.negativeone_or_nothing,
- /*path*/ Type.path,
- /*length*/ Type.off_t);
+ /* return*/Type.negativeone_or_nothing, Type.path,
+ /* length*/ Type.off_t);
- libc.declareLazyFFI(SysFile, "unlink",
+ libc.declareLazyFFI(SysFile, "unlink",
"unlink", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*path*/ Type.path);
+ /* return */ Type.negativeone_or_nothing,
+ /* path */ Type.path);
- libc.declareLazyFFI(SysFile, "write",
+ libc.declareLazyFFI(SysFile, "write",
"write", ctypes.default_abi,
- /*return*/ Type.negativeone_or_ssize_t,
- /*fd*/ Type.fd,
- /*buf*/ Type.void_t.in_ptr,
- /*nbytes*/ Type.size_t);
+ /* return */ Type.negativeone_or_ssize_t,
+ /* fd */ Type.fd,
+ /* buf */ Type.void_t.in_ptr,
+ /* nbytes */ Type.size_t);
// Weird cases that require special treatment
// OSes use a variety of hacks to differentiate between
// 32-bits and 64-bits versions of |stat|, |lstat|, |fstat|.
if (Const._DARWIN_FEATURE_64_BIT_INODE) {
// MacOS X 64-bits
- libc.declareLazyFFI(SysFile, "stat",
+ libc.declareLazyFFI(SysFile, "stat",
"stat$INODE64", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*path*/ Type.path,
- /*buf*/ Type.stat.out_ptr
+ /* return */ Type.negativeone_or_nothing,
+ /* path */ Type.path,
+ /* buf */ Type.stat.out_ptr
);
- libc.declareLazyFFI(SysFile, "lstat",
+ libc.declareLazyFFI(SysFile, "lstat",
"lstat$INODE64", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*path*/ Type.path,
- /*buf*/ Type.stat.out_ptr
+ /* return */ Type.negativeone_or_nothing,
+ /* path */ Type.path,
+ /* buf */ Type.stat.out_ptr
);
- libc.declareLazyFFI(SysFile, "fstat",
+ libc.declareLazyFFI(SysFile, "fstat",
"fstat$INODE64", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*path*/ Type.fd,
- /*buf*/ Type.stat.out_ptr
+ /* return */ Type.negativeone_or_nothing,
+ /* path */ Type.fd,
+ /* buf */ Type.stat.out_ptr
);
} else if (Const._STAT_VER != undefined) {
const ver = Const._STAT_VER;
let xstat_name, lxstat_name, fxstat_name;
if (OS.Constants.Sys.Name == "SunOS") {
// Solaris
xstat_name = "_xstat";
lxstat_name = "_lxstat";
@@ -593,97 +530,97 @@
} else {
// Linux, all widths
xstat_name = "__xstat";
lxstat_name = "__lxstat";
fxstat_name = "__fxstat";
}
let Stat = {};
- libc.declareLazyFFI(Stat, "xstat",
+ libc.declareLazyFFI(Stat, "xstat",
xstat_name, ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*_stat_ver*/ Type.int,
- /*path*/ Type.path,
- /*buf*/ Type.stat.out_ptr);
- libc.declareLazyFFI(Stat, "lxstat",
+ /* return */ Type.negativeone_or_nothing,
+ /* _stat_ver */ Type.int,
+ /* path */ Type.path,
+ /* buf */ Type.stat.out_ptr);
+ libc.declareLazyFFI(Stat, "lxstat",
lxstat_name, ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*_stat_ver*/ Type.int,
- /*path*/ Type.path,
- /*buf*/ Type.stat.out_ptr);
+ /* return */ Type.negativeone_or_nothing,
+ /* _stat_ver */ Type.int,
+ /* path */ Type.path,
+ /* buf */ Type.stat.out_ptr);
libc.declareLazyFFI(Stat, "fxstat",
fxstat_name, ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*_stat_ver*/ Type.int,
- /*fd*/ Type.fd,
- /*buf*/ Type.stat.out_ptr);
+ /* return */ Type.negativeone_or_nothing,
+ /* _stat_ver */ Type.int,
+ /* fd */ Type.fd,
+ /* buf */ Type.stat.out_ptr);
SysFile.stat = function stat(path, buf) {
return Stat.xstat(ver, path, buf);
};
SysFile.lstat = function lstat(path, buf) {
return Stat.lxstat(ver, path, buf);
};
SysFile.fstat = function fstat(fd, buf) {
return Stat.fxstat(ver, fd, buf);
};
} else if (OS.Constants.Sys.Name == "NetBSD") {
// NetBSD 5.0 and newer
- libc.declareLazyFFI(SysFile, "stat",
+ libc.declareLazyFFI(SysFile, "stat",
"__stat50", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*path*/ Type.path,
- /*buf*/ Type.stat.out_ptr
+ /* return */ Type.negativeone_or_nothing,
+ /* path */ Type.path,
+ /* buf */ Type.stat.out_ptr
);
- libc.declareLazyFFI(SysFile, "lstat",
+ libc.declareLazyFFI(SysFile, "lstat",
"__lstat50", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*path*/ Type.path,
- /*buf*/ Type.stat.out_ptr
+ /* return */ Type.negativeone_or_nothing,
+ /* path */ Type.path,
+ /* buf */ Type.stat.out_ptr
);
- libc.declareLazyFFI(SysFile, "fstat",
+ libc.declareLazyFFI(SysFile, "fstat",
"__fstat50", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*fd*/ Type.fd,
- /*buf*/ Type.stat.out_ptr
+ /* return */ Type.negativeone_or_nothing,
+ /* fd */ Type.fd,
+ /* buf */ Type.stat.out_ptr
);
} else {
// Mac OS X 32-bits, other Unix
- libc.declareLazyFFI(SysFile, "stat",
+ libc.declareLazyFFI(SysFile, "stat",
"stat", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*path*/ Type.path,
- /*buf*/ Type.stat.out_ptr
+ /* return */ Type.negativeone_or_nothing,
+ /* path */ Type.path,
+ /* buf */ Type.stat.out_ptr
);
- libc.declareLazyFFI(SysFile, "lstat",
+ libc.declareLazyFFI(SysFile, "lstat",
"lstat", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*path*/ Type.path,
- /*buf*/ Type.stat.out_ptr
+ /* return */ Type.negativeone_or_nothing,
+ /* path */ Type.path,
+ /* buf */ Type.stat.out_ptr
);
- libc.declareLazyFFI(SysFile, "fstat",
+ libc.declareLazyFFI(SysFile, "fstat",
"fstat", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*fd*/ Type.fd,
- /*buf*/ Type.stat.out_ptr
+ /* return */ Type.negativeone_or_nothing,
+ /* fd */ Type.fd,
+ /* buf */ Type.stat.out_ptr
);
}
// We cannot make a C array of CDataFinalizer, so
// pipe cannot be directly defined as a C function.
let Pipe = {};
libc.declareLazyFFI(Pipe, "_pipe",
"pipe", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*fds*/ new SharedAll.Type("two file descriptors",
+ /* return */ Type.negativeone_or_nothing,
+ /* fds */ new SharedAll.Type("two file descriptors",
ctypes.ArrayType(ctypes.int, 2)));
// A shared per-thread buffer used to communicate with |pipe|
let _pipebuf = new (ctypes.ArrayType(ctypes.int, 2))();
SysFile.pipe = function pipe(array) {
let result = Pipe._pipe(_pipebuf);
if (result == -1) {
@@ -692,41 +629,41 @@
array[0] = ctypes.CDataFinalizer(_pipebuf[0], SysFile._close);
array[1] = ctypes.CDataFinalizer(_pipebuf[1], SysFile._close);
return result;
};
if (OS.Constants.Sys.Name == "NetBSD") {
libc.declareLazyFFI(SysFile, "utimes",
"__utimes50", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*path*/ Type.path,
- /*timeval[2]*/ Type.timevals.out_ptr
+ /* return */ Type.negativeone_or_nothing,
+ /* path */ Type.path,
+ /* timeval[2] */ Type.timevals.out_ptr
);
} else {
libc.declareLazyFFI(SysFile, "utimes",
"utimes", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*path*/ Type.path,
- /*timeval[2]*/ Type.timevals.out_ptr
+ /* return */ Type.negativeone_or_nothing,
+ /* path */ Type.path,
+ /* timeval[2] */ Type.timevals.out_ptr
);
}
if (OS.Constants.Sys.Name == "NetBSD") {
libc.declareLazyFFI(SysFile, "futimes",
"__futimes50", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*fd*/ Type.fd,
- /*timeval[2]*/ Type.timevals.out_ptr
+ /* return */ Type.negativeone_or_nothing,
+ /* fd */ Type.fd,
+ /* timeval[2] */ Type.timevals.out_ptr
);
} else {
libc.declareLazyFFI(SysFile, "futimes",
"futimes", ctypes.default_abi,
- /*return*/ Type.negativeone_or_nothing,
- /*fd*/ Type.fd,
- /*timeval[2]*/ Type.timevals.out_ptr
+ /* return */ Type.negativeone_or_nothing,
+ /* fd */ Type.fd,
+ /* timeval[2] */ Type.timevals.out_ptr
);
}
};
exports.OS.Unix = {
File: {
_init: init
}
--- a/toolkit/components/osfile/modules/osfile_unix_front.jsm
+++ b/toolkit/components/osfile/modules/osfile_unix_front.jsm
@@ -72,17 +72,17 @@
}
if (result == -1) {
this._closeResult = new File.Error("close", ctypes.errno, this._path);
}
}
if (this._closeResult) {
throw this._closeResult;
}
- return;
+
};
/**
* Read some bytes from a file.
*
* @param {C pointer} buffer A buffer for holding the data
* once it is read.
* @param {number} nbytes The number of bytes to read. It must not
@@ -93,17 +93,17 @@
*
* @return {number} The number of bytes effectively read. If zero,
* the end of the file has been reached.
* @throws {OS.File.Error} In case of I/O error.
*/
File.prototype._read = function _read(buffer, nbytes, options = {}) {
// Populate the page cache with data from a file so the subsequent reads
// from that file will not block on disk I/O.
- if (typeof(UnixFile.posix_fadvise) === 'function' &&
+ if (typeof(UnixFile.posix_fadvise) === "function" &&
(options.sequential || !("sequential" in options))) {
UnixFile.posix_fadvise(this.fd, 0, nbytes,
OS.Constants.libc.POSIX_FADV_SEQUENTIAL);
}
return throw_on_negative("read",
UnixFile.read(this.fd, buffer, nbytes),
this._path
);
@@ -333,19 +333,19 @@
*
* @param {string} path The path to the file.
*
* @return {bool} true if the file exists, false otherwise.
*/
File.exists = function Unix_exists(path) {
if (UnixFile.access(path, Const.F_OK) == -1) {
return false;
- } else {
+ }
return true;
- }
+
};
/**
* Remove an existing file.
*
* @param {string} path The name of the file.
* @param {*=} options Additional options.
* - {bool} ignoreAbsent If |false|, throw an error if the file does
@@ -391,17 +391,17 @@
*
* @return {number} The number of bytes available for the current user.
* @throws {OS.File.Error} In case of any error.
*/
File.getAvailableFreeSpace = function Unix_getAvailableFreeSpace(sourcePath) {
let fileSystemInfo = new Type.statvfs.implementation();
let fileSystemInfoPtr = fileSystemInfo.address();
- throw_on_negative("statvfs", (UnixFile.statvfs || UnixFile.statfs)(sourcePath, fileSystemInfoPtr));
+ throw_on_negative("statvfs", (UnixFile.statvfs || UnixFile.statfs)(sourcePath, fileSystemInfoPtr));
let bytes = new Type.uint64_t.implementation(
fileSystemInfo.f_frsize * fileSystemInfo.f_bavail);
return bytes.value;
};
/**
@@ -597,17 +597,17 @@
if (!bytes_read) {
break;
}
total_read += bytes_read;
let bytes_written = throw_on_negative(
"pump",
UnixFile.splice(pipe_read, null,
dest_fd, null, bytes_read,
- (bytes_read == chunk_size)?Const.SPLICE_F_MORE:0
+ (bytes_read == chunk_size) ? Const.SPLICE_F_MORE : 0
));
if (!bytes_written) {
// This should never happen
throw new Error("Internal error: pipe disconnected");
}
total_written += bytes_written;
nbytes -= bytes_read;
if (!nbytes) {
@@ -644,19 +644,19 @@
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|
// won't work.
if (options.noOverwrite) {
- dest = File.open(destPath, {create:true, append:false});
+ dest = File.open(destPath, {create: true, append: false});
} else {
- dest = File.open(destPath, {trunc:true, append:false});
+ dest = File.open(destPath, {trunc: true, append: false});
}
if (options.unixUserland) {
result = pump_userland(source, dest, options);
} else {
result = pump(source, dest, options);
}
} catch (x) {
if (dest) {
@@ -848,17 +848,17 @@
serialized[key] = value[key];
}
return serialized;
};
let gStatData = new Type.stat.implementation();
let gStatDataPtr = gStatData.address();
- let MODE_MASK = 4095 /*= 07777*/;
+ let MODE_MASK = 4095 /* = 07777*/;
File.Info = function Info(stat, path) {
let isDir = (stat.st_mode & Const.S_IFMT) == Const.S_IFDIR;
let isSymLink = (stat.st_mode & Const.S_IFMT) == Const.S_IFLNK;
let size = Type.off_t.importFromC(stat.st_size);
let lastAccessDate = new Date(stat.st_atime * 1000);
let lastModificationDate = new Date(stat.st_mtime * 1000);
let unixLastStatusChangeDate = new Date(stat.st_ctime * 1000);
@@ -1158,17 +1158,17 @@
date = date.getTime();
}
if (typeof date !== "number" || Number.isNaN(date)) {
throw new TypeError("|date| parameter of " + fn + " must be a " +
"|Date| instance or number");
}
return date;
- };
+ }
/**
* Helper used by both versions of setPermissions.
*/
function unixMode(options) {
let mode = options.unixMode !== undefined ?
options.unixMode : DEFAULT_UNIX_MODE;
let unixHonorUmask = true;
--- a/toolkit/components/osfile/modules/osfile_win_allthreads.jsm
+++ b/toolkit/components/osfile/modules/osfile_win_allthreads.jsm
@@ -46,24 +46,20 @@ exports.libc = libc;
var declareFFI = SharedAll.declareFFI.bind(null, libc);
exports.declareFFI = declareFFI;
var Scope = {};
// Define Error
libc.declareLazy(Scope, "FormatMessage",
"FormatMessageW", ctypes.winapi_abi,
- /*return*/ ctypes.uint32_t,
- /*flags*/ ctypes.uint32_t,
- /*source*/ ctypes.voidptr_t,
- /*msgid*/ ctypes.uint32_t,
- /*langid*/ ctypes.uint32_t,
- /*buf*/ ctypes.char16_t.ptr,
- /*size*/ ctypes.uint32_t,
- /*Arguments*/ctypes.voidptr_t);
+ /* return*/ ctypes.uint32_t, ctypes.uint32_t,
+ /* source*/ ctypes.voidptr_t, ctypes.uint32_t,
+ /* langid*/ ctypes.uint32_t, ctypes.char16_t.ptr, ctypes.uint32_t,
+ /* Arguments*/ctypes.voidptr_t);
/**
* A File-related error.
*
* To obtain a human-readable error message, use method |toString|.
* To determine the cause of the error, use the various |becauseX|
* getters. To determine the operation that failed, use field
* |operation|.
@@ -94,28 +90,26 @@ var OSError = function OSError(operation
OSError.prototype = Object.create(SharedAll.OSError.prototype);
OSError.prototype.toString = function toString() {
let buf = new (ctypes.ArrayType(ctypes.char16_t, 1024))();
let result = Scope.FormatMessage(
Const.FORMAT_MESSAGE_FROM_SYSTEM |
Const.FORMAT_MESSAGE_IGNORE_INSERTS,
null,
/* The error number */ this.winLastError,
- /* Default language */ 0,
- /* Output buffer*/ buf,
- /* Minimum size of buffer */ 1024,
- /* Format args*/ null
+ /* Default language */ 0, buf,
+ /* Minimum size of buffer */ 1024, null
);
if (!result) {
buf = "additional error " +
ctypes.winLastError +
" while fetching system error message";
}
return "Win error " + this.winLastError + " during operation "
- + this.operation + (this.path? " on file " + this.path : "") +
+ + this.operation + (this.path ? " on file " + this.path : "") +
" (" + buf.readString() + ")";
};
OSError.prototype.toMsg = function toMsg() {
return OSError.toMsg(this);
};
/**
* |true| if the error was raised because a file or directory
@@ -411,15 +405,15 @@ var EXPORTED_SYMBOLS = [
"AbstractInfo",
"AbstractEntry",
"Type",
"POS_START",
"POS_CURRENT",
"POS_END"
];
-//////////// Boilerplate
+// ////////// Boilerplate
if (typeof Components != "undefined") {
this.EXPORTED_SYMBOLS = EXPORTED_SYMBOLS;
for (let symbol of EXPORTED_SYMBOLS) {
this[symbol] = exports[symbol];
}
}
--- a/toolkit/components/osfile/modules/osfile_win_back.jsm
+++ b/toolkit/components/osfile/modules/osfile_win_back.jsm
@@ -196,241 +196,187 @@
{ wSecond: ctypes.int16_t },
{ wMilliSeconds: ctypes.int16_t }
]));
// Special case: these functions are used by the
// finalizer
libc.declareLazy(SysFile, "_CloseHandle",
"CloseHandle", ctypes.winapi_abi,
- /*return */ctypes.bool,
- /*handle*/ ctypes.voidptr_t);
+ /* return */ctypes.bool,
+ /* handle*/ ctypes.voidptr_t);
SysFile.CloseHandle = function(fd) {
if (fd == INVALID_HANDLE) {
return true;
- } else {
+ }
return fd.dispose(); // Returns the value of |CloseHandle|.
- }
+
};
libc.declareLazy(SysFile, "_FindClose",
"FindClose", ctypes.winapi_abi,
- /*return */ctypes.bool,
- /*handle*/ ctypes.voidptr_t);
+ /* return */ctypes.bool,
+ /* handle*/ ctypes.voidptr_t);
SysFile.FindClose = function(handle) {
if (handle == INVALID_HANDLE) {
return true;
- } else {
+ }
return handle.dispose(); // Returns the value of |FindClose|.
- }
+
};
// Declare libc functions as functions of |OS.Win.File|
libc.declareLazyFFI(SysFile, "CopyFile",
"CopyFileW", ctypes.winapi_abi,
- /*return*/ Type.zero_or_nothing,
- /*sourcePath*/ Type.path,
- /*destPath*/ Type.path,
- /*bailIfExist*/Type.bool);
+ /* return*/ Type.zero_or_nothing,
+ /* sourcePath*/ Type.path, Type.path,
+ /* bailIfExist*/Type.bool);
libc.declareLazyFFI(SysFile, "CreateDirectory",
"CreateDirectoryW", ctypes.winapi_abi,
- /*return*/ Type.zero_or_nothing,
- /*name*/ Type.char16_t.in_ptr,
- /*security*/Type.SECURITY_ATTRIBUTES.in_ptr);
+ /* return*/ Type.zero_or_nothing, Type.char16_t.in_ptr,
+ /* security*/Type.SECURITY_ATTRIBUTES.in_ptr);
libc.declareLazyFFI(SysFile, "CreateFile",
- "CreateFileW", ctypes.winapi_abi,
- /*return*/ Type.file_HANDLE,
- /*name*/ Type.path,
- /*access*/ Type.DWORD_FLAGS,
- /*share*/ Type.DWORD_FLAGS,
- /*security*/Type.SECURITY_ATTRIBUTES.in_ptr,
- /*creation*/Type.DWORD_FLAGS,
- /*flags*/ Type.DWORD_FLAGS,
- /*template*/Type.HANDLE);
+ "CreateFileW", ctypes.winapi_abi, Type.file_HANDLE, Type.path, Type.DWORD_FLAGS, Type.DWORD_FLAGS,
+ /* security*/Type.SECURITY_ATTRIBUTES.in_ptr,
+ /* creation*/Type.DWORD_FLAGS, Type.DWORD_FLAGS,
+ /* template*/Type.HANDLE);
libc.declareLazyFFI(SysFile, "DeleteFile",
"DeleteFileW", ctypes.winapi_abi,
- /*return*/ Type.zero_or_nothing,
- /*path*/ Type.path);
+ /* return*/ Type.zero_or_nothing, Type.path);
libc.declareLazyFFI(SysFile, "FileTimeToSystemTime",
"FileTimeToSystemTime", ctypes.winapi_abi,
- /*return*/ Type.zero_or_nothing,
- /*filetime*/Type.FILETIME.in_ptr,
- /*systime*/ Type.SystemTime.out_ptr);
+ /* return*/ Type.zero_or_nothing,
+ /* filetime*/Type.FILETIME.in_ptr,
+ /* systime*/ Type.SystemTime.out_ptr);
libc.declareLazyFFI(SysFile, "SystemTimeToFileTime",
- "SystemTimeToFileTime", ctypes.winapi_abi,
- /*return*/ Type.zero_or_nothing,
- /*systime*/ Type.SystemTime.in_ptr,
- /*filetime*/ Type.FILETIME.out_ptr);
+ "SystemTimeToFileTime", ctypes.winapi_abi, Type.zero_or_nothing, Type.SystemTime.in_ptr,
+ /* filetime*/ Type.FILETIME.out_ptr);
libc.declareLazyFFI(SysFile, "FindFirstFile",
"FindFirstFileW", ctypes.winapi_abi,
- /*return*/ Type.find_HANDLE,
- /*pattern*/Type.path,
- /*data*/ Type.FindData.out_ptr);
+ /* return*/ Type.find_HANDLE,
+ /* pattern*/Type.path, Type.FindData.out_ptr);
libc.declareLazyFFI(SysFile, "FindNextFile",
"FindNextFileW", ctypes.winapi_abi,
- /*return*/ Type.zero_or_nothing,
- /*prev*/ Type.find_HANDLE,
- /*data*/ Type.FindData.out_ptr);
+ /* return*/ Type.zero_or_nothing, Type.find_HANDLE, Type.FindData.out_ptr);
libc.declareLazyFFI(SysFile, "FormatMessage",
"FormatMessageW", ctypes.winapi_abi,
- /*return*/ Type.DWORD,
- /*flags*/ Type.DWORD_FLAGS,
- /*source*/ Type.void_t.in_ptr,
- /*msgid*/ Type.DWORD_FLAGS,
- /*langid*/ Type.DWORD_FLAGS,
- /*buf*/ Type.out_wstring,
- /*size*/ Type.DWORD,
- /*Arguments*/Type.void_t.in_ptr
+ /* return*/ Type.DWORD, Type.DWORD_FLAGS,
+ /* source*/ Type.void_t.in_ptr, Type.DWORD_FLAGS,
+ /* langid*/ Type.DWORD_FLAGS, Type.out_wstring, Type.DWORD,
+ /* Arguments*/Type.void_t.in_ptr
);
libc.declareLazyFFI(SysFile, "GetCurrentDirectory",
"GetCurrentDirectoryW", ctypes.winapi_abi,
- /*return*/ Type.zero_or_DWORD,
- /*length*/ Type.DWORD,
- /*buf*/ Type.out_path
+ /* return*/ Type.zero_or_DWORD,
+ /* length*/ Type.DWORD, Type.out_path
);
libc.declareLazyFFI(SysFile, "GetFullPathName",
- "GetFullPathNameW", ctypes.winapi_abi,
- /*return*/ Type.zero_or_DWORD,
- /*fileName*/ Type.path,
- /*length*/ Type.DWORD,
- /*buf*/ Type.out_path,
- /*filePart*/ Type.DWORD
+ "GetFullPathNameW", ctypes.winapi_abi, Type.zero_or_DWORD,
+ /* fileName*/ Type.path, Type.DWORD, Type.out_path,
+ /* filePart*/ Type.DWORD
);
libc.declareLazyFFI(SysFile, "GetDiskFreeSpaceEx",
"GetDiskFreeSpaceExW", ctypes.winapi_abi,
- /*return*/ Type.zero_or_nothing,
- /*directoryName*/ Type.path,
- /*freeBytesForUser*/ Type.uint64_t.out_ptr,
- /*totalBytesForUser*/ Type.uint64_t.out_ptr,
- /*freeTotalBytesOnDrive*/ Type.uint64_t.out_ptr);
+ /* return*/ Type.zero_or_nothing,
+ /* directoryName*/ Type.path,
+ /* freeBytesForUser*/ Type.uint64_t.out_ptr,
+ /* totalBytesForUser*/ Type.uint64_t.out_ptr,
+ /* freeTotalBytesOnDrive*/ Type.uint64_t.out_ptr);
libc.declareLazyFFI(SysFile, "GetFileInformationByHandle",
"GetFileInformationByHandle", ctypes.winapi_abi,
- /*return*/ Type.zero_or_nothing,
- /*handle*/ Type.HANDLE,
- /*info*/ Type.FILE_INFORMATION.out_ptr);
+ /* return*/ Type.zero_or_nothing,
+ /* handle*/ Type.HANDLE, Type.FILE_INFORMATION.out_ptr);
libc.declareLazyFFI(SysFile, "MoveFileEx",
- "MoveFileExW", ctypes.winapi_abi,
- /*return*/ Type.zero_or_nothing,
- /*sourcePath*/ Type.path,
- /*destPath*/ Type.path,
- /*flags*/ Type.DWORD
+ "MoveFileExW", ctypes.winapi_abi, Type.zero_or_nothing,
+ /* sourcePath*/ Type.path,
+ /* destPath*/ Type.path, Type.DWORD
);
libc.declareLazyFFI(SysFile, "ReadFile",
"ReadFile", ctypes.winapi_abi,
- /*return*/ Type.zero_or_nothing,
- /*file*/ Type.HANDLE,
- /*buffer*/ Type.voidptr_t,
- /*nbytes*/ Type.DWORD,
- /*nbytes_read*/Type.DWORD.out_ptr,
- /*overlapped*/Type.void_t.inout_ptr // FIXME: Implement?
+ /* return*/ Type.zero_or_nothing, Type.HANDLE,
+ /* buffer*/ Type.voidptr_t,
+ /* nbytes*/ Type.DWORD,
+ /* nbytes_read*/Type.DWORD.out_ptr,
+ /* overlapped*/Type.void_t.inout_ptr // FIXME: Implement?
);
libc.declareLazyFFI(SysFile, "RemoveDirectory",
"RemoveDirectoryW", ctypes.winapi_abi,
- /*return*/ Type.zero_or_nothing,
- /*path*/ Type.path);
+ /* return*/ Type.zero_or_nothing, Type.path);
libc.declareLazyFFI(SysFile, "SetCurrentDirectory",
"SetCurrentDirectoryW", ctypes.winapi_abi,
- /*return*/ Type.zero_or_nothing,
- /*path*/ Type.path
+ /* return*/ Type.zero_or_nothing, Type.path
);
libc.declareLazyFFI(SysFile, "SetEndOfFile",
"SetEndOfFile", ctypes.winapi_abi,
- /*return*/ Type.zero_or_nothing,
- /*file*/ Type.HANDLE);
+ /* return*/ Type.zero_or_nothing, Type.HANDLE);
libc.declareLazyFFI(SysFile, "SetFilePointer",
"SetFilePointer", ctypes.winapi_abi,
- /*return*/ Type.DWORD,
- /*file*/ Type.HANDLE,
- /*distlow*/Type.long,
- /*disthi*/ Type.long.in_ptr,
- /*method*/ Type.DWORD);
+ /* return*/ Type.DWORD, Type.HANDLE,
+ /* distlow*/Type.long,
+ /* disthi*/ Type.long.in_ptr,
+ /* method*/ Type.DWORD);
libc.declareLazyFFI(SysFile, "SetFileTime",
- "SetFileTime", ctypes.winapi_abi,
- /*return*/ Type.zero_or_nothing,
- /*file*/ Type.HANDLE,
- /*creation*/ Type.FILETIME.in_ptr,
- /*access*/ Type.FILETIME.in_ptr,
- /*write*/ Type.FILETIME.in_ptr);
+ "SetFileTime", ctypes.winapi_abi, Type.zero_or_nothing, Type.HANDLE,
+ /* creation*/ Type.FILETIME.in_ptr, Type.FILETIME.in_ptr, Type.FILETIME.in_ptr);
libc.declareLazyFFI(SysFile, "WriteFile",
"WriteFile", ctypes.winapi_abi,
- /*return*/ Type.zero_or_nothing,
- /*file*/ Type.HANDLE,
- /*buffer*/ Type.voidptr_t,
- /*nbytes*/ Type.DWORD,
- /*nbytes_wr*/Type.DWORD.out_ptr,
- /*overlapped*/Type.void_t.inout_ptr // FIXME: Implement?
+ /* return*/ Type.zero_or_nothing, Type.HANDLE,
+ /* buffer*/ Type.voidptr_t,
+ /* nbytes*/ Type.DWORD,
+ /* nbytes_wr*/Type.DWORD.out_ptr,
+ /* overlapped*/Type.void_t.inout_ptr // FIXME: Implement?
);
libc.declareLazyFFI(SysFile, "FlushFileBuffers",
"FlushFileBuffers", ctypes.winapi_abi,
- /*return*/ Type.zero_or_nothing,
- /*file*/ Type.HANDLE);
+ /* return*/ Type.zero_or_nothing, Type.HANDLE);
libc.declareLazyFFI(SysFile, "GetFileAttributes",
- "GetFileAttributesW", ctypes.winapi_abi,
- /*return*/ Type.DWORD_FLAGS,
- /*fileName*/ Type.path);
+ "GetFileAttributesW", ctypes.winapi_abi, Type.DWORD_FLAGS,
+ /* fileName*/ Type.path);
libc.declareLazyFFI(SysFile, "SetFileAttributes",
- "SetFileAttributesW", ctypes.winapi_abi,
- /*return*/ Type.zero_or_nothing,
- /*fileName*/ Type.path,
- /*fileAttributes*/ Type.DWORD_FLAGS);
+ "SetFileAttributesW", ctypes.winapi_abi, Type.zero_or_nothing, Type.path,
+ /* fileAttributes*/ Type.DWORD_FLAGS);
advapi32.declareLazyFFI(SysFile, "GetNamedSecurityInfo",
- "GetNamedSecurityInfoW", ctypes.winapi_abi,
- /*return*/ Type.DWORD,
- /*objectName*/ Type.path,
- /*objectType*/ Type.DWORD,
- /*securityInfo*/ Type.DWORD,
- /*sidOwner*/ Type.PSID.out_ptr,
- /*sidGroup*/ Type.PSID.out_ptr,
- /*dacl*/ Type.PACL.out_ptr,
- /*sacl*/ Type.PACL.out_ptr,
- /*securityDesc*/ Type.PSECURITY_DESCRIPTOR.out_ptr);
+ "GetNamedSecurityInfoW", ctypes.winapi_abi, Type.DWORD, Type.path, Type.DWORD,
+ /* securityInfo*/ Type.DWORD, Type.PSID.out_ptr, Type.PSID.out_ptr, Type.PACL.out_ptr, Type.PACL.out_ptr,
+ /* securityDesc*/ Type.PSECURITY_DESCRIPTOR.out_ptr);
advapi32.declareLazyFFI(SysFile, "SetNamedSecurityInfo",
- "SetNamedSecurityInfoW", ctypes.winapi_abi,
- /*return*/ Type.DWORD,
- /*objectName*/ Type.path,
- /*objectType*/ Type.DWORD,
- /*securityInfo*/ Type.DWORD,
- /*sidOwner*/ Type.PSID,
- /*sidGroup*/ Type.PSID,
- /*dacl*/ Type.PACL,
- /*sacl*/ Type.PACL);
+ "SetNamedSecurityInfoW", ctypes.winapi_abi, Type.DWORD, Type.path, Type.DWORD,
+ /* securityInfo*/ Type.DWORD, Type.PSID, Type.PSID, Type.PACL, Type.PACL);
libc.declareLazyFFI(SysFile, "LocalFree",
- "LocalFree", ctypes.winapi_abi,
- /*return*/ Type.HLOCAL,
- /*mem*/ Type.HLOCAL);
+ "LocalFree", ctypes.winapi_abi, Type.HLOCAL, Type.HLOCAL);
};
exports.OS.Win = {
File: {
_init: init
}
};
})(this);
--- a/toolkit/components/osfile/modules/osfile_win_front.jsm
+++ b/toolkit/components/osfile/modules/osfile_win_front.jsm
@@ -90,17 +90,17 @@
}
if (result == -1) {
this._closeResult = new File.Error("close", ctypes.winLastError, this._path);
}
}
if (this._closeResult) {
throw this._closeResult;
}
- return;
+
};
/**
* Read some bytes from a file.
*
* @param {C pointer} buffer A buffer for holding the data
* once it is read.
* @param {number} nbytes The number of bytes to read. It must not
@@ -369,17 +369,17 @@
}
path = array.readString();
}
if ("winAccess" in options && "winDisposition" in options) {
access = options.winAccess;
disposition = options.winDisposition;
} else if (("winAccess" in options && !("winDisposition" in options))
- ||(!("winAccess" in options) && "winDisposition" in options)) {
+ || (!("winAccess" in options) && "winDisposition" in options)) {
throw new TypeError("OS.File.open requires either both options " +
"winAccess and winDisposition or neither");
} else {
if (mode.read) {
access |= Const.GENERIC_READ;
}
if (mode.write) {
access |= Const.GENERIC_WRITE;
@@ -533,17 +533,17 @@
return;
}
// If the user has no access, but it's a root directory, no error should be thrown
let splitPath = OS.Path.split(path);
// Removing last component if it's empty
// An empty last component is caused by trailing slashes in path
// This is always the case with root directories
- if( splitPath.components[splitPath.components.length - 1].length === 0 ) {
+ if ( splitPath.components[splitPath.components.length - 1].length === 0 ) {
splitPath.components.pop();
}
// One component consisting of a drive letter implies a directory root.
if (ctypes.winLastError == Const.ERROR_ACCESS_DENIED &&
splitPath.winDrive &&
splitPath.components.length === 1 ) {
return;
}
@@ -630,37 +630,37 @@
// filesystems support NTFS permissions or the user may not
// have the enough rights to read/write permissions).
// However we can safely ignore errors. The file was already
// moved. Setting permissions is not mandatory.
let dacl = new ctypes.voidptr_t();
let sd = new ctypes.voidptr_t();
WinFile.GetNamedSecurityInfo(destPath, Const.SE_FILE_OBJECT,
Const.DACL_SECURITY_INFORMATION,
- null /*sidOwner*/, null /*sidGroup*/,
- dacl.address(), null /*sacl*/,
+ null /* sidOwner*/, null /* sidGroup*/,
+ dacl.address(), null /* sacl*/,
sd.address());
// dacl will be set only if the function succeeds.
if (!dacl.isNull()) {
WinFile.SetNamedSecurityInfo(destPath, Const.SE_FILE_OBJECT,
Const.DACL_SECURITY_INFORMATION |
Const.UNPROTECTED_DACL_SECURITY_INFORMATION,
- null /*sidOwner*/, null /*sidGroup*/,
- dacl, null /*sacl*/);
+ null /* sidOwner*/, null /* sidGroup*/,
+ dacl, null /* sacl*/);
}
// sd will be set only if the function succeeds.
if (!sd.isNull()) {
WinFile.LocalFree(Type.HLOCAL.cast(sd));
}
};
/**
* Gets the number of bytes available on disk to the current user.
*
- * @param {string} sourcePath Platform-specific path to a directory on
+ * @param {string} sourcePath Platform-specific path to a directory on
* the disk to query for free available bytes.
*
* @return {number} The number of bytes available for the current user.
* @throws {OS.File.Error} In case of any error.
*/
File.getAvailableFreeSpace = function Win_getAvailableFreeSpace(sourcePath) {
let freeBytesAvailableToUser = new Type.uint64_t.implementation(0);
let freeBytesAvailableToUserPtr = freeBytesAvailableToUser.address();
@@ -688,17 +688,17 @@
throw_on_zero("FILETIME_to_Date",
WinFile.FileTimeToSystemTime(fileTime.address(),
gSystemTimePtr),
path);
// Windows counts hours, minutes, seconds from UTC,
// JS counts from local time, so we need to go through UTC.
let utc = Date.UTC(gSystemTime.wYear,
gSystemTime.wMonth - 1
- /*Windows counts months from 1, JS from 0*/,
+ /* Windows counts months from 1, JS from 0*/,
gSystemTime.wDay, gSystemTime.wHour,
gSystemTime.wMinute, gSystemTime.wSecond,
gSystemTime.wMilliSeconds);
return new Date(utc);
};
/**
* Utility function: convert Javascript Date to FileTime.
@@ -805,25 +805,25 @@
// during construction.
if (this._first) {
this._first = false;
return this._findData;
}
if (WinFile.FindNextFile(this._handle, this._findDataPtr)) {
return this._findData;
- } else {
+ }
let error = ctypes.winLastError;
this.close();
if (error == Const.ERROR_NO_MORE_FILES) {
return null;
- } else {
+ }
throw new File.Error("iter (FindNextFile)", error, this._path);
- }
- }
+
+
},
/**
* Return the next entry in the directory, if any such entry is
* available.
*
* Skip special directories "." and "..".
*
--- a/toolkit/components/osfile/modules/ospath_unix.jsm
+++ b/toolkit/components/osfile/modules/ospath_unix.jsm
@@ -109,32 +109,30 @@ var normalize = function(path) {
let absolute;
if (path.length >= 0 && path[0] == "/") {
absolute = true;
} else {
absolute = false;
}
path.split("/").forEach(function(v) {
switch (v) {
- case "": case ".":// fallthrough
+ case "": case ".":// fallthrough
break;
case "..":
if (stack.length == 0) {
if (absolute) {
throw new Error("Path is ill-formed: attempting to go past root");
} else {
stack.push("..");
}
- } else {
- if (stack[stack.length - 1] == "..") {
+ } else if (stack[stack.length - 1] == "..") {
stack.push("..");
} else {
stack.pop();
}
- }
break;
default:
stack.push(v);
}
});
let string = stack.join("/");
return absolute ? "/" + string : string;
};
@@ -158,20 +156,20 @@ var split = function(path) {
};
};
exports.split = split;
/**
* Returns the file:// URI file path of the given local file path.
*/
// The case of %3b is designed to match Services.io, but fundamentally doesn't matter.
-var toFileURIExtraEncodings = {';': '%3b', '?': '%3F', '#': '%23'};
+var toFileURIExtraEncodings = {";": "%3b", "?": "%3F", "#": "%23"};
var toFileURI = function toFileURI(path) {
// Per https://url.spec.whatwg.org we should not encode [] in the path
- let dontNeedEscaping = {'%5B': '[', '%5D': ']'};
+ let dontNeedEscaping = {"%5B": "[", "%5D": "]"};
let uri = encodeURI(this.normalize(path)).replace(/%(5B|5D)/gi,
match => dontNeedEscaping[match]);
// add a prefix, and encodeURI doesn't escape a few characters that we do
// want to escape, so fix that up
let prefix = "file://";
uri = prefix + uri.replace(/[;?#]/g, match => toFileURIExtraEncodings[match]);
@@ -179,24 +177,24 @@ var toFileURI = function toFileURI(path)
};
exports.toFileURI = toFileURI;
/**
* Returns the local file path from a given file URI.
*/
var fromFileURI = function fromFileURI(uri) {
let url = new URL(uri);
- if (url.protocol != 'file:') {
+ if (url.protocol != "file:") {
throw new Error("fromFileURI expects a file URI");
}
let path = this.normalize(decodeURIComponent(url.pathname));
return path;
};
exports.fromFileURI = fromFileURI;
-//////////// Boilerplate
+// ////////// Boilerplate
if (typeof Components != "undefined") {
this.EXPORTED_SYMBOLS = EXPORTED_SYMBOLS;
for (let symbol of EXPORTED_SYMBOLS) {
this[symbol] = exports[symbol];
}
}
--- a/toolkit/components/osfile/modules/ospath_win.jsm
+++ b/toolkit/components/osfile/modules/ospath_win.jsm
@@ -89,29 +89,28 @@ var dirname = function(path, options) {
// Find the last occurrence of "\\"
let index = path.lastIndexOf("\\");
if (index == -1) {
// If there is no directory component...
if (!noDrive) {
// Return the drive path if possible, falling back to "."
return this.winGetDrive(path) || ".";
- } else {
- // Or just "."
- return ".";
}
+ // Or just "."
+ return ".";
}
if (index == 1 && path.charAt(0) == "\\") {
// The path is reduced to a UNC drive
if (noDrive) {
return ".";
- } else {
- return path;
}
+ return path;
+
}
// Ignore any occurrence of "\\: immediately before that one
while (index >= 0 && path[index] == "\\") {
--index;
}
// Compute what is left, removing the drive name if necessary
@@ -242,32 +241,30 @@ var normalize = function(path) {
// Remember whether we need to restore a leading "\\" or drive name.
let absolute = this.winIsAbsolute(path);
// And now, fill |stack| from the components,
// popping whenever there is a ".."
path.split("\\").forEach(function loop(v) {
switch (v) {
- case "": case ".": // Ignore
+ case "": case ".": // Ignore
break;
case "..":
if (stack.length == 0) {
if (absolute) {
throw new Error("Path is ill-formed: attempting to go past root");
} else {
stack.push("..");
}
- } else {
- if (stack[stack.length - 1] == "..") {
+ } else if (stack[stack.length - 1] == "..") {
stack.push("..");
} else {
stack.pop();
}
- }
break;
default:
stack.push(v);
}
});
// Put everything back together
let result = stack.join("\\");
@@ -301,45 +298,45 @@ var split = function(path) {
};
};
exports.split = split;
/**
* Return the file:// URI file path of the given local file path.
*/
// The case of %3b is designed to match Services.io, but fundamentally doesn't matter.
-var toFileURIExtraEncodings = {';': '%3b', '?': '%3F', '#': '%23'};
+var toFileURIExtraEncodings = {";": "%3b", "?": "%3F", "#": "%23"};
var toFileURI = function toFileURI(path) {
// URI-escape forward slashes and convert backward slashes to forward
- path = this.normalize(path).replace(/[\\\/]/g, m => (m=='\\')? '/' : '%2F');
+ path = this.normalize(path).replace(/[\\\/]/g, m => (m == "\\") ? "/" : "%2F");
// Per https://url.spec.whatwg.org we should not encode [] in the path
- let dontNeedEscaping = {'%5B': '[', '%5D': ']'};
+ let dontNeedEscaping = {"%5B": "[", "%5D": "]"};
let uri = encodeURI(path).replace(/%(5B|5D)/gi,
match => dontNeedEscaping[match]);
// add a prefix, and encodeURI doesn't escape a few characters that we do
// want to escape, so fix that up
let prefix = "file:///";
uri = prefix + uri.replace(/[;?#]/g, match => toFileURIExtraEncodings[match]);
// turn e.g., file:///C: into file:///C:/
- if (uri.charAt(uri.length - 1) === ':') {
+ if (uri.charAt(uri.length - 1) === ":") {
uri += "/"
}
return uri;
};
exports.toFileURI = toFileURI;
/**
* Returns the local file path from a given file URI.
*/
var fromFileURI = function fromFileURI(uri) {
let url = new URL(uri);
- if (url.protocol != 'file:') {
+ if (url.protocol != "file:") {
throw new Error("fromFileURI expects a file URI");
}
// strip leading slash, since Windows paths don't start with one
uri = url.pathname.substr(1);
let path = decodeURI(uri);
// decode a few characters where URL's parsing is overzealous
@@ -356,18 +353,18 @@ var fromFileURI = function fromFileURI(u
};
exports.fromFileURI = fromFileURI;
/**
* Utility function: Remove any leading/trailing backslashes
* from a string.
*/
var trimBackslashes = function trimBackslashes(string) {
- return string.replace(/^\\+|\\+$/g,'');
+ return string.replace(/^\\+|\\+$/g, "");
};
-//////////// Boilerplate
+// ////////// Boilerplate
if (typeof Components != "undefined") {
this.EXPORTED_SYMBOLS = EXPORTED_SYMBOLS;
for (let symbol of EXPORTED_SYMBOLS) {
this[symbol] = exports[symbol];
}
}
--- a/toolkit/components/osfile/tests/mochi/main_test_osfile_async.js
+++ b/toolkit/components/osfile/tests/mochi/main_test_osfile_async.js
@@ -118,17 +118,17 @@ var reference_dir_contents = function re
while (entries.hasMoreElements()) {
let entry = entries.getNext().QueryInterface(Components.interfaces.nsIFile);
result.push(entry.path);
}
return result;
};
// Set/Unset OS.Shared.DEBUG, OS.Shared.TEST and a console listener.
-function toggleDebugTest (pref, consoleListener) {
+function toggleDebugTest(pref, consoleListener) {
Services.prefs.setBoolPref("toolkit.osfile.log", pref);
Services.prefs.setBoolPref("toolkit.osfile.log.redirect", pref);
Services.console[pref ? "registerListener" : "unregisterListener"](
consoleListener);
}
var test = maketest("Main", function main(test) {
return (async function() {
@@ -271,17 +271,17 @@ var test_iter = maketest("iter", functio
}
await iterator.close();
test.info("Closed iterator");
test.info("Double closing DirectoryIterator");
iterator = new OS.File.DirectoryIterator(currentDir);
await iterator.close();
- await iterator.close(); //double closing |DirectoryIterator|
+ await iterator.close(); // double closing |DirectoryIterator|
test.ok(true, "|DirectoryIterator| was closed twice successfully");
let allFiles2 = [];
let i = 0;
iterator = new OS.File.DirectoryIterator(currentDir);
await iterator.forEach(function(entry, index) {
test.is(i++, index, "Getting the correct index");
allFiles2.push(entry);
@@ -304,17 +304,17 @@ var test_iter = maketest("iter", functio
let someFiles1 = await iterator.nextBatch(BATCH_LENGTH);
let someFiles2 = await iterator.nextBatch(BATCH_LENGTH);
await iterator.close();
iterator = new OS.File.DirectoryIterator(currentDir);
await iterator.forEach(function cb(entry, index, iterator) {
if (index < BATCH_LENGTH) {
test.is(entry.path, someFiles1[index].path, "Both runs return the same files (part 1)");
- } else if (index < 2*BATCH_LENGTH) {
+ } else if (index < 2 * BATCH_LENGTH) {
test.is(entry.path, someFiles2[index - BATCH_LENGTH].path, "Both runs return the same files (part 2)");
} else if (index == 2 * BATCH_LENGTH) {
test.info("Attempting to stop asynchronous forEach");
return iterator.close();
} else {
test.fail("Can we stop an asynchronous forEach? " + index);
}
return null;
@@ -375,17 +375,17 @@ var test_exists = maketest("exists", fun
})();
});
/**
* Test changes to OS.Shared.DEBUG flag.
*/
var test_debug = maketest("debug", function debug(test) {
return (async function() {
- function testSetDebugPref (pref) {
+ function testSetDebugPref(pref) {
try {
Services.prefs.setBoolPref("toolkit.osfile.log", pref);
} catch (x) {
test.fail("Setting OS.Shared.DEBUG to " + pref +
" should not cause error.");
} finally {
test.is(OS.Shared.DEBUG, pref, "OS.Shared.DEBUG is set correctly.");
}
@@ -402,17 +402,17 @@ var test_debug = maketest("debug", funct
/**
* Test logging in the main thread with set OS.Shared.DEBUG and
* OS.Shared.TEST flags.
*/
var test_debug_test = maketest("debug_test", function debug_test(test) {
return (async function() {
// Create a console listener.
let consoleListener = {
- observe: function (aMessage) {
+ observe: function(aMessage) {
// Ignore unexpected messages.
if (!(aMessage instanceof Components.interfaces.nsIConsoleMessage)) {
return;
}
if (aMessage.message.indexOf("TEST OS") < 0) {
return;
}
test.ok(true, "DEBUG TEST messages are logged correctly.");
--- a/toolkit/components/osfile/tests/mochi/worker_handler.js
+++ b/toolkit/components/osfile/tests/mochi/worker_handler.js
@@ -6,29 +6,29 @@ function worker_handler(worker) {
error.preventDefault();
ok(false, "Worker error " + error.message);
}
worker.onmessage = function(msg) {
ok(true, "MAIN: onmessage " + JSON.stringify(msg.data));
switch (msg.data.kind) {
case "is":
SimpleTest.ok(msg.data.outcome, msg.data.description +
- "( "+ msg.data.a + " ==? " + msg.data.b + ")" );
+ "( " + msg.data.a + " ==? " + msg.data.b + ")" );
return;
case "isnot":
SimpleTest.ok(msg.data.outcome, msg.data.description +
- "( "+ msg.data.a + " !=? " + msg.data.b + ")" );
+ "( " + msg.data.a + " !=? " + msg.data.b + ")" );
return;
case "ok":
SimpleTest.ok(msg.data.condition, msg.data.description);
return;
case "info":
SimpleTest.info(msg.data.description);
return;
case "finish":
SimpleTest.finish();
return;
default:
SimpleTest.ok(false, "test_osfile.xul: wrong message " + JSON.stringify(msg.data));
- return;
+
}
};
}
--- a/toolkit/components/osfile/tests/mochi/worker_test_osfile_comms.js
+++ b/toolkit/components/osfile/tests/mochi/worker_test_osfile_comms.js
@@ -1,14 +1,14 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
-importScripts('worker_test_osfile_shared.js');
+importScripts("worker_test_osfile_shared.js");
// The set of samples for communications test. Declare as a global
// variable to prevent this from being garbage-collected too early.
var samples;
self.onmessage = function(msg) {
info("Initializing");
self.onmessage = function on_unexpected_message(msg) {
@@ -125,17 +125,17 @@ self.onmessage = function(msg) {
// 3. Local test deserialized value
info("Running test on deserialized value " + deserialized +
" aka " + JSON.stringify(deserialized));
check(deserialized, "Local test: ");
// 4. Test sending serialized
info("Attempting to send message");
try {
- self.postMessage({kind:"value",
+ self.postMessage({kind: "value",
typename: sample.typename,
value: serialized,
check: check.toSource()});
} catch (ex) {
exn = ex;
}
is(exn, null, "Can I send the following message? " + serialized
+ " aka " + JSON.stringify(serialized));
--- a/toolkit/components/osfile/tests/mochi/worker_test_osfile_front.js
+++ b/toolkit/components/osfile/tests/mochi/worker_test_osfile_front.js
@@ -1,12 +1,12 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
-importScripts('worker_test_osfile_shared.js');
+importScripts("worker_test_osfile_shared.js");
importScripts("resource://gre/modules/workers/require.js");
var SharedAll = require("resource://gre/modules/osfile/osfile_shared_allthreads.jsm");
SharedAll.Config.DEBUG = true;
function should_throw(f) {
try {
f();
@@ -45,28 +45,26 @@ self.onmessage = function onmessage_star
function test_init() {
info("Starting test_init");
importScripts("resource://gre/modules/osfile.jsm");
}
/**
* Test that we can open an existing file.
*/
-function test_open_existing_file()
-{
+function test_open_existing_file() {
info("Starting test_open_existing");
let file = OS.File.open("chrome/toolkit/components/osfile/tests/mochi/worker_test_osfile_unix.js");
file.close();
}
/**
* Test that opening a file that does not exist fails with the right error.
*/
-function test_open_non_existing_file()
-{
+function test_open_non_existing_file() {
info("Starting test_open_non_existing");
let exn;
try {
let file = OS.File.open("/I do not exist");
} catch (x) {
exn = x;
info("test_open_non_existing_file: Exception detail " + exn);
}
@@ -74,18 +72,17 @@ function test_open_non_existing_file()
ok(exn instanceof OS.File.Error, "test_open_non_existing_file: Exception was a OS.File.Error");
ok(exn.becauseNoSuchFile, "test_open_non_existing_file: Exception confirms that the file does not exist");
}
/**
* Test that to ensure that |foo.flush()| does not
* cause an error, where |foo| is an open file.
*/
-function test_flush_open_file()
-{
+function test_flush_open_file() {
info("Starting test_flush_open_file");
let tmp = "test_flush.tmp";
let file = OS.File.open(tmp, {create: true, write: true});
file.flush();
file.close();
OS.File.remove(tmp);
}
@@ -96,18 +93,17 @@ function test_flush_open_file()
* are not identical.
*
* @param {string} test The name of the test (used for logging).
* @param {string} sourcePath The name of the first file.
* @param {string} destPath The name of the second file.
* @param {number=} prefix If specified, only compare the |prefix|
* first bytes of |sourcePath| and |destPath|.
*/
-function compare_files(test, sourcePath, destPath, prefix)
-{
+function compare_files(test, sourcePath, destPath, prefix) {
info(test + ": Comparing " + sourcePath + " and " + destPath);
let source = OS.File.open(sourcePath);
let dest = OS.File.open(destPath);
info("Files are open");
let sourceResult, destResult;
try {
if (prefix != undefined) {
sourceResult = source.read(prefix);
@@ -128,18 +124,17 @@ function compare_files(test, sourcePath,
dest.close();
}
info(test + ": Comparison complete");
}
/**
* Test that copying a file using |copy| works.
*/
-function test_copy_existing_file()
-{
+function test_copy_existing_file() {
let src_file_name =
OS.Path.join("chrome", "toolkit", "components", "osfile", "tests", "mochi",
"worker_test_osfile_front.js");
let tmp_file_name = "test_osfile_front.tmp";
info("Starting test_copy_existing");
OS.File.copy(src_file_name, tmp_file_name);
info("test_copy_existing: Copy complete");
@@ -155,30 +150,29 @@ function test_copy_existing_file()
OS.File.copy(src_file_name, tmp_file_name);
compare_files("test_copy_existing 2", src_file_name, tmp_file_name);
// Attempt to overwrite with noOverwrite
let exn;
try {
OS.File.copy(src_file_name, tmp_file_name, {noOverwrite: true});
- } catch(x) {
+ } catch (x) {
exn = x;
}
ok(!!exn, "test_copy_existing: noOverwrite prevents overwriting existing files");
info("test_copy_existing: Cleaning up");
OS.File.remove(tmp_file_name);
}
/**
* Test that moving a file works.
*/
-function test_move_file()
-{
+function test_move_file() {
info("test_move_file: Starting");
// 1. Copy file into a temporary file
let src_file_name =
OS.Path.join("chrome", "toolkit", "components", "osfile", "tests", "mochi",
"worker_test_osfile_front.js");
let tmp_file_name = "test_osfile_front.tmp";
let tmp2_file_name = "test_osfile_front.tmp2";
OS.File.copy(src_file_name, tmp_file_name);
@@ -201,23 +195,22 @@ function test_move_file()
exn = x;
}
ok(!!exn, "test_move_file: Original file has been removed");
info("test_move_file: Cleaning up");
OS.File.remove(tmp2_file_name);
}
-function test_iter_dir()
-{
+function test_iter_dir() {
info("test_iter_dir: Starting");
// Create a file, to be sure that it exists
let tmp_file_name = "test_osfile_front.tmp";
- let tmp_file = OS.File.open(tmp_file_name, {write: true, trunc:true});
+ let tmp_file = OS.File.open(tmp_file_name, {write: true, trunc: true});
tmp_file.close();
let parent = OS.File.getCurrentDirectory();
info("test_iter_dir: directory " + parent);
let iterator = new OS.File.DirectoryIterator(parent);
info("test_iter_dir: iterator created");
let encountered_tmp_file = false;
for (let entry in iterator) {
@@ -322,17 +315,17 @@ function test_iter_dir()
iterator.close();
} else {
ok(false, "test_iter_dir: Checking that forEach can be stopped early");
}
++index;
});
iterator.close();
- //test for prototype |OS.File.DirectoryIterator.unixAsFile|
+ // test for prototype |OS.File.DirectoryIterator.unixAsFile|
if ("unixAsFile" in OS.File.DirectoryIterator.prototype) {
info("testing property unixAsFile");
let path = OS.Path.join("chrome", "toolkit", "components", "osfile", "tests", "mochi");
iterator = new OS.File.DirectoryIterator(path);
let dir_file = iterator.unixAsFile();// return |File|
let stat0 = dir_file.stat();
let stat1 = OS.File.stat(path);
@@ -422,17 +415,17 @@ function test_info() {
// We round down/up by 1s as file system precision is lower than
// Date precision (no clear specifications about that, but it seems
// that this can be a little over 1 second under ext3 and 2 seconds
// under FAT).
let SLOPPY_FILE_SYSTEM_ADJUSTMENT = 3000;
let startMs = start.getTime() - SLOPPY_FILE_SYSTEM_ADJUSTMENT;
let stopMs = stop.getTime() + SLOPPY_FILE_SYSTEM_ADJUSTMENT;
- info("Testing stat with bounds [ " + startMs + ", " + stopMs +" ]");
+ info("Testing stat with bounds [ " + startMs + ", " + stopMs + " ]");
(function() {
let birth;
if ("winBirthDate" in stat) {
birth = stat.winBirthDate;
} else if ("macBirthDate" in stat) {
birth = stat.macBirthDate;
} else {
@@ -469,17 +462,17 @@ function test_info() {
ok(!stat.isSymLink, "test_info: file is not a link 2");
is(stat.size.toString(), size, "test_info: correct size 2");
stop = new Date();
// Round up/down as above
startMs = start.getTime() - SLOPPY_FILE_SYSTEM_ADJUSTMENT;
stopMs = stop.getTime() + SLOPPY_FILE_SYSTEM_ADJUSTMENT;
- info("Testing stat 2 with bounds [ " + startMs + ", " + stopMs +" ]");
+ info("Testing stat 2 with bounds [ " + startMs + ", " + stopMs + " ]");
let access = stat.lastAccessDate;
info("Testing lastAccessDate: " + access);
ok(access.getTime() >= startMs && access.getTime() <= stopMs,
"test_info: lastAccessDate is consistent");
change = stat.lastModificationDate;
info("Testing lastModificationDate 2: " + change);
@@ -491,18 +484,17 @@ function test_info() {
ok(!!stat, "test_info: info on directory acquired");
ok(stat.isDir, "test_info: directory is a directory");
info("test_info: Complete");
}
// Note that most of the features of path are tested in
// worker_test_osfile_{unix, win}.js
-function test_path()
-{
+function test_path() {
info("test_path: starting");
let abcd = OS.Path.join("a", "b", "c", "d");
is(OS.Path.basename(abcd), "d", "basename of a/b/c/d");
let abc = OS.Path.join("a", "b", "c");
is(OS.Path.dirname(abcd), abc, "dirname of a/b/c/d");
let abdotsc = OS.Path.join("a", "b", "..", "c");
@@ -512,37 +504,35 @@ function test_path()
is(OS.Path.normalize(adotsdotsdots), OS.Path.join("..", ".."), "normalize a/../../..");
info("test_path: Complete");
}
/**
* Test the file |exists| method.
*/
-function test_exists_file()
-{
- let file_name = OS.Path.join("chrome", "toolkit", "components" ,"osfile",
+function test_exists_file() {
+ let file_name = OS.Path.join("chrome", "toolkit", "components", "osfile",
"tests", "mochi", "test_osfile_front.xul");
info("test_exists_file: starting");
ok(OS.File.exists(file_name), "test_exists_file: file exists (OS.File.exists)");
ok(!OS.File.exists(file_name + ".tmp"), "test_exists_file: file does not exists (OS.File.exists)");
- let dir_name = OS.Path.join("chrome", "toolkit", "components" ,"osfile",
+ let dir_name = OS.Path.join("chrome", "toolkit", "components", "osfile",
"tests", "mochi");
ok(OS.File.exists(dir_name), "test_exists_file: directory exists");
ok(!OS.File.exists(dir_name) + ".tmp", "test_exists_file: directory does not exist");
info("test_exists_file: complete");
}
/**
* Test the file |remove| method.
*/
-function test_remove_file()
-{
+function test_remove_file() {
let absent_file_name = "test_osfile_front_absent.tmp";
// Check that removing absent files is handled correctly
let exn = should_throw(function() {
OS.File.remove(absent_file_name, {ignoreAbsent: false});
});
ok(!!exn, "test_remove_file: throws if there is no such file");
--- a/toolkit/components/osfile/tests/mochi/worker_test_osfile_unix.js
+++ b/toolkit/components/osfile/tests/mochi/worker_test_osfile_unix.js
@@ -1,17 +1,17 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
-importScripts('worker_test_osfile_shared.js');
+importScripts("worker_test_osfile_shared.js");
self.onmessage = function(msg) {
- log("received message "+JSON.stringify(msg.data));
+ log("received message " + JSON.stringify(msg.data));
self.onmessage = function(msg) {
- log("ignored message "+JSON.stringify(msg.data));
+ log("ignored message " + JSON.stringify(msg.data));
};
test_init();
test_getcwd();
test_open_close();
test_create_file();
test_access();
test_read_write();
test_passing_undefined();
@@ -23,38 +23,36 @@ function test_init() {
importScripts("resource://gre/modules/osfile.jsm");
}
function test_open_close() {
info("Starting test_open_close");
is(typeof OS.Unix.File.open, "function", "OS.Unix.File.open is a function");
let file = OS.Unix.File.open("chrome/toolkit/components/osfile/tests/mochi/worker_test_osfile_unix.js", OS.Constants.libc.O_RDONLY, 0);
isnot(file, -1, "test_open_close: opening succeeded");
- info("Close: "+OS.Unix.File.close.toSource());
+ info("Close: " + OS.Unix.File.close.toSource());
let result = OS.Unix.File.close(file);
is(result, 0, "test_open_close: close succeeded");
file = OS.Unix.File.open("/i do not exist", OS.Constants.libc.O_RDONLY, 0);
is(file, -1, "test_open_close: opening of non-existing file failed");
is(ctypes.errno, OS.Constants.libc.ENOENT, "test_open_close: error is ENOENT");
}
-function test_create_file()
-{
+function test_create_file() {
info("Starting test_create_file");
let file = OS.Unix.File.open("test.tmp", OS.Constants.libc.O_RDWR
| OS.Constants.libc.O_CREAT
| OS.Constants.libc.O_TRUNC,
OS.Constants.libc.S_IRWXU);
isnot(file, -1, "test_create_file: file created");
OS.Unix.File.close(file);
}
-function test_access()
-{
+function test_access() {
info("Starting test_access");
let file = OS.Unix.File.open("test1.tmp", OS.Constants.libc.O_RDWR
| OS.Constants.libc.O_CREAT
| OS.Constants.libc.O_TRUNC,
OS.Constants.libc.S_IRWXU);
let result = OS.Unix.File.access("test1.tmp", OS.Constants.libc.R_OK | OS.Constants.libc.W_OK | OS.Constants.libc.X_OK | OS.Constants.libc.F_OK);
is(result, 0, "first call to access() succeeded");
OS.Unix.File.close(file);
@@ -69,18 +67,17 @@ function test_access()
| OS.Constants.libc.W_OK
| OS.Constants.libc.X_OK
| OS.Constants.libc.F_OK);
is(result, -1, "test_access: second call to access() failed as expected");
is(ctypes.errno, OS.Constants.libc.ENOENT, "This is the correct error");
OS.Unix.File.close(file);
}
-function test_getcwd()
-{
+function test_getcwd() {
let array = new (ctypes.ArrayType(ctypes.char, 32768))();
let path = OS.Unix.File.getcwd(array, array.length);
if (ctypes.char.ptr(path).isNull()) {
ok(false, "test_get_cwd: getcwd returned null, errno: " + ctypes.errno);
}
let path2;
if (OS.Unix.File.get_current_dir_name) {
path2 = OS.Unix.File.get_current_dir_name();
@@ -88,18 +85,17 @@ function test_getcwd()
path2 = OS.Unix.File.getwd_auto(null);
}
if (ctypes.char.ptr(path2).isNull()) {
ok(false, "test_get_cwd: getwd_auto/get_current_dir_name returned null, errno: " + ctypes.errno);
}
is(path.readString(), path2.readString(), "test_get_cwd: getcwd and getwd return the same path");
}
-function test_read_write()
-{
+function test_read_write() {
let output_name = "osfile_copy.tmp";
// Copy file
let input = OS.Unix.File.open(
"chrome/toolkit/components/osfile/tests/mochi/worker_test_osfile_unix.js",
OS.Constants.libc.O_RDONLY, 0);
isnot(input, -1, "test_read_write: input file opened");
let output = OS.Unix.File.open("osfile_copy.tmp", OS.Constants.libc.O_RDWR
| OS.Constants.libc.O_CREAT
@@ -144,17 +140,17 @@ function test_read_write()
let array2 = new (ctypes.ArrayType(ctypes.char, 4096))();
let bytes2 = -1;
let pos = 0;
while (true) {
bytes = OS.Unix.File.read(input, array, 4096);
isnot(bytes, -1, "test_read_write: input read succeeded");
bytes2 = OS.Unix.File.read(output, array2, 4096);
isnot(bytes, -1, "test_read_write: output read succeeded");
- is(bytes > 0, bytes2 > 0, "Both files contain data or neither does "+bytes+", "+bytes2);
+ is(bytes > 0, bytes2 > 0, "Both files contain data or neither does " + bytes + ", " + bytes2);
if (bytes == 0) {
break;
}
if (bytes != bytes2) {
// This would be surprising, but theoretically possible with a
// remote file system, I believe.
bytes = Math.min(bytes, bytes2);
pos += bytes;
@@ -163,41 +159,40 @@ function test_read_write()
result = OS.Unix.File.lseek(output, pos, OS.Constants.libc.SEEK_SET);
isnot(result, -1, "test_read_write: output seek succeeded");
} else {
pos += bytes;
}
for (let i = 0; i < bytes; ++i) {
if (array[i] != array2[i]) {
ok(false, "Files do not match at position " + i
- + " ("+array[i] + "/"+array2[i] + ")");
+ + " (" + array[i] + "/" + array2[i] + ")");
}
}
}
info("test_read_write test complete");
result = OS.Unix.File.close(input);
isnot(result, -1, "test_read_write: input close succeeded");
result = OS.Unix.File.close(output);
isnot(result, -1, "test_read_write: output close succeeded");
result = OS.Unix.File.unlink(output_name);
isnot(result, -1, "test_read_write: input remove succeeded");
info("test_read_write cleanup complete");
}
-function test_passing_undefined()
-{
+function test_passing_undefined() {
info("Testing that an exception gets thrown when an FFI function is passed 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);
- } catch(e) {
+ } catch (e) {
if (e instanceof TypeError && e.message.indexOf("open") > -1) {
exceptionRaised = true;
} else {
throw e;
}
}
ok(exceptionRaised, "test_passing_undefined: exception gets thrown")
--- a/toolkit/components/osfile/tests/mochi/worker_test_osfile_win.js
+++ b/toolkit/components/osfile/tests/mochi/worker_test_osfile_win.js
@@ -1,16 +1,16 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
-importScripts('worker_test_osfile_shared.js');
+importScripts("worker_test_osfile_shared.js");
self.onmessage = function(msg) {
self.onmessage = function(msg) {
- log("ignored message "+JSON.stringify(msg.data));
+ log("ignored message " + JSON.stringify(msg.data));
};
test_init();
test_GetCurrentDirectory();
test_OpenClose();
test_CreateFile();
test_ReadWrite();
test_passing_undefined();
@@ -50,42 +50,39 @@ function test_OpenClose() {
null,
OS.Constants.Win.OPEN_EXISTING,
OS.Constants.Win.FILE_ATTRIBUTE_NORMAL,
null);
is(file, OS.Constants.Win.INVALID_HANDLE_VALUE, "test_OpenClose: cannot open non-existing file");
is(ctypes.winLastError, OS.Constants.Win.ERROR_FILE_NOT_FOUND, "test_OpenClose: error is ERROR_FILE_NOT_FOUND");
}
-function test_CreateFile()
-{
+function test_CreateFile() {
info("Starting test_CreateFile");
let file = OS.Win.File.CreateFile(
"test.tmp",
OS.Constants.Win.GENERIC_READ | OS.Constants.Win.GENERIC_WRITE,
OS.Constants.Win.FILE_SHARE_READ | OS.Constants.FILE_SHARE_WRITE,
null,
OS.Constants.Win.CREATE_ALWAYS,
OS.Constants.Win.FILE_ATTRIBUTE_NORMAL,
null);
isnot(file, OS.Constants.Win.INVALID_HANDLE_VALUE, "test_CreateFile: opening succeeded");
let result = OS.Win.File.CloseHandle(file);
isnot(result, 0, "test_CreateFile: close succeeded");
}
-function test_GetCurrentDirectory()
-{
+function test_GetCurrentDirectory() {
let array = new (ctypes.ArrayType(ctypes.char16_t, 4096))();
let result = OS.Win.File.GetCurrentDirectory(4096, array);
ok(result < array.length, "test_GetCurrentDirectory: length sufficient");
ok(result > 0, "test_GetCurrentDirectory: length != 0");
}
-function test_ReadWrite()
-{
+function test_ReadWrite() {
info("Starting test_ReadWrite");
let output_name = "osfile_copy.tmp";
// Copy file
let input = OS.Win.File.CreateFile(
"chrome\\toolkit\\components\\osfile\\tests\\mochi\\worker_test_osfile_win.js",
OS.Constants.Win.GENERIC_READ,
0,
null,
@@ -100,50 +97,50 @@ function test_ReadWrite()
null,
OS.Constants.Win.CREATE_ALWAYS,
OS.Constants.Win.FILE_ATTRIBUTE_NORMAL,
null);
isnot(output, OS.Constants.Win.INVALID_HANDLE_VALUE, "test_ReadWrite: output file opened");
let array = new (ctypes.ArrayType(ctypes.char, 4096))();
let bytes_read = new ctypes.uint32_t(0);
let bytes_read_ptr = bytes_read.address();
- log("We have a pointer for bytes read: "+bytes_read_ptr);
+ log("We have a pointer for bytes read: " + bytes_read_ptr);
let bytes_written = new ctypes.uint32_t(0);
let bytes_written_ptr = bytes_written.address();
- log("We have a pointer for bytes written: "+bytes_written_ptr);
+ log("We have a pointer for bytes written: " + bytes_written_ptr);
log("test_ReadWrite: buffer and pointers ready");
let result;
while (true) {
log("test_ReadWrite: reading");
result = OS.Win.File.ReadFile(input, array, 4096, bytes_read_ptr, null);
- isnot (result, 0, "test_ReadWrite: read success");
+ isnot(result, 0, "test_ReadWrite: read success");
let write_from = 0;
let bytes_left = bytes_read;
log("test_ReadWrite: read chunk complete " + bytes_left.value);
if (bytes_left.value == 0) {
break;
}
while (bytes_left.value > 0) {
- log("test_ReadWrite: writing "+bytes_left.value);
+ log("test_ReadWrite: writing " + bytes_left.value);
let ptr = 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");
+ isnot(result, 0, "test_ReadWrite: write success");
write_from += bytes_written;
bytes_left -= bytes_written;
}
}
info("test_ReadWrite: copy complete");
// Compare files
result = OS.Win.File.SetFilePointer(input, 0, null, OS.Constants.Win.FILE_BEGIN);
- isnot (result, OS.Constants.Win.INVALID_SET_FILE_POINTER, "test_ReadWrite: input reset");
+ isnot(result, OS.Constants.Win.INVALID_SET_FILE_POINTER, "test_ReadWrite: input reset");
result = OS.Win.File.SetFilePointer(output, 0, null, OS.Constants.Win.FILE_BEGIN);
- isnot (result, OS.Constants.Win.INVALID_SET_FILE_POINTER, "test_ReadWrite: output reset");
+ isnot(result, OS.Constants.Win.INVALID_SET_FILE_POINTER, "test_ReadWrite: output reset");
let array2 = new (ctypes.ArrayType(ctypes.char, 4096))();
let bytes_read2 = new ctypes.uint32_t(0);
let bytes_read2_ptr = bytes_read2.address();
let pos = 0;
while (true) {
result = OS.Win.File.ReadFile(input, array, 4096, bytes_read_ptr, null);
isnot(result, 0, "test_ReadWrite: input read succeeded");
@@ -157,58 +154,57 @@ function test_ReadWrite()
break;
}
let bytes;
if (bytes_read.value != bytes_read2.value) {
// This would be surprising, but theoretically possible with a
// remote file system, I believe.
bytes = Math.min(bytes_read.value, bytes_read2.value);
pos += bytes;
- result = OS.Win.File.SetFilePointer(input, pos, null, OS.Constants.Win.FILE_BEGIN);
+ result = OS.Win.File.SetFilePointer(input, pos, null, OS.Constants.Win.FILE_BEGIN);
isnot(result, 0, "test_ReadWrite: input seek succeeded");
result = OS.Win.File.SetFilePointer(output, pos, null, OS.Constants.Win.FILE_BEGIN);
isnot(result, 0, "test_ReadWrite: output seek succeeded");
} else {
bytes = bytes_read.value;
pos += bytes;
}
for (let i = 0; i < bytes; ++i) {
if (array[i] != array2[i]) {
ok(false, "Files do not match at position " + i
- + " ("+array[i] + "/"+array2[i] + ")");
+ + " (" + array[i] + "/" + array2[i] + ")");
}
}
}
info("test_ReadWrite test complete");
result = OS.Win.File.CloseHandle(input);
isnot(result, 0, "test_ReadWrite: inpout close succeeded");
result = OS.Win.File.CloseHandle(output);
isnot(result, 0, "test_ReadWrite: outpout close succeeded");
result = OS.Win.File.DeleteFile(output_name);
isnot(result, 0, "test_ReadWrite: output remove succeeded");
info("test_ReadWrite cleanup complete");
}
-function test_passing_undefined()
-{
+function test_passing_undefined() {
info("Testing that an exception gets thrown when an FFI function is passed undefined");
let exceptionRaised = false;
try {
let file = OS.Win.File.CreateFile(
undefined,
OS.Constants.Win.GENERIC_READ,
0,
null,
OS.Constants.Win.OPEN_EXISTING,
0,
null);
- } catch(e) {
+ } catch (e) {
if (e instanceof TypeError && e.message.indexOf("CreateFile") > -1) {
exceptionRaised = true;
} else {
throw e;
}
}
ok(exceptionRaised, "test_passing_undefined: exception gets thrown")
--- a/toolkit/components/osfile/tests/xpcshell/head.js
+++ b/toolkit/components/osfile/tests/xpcshell/head.js
@@ -70,17 +70,17 @@ function reference_fetch_file(path, test
if (reject) {
reject(reject);
} else {
resolve(result);
}
});
});
-};
+}
/**
* Compare asynchronously the contents two files using xpcom.
*
* Used for comparing xpcom-based results to os.file-based results.
*
* @param {string} a The _absolute_ path to the first file.
* @param {string} b The _absolute_ path to the second file.
@@ -89,17 +89,17 @@ function reference_fetch_file(path, test
*/
function reference_compare_files(a, b, test) {
return (async function() {
do_print("Comparing files " + a + " and " + b);
let a_contents = await reference_fetch_file(a, test);
let b_contents = await reference_fetch_file(b, test);
do_check_eq(a_contents, b_contents);
})();
-};
+}
async function removeTestFile(filePath, ignoreNoSuchFile = true) {
try {
await OS.File.remove(filePath);
} catch (ex) {
if (!ignoreNoSuchFile || !ex.becauseNoSuchFile) {
do_throw(ex);
}
--- a/toolkit/components/osfile/tests/xpcshell/test_compression.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_compression.js
@@ -47,17 +47,17 @@ add_task(async function test_uncompresse
}
do_check_true(!!exn);
// Check the exception message (and that it contains the file name)
do_check_true(exn.message.indexOf(`Invalid header (no magic number) - Data: ${ path }`) != -1);
});
add_task(async function test_no_header() {
let path = OS.Path.join(OS.Constants.Path.tmpDir, "no_header.tmp");
- let array = new Uint8Array(8).fill(0,0); // Small array with no header
+ let array = new Uint8Array(8).fill(0, 0); // Small array with no header
do_print("Writing data with no header");
let bytes = await OS.File.writeAtomic(path, array); // No compression
let exn;
// Force decompression, reading should fail
try {
await OS.File.read(path, { compression: "lz4" });
@@ -67,17 +67,17 @@ add_task(async function test_no_header()
do_check_true(!!exn);
// Check the exception message (and that it contains the file name)
do_check_true(exn.message.indexOf(`Buffer is too short (no header) - Data: ${ path }`) != -1);
});
add_task(async function test_invalid_content() {
let path = OS.Path.join(OS.Constants.Path.tmpDir, "invalid_content.tmp");
let arr1 = new Uint8Array([109, 111, 122, 76, 122, 52, 48, 0]);
- let arr2 = new Uint8Array(248).fill(1,0);
+ let arr2 = new Uint8Array(248).fill(1, 0);
let array = new Uint8Array(arr1.length + arr2.length);
array.set(arr1);
array.set(arr2, arr1.length);
do_print("Writing invalid data (with a valid header and only ones after that)");
let bytes = await OS.File.writeAtomic(path, array); // No compression
--- a/toolkit/components/osfile/tests/xpcshell/test_constants.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_constants.js
@@ -5,22 +5,22 @@ Components.utils.import("resource://gre/
Components.utils.import("resource://gre/modules/Services.jsm", this);
function run_test() {
run_next_test();
}
// Test that OS.Constants is defined correctly.
add_task(async function check_definition() {
- do_check_true(OS.Constants!=null);
+ do_check_true(OS.Constants != null);
do_check_true(!!OS.Constants.Win || !!OS.Constants.libc);
- do_check_true(OS.Constants.Path!=null);
- do_check_true(OS.Constants.Sys!=null);
- //check system name
+ do_check_true(OS.Constants.Path != null);
+ do_check_true(OS.Constants.Sys != null);
+ // check system name
do_check_eq(Services.appinfo.OS, OS.Constants.Sys.Name);
- //check if using DEBUG build
+ // check if using DEBUG build
if (Components.classes["@mozilla.org/xpcom/debug;1"].getService(Components.interfaces.nsIDebug2).isDebugBuild == true) {
do_check_true(OS.Constants.Sys.DEBUG);
} else {
- do_check_true(typeof(OS.Constants.Sys.DEBUG) == 'undefined');
+ do_check_true(typeof(OS.Constants.Sys.DEBUG) == "undefined");
}
});
--- a/toolkit/components/osfile/tests/xpcshell/test_creationDate.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_creationDate.js
@@ -4,24 +4,24 @@ function run_test() {
do_test_pending();
run_next_test();
}
/**
* Test to ensure that deprecation warning is issued on use
* of creationDate.
*/
-add_task(async function test_deprecatedCreationDate () {
+add_task(async function test_deprecatedCreationDate() {
let currentDir = await OS.File.getCurrentDirectory();
let path = OS.Path.join(currentDir, "test_creationDate.js");
let consoleMessagePromise = new Promise(resolve => {
let consoleListener = {
- observe: function (aMessage) {
- if(aMessage.message.indexOf("Field 'creationDate' is deprecated.") > -1) {
+ observe: function(aMessage) {
+ if (aMessage.message.indexOf("Field 'creationDate' is deprecated.") > -1) {
do_print("Deprecation message printed");
do_check_true(true);
Services.console.unregisterListener(consoleListener);
resolve();
}
}
}
Services.console.registerListener(consoleListener);
--- a/toolkit/components/osfile/tests/xpcshell/test_file_URL_conversion.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_file_URL_conversion.js
@@ -6,86 +6,86 @@ function run_test() {
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/osfile.jsm");
Components.utils.import("resource://gre/modules/FileUtils.jsm");
let isWindows = ("@mozilla.org/windows-registry-key;1" in Components.classes);
// Test cases for filePathToURI
let paths = isWindows ? [
- 'C:\\',
- 'C:\\test',
- 'C:\\test\\',
- 'C:\\test%2f',
- 'C:\\test\\test\\test',
- 'C:\\test;+%',
- 'C:\\test?action=index\\',
- 'C:\\test\ test',
- '\\\\C:\\a\\b\\c',
- '\\\\Server\\a\\b\\c',
+ "C:\\",
+ "C:\\test",
+ "C:\\test\\",
+ "C:\\test%2f",
+ "C:\\test\\test\\test",
+ "C:\\test;+%",
+ "C:\\test?action=index\\",
+ "C:\\test\ test",
+ "\\\\C:\\a\\b\\c",
+ "\\\\Server\\a\\b\\c",
// note that per http://support.microsoft.com/kb/177506 (under more info),
// the following characters are allowed on Windows:
- 'C:\\char^',
- 'C:\\char&',
- 'C:\\char\'',
- 'C:\\char@',
- 'C:\\char{',
- 'C:\\char}',
- 'C:\\char[',
- 'C:\\char]',
- 'C:\\char,',
- 'C:\\char$',
- 'C:\\char=',
- 'C:\\char!',
- 'C:\\char-',
- 'C:\\char#',
- 'C:\\char(',
- 'C:\\char)',
- 'C:\\char%',
- 'C:\\char.',
- 'C:\\char+',
- 'C:\\char~',
- 'C:\\char_'
+ "C:\\char^",
+ "C:\\char&",
+ "C:\\char'",
+ "C:\\char@",
+ "C:\\char{",
+ "C:\\char}",
+ "C:\\char[",
+ "C:\\char]",
+ "C:\\char,",
+ "C:\\char$",
+ "C:\\char=",
+ "C:\\char!",
+ "C:\\char-",
+ "C:\\char#",
+ "C:\\char(",
+ "C:\\char)",
+ "C:\\char%",
+ "C:\\char.",
+ "C:\\char+",
+ "C:\\char~",
+ "C:\\char_"
] : [
- '/',
- '/test',
- '/test/',
- '/test%2f',
- '/test/test/test',
- '/test;+%',
- '/test?action=index/',
- '/test\ test',
+ "/",
+ "/test",
+ "/test/",
+ "/test%2f",
+ "/test/test/test",
+ "/test;+%",
+ "/test?action=index/",
+ "/test\ test",
'/punctuation/;,/?:@&=+$-_.!~*\'()[]"#',
- '/CasePreserving'
+ "/CasePreserving"
];
// some additional URIs to test, beyond those generated from paths
let uris = isWindows ? [
- 'file:///C:/test/',
- 'file://localhost/C:/test',
- 'file:///c:/test/test.txt',
- //'file:///C:/foo%2f', // trailing, encoded slash
- 'file:///C:/%3f%3F',
- 'file:///C:/%3b%3B',
- 'file:///C:/%3c%3C', // not one of the special-cased ? or ;
- 'file:///C:/%78', // 'x', not usually uri encoded
- 'file:///C:/test#frag', // a fragment identifier
- 'file:///C:/test?action=index' // an actual query component
+ "file:///C:/test/",
+ "file://localhost/C:/test",
+ "file:///c:/test/test.txt",
+ // 'file:///C:/foo%2f', // trailing, encoded slash
+ "file:///C:/%3f%3F",
+ "file:///C:/%3b%3B",
+ "file:///C:/%3c%3C", // not one of the special-cased ? or ;
+ "file:///C:/%78", // 'x', not usually uri encoded
+ "file:///C:/test#frag", // a fragment identifier
+ "file:///C:/test?action=index" // an actual query component
] : [
- 'file:///test/',
- 'file://localhost/test',
- 'file:///test/test.txt',
- 'file:///foo%2f', // trailing, encoded slash
- 'file:///%3f%3F',
- 'file:///%3b%3B',
- 'file:///%3c%3C', // not one of the special-cased ? or ;
- 'file:///%78', // 'x', not usually uri encoded
- 'file:///test#frag', // a fragment identifier
- 'file:///test?action=index' // an actual query component
+ "file:///test/",
+ "file://localhost/test",
+ "file:///test/test.txt",
+ "file:///foo%2f", // trailing, encoded slash
+ "file:///%3f%3F",
+ "file:///%3b%3B",
+ "file:///%3c%3C", // not one of the special-cased ? or ;
+ "file:///%78", // 'x', not usually uri encoded
+ "file:///test#frag", // a fragment identifier
+ "file:///test?action=index" // an actual query component
];
for (let path of paths) {
// convert that to a uri using FileUtils and Services, which toFileURI is trying to model
let file = FileUtils.File(path);
let uri = Services.io.newFileURI(file).spec;
do_check_eq(uri, OS.Path.toFileURI(path));
@@ -100,15 +100,15 @@ function run_test() {
// convert URIs to paths with nsIFileURI, which fromFileURI is trying to model
let path = Services.io.newURI(uri).QueryInterface(Components.interfaces.nsIFileURL).file.path;
do_check_eq(path, OS.Path.fromFileURI(uri));
}
// check that non-file URLs aren't allowed
let thrown = false;
try {
- OS.Path.fromFileURI('http://test.com')
+ OS.Path.fromFileURI("http://test.com")
} catch (e) {
do_check_eq(e.message, "fromFileURI expects a file URI");
thrown = true;
}
do_check_true(thrown);
}
--- a/toolkit/components/osfile/tests/xpcshell/test_loader.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_loader.js
@@ -2,36 +2,36 @@
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Test that OS.File can be loaded using the CommonJS loader.
*/
-var { Loader } = Components.utils.import('resource://gre/modules/commonjs/toolkit/loader.js', {});
+var { Loader } = Components.utils.import("resource://gre/modules/commonjs/toolkit/loader.js", {});
function run_test() {
run_next_test();
}
add_task(async function() {
let dataDir = Services.io.newFileURI(do_get_file("test_loader/", true)).spec + "/";
let loader = Loader.Loader({
- paths: {'': dataDir }
+ paths: {"": dataDir }
});
- let require = Loader.Require(loader, Loader.Module('module_test_loader', 'foo'));
+ let require = Loader.Require(loader, Loader.Module("module_test_loader", "foo"));
do_print("Require is ready");
try {
- require('module_test_loader');
+ require("module_test_loader");
} catch (error) {
- dump('Bootstrap error: ' +
- (error.message ? error.message : String(error)) + '\n' +
- (error.stack || error.fileName + ': ' + error.lineNumber) + '\n');
+ dump("Bootstrap error: " +
+ (error.message ? error.message : String(error)) + "\n" +
+ (error.stack || error.fileName + ": " + error.lineNumber) + "\n");
throw error;
}
do_print("Require has worked");
});
--- a/toolkit/components/osfile/tests/xpcshell/test_loader/module_test_loader.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_loader/module_test_loader.js
@@ -1,9 +1,9 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Load OS.File from a module loaded with the CommonJS/addon-sdk loader
var {Cu} = require("chrome");
-Cu.import('resource://gre/modules/osfile.jsm');
+Cu.import("resource://gre/modules/osfile.jsm");
--- a/toolkit/components/osfile/tests/xpcshell/test_logging.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_logging.js
@@ -10,44 +10,44 @@ Components.utils.import("resource://gre/
function run_test() {
do_test_pending();
let messageCount = 0;
do_print("Test starting");
// Create a console listener.
let consoleListener = {
- observe: function (aMessage) {
- //Ignore unexpected messages.
+ observe: function(aMessage) {
+ // Ignore unexpected messages.
if (!(aMessage instanceof Components.interfaces.nsIConsoleMessage)) {
return;
}
// This is required, as printing to the |Services.console|
// while in the observe function causes an exception.
do_execute_soon(function() {
do_print("Observing message " + aMessage.message);
if (aMessage.message.indexOf("TEST OS") < 0) {
return;
}
++messageCount;
- if(messageCount == 1) {
+ if (messageCount == 1) {
do_check_eq(aMessage.message, "TEST OS {\"name\":\"test\"}\n");
}
- if(messageCount == 2) {
+ if (messageCount == 2) {
do_check_eq(aMessage.message, "TEST OS name is test\n");
toggleConsoleListener(false);
do_test_finished();
}
});
}
};
// Set/Unset the console listener.
- function toggleConsoleListener (pref) {
+ function toggleConsoleListener(pref) {
do_print("Setting console listener: " + pref);
Services.prefs.setBoolPref("toolkit.osfile.log", pref);
Services.prefs.setBoolPref("toolkit.osfile.log.redirect", pref);
Services.console[pref ? "registerListener" : "unregisterListener"](
consoleListener);
}
toggleConsoleListener(true);
--- a/toolkit/components/osfile/tests/xpcshell/test_makeDir.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_makeDir.js
@@ -38,17 +38,17 @@ add_task(async function test_basic() {
let dir = Path.join(profileDir, "directory");
// Sanity checking for the test
do_check_false((await OS.File.exists(dir)));
// Make a directory
await OS.File.makeDir(dir);
- //check if the directory exists
+ // check if the directory exists
await OS.File.stat(dir);
// Make a directory that already exists, this should succeed
await OS.File.makeDir(dir);
// Make a directory with ignoreExisting
await OS.File.makeDir(dir, {ignoreExisting: true});
@@ -82,17 +82,17 @@ add_task(async function test_option_from
let dir = Path.join(profileDir, "a", "b", "c");
// Sanity checking for the test
do_check_false((await OS.File.exists(dir)));
// Make a directory
await OS.File.makeDir(dir, {from: profileDir});
- //check if the directory exists
+ // check if the directory exists
await OS.File.stat(dir);
// Make a directory that already exists, this should succeed
await OS.File.makeDir(dir);
// Make a directory with ignoreExisting
await OS.File.makeDir(dir, {ignoreExisting: true});
--- a/toolkit/components/osfile/tests/xpcshell/test_open.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_open.js
@@ -53,17 +53,17 @@ add_task(async function() {
do_print("Attempting to close a file again");
await openedFile.close();
});
/**
* Test the error thrown by OS.File.open when attempting to open a directory
* that does not exist.
*/
-add_task(async function test_error_attributes () {
+add_task(async function test_error_attributes() {
let dir = OS.Path.join(do_get_profile().path, "test_osfileErrorAttrs");
let fpath = OS.Path.join(dir, "test_error_attributes.txt");
try {
await OS.File.open(fpath, {truncate: true}, {});
do_check_true(false, "Opening path suceeded (it should fail) " + fpath);
} catch (err) {
--- a/toolkit/components/osfile/tests/xpcshell/test_osfile_async_largefiles.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_osfile_async_largefiles.js
@@ -15,17 +15,17 @@ Components.utils.import("resource://gre/
async function test_setPosition(forward, current, backward) {
let path = OS.Path.join(OS.Constants.Path.tmpDir,
"test_osfile_async_largefiles.tmp");
// Clear any left-over files from previous runs.
await removeTestFile(path);
try {
- let file = await OS.File.open(path, {write:true, append:false});
+ let file = await OS.File.open(path, {write: true, append: false});
try {
let pos = 0;
// 1. seek forward from start
do_print("Moving forward: " + forward);
await file.setPosition(forward, OS.File.POS_START);
pos += forward;
do_check_eq((await file.getPosition()), pos);
@@ -41,31 +41,31 @@ async function test_setPosition(forward,
await file.setPosition(-backward, OS.File.POS_CURRENT);
pos -= backward;
do_check_eq((await file.getPosition()), pos);
} finally {
await file.setPosition(0, OS.File.POS_START);
await file.close();
}
- } catch(ex) {
+ } catch (ex) {
await removeTestFile(path);
}
}
// Test setPosition/getPosition expected failures.
async function test_setPosition_failures() {
let path = OS.Path.join(OS.Constants.Path.tmpDir,
"test_osfile_async_largefiles.tmp");
// Clear any left-over files from previous runs.
await removeTestFile(path);
try {
- let file = await OS.File.open(path, {write:true, append:false});
+ 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);
do_throw("Shouldn't have succeeded");
} catch (ex) {
@@ -98,17 +98,17 @@ async function test_setPosition_failures
do_check_true(!!ex);
}
} finally {
await file.setPosition(0, OS.File.POS_START);
await file.close();
await removeTestFile(path);
}
- } catch(ex) {
+ } catch (ex) {
do_throw(ex);
}
}
function run_test() {
// First verify stuff works for small values.
add_task(test_setPosition.bind(null, 0, 100, 50));
add_task(test_setPosition.bind(null, 1000, 100, 50));
--- a/toolkit/components/osfile/tests/xpcshell/test_osfile_async_setPermissions.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_osfile_async_setPermissions.js
@@ -16,19 +16,19 @@
* octal number, with a leading '0' per C (not JS) convention. When the
* numeric value is 0o777 or lower, it is padded on the left with zeroes to
* four digits wide.
* Sample outputs: 0022, 0644, 04755.
*/
function format_mode(mode) {
if (mode <= 0o777) {
return ("0000" + mode.toString(8)).slice(-4);
- } else {
+ }
return "0" + mode.toString(8);
- }
+
}
const _umask = OS.Constants.Sys.umask;
do_print("umask: " + format_mode(_umask));
/**
* Compute the mode that a file should have after applying the umask,
* whatever it happens to be.
--- a/toolkit/components/osfile/tests/xpcshell/test_osfile_kill.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_osfile_kill.js
@@ -54,47 +54,47 @@ var Scheduler = AsyncFrontGlobal.Schedul
* eat rejections, there is an important difference between the value of
* `queue` and the value returned by the first OS.File request.)
*/
add_task(async function test_kill_race() {
// Ensure the worker has been created and that SET_DEBUG has taken effect.
// We have chosen OS.File.exists for our tests because it does not trigger
// a rejection and we absolutely do not care what the operation is other
// than it does not invoke a native fast-path.
- await OS.File.exists('foo.foo');
+ await OS.File.exists("foo.foo");
- do_print('issuing first request');
- let firstRequest = OS.File.exists('foo.bar');
+ do_print("issuing first request");
+ let firstRequest = OS.File.exists("foo.bar");
let secondRequest;
let secondResolved = false;
// As noted in our big block comment, we want to wait to schedule the
// second request so that it races `kill`'s call to `worker.post`. Having
// ourselves wait on the same promise, `queue`, and registering ourselves
// before we issue the kill request means we will get run before the `kill`
// task resumes and allow us to precisely create the desired race.
Scheduler.queue.then(function() {
- do_print('issuing second request');
- secondRequest = OS.File.exists('foo.baz');
+ do_print("issuing second request");
+ secondRequest = OS.File.exists("foo.baz");
secondRequest.then(function() {
secondResolved = true;
});
});
- do_print('issuing kill request');
+ do_print("issuing kill request");
let killRequest = Scheduler.kill({ reset: true, shutdown: false });
// Wait on the killRequest so that we can schedule a new OS.File request
// after it completes...
await killRequest;
// ...because our ordering guarantee ensures that there is at most one
// worker (and this usage here should not be vulnerable even with the
// bug present), so when this completes the secondRequest has either been
// resolved or lost.
- await OS.File.exists('foo.goz');
+ await OS.File.exists("foo.goz");
ok(secondResolved,
- 'The second request was resolved so we avoided the bug. Victory!');
+ "The second request was resolved so we avoided the bug. Victory!");
});
function run_test() {
run_next_test();
}
--- a/toolkit/components/osfile/tests/xpcshell/test_osfile_writeAtomic_zerobytes.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_osfile_writeAtomic_zerobytes.js
@@ -19,9 +19,9 @@ add_test_pair(async function test_osfile
let bin = await OS.File.read(SHARED_PATH);
let string2 = decoder.decode(bin);
// Checking if writeAtomic supports writing encoded zero-byte strings
Assert.equal(string2, string1, "Read the expected (empty) string.");
});
function run_test() {
run_next_test();
-}
\ No newline at end of file
+}
--- a/toolkit/components/osfile/tests/xpcshell/test_path.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_path.js
@@ -11,29 +11,27 @@ Services.prefs.setBoolPref("toolkit.osfi
var ImportWin = {};
var ImportUnix = {};
Components.utils.import("resource://gre/modules/osfile/ospath_win.jsm", ImportWin);
Components.utils.import("resource://gre/modules/osfile/ospath_unix.jsm", ImportUnix);
var Win = ImportWin;
var Unix = ImportUnix;
-function do_check_fail(f)
-{
+function do_check_fail(f) {
try {
let result = f();
do_print("Failed do_check_fail: " + result);
do_check_true(false);
} catch (ex) {
do_check_true(true);
}
-};
+}
-function run_test()
-{
+function run_test() {
do_print("Testing Windows paths");
do_print("Backslash-separated, no drive");
do_check_eq(Win.basename("a\\b"), "b");
do_check_eq(Win.basename("a\\b\\"), "");
do_check_eq(Win.basename("abc"), "abc");
do_check_eq(Win.dirname("a\\b"), "a");
do_check_eq(Win.dirname("a\\b\\"), "a\\b");
--- a/toolkit/components/osfile/tests/xpcshell/test_path_constants.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_path_constants.js
@@ -11,17 +11,17 @@ Cu.import("resource://testing-common/App
function run_test() {
run_next_test();
}
function compare_paths(ospath, key) {
let file;
try {
file = Services.dirsvc.get(key, Components.interfaces.nsIFile);
- } catch(ex) {}
+ } catch (ex) {}
if (file) {
do_check_true(!!ospath);
do_check_eq(ospath, file.path);
} else {
do_print("WARNING: " + key + " is not defined. Test may not be testing anything!");
do_check_false(!!ospath);
}
--- a/toolkit/components/osfile/tests/xpcshell/test_queue.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_queue.js
@@ -27,12 +27,12 @@ add_task(async function check_success()
add_task(async function check_failure() {
let exception;
try {
do_print("Attempting to open a non existing file");
await OS.File.open(OS.Path.join(".", "Bigfoot"));
} catch (err) {
exception = err;
await OS.File.queue;
- }
- do_check_true(exception!=null);
+ }
+ do_check_true(exception != null);
do_print("Function resolved");
-});
\ No newline at end of file
+});
--- a/toolkit/components/osfile/tests/xpcshell/test_unique.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_unique.js
@@ -29,47 +29,47 @@ function testFiles(filename) {
await openedFile.file.close();
exists = await OS.File.exists(openedFile.path);
do_check_true(exists);
fileInfo = await OS.File.stat(openedFile.path);
do_check_true(fileInfo.size == 0);
// Ensure that openUnique() generates different file names each time, using the HEX number algorithm
let filenames = new Set();
- for (let i=0; i < MAX_TRIES; i++) {
+ for (let i = 0; i < MAX_TRIES; i++) {
openedFile = await OS.File.openUnique(path);
await openedFile.file.close();
filenames.add(openedFile.path);
}
do_check_eq(filenames.size, MAX_TRIES);
// Ensure that openUnique() creates a new human readable file name using, as the original name is already taken.
- openedFile = await OS.File.openUnique(path, {humanReadable : true});
+ openedFile = await OS.File.openUnique(path, {humanReadable: true});
do_print("\nCreate unique Human Readable file: " + openedFile.path);
await openedFile.file.close();
exists = await OS.File.exists(openedFile.path);
do_check_true(exists);
fileInfo = await OS.File.stat(openedFile.path);
do_check_true(fileInfo.size == 0);
// Ensure that openUnique() generates different human readable file names each time
filenames = new Set();
- for (let i=0; i < MAX_TRIES; i++) {
- openedFile = await OS.File.openUnique(path, {humanReadable : true});
+ for (let i = 0; i < MAX_TRIES; i++) {
+ openedFile = await OS.File.openUnique(path, {humanReadable: true});
await openedFile.file.close();
filenames.add(openedFile.path);
}
do_check_eq(filenames.size, MAX_TRIES);
let exn;
try {
- for (let i=0; i < 100; i++) {
- openedFile = await OS.File.openUnique(path, {humanReadable : true});
+ for (let i = 0; i < 100; i++) {
+ openedFile = await OS.File.openUnique(path, {humanReadable: true});
await openedFile.file.close();
}
} catch (ex) {
exn = ex;
}
do_print("Ensure that this raises the correct error");
do_check_true(!!exn);