michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: module.metadata = { michael@0: "stability": "experimental" michael@0: }; michael@0: michael@0: const { get, format } = require("../console/traceback"); michael@0: const { get: getPref } = require("../preferences/service"); michael@0: const PREFERENCE = "devtools.errorconsole.deprecation_warnings"; michael@0: michael@0: function deprecateUsage(msg) { michael@0: // Print caller stacktrace in order to help figuring out which code michael@0: // does use deprecated thing michael@0: let stack = get().slice(2); michael@0: michael@0: if (getPref(PREFERENCE)) michael@0: console.error("DEPRECATED: " + msg + "\n" + format(stack)); michael@0: } michael@0: exports.deprecateUsage = deprecateUsage; michael@0: michael@0: function deprecateFunction(fun, msg) { michael@0: return function deprecated() { michael@0: deprecateUsage(msg); michael@0: return fun.apply(this, arguments); michael@0: }; michael@0: } michael@0: exports.deprecateFunction = deprecateFunction; michael@0: michael@0: function deprecateEvent(fun, msg, evtTypes) { michael@0: return function deprecateEvent(evtType) { michael@0: if (evtTypes.indexOf(evtType) >= 0) michael@0: deprecateUsage(msg); michael@0: return fun.apply(this, arguments); michael@0: }; michael@0: } michael@0: exports.deprecateEvent = deprecateEvent;