File: __get__.js

package info (click to toggle)
node-rewire 6.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 392 kB
  • sloc: javascript: 1,386; makefile: 2
file content (21 lines) | stat: -rw-r--r-- 726 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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");
    }
}

module.exports = __get__;