Backed out changesets 19dd0130c6ae and d986a560fbdd (bug 865387) for Android test failures on a CLOSED TREE.

This commit is contained in:
Ryan VanderMeulen 2013-08-26 15:02:15 -04:00
parent 4100d03bce
commit b61aea647b
7 changed files with 60 additions and 92 deletions

View File

@ -15,10 +15,6 @@
#include "sys/stat.h"
#endif // defined(XP_UNIX)
#if defined(XP_LINUX)
#include <linux/fadvise.h>
#endif // defined(XP_LINUX)
#if defined(XP_MACOSX)
#include "copyfile.h"
#endif // defined(XP_MACOSX)
@ -324,10 +320,6 @@ static const dom::ConstantSpec gLibcProperties[] =
INT_CONSTANT(AT_SYMLINK_NOFOLLOW),
#endif //defined(AT_SYMLINK_NOFOLLOW)
#if defined(POSIX_FADV_SEQUENTIAL)
INT_CONSTANT(POSIX_FADV_SEQUENTIAL),
#endif //defined(POSIX_FADV_SEQUENTIAL)
// access
#if defined(F_OK)
INT_CONSTANT(F_OK),

View File

@ -94,9 +94,47 @@ if (!("localProfileDir" in OS.Constants.Path)) {
}
/**
* Return a shallow clone of the enumerable properties of an object.
* A global constant used as a default refs parameter value when cloning.
*/
let clone = SharedAll.clone;
const noRefs = [];
/**
* Return a shallow clone of the enumerable properties of an object.
*
* Utility used whenever normalizing options requires making (shallow)
* changes to an option object. The copy ensures that we do not modify
* a client-provided object by accident.
*
* 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.
*/
let clone = function clone(object, refs = noRefs) {
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];
},
set: function(value) {
object[key] = value;
}
});
};
for (let k in object) {
if (refs.indexOf(k) < 0) {
result[k] = object[k];
} else {
refer(result, k, object);
}
}
return result;
};
let worker = new PromiseWorker(
"resource://gre/modules/osfile/osfile_async_worker.js", LOG);
@ -329,8 +367,9 @@ File.prototype = {
// 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
if (isTypedArray(buffer) && !("bytes" in options)) {
// Preserve reference to option |outExecutionDuration|, if it is passed.
if (isTypedArray(buffer) && (!options || !("bytes" in options))) {
// Preserve the reference to |outExecutionDuration| option if it is
// passed.
options = clone(options, ["outExecutionDuration"]);
options.bytes = buffer.byteLength;
}
@ -366,8 +405,9 @@ File.prototype = {
// 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
if (isTypedArray(buffer)) {
// Preserve reference to option |outExecutionDuration|, if it is passed.
if (isTypedArray(buffer) && (!options || !("bytes" in options))) {
// Preserve the reference to |outExecutionDuration| option if it is
// passed.
options = clone(options, ["outExecutionDuration"]);
options.bytes = buffer.byteLength;
}
@ -388,14 +428,13 @@ File.prototype = {
* @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.
* @param {JSON} options
* @return {promise}
* @resolves {Uint8Array} An array containing the bytes read.
*/
read: function read(nbytes, options = {}) {
read: function read(nbytes) {
let promise = Scheduler.post("File_prototype_read",
[this._fdmsg,
nbytes, options]);
nbytes]);
return promise.then(
function onSuccess(data) {
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
@ -600,11 +639,6 @@ File.makeDir = function makeDir(path, options) {
* @param {number=} bytes Optionally, an upper bound to the number of bytes
* to read.
* @param {JSON} options Additional options.
* - {boolean} sequential A flag that triggers a population of the page cache
* with data from a file so that subsequent reads from that file would not
* block on disk I/O. If |true| or unspecified, inform the system that the
* contents of the file will be read in order. Otherwise, make no such
* assumption. |true| by default.
*
* @resolves {Uint8Array} A buffer holding the bytes
* read from the file.

View File

@ -272,7 +272,7 @@ if (this.Components) {
});
},
read: function read(path, bytes, options) {
let data = File.read(Type.path.fromMsg(path), bytes, options);
let data = File.read(Type.path.fromMsg(path), bytes);
return new Transfer({buffer: data.buffer, byteOffset: data.byteOffset, byteLength: data.byteLength}, [data.buffer]);
},
exists: function exists(path) {

View File

@ -34,7 +34,6 @@ if (typeof Components != "undefined") {
let EXPORTED_SYMBOLS = [
"LOG",
"clone",
"Config",
"Constants",
"Type",
@ -163,46 +162,6 @@ let LOG = function (...args) {
exports.LOG = LOG;
/**
* Return a shallow clone of the enumerable properties of an object.
*
* Utility used whenever normalizing options requires making (shallow)
* changes to an option object. The copy ensures that we do not modify
* a client-provided object by accident.
*
* 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.
*/
let 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];
},
set: function(value) {
object[key] = value;
}
});
};
for (let k in object) {
if (refs.indexOf(k) < 0) {
result[k] = object[k];
} else {
refer(result, k, object);
}
}
return result;
};
exports.clone = clone;
///////////////////// Abstractions above js-ctypes
/**
@ -1015,7 +974,6 @@ exports.OS = {
Constants: exports.Constants,
Shared: {
LOG: LOG,
clone: clone,
Type: Type,
HollowStructure: HollowStructure,
Error: OSError,
@ -1057,3 +1015,4 @@ if (typeof Components != "undefined") {
this[symbol] = exports[symbol];
}
}

View File

@ -17,7 +17,6 @@ if (typeof Components != "undefined") {
exports.OS = require("resource://gre/modules/osfile/osfile_shared_allthreads.jsm").OS;
let LOG = exports.OS.Shared.LOG.bind(OS.Shared, "Shared front-end");
let clone = exports.OS.Shared.clone;
/**
* Code shared by implementations of File.
@ -45,17 +44,17 @@ AbstractFile.prototype = {
* 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 notclone
* this file. If specified, read |bytes| bytes, or less if the file does not
* contain that many bytes.
* @param {JSON} options
* @return {Uint8Array} An array containing the bytes read.
*/
read: function read(bytes, options = {}) {
options = clone(options);
options.bytes = bytes == null ? this.stat().size : bytes;
let buffer = new Uint8Array(options.bytes);
let size = this.readTo(buffer, options);
if (size == options.bytes) {
read: function read(bytes) {
if (bytes == null) {
bytes = this.stat().size;
}
let buffer = new Uint8Array(bytes);
let size = this.readTo(buffer, {bytes: bytes});
if (size == bytes) {
return buffer;
} else {
return buffer.subarray(0, size);
@ -292,15 +291,14 @@ AbstractFile.normalizeOpenMode = function normalizeOpenMode(mode) {
* @param {string} path The path to the file.
* @param {number=} bytes Optionally, an upper bound to the number of bytes
* to read.
* @param {JSON} options Optionally contains additional options.
*
* @return {Uint8Array} A buffer holding the bytes
* and the number of bytes read from the file.
*/
AbstractFile.read = function read(path, bytes, options = {}) {
AbstractFile.read = function read(path, bytes) {
let file = exports.OS.File.open(path);
try {
return file.read(bytes, options);
return file.read(bytes);
} finally {
file.close();
}

View File

@ -447,14 +447,6 @@
/*buf*/ Types.void_t.out_ptr,
/*nbytes*/Types.size_t);
UnixFile.posix_fadvise =
declareFFI("posix_fadvise", ctypes.default_abi,
/*return*/ Types.int,
/*fd*/ Types.fd,
/*offset*/ Types.off_t,
/*len*/ Types.off_t,
/*advise*/ Types.int);
if (OS.Constants.libc._DARWIN_FEATURE_64_BIT_INODE) {
// Special case for MacOS X 10.5+
// Symbol name "readdir" still exists but is used for a

View File

@ -92,13 +92,6 @@
* @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 ((UnixFile.posix_fadvise &&
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)
);