1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/addon-sdk/source/lib/sdk/private-browsing/window/utils.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,33 @@ 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 +'use strict'; 1.8 + 1.9 +module.metadata = { 1.10 + 'stability': 'unstable' 1.11 +}; 1.12 + 1.13 +const privateNS = require('../../core/namespace').ns(); 1.14 + 1.15 +function getOwnerWindow(thing) { 1.16 + try { 1.17 + // check for and return associated window 1.18 + let fn = (privateNS(thing.prototype) || privateNS(thing) || {}).getOwnerWindow; 1.19 + 1.20 + if (fn) 1.21 + return fn.apply(fn, [thing].concat(arguments)); 1.22 + } 1.23 + // stuff like numbers and strings throw errors with namespaces 1.24 + catch(e) {} 1.25 + // default 1.26 + return undefined; 1.27 +} 1.28 +getOwnerWindow.define = function(Type, fn) { 1.29 + privateNS(Type.prototype).getOwnerWindow = fn; 1.30 +} 1.31 + 1.32 +getOwnerWindow.implement = function(instance, fn) { 1.33 + privateNS(instance).getOwnerWindow = fn; 1.34 +} 1.35 + 1.36 +exports.getOwnerWindow = getOwnerWindow;