Backed out changeset d319322e33cc (bug 1379256)

This commit is contained in:
Sebastian Hengst 2017-08-12 13:48:01 +02:00
Родитель 38703f6066
Коммит 1f19257b7d
26 изменённых файлов: 147 добавлений и 97 удалений

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

@ -0,0 +1,14 @@
"use strict";
module.exports = {
"rules": {
"consistent-return": "off",
"no-irregular-whitespace": "off",
"no-lone-blocks": "off",
"no-redeclare": "off",
"no-self-assign": "off",
"no-shadow": "off",
"no-unused-vars": "off",
"object-shorthand": "off",
}
};

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

@ -261,7 +261,7 @@ var Scheduler = this.Scheduler = {
/** /**
* Restart the OS.File worker killer timer. * Restart the OS.File worker killer timer.
*/ */
restartTimer(arg) { restartTimer: function(arg) {
this.hasRecentActivity = true; this.hasRecentActivity = true;
}, },
@ -275,7 +275,7 @@ var Scheduler = this.Scheduler = {
* would not cause leaks. Otherwise, assume that the worker will be shutdown * would not cause leaks. Otherwise, assume that the worker will be shutdown
* through some other mean. * through some other mean.
*/ */
kill({shutdown, reset}) { kill: function({shutdown, reset}) {
// Grab the kill queue to make sure that we // Grab the kill queue to make sure that we
// cannot be interrupted by another call to `kill`. // cannot be interrupted by another call to `kill`.
let killQueue = this._killQueue; let killQueue = this._killQueue;
@ -382,7 +382,7 @@ var Scheduler = this.Scheduler = {
* @return {Promise} A promise with the same behavior as * @return {Promise} A promise with the same behavior as
* the promise returned by |code|. * the promise returned by |code|.
*/ */
push(code) { push: function(code) {
let promise = this.queue.then(code); let promise = this.queue.then(code);
// By definition, |this.queue| can never reject. // By definition, |this.queue| can never reject.
this.queue = promise.catch(() => undefined); this.queue = promise.catch(() => undefined);
@ -482,7 +482,7 @@ var Scheduler = this.Scheduler = {
* *
* This is only useful on first launch. * This is only useful on first launch.
*/ */
_updateTelemetry() { _updateTelemetry: function() {
let worker = this.worker; let worker = this.worker;
let workerTimeStamps = worker.workerTimeStamps; let workerTimeStamps = worker.workerTimeStamps;
if (!workerTimeStamps) { if (!workerTimeStamps) {
@ -1270,10 +1270,10 @@ var DirectoryIterator = function DirectoryIterator(path, options) {
this._isClosed = false; this._isClosed = false;
}; };
DirectoryIterator.prototype = { DirectoryIterator.prototype = {
iterator() { iterator: function() {
return this; return this;
}, },
__iterator__() { __iterator__: function() {
return this; return this;
}, },
@ -1481,7 +1481,7 @@ this.OS.Path = Path;
// Returns a resolved promise when all the queued operation have been completed. // Returns a resolved promise when all the queued operation have been completed.
Object.defineProperty(OS.File, "queue", { Object.defineProperty(OS.File, "queue", {
get() { get: function() {
return Scheduler.queue; return Scheduler.queue;
} }
}); });
@ -1500,7 +1500,7 @@ var Barriers = {
/** /**
* Return the shutdown state of OS.File * Return the shutdown state of OS.File
*/ */
getDetails() { getDetails: function() {
let result = { let result = {
launched: Scheduler.launched, launched: Scheduler.launched,
shutdown: Scheduler.shutdown, shutdown: Scheduler.shutdown,

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

@ -59,7 +59,7 @@ if (this.Components) {
/** /**
* Get a resource from its unique identifier. * Get a resource from its unique identifier.
*/ */
get(id) { get: function(id) {
let result = this._map.get(id); let result = this._map.get(id);
if (result == null) { if (result == null) {
return result; return result;
@ -69,7 +69,7 @@ if (this.Components) {
/** /**
* Remove a resource from its unique identifier. * Remove a resource from its unique identifier.
*/ */
remove(id) { remove: function(id) {
if (!this._map.has(id)) { if (!this._map.has(id)) {
throw new Error("Cannot find resource id " + id); throw new Error("Cannot find resource id " + id);
} }
@ -84,9 +84,9 @@ if (this.Components) {
* @return {*} A unique identifier. For the moment, this is a number, * @return {*} A unique identifier. For the moment, this is a number,
* but this might not remain the case forever. * but this might not remain the case forever.
*/ */
add(resource, info) { add: function(resource, info) {
let id = this._idgen++; let id = this._idgen++;
this._map.set(id, {resource, info}); this._map.set(id, {resource: resource, info: info});
return id; return id;
}, },
/** /**
@ -154,12 +154,12 @@ if (this.Components) {
*/ */
let Agent = { let Agent = {
// Update worker's OS.Shared.DEBUG flag message from controller. // Update worker's OS.Shared.DEBUG flag message from controller.
SET_DEBUG(aDEBUG) { SET_DEBUG: function(aDEBUG) {
SharedAll.Config.DEBUG = aDEBUG; SharedAll.Config.DEBUG = aDEBUG;
}, },
// Return worker's current OS.Shared.DEBUG value to controller. // Return worker's current OS.Shared.DEBUG value to controller.
// Note: This is used for testing purposes. // Note: This is used for testing purposes.
GET_DEBUG() { GET_DEBUG: function() {
return SharedAll.Config.DEBUG; return SharedAll.Config.DEBUG;
}, },
/** /**
@ -168,7 +168,7 @@ if (this.Components) {
* @param {bool} If |true|, kill the worker if this would not cause * @param {bool} If |true|, kill the worker if this would not cause
* leaks. * leaks.
*/ */
Meta_shutdown(kill) { Meta_shutdown: function(kill) {
let result = { let result = {
openedFiles: OpenedFiles.listOpenedResources(), openedFiles: OpenedFiles.listOpenedResources(),
openedDirectoryIterators: OpenedDirectoryIterators.listOpenedResources(), openedDirectoryIterators: OpenedDirectoryIterators.listOpenedResources(),
@ -269,7 +269,7 @@ if (this.Components) {
options options
); );
}, },
removeDir(path, options) { removeDir: function(path, options) {
return File.removeDir(Type.path.fromMsg(path), options); return File.removeDir(Type.path.fromMsg(path), options);
}, },
new_DirectoryIterator: function new_DirectoryIterator(path, options) { new_DirectoryIterator: function new_DirectoryIterator(path, options) {

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

@ -109,7 +109,7 @@ var defineLazyGetter = function defineLazyGetter(object, name, getter) {
delete this[name]; delete this[name];
let value = getter.call(this); let value = getter.call(this);
Object.defineProperty(object, name, { Object.defineProperty(object, name, {
value value: value
}); });
return value; return value;
} }
@ -213,10 +213,10 @@ var clone = function(object, refs = []) {
let refer = function refer(result, key, object) { let refer = function refer(result, key, object) {
Object.defineProperty(result, key, { Object.defineProperty(result, key, {
enumerable: true, enumerable: true,
get() { get: function() {
return object[key]; return object[key];
}, },
set(value) { set: function(value) {
object[key] = value; object[key] = value;
} }
}); });
@ -301,7 +301,7 @@ Type.prototype = {
this); this);
Object.defineProperty(this, "in_ptr", Object.defineProperty(this, "in_ptr",
{ {
get() { get: function() {
return ptr_t; return ptr_t;
} }
}); });
@ -319,7 +319,7 @@ Type.prototype = {
this); this);
Object.defineProperty(this, "out_ptr", Object.defineProperty(this, "out_ptr",
{ {
get() { get: function() {
return ptr_t; return ptr_t;
} }
}); });
@ -341,7 +341,7 @@ Type.prototype = {
this); this);
Object.defineProperty(this, "inout_ptr", Object.defineProperty(this, "inout_ptr",
{ {
get() { get: function() {
return ptr_t; return ptr_t;
} }
}); });
@ -865,7 +865,7 @@ HollowStructure.prototype = {
" at offset " + offset + " at offset " + offset +
" without exceeding its size of " + this.size); " without exceeding its size of " + this.size);
} }
let field = {name, type}; let field = {name: name, type: type};
this.offset_to_field_info[offset] = field; this.offset_to_field_info[offset] = field;
}, },
@ -991,7 +991,7 @@ Library.prototype = Object.freeze({
} }
let error = new Error("Could not open library " + this.name); let error = new Error("Could not open library " + this.name);
Object.defineProperty(this, "library", { Object.defineProperty(this, "library", {
get() { get: function() {
throw error; throw error;
} }
}); });
@ -1010,10 +1010,10 @@ Library.prototype = Object.freeze({
* @param {Type} returnType The type of values returned by the function. * @param {Type} returnType The type of values returned by the function.
* @param {...Type} argTypes The type of arguments to the function. * @param {...Type} argTypes The type of arguments to the function.
*/ */
declareLazyFFI(object, field, ...args) { declareLazyFFI: function(object, field, ...args) {
let lib = this; let lib = this;
Object.defineProperty(object, field, { Object.defineProperty(object, field, {
get() { get: function() {
delete this[field]; delete this[field];
let ffi = declareFFI(lib.library, ...args); let ffi = declareFFI(lib.library, ...args);
if (ffi) { if (ffi) {
@ -1037,10 +1037,10 @@ Library.prototype = Object.freeze({
* @param {ctypes.CType} returnType The type of values returned by the function. * @param {ctypes.CType} returnType The type of values returned by the function.
* @param {...ctypes.CType} argTypes The type of arguments to the function. * @param {...ctypes.CType} argTypes The type of arguments to the function.
*/ */
declareLazy(object, field, ...args) { declareLazy: function(object, field, ...args) {
let lib = this; let lib = this;
Object.defineProperty(object, field, { Object.defineProperty(object, field, {
get() { get: function() {
delete this[field]; delete this[field];
let ffi = lib.library.declare(...args); let ffi = lib.library.declare(...args);
if (ffi) { if (ffi) {
@ -1067,10 +1067,10 @@ Library.prototype = Object.freeze({
* @param {ctypes.CType} returnType The type of values returned by the function. * @param {ctypes.CType} returnType The type of values returned by the function.
* @param {...ctypes.CType} argTypes The type of arguments to the function. * @param {...ctypes.CType} argTypes The type of arguments to the function.
*/ */
declareLazyWithFallback(fallbacklibrary, object, field, ...args) { declareLazyWithFallback: function(fallbacklibrary, object, field, ...args) {
let lib = this; let lib = this;
Object.defineProperty(object, field, { Object.defineProperty(object, field, {
get() { get: function() {
delete this[field]; delete this[field];
try { try {
let ffi = lib.library.declare(...args); let ffi = lib.library.declare(...args);
@ -1089,7 +1089,7 @@ Library.prototype = Object.freeze({
}); });
}, },
toString() { toString: function() {
return "[Library " + this.name + "]"; return "[Library " + this.name + "]";
} }
}); });
@ -1126,6 +1126,7 @@ var declareFFI = function declareFFI(lib, symbol, abi,
throw new TypeError("declareFFI expects as third argument an instance of Type"); throw new TypeError("declareFFI expects as third argument an instance of Type");
} }
let signature = [symbol, abi]; let signature = [symbol, abi];
let argtypes = [];
for (let i = 3; i < arguments.length; ++i) { for (let i = 3; i < arguments.length; ++i) {
let current = arguments[i]; let current = arguments[i];
if (!current) { if (!current) {
@ -1175,7 +1176,7 @@ exports.declareFFI = declareFFI;
*/ */
function declareLazyFFI(object, field, ...declareFFIArgs) { function declareLazyFFI(object, field, ...declareFFIArgs) {
Object.defineProperty(object, field, { Object.defineProperty(object, field, {
get() { get: function() {
delete this[field]; delete this[field];
let ffi = declareFFI(...declareFFIArgs); let ffi = declareFFI(...declareFFIArgs);
if (ffi) { if (ffi) {
@ -1203,7 +1204,7 @@ exports.declareLazyFFI = declareLazyFFI;
*/ */
function declareLazy(object, field, lib, ...declareArgs) { function declareLazy(object, field, lib, ...declareArgs) {
Object.defineProperty(object, field, { Object.defineProperty(object, field, {
get() { get: function() {
delete this[field]; delete this[field];
try { try {
let ffi = lib.declare(...declareArgs); let ffi = lib.declare(...declareArgs);
@ -1278,31 +1279,31 @@ exports.OSError = OSError;
exports.OS = { exports.OS = {
Constants: exports.Constants, Constants: exports.Constants,
Shared: { Shared: {
LOG, LOG: LOG,
clone, clone: clone,
Type, Type: Type,
HollowStructure, HollowStructure: HollowStructure,
Error: OSError, Error: OSError,
declareFFI, declareFFI: declareFFI,
projectValue, projectValue: projectValue,
isTypedArray, isTypedArray: isTypedArray,
defineLazyGetter defineLazyGetter: defineLazyGetter
} }
}; };
Object.defineProperty(exports.OS.Shared, "DEBUG", { Object.defineProperty(exports.OS.Shared, "DEBUG", {
get() { get: function() {
return Config.DEBUG; return Config.DEBUG;
}, },
set(x) { set: function(x) {
return Config.DEBUG = x; return Config.DEBUG = x;
} }
}); });
Object.defineProperty(exports.OS.Shared, "TEST", { Object.defineProperty(exports.OS.Shared, "TEST", {
get() { get: function() {
return Config.TEST; return Config.TEST;
}, },
set(x) { set: function(x) {
return Config.TEST = x; return Config.TEST = x;
} }
}); });

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

@ -22,7 +22,7 @@ var SharedAll =
var Path = require("resource://gre/modules/osfile/ospath.jsm"); var Path = require("resource://gre/modules/osfile/ospath.jsm");
var Lz4 = var Lz4 =
require("resource://gre/modules/lz4.js"); require("resource://gre/modules/lz4.js");
SharedAll.LOG.bind(SharedAll, "Shared front-end"); var LOG = SharedAll.LOG.bind(SharedAll, "Shared front-end");
var clone = SharedAll.clone; var clone = SharedAll.clone;
/** /**
@ -152,7 +152,7 @@ AbstractFile.openUnique = function openUnique(path, options = {}) {
try { try {
return { return {
path, path: path,
file: OS.File.open(path, mode) file: OS.File.open(path, mode)
}; };
} catch (ex) { } catch (ex) {
@ -179,7 +179,6 @@ AbstractFile.openUnique = function openUnique(path, options = {}) {
} }
throw OS.File.Error.exists("could not find an unused file name.", path); throw OS.File.Error.exists("could not find an unused file name.", path);
} }
throw ex;
} }
}; };

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

@ -37,7 +37,7 @@ if (typeof Components != "undefined") {
throw new Error("Please open this module with Component.utils.import or with require()"); throw new Error("Please open this module with Component.utils.import or with require()");
} }
SharedAll.LOG.bind(SharedAll, "Unix", "allthreads"); var LOG = SharedAll.LOG.bind(SharedAll, "Unix", "allthreads");
var Const = SharedAll.Constants.libc; var Const = SharedAll.Constants.libc;
// Open libc // Open libc

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

@ -5,7 +5,6 @@
/* eslint-env mozilla/chrome-worker, node */ /* eslint-env mozilla/chrome-worker, node */
/* global OS */ /* global OS */
// eslint-disable-next-line no-lone-blocks
{ {
if (typeof Components != "undefined") { if (typeof Components != "undefined") {
// We do not wish osfile_unix_back.jsm to be used directly as a main thread // We do not wish osfile_unix_back.jsm to be used directly as a main thread
@ -25,7 +24,7 @@
require("resource://gre/modules/osfile/osfile_shared_allthreads.jsm"); require("resource://gre/modules/osfile/osfile_shared_allthreads.jsm");
let SysAll = let SysAll =
require("resource://gre/modules/osfile/osfile_unix_allthreads.jsm"); require("resource://gre/modules/osfile/osfile_unix_allthreads.jsm");
SharedAll.LOG.bind(SharedAll, "Unix", "back"); let LOG = SharedAll.LOG.bind(SharedAll, "Unix", "back");
let libc = SysAll.libc; let libc = SysAll.libc;
let Const = SharedAll.Constants.libc; let Const = SharedAll.Constants.libc;
@ -36,18 +35,19 @@
*/ */
// FIXME: Both |init| and |aDeclareFFI| are deprecated, we should remove them // FIXME: Both |init| and |aDeclareFFI| are deprecated, we should remove them
let init = function init(aDeclareFFI) { let init = function init(aDeclareFFI) {
let declareFFI;
if (aDeclareFFI) { if (aDeclareFFI) {
aDeclareFFI.bind(null, libc); declareFFI = aDeclareFFI.bind(null, libc);
} else { } else {
SysAll.declareFFI; declareFFI = SysAll.declareFFI;
} }
SharedAll.declareLazyFFI; let declareLazyFFI = SharedAll.declareLazyFFI;
// Initialize types that require additional OS-specific // Initialize types that require additional OS-specific
// support - either finalization or matching against // support - either finalization or matching against
// OS-specific constants. // OS-specific constants.
let Type = Object.create(SysAll.Type); let Type = Object.create(SysAll.Type);
let SysFile = exports.OS.Unix.File = { Type }; let SysFile = exports.OS.Unix.File = { Type: Type };
/** /**
* A file descriptor. * A file descriptor.

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

@ -12,7 +12,6 @@
/* eslint-env mozilla/chrome-worker, node */ /* eslint-env mozilla/chrome-worker, node */
/* global OS */ /* global OS */
// eslint-disable-next-line no-lone-blocks
{ {
if (typeof Components != "undefined") { if (typeof Components != "undefined") {
// We do not wish osfile_unix_front.jsm to be used directly as a main thread // We do not wish osfile_unix_front.jsm to be used directly as a main thread
@ -32,7 +31,7 @@
let Path = require("resource://gre/modules/osfile/ospath.jsm"); let Path = require("resource://gre/modules/osfile/ospath.jsm");
let SysAll = require("resource://gre/modules/osfile/osfile_unix_allthreads.jsm"); let SysAll = require("resource://gre/modules/osfile/osfile_unix_allthreads.jsm");
exports.OS.Unix.File._init(); exports.OS.Unix.File._init();
SharedAll.LOG.bind(SharedAll, "Unix front-end"); let LOG = SharedAll.LOG.bind(SharedAll, "Unix front-end");
let Const = SharedAll.Constants.libc; let Const = SharedAll.Constants.libc;
let UnixFile = exports.OS.Unix.File; let UnixFile = exports.OS.Unix.File;
let Type = UnixFile.Type; let Type = UnixFile.Type;
@ -223,7 +222,7 @@
*/ */
if (SharedAll.Constants.Sys.Name != "Android") { if (SharedAll.Constants.Sys.Name != "Android") {
File.prototype.setDates = function(accessDate, modificationDate) { File.prototype.setDates = function(accessDate, modificationDate) {
let { /* value, */ ptr} = datesToTimevals(accessDate, modificationDate); let {value, ptr} = datesToTimevals(accessDate, modificationDate);
throw_on_negative("setDates", throw_on_negative("setDates",
UnixFile.futimes(this.fd, ptr), UnixFile.futimes(this.fd, ptr),
this._path); this._path);
@ -556,6 +555,7 @@
// Perform actual copy // Perform actual copy
let total_read = 0; let total_read = 0;
while (true) { while (true) {
let chunk_size = Math.min(nbytes, bufSize);
let bytes_just_read = read(pump_buffer, bufSize); let bytes_just_read = read(pump_buffer, bufSize);
if (bytes_just_read == 0) { if (bytes_just_read == 0) {
return total_read; return total_read;
@ -646,6 +646,7 @@
// copy directories // copy directories
File.copy = function copy(sourcePath, destPath, options = {}) { File.copy = function copy(sourcePath, destPath, options = {}) {
let source, dest; let source, dest;
let result;
try { try {
source = File.open(sourcePath); source = File.open(sourcePath);
// Need to open the output file with |append:false|, or else |splice| // Need to open the output file with |append:false|, or else |splice|
@ -656,9 +657,9 @@
dest = File.open(destPath, {trunc: true, append: false}); dest = File.open(destPath, {trunc: true, append: false});
} }
if (options.unixUserland) { if (options.unixUserland) {
pump_userland(source, dest, options); result = pump_userland(source, dest, options);
} else { } else {
pump(source, dest, options); result = pump(source, dest, options);
} }
} catch (x) { } catch (x) {
if (dest) { if (dest) {
@ -1001,7 +1002,7 @@
* @throws {OS.File.Error} In case of I/O error. * @throws {OS.File.Error} In case of I/O error.
*/ */
File.setDates = function setDates(path, accessDate, modificationDate) { File.setDates = function setDates(path, accessDate, modificationDate) {
let {/* value, */ ptr} = datesToTimevals(accessDate, modificationDate); let {value, ptr} = datesToTimevals(accessDate, modificationDate);
throw_on_negative("setDates", throw_on_negative("setDates",
UnixFile.utimes(path, ptr), UnixFile.utimes(path, ptr),
path); path);
@ -1081,10 +1082,10 @@
* Get/set the current directory. * Get/set the current directory.
*/ */
Object.defineProperty(File, "curDir", { Object.defineProperty(File, "curDir", {
set(path) { set: function(path) {
this.setCurrentDirectory(path); this.setCurrentDirectory(path);
}, },
get() { get: function() {
return this.getCurrentDirectory(); return this.getCurrentDirectory();
} }
} }

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

@ -37,7 +37,7 @@ if (typeof Components != "undefined") {
throw new Error("Please open this module with Component.utils.import or with require()"); throw new Error("Please open this module with Component.utils.import or with require()");
} }
SharedAll.LOG.bind(SharedAll, "Win", "allthreads"); var LOG = SharedAll.LOG.bind(SharedAll, "Win", "allthreads");
var Const = SharedAll.Constants.Win; var Const = SharedAll.Constants.Win;
// Open libc // Open libc
@ -85,6 +85,7 @@ libc.declareLazy(Scope, "FormatMessage",
*/ */
var OSError = function OSError(operation = "unknown operation", var OSError = function OSError(operation = "unknown operation",
lastError = ctypes.winLastError, path = "") { lastError = ctypes.winLastError, path = "") {
operation = operation;
SharedAll.OSError.call(this, operation, path); SharedAll.OSError.call(this, operation, path);
this.winLastError = lastError; this.winLastError = lastError;
}; };

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

@ -22,7 +22,6 @@
/* eslint-env mozilla/chrome-worker, node */ /* eslint-env mozilla/chrome-worker, node */
/* global OS */ /* global OS */
// eslint-disable-next-line no-lone-blocks
{ {
if (typeof Components != "undefined") { if (typeof Components != "undefined") {
// We do not wish osfile_win.jsm to be used directly as a main thread // We do not wish osfile_win.jsm to be used directly as a main thread
@ -41,7 +40,7 @@
let SharedAll = require("resource://gre/modules/osfile/osfile_shared_allthreads.jsm"); let SharedAll = require("resource://gre/modules/osfile/osfile_shared_allthreads.jsm");
let SysAll = require("resource://gre/modules/osfile/osfile_win_allthreads.jsm"); let SysAll = require("resource://gre/modules/osfile/osfile_win_allthreads.jsm");
SharedAll.LOG.bind(SharedAll, "Unix", "back"); let LOG = SharedAll.LOG.bind(SharedAll, "Unix", "back");
let libc = SysAll.libc; let libc = SysAll.libc;
let advapi32 = new SharedAll.Library("advapi32", "advapi32.dll"); let advapi32 = new SharedAll.Library("advapi32", "advapi32.dll");
let Const = SharedAll.Constants.Win; let Const = SharedAll.Constants.Win;
@ -53,19 +52,19 @@
*/ */
// FIXME: Both |init| and |aDeclareFFI| are deprecated, we should remove them // FIXME: Both |init| and |aDeclareFFI| are deprecated, we should remove them
let init = function init(aDeclareFFI) { let init = function init(aDeclareFFI) {
let declareFFI; // eslint-disable-line no-unused-vars let declareFFI;
if (aDeclareFFI) { if (aDeclareFFI) {
declareFFI = aDeclareFFI.bind(null, libc); declareFFI = aDeclareFFI.bind(null, libc);
} else { } else {
declareFFI = SysAll.declareFFI; declareFFI = SysAll.declareFFI;
} }
let declareLazyFFI = SharedAll.declareLazyFFI; // eslint-disable-line no-unused-vars let declareLazyFFI = SharedAll.declareLazyFFI;
// Initialize types that require additional OS-specific // Initialize types that require additional OS-specific
// support - either finalization or matching against // support - either finalization or matching against
// OS-specific constants. // OS-specific constants.
let Type = Object.create(SysAll.Type); let Type = Object.create(SysAll.Type);
let SysFile = exports.OS.Win.File = { Type }; let SysFile = exports.OS.Win.File = { Type: Type };
// Initialize types // Initialize types

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

@ -12,7 +12,6 @@
/* eslint-env mozilla/chrome-worker, node */ /* eslint-env mozilla/chrome-worker, node */
/* global OS */ /* global OS */
// eslint-disable-next-line no-lone-blocks
{ {
if (typeof Components != "undefined") { if (typeof Components != "undefined") {
// We do not wish osfile_win_front.jsm to be used directly as a main thread // We do not wish osfile_win_front.jsm to be used directly as a main thread
@ -1154,10 +1153,10 @@
* Get/set the current directory by |curDir|. * Get/set the current directory by |curDir|.
*/ */
Object.defineProperty(File, "curDir", { Object.defineProperty(File, "curDir", {
set(path) { set: function(path) {
this.setCurrentDirectory(path); this.setCurrentDirectory(path);
}, },
get() { get: function() {
return this.getCurrentDirectory(); return this.getCurrentDirectory();
} }
} }
@ -1196,6 +1195,40 @@
return result; return result;
} }
/**
* Utility function to sort errors represented as "-1" from successes.
*
* @param {string=} operation The name of the operation. If unspecified,
* the name of the caller function.
* @param {number} result The result of the operation that may
* represent either an error or a success. If -1, this function raises
* an error holding ctypes.winLastError, otherwise it returns |result|.
* @param {string=} path The path of the file.
*/
function throw_on_negative(operation, result, path) {
if (result < 0) {
throw new File.Error(operation, ctypes.winLastError, path);
}
return result;
}
/**
* Utility function to sort errors represented as |null| from successes.
*
* @param {string=} operation The name of the operation. If unspecified,
* the name of the caller function.
* @param {pointer} result The result of the operation that may
* represent either an error or a success. If |null|, this function raises
* an error holding ctypes.winLastError, otherwise it returns |result|.
* @param {string=} path The path of the file.
*/
function throw_on_null(operation, result, path) {
if (result == null || (result.isNull && result.isNull())) {
throw new File.Error(operation, ctypes.winLastError, path);
}
return result;
}
/** /**
* Helper used by both versions of setPermissions * Helper used by both versions of setPermissions
*/ */

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

@ -407,7 +407,7 @@ var test_debug_test = maketest("debug_test", function debug_test(test) {
return (async function() { return (async function() {
// Create a console listener. // Create a console listener.
let consoleListener = { let consoleListener = {
observe(aMessage) { observe: function(aMessage) {
// Ignore unexpected messages. // Ignore unexpected messages.
if (!(aMessage instanceof Components.interfaces.nsIConsoleMessage)) { if (!(aMessage instanceof Components.interfaces.nsIConsoleMessage)) {
return; return;
@ -420,7 +420,7 @@ var test_debug_test = maketest("debug_test", function debug_test(test) {
}; };
toggleDebugTest(true, consoleListener); toggleDebugTest(true, consoleListener);
// Execution of OS.File.exist method will trigger OS.File.LOG several times. // Execution of OS.File.exist method will trigger OS.File.LOG several times.
await OS.File.exists(EXISTING_FILE); let fileExists = await OS.File.exists(EXISTING_FILE);
toggleDebugTest(false, consoleListener); toggleDebugTest(false, consoleListener);
})(); })();
}); });

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

@ -65,7 +65,7 @@ function test_open_non_existing_file() {
info("Starting test_open_non_existing"); info("Starting test_open_non_existing");
let exn; let exn;
try { try {
OS.File.open("/I do not exist"); let file = OS.File.open("/I do not exist");
} catch (x) { } catch (x) {
exn = x; exn = x;
info("test_open_non_existing_file: Exception detail " + exn); info("test_open_non_existing_file: Exception detail " + exn);

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

@ -19,12 +19,12 @@ function ok(condition, description) {
function is(a, b, description) { function is(a, b, description) {
let outcome = a == b; // Need to decide outcome here, as not everything can be serialized let outcome = a == b; // Need to decide outcome here, as not everything can be serialized
send({kind: "is", outcome, description: "" + description, a: "" + a, b: "" + b}); send({kind: "is", outcome: outcome, description: "" + description, a: "" + a, b: "" + b});
} }
function isnot(a, b, description) { function isnot(a, b, description) {
let outcome = a != b; // Need to decide outcome here, as not everything can be serialized let outcome = a != b; // Need to decide outcome here, as not everything can be serialized
send({kind: "isnot", outcome, description: "" + description, a: "" + a, b: "" + b}); send({kind: "isnot", outcome: outcome, description: "" + description, a: "" + a, b: "" + b});
} }
function info(description) { function info(description) {

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

@ -118,7 +118,7 @@ function test_read_write() {
break; break;
} }
while (bytes > 0) { while (bytes > 0) {
array.addressOfElement(write_from); let ptr = array.addressOfElement(write_from);
// Note: |write| launches an exception in case of error // Note: |write| launches an exception in case of error
let written = OS.Unix.File.write(output, array, bytes); let written = OS.Unix.File.write(output, array, bytes);
isnot(written, -1, "test_read_write: no write error"); isnot(written, -1, "test_read_write: no write error");
@ -186,10 +186,10 @@ function test_passing_undefined() {
let exceptionRaised = false; let exceptionRaised = false;
try { try {
OS.Unix.File.open(undefined, OS.Constants.libc.O_RDWR let file = OS.Unix.File.open(undefined, OS.Constants.libc.O_RDWR
| OS.Constants.libc.O_CREAT | OS.Constants.libc.O_CREAT
| OS.Constants.libc.O_TRUNC, | OS.Constants.libc.O_TRUNC,
OS.Constants.libc.S_IRWXU); OS.Constants.libc.S_IRWXU);
} catch (e) { } catch (e) {
if (e instanceof TypeError && e.message.indexOf("open") > -1) { if (e instanceof TypeError && e.message.indexOf("open") > -1) {
exceptionRaised = true; exceptionRaised = true;

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

@ -122,7 +122,7 @@ function test_ReadWrite() {
} }
while (bytes_left.value > 0) { while (bytes_left.value > 0) {
log("test_ReadWrite: writing " + bytes_left.value); log("test_ReadWrite: writing " + bytes_left.value);
array.addressOfElement(write_from); let ptr = array.addressOfElement(write_from);
// Note: |WriteFile| launches an exception in case of error // Note: |WriteFile| launches an exception in case of error
result = OS.Win.File.WriteFile(output, array, bytes_left, bytes_written_ptr, null); 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");
@ -193,7 +193,7 @@ function test_passing_undefined() {
let exceptionRaised = false; let exceptionRaised = false;
try { try {
OS.Win.File.CreateFile( let file = OS.Win.File.CreateFile(
undefined, undefined,
OS.Constants.Win.GENERIC_READ, OS.Constants.Win.GENERIC_READ,
0, 0,

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

@ -36,7 +36,7 @@ add_task(async function test_uncompressed() {
for (let i = 0; i < array.byteLength; ++i) { for (let i = 0; i < array.byteLength; ++i) {
array[i] = i; array[i] = i;
} }
await OS.File.writeAtomic(path, array); // No compression let bytes = await OS.File.writeAtomic(path, array); // No compression
let exn; let exn;
// Force decompression, reading should fail // Force decompression, reading should fail
@ -56,7 +56,7 @@ add_task(async function test_no_header() {
do_print("Writing data with no header"); do_print("Writing data with no header");
await OS.File.writeAtomic(path, array); // No compression let bytes = await OS.File.writeAtomic(path, array); // No compression
let exn; let exn;
// Force decompression, reading should fail // Force decompression, reading should fail
try { try {
@ -80,7 +80,7 @@ add_task(async function test_invalid_content() {
do_print("Writing invalid data (with a valid header and only ones after that)"); do_print("Writing invalid data (with a valid header and only ones after that)");
await OS.File.writeAtomic(path, array); // No compression let bytes = await OS.File.writeAtomic(path, array); // No compression
let exn; let exn;
// Force decompression, reading should fail // Force decompression, reading should fail
try { try {

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

@ -15,7 +15,7 @@ add_task(async function test_deprecatedCreationDate() {
let consoleMessagePromise = new Promise(resolve => { let consoleMessagePromise = new Promise(resolve => {
let consoleListener = { let consoleListener = {
observe(aMessage) { observe: function(aMessage) {
if (aMessage.message.indexOf("Field 'creationDate' is deprecated.") > -1) { if (aMessage.message.indexOf("Field 'creationDate' is deprecated.") > -1) {
do_print("Deprecation message printed"); do_print("Deprecation message printed");
do_check_true(true); do_check_true(true);

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

@ -59,7 +59,7 @@ add_task(async function duration() {
// duration measurement then progressively incremented. // duration measurement then progressively incremented.
outSerializationDuration: null, outSerializationDuration: null,
outExecutionDuration: null, outExecutionDuration: null,
tmpPath tmpPath: tmpPath
}; };
await OS.File.writeAtomic(pathDest, contents, writeAtomicOptions); await OS.File.writeAtomic(pathDest, contents, writeAtomicOptions);
testOptions(writeAtomicOptions, "OS.File.writeAtomic"); testOptions(writeAtomicOptions, "OS.File.writeAtomic");

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

@ -15,7 +15,7 @@ function run_test() {
// Create a console listener. // Create a console listener.
let consoleListener = { let consoleListener = {
observe(aMessage) { observe: function(aMessage) {
// Ignore unexpected messages. // Ignore unexpected messages.
if (!(aMessage instanceof Components.interfaces.nsIConsoleMessage)) { if (!(aMessage instanceof Components.interfaces.nsIConsoleMessage)) {
return; return;
@ -71,3 +71,4 @@ function run_test() {
// Once both messages are observed OS.Shared.DEBUG, and OS.Shared.TEST // Once both messages are observed OS.Shared.DEBUG, and OS.Shared.TEST
// are reset to false. // are reset to false.
} }

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

@ -62,6 +62,8 @@ async function test_setPosition_failures() {
try { try {
let file = await OS.File.open(path, {write: true, append: false}); let file = await OS.File.open(path, {write: true, append: false});
try { try {
let pos = 0;
// 1. Use an invalid position value // 1. Use an invalid position value
try { try {
await file.setPosition(0.5, OS.File.POS_START); await file.setPosition(0.5, OS.File.POS_START);
@ -112,7 +114,7 @@ function run_test() {
add_task(test_setPosition.bind(null, 1000, 100, 50)); add_task(test_setPosition.bind(null, 1000, 100, 50));
add_task(test_setPosition.bind(null, 1000, -100, -50)); add_task(test_setPosition.bind(null, 1000, -100, -50));
if (OS.Constants.Win || ctypes.off_t.size >= 8) { if (OS.Constants.Win || ctypes.off_t.size >= 8) {
// Now verify stuff still works for large values. // Now verify stuff still works for large values.
// 1. Multiple small seeks, which add up to > MAXINT32 // 1. Multiple small seeks, which add up to > MAXINT32
add_task(test_setPosition.bind(null, 0x7fffffff, 0x7fffffff, 0)); add_task(test_setPosition.bind(null, 0x7fffffff, 0x7fffffff, 0));

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

@ -1,7 +1,5 @@
"use strict"; "use strict";
/* eslint-disable no-lone-blocks */
Components.utils.import("resource://gre/modules/osfile.jsm"); Components.utils.import("resource://gre/modules/osfile.jsm");
/** /**
@ -108,7 +106,7 @@ add_task(async function test_proto() {
"test_osfile_async_setDates_proto.tmp"); "test_osfile_async_setDates_proto.tmp");
await OS.File.writeAtomic(path, new Uint8Array(1)); await OS.File.writeAtomic(path, new Uint8Array(1));
try { try {
let fd = await OS.File.open(path, {write: true}); let fd = await OS.File.open(path, {write: true});
try { try {

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

@ -62,7 +62,7 @@ add_task(async function test_kill_race() {
await OS.File.exists("foo.foo"); await OS.File.exists("foo.foo");
do_print("issuing first request"); do_print("issuing first request");
let firstRequest = OS.File.exists("foo.bar"); // eslint-disable-line no-unused-vars let firstRequest = OS.File.exists("foo.bar");
let secondRequest; let secondRequest;
let secondResolved = false; let secondResolved = false;

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

@ -103,6 +103,7 @@ add_task(async function test_non_backupTo_option() {
* @result no back up file exists * @result no back up file exists
*/ */
add_task(async function test_backupTo_option_without_destination_file() { add_task(async function test_backupTo_option_without_destination_file() {
let DEFAULT_CONTENTS = "default contents" + Math.random();
let WRITE_CONTENTS = "abc" + Math.random(); let WRITE_CONTENTS = "abc" + Math.random();
let path = Path.join(Constants.Path.tmpDir, let path = Path.join(Constants.Path.tmpDir,
"test_backupTo_option_without_destination_file.tmp"); "test_backupTo_option_without_destination_file.tmp");

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

@ -16,7 +16,7 @@ add_task(async function check_init() {
// after an operation is successful. // after an operation is successful.
add_task(async function check_success() { add_task(async function check_success() {
do_print("Attempting to open a file correctly"); do_print("Attempting to open a file correctly");
await OS.File.open(OS.Path.join(do_get_cwd().path, "test_queue.js")); let openedFile = await OS.File.open(OS.Path.join(do_get_cwd().path, "test_queue.js"));
do_print("File opened correctly"); do_print("File opened correctly");
await OS.File.queue; await OS.File.queue;
do_print("Function resolved"); do_print("Function resolved");

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

@ -86,7 +86,7 @@ add_test_pair(async function read_write_all() {
let array2 = await OS.File.read(DEST_PATH); let array2 = await OS.File.read(DEST_PATH);
do_check_eq(LENGTH, array2.length); do_check_eq(LENGTH, array2.length);
for (var j = 0; j < LENGTH; j++) for (var i = 0; i < LENGTH; i++)
do_check_eq(array2[i], (i + START) % 256); do_check_eq(array2[i], (i + START) % 256);
// Cleanup. // Cleanup.