Bug 827805 - [OS.File] Use Deprecated.jsm to mark deprecation of OS.File.Info.prototype.creationDate. r=yoric

This commit is contained in:
Sunny 2013-08-09 14:10:44 -04:00
Родитель 01608cd4b2
Коммит aaba8eb2da
3 изменённых файлов: 57 добавлений и 1 удалений

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

@ -23,6 +23,7 @@ this.EXPORTED_SYMBOLS = ["OS"];
let SharedAll = {};
Components.utils.import("resource://gre/modules/osfile/osfile_shared_allthreads.jsm", SharedAll);
Components.utils.import("resource://gre/modules/Deprecated.jsm", this);
// Boilerplate, to simplify the transition to require()
let OS = SharedAll.OS;
@ -725,7 +726,14 @@ File.writeAtomic = function writeAtomic(path, buffer, options = {}) {
* @constructor
*/
File.Info = function Info(value) {
return value;
// Note that we can't just do this[k] = value[k] because our
// prototype defines getters for all of these fields.
for (let k in value) {
if (k != "creationDate") {
Object.defineProperty(this, k, {value: value[k]});
}
}
Object.defineProperty(this, "_deprecatedCreationDate", {value: value["creationDate"]});
};
if (OS.Constants.Win) {
File.Info.prototype = Object.create(OS.Shared.Win.AbstractInfo.prototype);
@ -735,6 +743,14 @@ if (OS.Constants.Win) {
throw new Error("I am neither under Windows nor under a Posix system");
}
// Deprecated
Object.defineProperty(File.Info.prototype, "creationDate", {
get: function creationDate() {
Deprecated.warning("Field 'creationDate' is deprecated.", "https://developer.mozilla.org/en-US/docs/JavaScript_OS.File/OS.File.Info#Cross-platform_Attributes");
return this._deprecatedCreationDate;
}
});
File.Info.fromMsg = function fromMsg(value) {
return new File.Info(value);
};

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

@ -0,0 +1,39 @@
"use strict";
const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.import("resource://gre/modules/osfile.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/Task.jsm");
Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js");
function run_test() {
do_test_pending();
run_next_test();
}
/**
* Test to ensure that deprecation warning is issued on use
* of creationDate.
*/
add_task(function test_deprecatedCreationDate () {
let deferred = Promise.defer();
let consoleListener = {
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);
deferred.resolve();
}
}
};
let currentDir = yield OS.File.getCurrentDirectory();
let path = OS.Path.join(currentDir, "test_creationDate.js");
Services.console.registerListener(consoleListener);
(yield OS.File.stat(path)).creationDate;
});
add_task(do_test_finished);

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

@ -7,5 +7,6 @@ tail =
[test_osfile_async.js]
[test_profiledir.js]
[test_logging.js]
[test_creationDate.js]
# bug 845190 - thread pool wasn't shutdown assertions
skip-if = (os == "win" || "linux") && debug