From d3cbd02b3d9de6cbfb518c31f9c70472508912c3 Mon Sep 17 00:00:00 2001 From: Rens Baardman Date: Tue, 11 Jun 2019 14:11:16 +0200 Subject: Change line endings from carriage returns to line feeds --- LICENSE | 36 ++++++------ lib/__get__.js | 40 ++++++------- lib/detectStrictMode.js | 56 +++++++++--------- test/getImportGlobalsSrc.test.js | 122 +++++++++++++++++++-------------------- 4 files changed, 127 insertions(+), 127 deletions(-) diff --git a/LICENSE b/LICENSE index 09d798f..99b4d47 100644 --- a/LICENSE +++ b/LICENSE @@ -1,18 +1,18 @@ -Copyright (c) 2012 Johannes Ewald - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +Copyright (c) 2012 Johannes Ewald + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/lib/__get__.js b/lib/__get__.js index 74e652f..cb6fe68 100644 --- a/lib/__get__.js +++ b/lib/__get__.js @@ -1,21 +1,21 @@ -/** - * This function will be stringified and then injected into every rewired module. - * Then you can leak private variables by calling myModule.__get__("myPrivateVar"); - * - * All variables within this function are namespaced in the arguments array because every - * var declaration could possibly clash with a variable in the module scope. - * - * @param {!String} name name of the variable to retrieve - * @throws {TypeError} - * @return {*} - */ -function __get__() { - arguments.varName = arguments[0]; - if (arguments.varName && typeof arguments.varName === "string") { - return eval(arguments.varName); - } else { - throw new TypeError("__get__ expects a non-empty string"); - } -} - +/** + * This function will be stringified and then injected into every rewired module. + * Then you can leak private variables by calling myModule.__get__("myPrivateVar"); + * + * All variables within this function are namespaced in the arguments array because every + * var declaration could possibly clash with a variable in the module scope. + * + * @param {!String} name name of the variable to retrieve + * @throws {TypeError} + * @return {*} + */ +function __get__() { + arguments.varName = arguments[0]; + if (arguments.varName && typeof arguments.varName === "string") { + return eval(arguments.varName); + } else { + throw new TypeError("__get__ expects a non-empty string"); + } +} + module.exports = __get__; \ No newline at end of file diff --git a/lib/detectStrictMode.js b/lib/detectStrictMode.js index 57dc14d..30f59fd 100644 --- a/lib/detectStrictMode.js +++ b/lib/detectStrictMode.js @@ -1,28 +1,28 @@ -var multiLineComment = /^\s*\/\*.*?\*\//; -var singleLineComment = /^\s*\/\/.*?[\r\n]/; -var strictMode = /^\s*(?:"use strict"|'use strict')[ \t]*(?:[\r\n]|;)/; - -/** - * Returns true if the source code is intended to run in strict mode. Does not detect - * "use strict" if it occurs in a nested function. - * - * @param {String} src - * @return {Boolean} - */ -function detectStrictMode(src) { - var singleLine; - var multiLine; - - while ((singleLine = singleLineComment.test(src)) || (multiLine = multiLineComment.test(src))) { - if (singleLine) { - src = src.replace(singleLineComment, ""); - } - if (multiLine) { - src = src.replace(multiLineComment, ""); - } - } - - return strictMode.test(src); -} - -module.exports = detectStrictMode; +var multiLineComment = /^\s*\/\*.*?\*\//; +var singleLineComment = /^\s*\/\/.*?[\r\n]/; +var strictMode = /^\s*(?:"use strict"|'use strict')[ \t]*(?:[\r\n]|;)/; + +/** + * Returns true if the source code is intended to run in strict mode. Does not detect + * "use strict" if it occurs in a nested function. + * + * @param {String} src + * @return {Boolean} + */ +function detectStrictMode(src) { + var singleLine; + var multiLine; + + while ((singleLine = singleLineComment.test(src)) || (multiLine = multiLineComment.test(src))) { + if (singleLine) { + src = src.replace(singleLineComment, ""); + } + if (multiLine) { + src = src.replace(multiLineComment, ""); + } + } + + return strictMode.test(src); +} + +module.exports = detectStrictMode; diff --git a/test/getImportGlobalsSrc.test.js b/test/getImportGlobalsSrc.test.js index 0c40e5a..b85736c 100644 --- a/test/getImportGlobalsSrc.test.js +++ b/test/getImportGlobalsSrc.test.js @@ -1,61 +1,61 @@ -var expect = require("expect.js"), - vm = require("vm"), - getImportGlobalsSrc = require("../lib/getImportGlobalsSrc.js"); - -describe("getImportGlobalsSrc", function () { - it("should declare all globals with a var", function () { - var context = { - global: global - }, - expectedGlobals, - src, - actualGlobals; - - // Temporarily set module-internal variables on the global scope to check if getImportGlobalsSrc() - // ignores them properly - global.module = module; - global.exports = exports; - global.require = require; - - // Also make sure it ignores invalid variable names - global['a-b'] = true; - - src = getImportGlobalsSrc(); - - delete global.module; - delete global.exports; - delete global.require; - delete global['__core-js_shared__']; - delete global['a-b']; - - expectedGlobals = Object.keys(global); - - vm.runInNewContext(src, context); - actualGlobals = Object.keys(context); - actualGlobals.sort(); - expectedGlobals.sort(); - expect(actualGlobals).to.eql(expectedGlobals); - expect(actualGlobals.length).to.be.above(1); - }); - it("should ignore the given variables", function () { - var context = { - global: global - }, - ignore = ["console", "setTimeout"], - src, - actualGlobals, - expectedGlobals = Object.keys(global); - - // getImportGlobalsSrc modifies the ignore array, so let's create a copy - src = getImportGlobalsSrc(ignore.slice(0)); - expectedGlobals = expectedGlobals.filter(function filterIgnoredVars(value) { - return ignore.indexOf(value) === -1; - }); - vm.runInNewContext(src, context); - actualGlobals = Object.keys(context); - actualGlobals.sort(); - expectedGlobals.sort(); - expect(actualGlobals).to.eql(expectedGlobals); - expect(actualGlobals.length).to.be.above(1); - }); -}); +var expect = require("expect.js"), + vm = require("vm"), + getImportGlobalsSrc = require("../lib/getImportGlobalsSrc.js"); + +describe("getImportGlobalsSrc", function () { + it("should declare all globals with a var", function () { + var context = { + global: global + }, + expectedGlobals, + src, + actualGlobals; + + // Temporarily set module-internal variables on the global scope to check if getImportGlobalsSrc() + // ignores them properly + global.module = module; + global.exports = exports; + global.require = require; + + // Also make sure it ignores invalid variable names + global['a-b'] = true; + + src = getImportGlobalsSrc(); + + delete global.module; + delete global.exports; + delete global.require; + delete global['__core-js_shared__']; + delete global['a-b']; + + expectedGlobals = Object.keys(global); + + vm.runInNewContext(src, context); + actualGlobals = Object.keys(context); + actualGlobals.sort(); + expectedGlobals.sort(); + expect(actualGlobals).to.eql(expectedGlobals); + expect(actualGlobals.length).to.be.above(1); + }); + it("should ignore the given variables", function () { + var context = { + global: global + }, + ignore = ["console", "setTimeout"], + src, + actualGlobals, + expectedGlobals = Object.keys(global); + + // getImportGlobalsSrc modifies the ignore array, so let's create a copy + src = getImportGlobalsSrc(ignore.slice(0)); + expectedGlobals = expectedGlobals.filter(function filterIgnoredVars(value) { + return ignore.indexOf(value) === -1; + }); + vm.runInNewContext(src, context); + actualGlobals = Object.keys(context); + actualGlobals.sort(); + expectedGlobals.sort(); + expect(actualGlobals).to.eql(expectedGlobals); + expect(actualGlobals.length).to.be.above(1); + }); +}); -- cgit v1.2.3