diff --git a/lib/weakmap.js b/lib/weakmap.js index ed2ddd9..efceb8b 100644 --- a/lib/weakmap.js +++ b/lib/weakmap.js @@ -30,6 +30,7 @@ void function(global, undefined_, undefined){ var getProps = Object.getOwnPropertyNames, + cachedWindowNames = typeof window === 'object' ? Object.getOwnPropertyNames(window) : [], defProp = Object.defineProperty, toSource = Function.prototype.toString, create = Object.create, @@ -87,7 +88,16 @@ void function(global, undefined_, undefined){ // common per-object storage area made visible by patching getOwnPropertyNames' define(Object, namedFunction('getOwnPropertyNames', function getOwnPropertyNames(obj){ - var props = getProps(obj); + var coercedObj = Object(obj), props; + if (coercedObj.toString() === '[object Window]') { + try { + props = getProps(obj); + } catch (e) { + props = cachedWindowNames; + } + } else { + props = getProps(obj); + } if (hasOwn.call(obj, globalID)) props.splice(props.indexOf(globalID), 1); return props;