Bug 881483 - Remove noOptions constant in favor of an object literal. r=yoric

This commit is contained in:
Yura Zenevich 2013-06-11 09:50:35 -04:00
parent 1d2c4c97c5
commit 94cce00d46
4 changed files with 20 additions and 35 deletions

View File

@ -111,11 +111,6 @@ let clone = function clone(object, refs = noRefs) {
return result;
};
/**
* A shared constant used to normalize a set of options to nothing.
*/
const noOptions = {};
let worker = new PromiseWorker(
"resource://gre/modules/osfile/osfile_async_worker.js", LOG);
let Scheduler = {
@ -313,7 +308,7 @@ File.prototype = {
* @resolves {number} The number of bytes effectively read.
* @rejects {OS.File.Error}
*/
readTo: function readTo(buffer, options = noOptions) {
readTo: function readTo(buffer, options = {}) {
// If |buffer| is a typed array and there is no |bytes| options, we
// need to extract the |byteLength| now, as it will be lost by
// communication
@ -351,7 +346,7 @@ File.prototype = {
*
* @return {number} The number of bytes actually written.
*/
write: function write(buffer, options = noOptions) {
write: function write(buffer, options = {}) {
// If |buffer| is a typed array and there is no |bytes| options,
// we need to extract the |byteLength| now, as it will be lost
// by communication
@ -652,7 +647,7 @@ File.exists = function exists(path) {
* @return {promise}
* @resolves {number} The number of bytes actually written.
*/
File.writeAtomic = function writeAtomic(path, buffer, options = noOptions) {
File.writeAtomic = function writeAtomic(path, buffer, options = {}) {
// Copy |options| to avoid modifying the original object but preserve the
// reference to |outExecutionDuration| option if it is passed.
options = clone(options, ["outExecutionDuration"]);

View File

@ -16,9 +16,6 @@ if (typeof Components != "undefined") {
let LOG = exports.OS.Shared.LOG.bind(OS.Shared, "Shared front-end");
const noOptions = {};
/**
* Code shared by implementations of File.
*
@ -80,7 +77,7 @@ AbstractFile.prototype = {
* @return {number} The number of bytes actually read, which may be
* less than |bytes| if the file did not contain that many bytes left.
*/
readTo: function readTo(buffer, options = noOptions) {
readTo: function readTo(buffer, options = {}) {
let {ptr, bytes} = AbstractFile.normalizeToPointer(buffer, options.bytes);
let pos = 0;
while (pos < bytes) {
@ -112,7 +109,7 @@ AbstractFile.prototype = {
*
* @return {number} The number of bytes actually written.
*/
write: function write(buffer, options = noOptions) {
write: function write(buffer, options = {}) {
let {ptr, bytes} = AbstractFile.normalizeToPointer(buffer, options.bytes);
@ -340,7 +337,7 @@ AbstractFile.read = function read(path, bytes) {
* @return {number} The number of bytes actually written.
*/
AbstractFile.writeAtomic =
function writeAtomic(path, buffer, options = noOptions) {
function writeAtomic(path, buffer, options = {}) {
// Verify that path is defined and of the correct type
if (typeof path != "string" || path == "") {

View File

@ -166,10 +166,6 @@
throw_on_negative("flush", UnixFile.fsync(this.fd));
};
// Constant used to normalize options.
const noOptions = {};
// The default unix mode for opening (0600)
const DEFAULT_UNIX_MODE = 384;
@ -216,7 +212,7 @@
* @return {File} A file object.
* @throws {OS.File.Error} If the file could not be opened.
*/
File.open = function Unix_open(path, mode, options = noOptions) {
File.open = function Unix_open(path, mode, options = {}) {
let omode = options.unixMode || DEFAULT_UNIX_MODE;
let flags;
if (options.unixFlags) {
@ -287,7 +283,7 @@
* - {bool} ignoreAbsent If |true|, do not fail if the
* directory does not exist yet.
*/
File.removeEmptyDir = function removeEmptyDir(path, options = noOptions) {
File.removeEmptyDir = function removeEmptyDir(path, options = {}) {
let result = UnixFile.rmdir(path);
if (result == -1) {
if (options.ignoreAbsent && ctypes.errno == Const.ENOENT) {
@ -316,7 +312,7 @@
* - {bool} ignoreExisting If |true|, do not fail if the
* directory already exists.
*/
File.makeDir = function makeDir(path, options = noOptions) {
File.makeDir = function makeDir(path, options = {}) {
let omode = options.unixMode || DEFAULT_UNIX_MODE_DIR;
let result = UnixFile.mkdir(path, omode);
if (result != -1 ||
@ -383,7 +379,7 @@
// This implementation uses |copyfile(3)|, from the BSD library.
// Adding copying of hierarchies and/or attributes is just a flag
// away.
File.copy = function copyfile(sourcePath, destPath, options = noOptions) {
File.copy = function copyfile(sourcePath, destPath, options = {}) {
let flags = Const.COPYFILE_DATA;
if (options.noOverwrite) {
flags |= Const.COPYFILE_EXCL;
@ -421,7 +417,7 @@
let pump_buffer = null;
// An implementation of |pump| using |read|/|write|
let pump_userland = function pump_userland(source, dest, options = noOptions) {
let pump_userland = function pump_userland(source, dest, options = {}) {
let bufSize = options.bufSize || 4096;
let nbytes = options.nbytes || Infinity;
if (!pump_buffer || pump_buffer.length < bufSize) {
@ -457,7 +453,7 @@
const BUFSIZE = 1 << 17;
// An implementation of |pump| using |splice| (for Linux/Android)
pump = function pump_splice(source, dest, options = noOptions) {
pump = function pump_splice(source, dest, options = {}) {
let nbytes = options.nbytes || Infinity;
let pipe = [];
throw_on_negative("pump", UnixFile.pipe(pipe));
@ -521,7 +517,7 @@
// Implement |copy| using |pump|.
// This implementation would require some work before being able to
// copy directories
File.copy = function copy(sourcePath, destPath, options = noOptions) {
File.copy = function copy(sourcePath, destPath, options = {}) {
let source, dest;
let result;
try {
@ -546,7 +542,7 @@
// Implement |move| using |rename| (wherever possible) or |copy|
// (if files are on distinct devices).
File.move = function move(sourcePath, destPath, options = noOptions) {
File.move = function move(sourcePath, destPath, options = {}) {
// An implementation using |rename| whenever possible or
// |File.pump| when required, for other Unices.
// It can move directories on one file system, not
@ -795,7 +791,7 @@
*
* @return {File.Information}
*/
File.stat = function stat(path, options = noOptions) {
File.stat = function stat(path, options = {}) {
if (options.unixNoFollowingLinks) {
throw_on_negative("stat", UnixFile.lstat(path, gStatDataPtr));
} else {

View File

@ -188,9 +188,6 @@
throw_on_zero("flush", WinFile.FlushFileBuffers(this.fd));
};
// Constant used to normalize options.
const noOptions = {};
// The default sharing mode for opening files: files are not
// locked against being reopened for reading/writing or against
// being deleted by the same process or another process.
@ -255,7 +252,7 @@
* @return {File} A file object.
* @throws {OS.File.Error} If the file could not be opened.
*/
File.open = function Win_open(path, mode = noOptions, options = noOptions) {
File.open = function Win_open(path, mode = {}, options = {}) {
let share = options.winShare || DEFAULT_SHARE;
let security = options.winSecurity || null;
let flags = options.winFlags || DEFAULT_FLAGS;
@ -347,7 +344,7 @@
* - {bool} ignoreAbsent If |true|, do not fail if the
* directory does not exist yet.
*/
File.removeEmptyDir = function removeEmptyDir(path, options = noOptions) {
File.removeEmptyDir = function removeEmptyDir(path, options = {}) {
let result = WinFile.RemoveDirectory(path);
if (!result) {
if (options.ignoreAbsent &&
@ -372,7 +369,7 @@
* - {bool} ignoreExisting If |true|, do not fail if the
* directory already exists.
*/
File.makeDir = function makeDir(path, options = noOptions) {
File.makeDir = function makeDir(path, options = {}) {
let security = options.winSecurity || null;
let result = WinFile.CreateDirectory(path, security);
if (result ||
@ -406,7 +403,7 @@
* is unspecified. Metadata may or may not be copied with the file. The
* behavior may not be the same across all platforms.
*/
File.copy = function copy(sourcePath, destPath, options = noOptions) {
File.copy = function copy(sourcePath, destPath, options = {}) {
throw_on_zero("copy",
WinFile.CopyFile(sourcePath, destPath, options.noOverwrite || false)
);
@ -438,7 +435,7 @@
* is unspecified. Metadata may or may not be moved with the file. The
* behavior may not be the same across all platforms.
*/
File.move = function move(sourcePath, destPath, options = noOptions) {
File.move = function move(sourcePath, destPath, options = {}) {
let flags = 0;
if (!options.noCopy) {
flags = Const.MOVEFILE_COPY_ALLOWED;