From 1881f5cb39810a7e2eb9ed655fbb187c38d54ff0 Mon Sep 17 00:00:00 2001 From: jdalton Date: Thu, 25 Jun 2015 08:03:38 -0700 Subject: [PATCH] Ensure `_.noConflict` operates on `root` and not `context`. --- lodash.src.js | 4 ++-- test/test.js | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lodash.src.js b/lodash.src.js index 0cd5c13d2..2692c43ec 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -738,7 +738,7 @@ var objToString = objectProto.toString; /** Used to restore the original `_` reference in `_.noConflict`. */ - var oldDash = context._; + var oldDash = root._; /** Used to detect if a method is native. */ var reIsNative = RegExp('^' + @@ -11558,7 +11558,7 @@ * var lodash = _.noConflict(); */ function noConflict() { - context._ = oldDash; + root._ = oldDash; return this; } diff --git a/test/test.js b/test/test.js index 032e5ce39..8f4fd1a16 100644 --- a/test/test.js +++ b/test/test.js @@ -11443,23 +11443,30 @@ QUnit.module('lodash.noConflict'); (function() { - test('should return the `lodash` function', 1, function() { + test('should return the `lodash` function', 2, function() { if (!isModularize) { var oldDash = root._; strictEqual(_.noConflict(), oldDash); + + if (!(isRhino && typeof require == 'function')) { + notStrictEqual(root._, oldDash); + } + else { + skipTest(); + } root._ = oldDash; } else { - skipTest(); + skipTest(2); } }); - test('should work with a `context` of `this`', 2, function() { + test('should work with a `root` of `this`', 2, function() { if (!isModularize && !document && _._object) { var fs = require('fs'), vm = require('vm'), expected = {}, - context = vm.createContext({ '_': expected }), + context = vm.createContext({ '_': expected, 'console': console }), source = fs.readFileSync(filePath); vm.runInContext(source + '\nthis.lodash = this._.noConflict()', context);