diff --git a/test/asset/set.js b/test/asset/set.js index 560615b84..893291aa1 100644 --- a/test/asset/set.js +++ b/test/asset/set.js @@ -21,7 +21,7 @@ /*--------------------------------------------------------------------------*/ /** - * Creates a Set object to optimize linear searches of large arrays. + * Creates a `Set` object. */ function Set() { this.__cache__ = {}; @@ -81,7 +81,7 @@ * Adds `value` to the set. * * @memberOf Set - * @param {*} value The value to add to the set. + * @param {*} value The value to add. */ function add(value) { var cache = this.__cache__, diff --git a/test/asset/weakmap.js b/test/asset/weakmap.js new file mode 100644 index 000000000..01d02be00 --- /dev/null +++ b/test/asset/weakmap.js @@ -0,0 +1,76 @@ +;(function() { + + /** Used to determine if values are of the language type Object */ + var objectTypes = { + 'function': true, + 'object': true + }; + + /** Used as the `WeakMap#toString` return value */ + var nativeString = String(Object.prototype.toString).replace(/toString/g, 'WeakMap'); + + /** Used as a reference to the global object */ + var root = (objectTypes[typeof window] && window) || this; + + /** Detect free variable `global` from Node.js or Browserified code and use it as `root` */ + var freeGlobal = objectTypes[typeof global] && global; + if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) { + root = freeGlobal; + } + + /*--------------------------------------------------------------------------*/ + + /** + * Creates a `WeakMap` object. + */ + function WeakMap() { + // no-op + } + + /*--------------------------------------------------------------------------*/ + + /** + * Gets the value associated with the given key. + * + * @memberOf WeakMap + * @param {Object} key The key object. + * @returns {*} Returns the associated value, else `undefined`. + */ + function get(key) { + return key.__weakmap__; + } + + /** + * Sets a value for the given key. + * + * @memberOf WeakMap + * @param {Object} key The key object. + * @param {*} value The value to set. + */ + function set(key, value) { + key.__weakmap__ = value; + return this; + } + + /** + * Produces the `toString` result of `WeakMap`. + * + * @static + * @memberOf WeakMap + * @returns {string} Returns the string result. + */ + function toString() { + return nativeString; + } + + /*--------------------------------------------------------------------------*/ + + WeakMap.toString = toString; + WeakMap.prototype.get = get; + WeakMap.prototype.set = set; + + // expose `WeakMap` + if (!root.WeakMap) { + root.WeakMap = WeakMap; + } +}.call(this)); diff --git a/test/index.html b/test/index.html index 8e80e4e46..f9a90d713 100644 --- a/test/index.html +++ b/test/index.html @@ -26,6 +26,7 @@ +
@@ -154,6 +155,9 @@ return Float64Array; }()); } + setProperty(window, '_Set', window.Set); + setProperty(window, 'Set', noop); + setProperty(window, '_WeakMap', window.WeakMap); setProperty(window, 'WeakMap', noop); @@ -238,6 +242,11 @@ } setProperty(window, '_ArrayBuffer', undefined); + if (window._Set) { + Set = _Set; + } + setProperty(window, '_Set', undefined); + if (window._WeakMap) { WeakMap = _WeakMap; } @@ -274,6 +283,7 @@ // store Lo-Dash to test for bad extensions/shims if (!ui.isModularize) { var lodashBizarro = window._; + lodashBizarro.support.funcNames = !lodashBizarro.support.funcNames; window._ = undefined; removeBizarroMethods(); } diff --git a/test/test.js b/test/test.js index b57950402..92c58a276 100644 --- a/test/test.js +++ b/test/test.js @@ -38,6 +38,7 @@ noop = function() {}, params = root.arguments, push = arrayProto.push, + Set = root.Set, slice = arrayProto.slice, system = root.system, toString = objectProto.toString, @@ -339,8 +340,9 @@ function createToString(funcName) { return _.constant(nativeString.replace(reToString, funcName)); } - // load ES6 Set shim + // load ES6 Set and WeakMap shims require('./asset/set'); + require('./asset/weakmap'); // expose `baseEach` for better code coverage if (isModularize && !isNpm) { @@ -443,6 +445,12 @@ }; }())); + if (Set) { + setProperty(root, 'Set', _.noop); + } + if (WeakMap) { + setProperty(root, 'WeakMap', _.noop); + } // fake `WinRTError` setProperty(root, 'WinRTError', Error); @@ -485,6 +493,16 @@ } else { delete root.ArrayBuffer; } + if (Set) { + setProperty(root, 'Set', Set); + } else { + delete root.Set; + } + if (WeakMap) { + setProperty(root, 'WeakMap', WeakMap); + } else { + delete root.WeakMap; + } delete root.WinRTError; delete root.window; delete funcProto._method;