|
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 |
|
6 module.metadata = { |
|
7 'stability': 'unstable' |
|
8 }; |
|
9 |
|
10 const privateNS = require('../../core/namespace').ns(); |
|
11 |
|
12 function getOwnerWindow(thing) { |
|
13 try { |
|
14 // check for and return associated window |
|
15 let fn = (privateNS(thing.prototype) || privateNS(thing) || {}).getOwnerWindow; |
|
16 |
|
17 if (fn) |
|
18 return fn.apply(fn, [thing].concat(arguments)); |
|
19 } |
|
20 // stuff like numbers and strings throw errors with namespaces |
|
21 catch(e) {} |
|
22 // default |
|
23 return undefined; |
|
24 } |
|
25 getOwnerWindow.define = function(Type, fn) { |
|
26 privateNS(Type.prototype).getOwnerWindow = fn; |
|
27 } |
|
28 |
|
29 getOwnerWindow.implement = function(instance, fn) { |
|
30 privateNS(instance).getOwnerWindow = fn; |
|
31 } |
|
32 |
|
33 exports.getOwnerWindow = getOwnerWindow; |