deprecate.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. "use strict";
  5. module.metadata = {
  6. "stability": "experimental"
  7. };
  8. const { get, format } = require("../console/traceback");
  9. const { get: getPref } = require("../preferences/service");
  10. const PREFERENCE = "devtools.errorconsole.deprecation_warnings";
  11. function deprecateUsage(msg) {
  12. // Print caller stacktrace in order to help figuring out which code
  13. // does use deprecated thing
  14. let stack = get().slice(2);
  15. if (getPref(PREFERENCE))
  16. console.error("DEPRECATED: " + msg + "\n" + format(stack));
  17. }
  18. exports.deprecateUsage = deprecateUsage;
  19. function deprecateFunction(fun, msg) {
  20. return function deprecated() {
  21. deprecateUsage(msg);
  22. return fun.apply(this, arguments);
  23. };
  24. }
  25. exports.deprecateFunction = deprecateFunction;
  26. function deprecateEvent(fun, msg, evtTypes) {
  27. return function deprecateEvent(evtType) {
  28. if (evtTypes.indexOf(evtType) >= 0)
  29. deprecateUsage(msg);
  30. return fun.apply(this, arguments);
  31. };
  32. }
  33. exports.deprecateEvent = deprecateEvent;