addon-sdk/source/lib/sdk/util/deprecate.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/lib/sdk/util/deprecate.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,40 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +"use strict";
     1.9 +
    1.10 +module.metadata = {
    1.11 +  "stability": "experimental"
    1.12 +};
    1.13 +
    1.14 +const { get, format } = require("../console/traceback");
    1.15 +const { get: getPref } = require("../preferences/service");
    1.16 +const PREFERENCE = "devtools.errorconsole.deprecation_warnings";
    1.17 +
    1.18 +function deprecateUsage(msg) {
    1.19 +  // Print caller stacktrace in order to help figuring out which code
    1.20 +  // does use deprecated thing
    1.21 +  let stack = get().slice(2);
    1.22 +
    1.23 +  if (getPref(PREFERENCE)) 
    1.24 +    console.error("DEPRECATED: " + msg + "\n" + format(stack));
    1.25 +}
    1.26 +exports.deprecateUsage = deprecateUsage;
    1.27 +
    1.28 +function deprecateFunction(fun, msg) {
    1.29 +  return function deprecated() {
    1.30 +    deprecateUsage(msg);
    1.31 +    return fun.apply(this, arguments);
    1.32 +  };
    1.33 +}
    1.34 +exports.deprecateFunction = deprecateFunction;
    1.35 +
    1.36 +function deprecateEvent(fun, msg, evtTypes) {
    1.37 +  return function deprecateEvent(evtType) {
    1.38 +  	if (evtTypes.indexOf(evtType) >= 0)
    1.39 +      deprecateUsage(msg);
    1.40 +    return fun.apply(this, arguments);
    1.41 +  };
    1.42 +}
    1.43 +exports.deprecateEvent = deprecateEvent;

mercurial