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: 'use strict'; michael@0: michael@0: module.metadata = { michael@0: 'stability': 'unstable' michael@0: }; michael@0: michael@0: const privateNS = require('../../core/namespace').ns(); michael@0: michael@0: function getOwnerWindow(thing) { michael@0: try { michael@0: // check for and return associated window michael@0: let fn = (privateNS(thing.prototype) || privateNS(thing) || {}).getOwnerWindow; michael@0: michael@0: if (fn) michael@0: return fn.apply(fn, [thing].concat(arguments)); michael@0: } michael@0: // stuff like numbers and strings throw errors with namespaces michael@0: catch(e) {} michael@0: // default michael@0: return undefined; michael@0: } michael@0: getOwnerWindow.define = function(Type, fn) { michael@0: privateNS(Type.prototype).getOwnerWindow = fn; michael@0: } michael@0: michael@0: getOwnerWindow.implement = function(instance, fn) { michael@0: privateNS(instance).getOwnerWindow = fn; michael@0: } michael@0: michael@0: exports.getOwnerWindow = getOwnerWindow;