Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/rewire.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJohannes <mail@johannesewald.de>2012-06-03 23:01:29 +0400
committerJohannes <mail@johannesewald.de>2012-06-03 23:01:29 +0400
commitd4eea33555f4e67be674c046ff1d1a9a460af94a (patch)
tree60672c8764687cd532f219dbb08e8c6d6f239548 /lib
parent07496ad0283cf5cc2184ecdf57b7d80cdc8348eb (diff)
changed injection behaviour
Diffstat (limited to 'lib')
-rw-r--r--lib/getInjectionSrc.js28
-rw-r--r--lib/getMonkeyPatchSrc.js33
-rw-r--r--lib/trick.js4
3 files changed, 30 insertions, 35 deletions
diff --git a/lib/getInjectionSrc.js b/lib/getInjectionSrc.js
new file mode 100644
index 0000000..67c15ec
--- /dev/null
+++ b/lib/getInjectionSrc.js
@@ -0,0 +1,28 @@
+"use strict"; // run code in ES5 strict mode
+
+var toSrc = require("toSrc");
+
+function getMonkeyPatchSrc(obj) {
+ function walkObj(obj, level) {
+ var key,
+ value,
+ src = "";
+
+ for (key in obj) {
+ if (obj.hasOwnProperty(key)) {
+ value = obj[key];
+ if (level === 0) {
+ src += "var "; // on the top level, we need a var statement to override variables
+ }
+ src += key + "=" + toSrc(value, 9999) + ";";
+ }
+ }
+
+
+ return src;
+ }
+
+ return walkObj(obj, 0);
+}
+
+module.exports = getMonkeyPatchSrc; \ No newline at end of file
diff --git a/lib/getMonkeyPatchSrc.js b/lib/getMonkeyPatchSrc.js
deleted file mode 100644
index 408b6ee..0000000
--- a/lib/getMonkeyPatchSrc.js
+++ /dev/null
@@ -1,33 +0,0 @@
-"use strict"; // run code in ES5 strict mode
-
-var toSrc = require("toSrc");
-
-function getMonkeyPatchSrc(obj) {
- function walkObj(obj, level) {
- var key,
- value,
- src = "";
-
- for (key in obj) {
- if (obj.hasOwnProperty(key)) {
- value = obj[key];
- if (typeof value === "object" && Array.isArray(value) === false) {
- src += key + ".";
- src += walkObj(value, level + 1);
- } else {
- if (level === 0) {
- src += "var "; // in the top level, we need a var statement to override variables
- }
- src += key + "=" + toSrc(value, 9999) + ";";
- }
- }
- }
-
-
- return src;
- }
-
- return walkObj(obj, 0);
-}
-
-module.exports = getMonkeyPatchSrc; \ No newline at end of file
diff --git a/lib/trick.js b/lib/trick.js
index 36644be..89cbe32 100644
--- a/lib/trick.js
+++ b/lib/trick.js
@@ -4,7 +4,7 @@ var Module = require("module"),
nodeWrapper0 = Module.wrapper[0], // caching original wrapper
nodeWrapper1 = Module.wrapper[1],
getLeakingSrc = require("./getLeakingSrc.js"),
- getMonkeyPatchSrc = require("./getMonkeyPatchSrc.js");
+ getInjectionSrc = require("./getInjectionSrc.js");
function restoreOriginalWrappers() {
Module.wrapper[0] = nodeWrapper0;
@@ -37,7 +37,7 @@ function trick(parentModule, filename, mocks, injections, leaks, cache) {
// Prepare module for injection
if (typeof injections === "object") {
- Module.wrapper[0] = nodeWrapper0 + getMonkeyPatchSrc(injections);
+ Module.wrapper[0] = nodeWrapper0 + getInjectionSrc(injections);
} else if (typeof injections === "string") {
Module.wrapper[0] = nodeWrapper0 + injections;
}