Make a list of known globals
authorRyan Dahl <ry@tinyclouds.org>
Wed, 15 Sep 2010 06:02:48 +0000 (23:02 -0700)
committerRyan Dahl <ry@tinyclouds.org>
Wed, 15 Sep 2010 06:03:29 +0000 (23:03 -0700)
And fix missing var!

It would be good to get this script running at the end of every test, so we
know that modules aren't leaking either - but it will require a lot
modification of the tests so that they themselves aren't leaking globals.

src/node.js
test/simple/test-global-leak.js [new file with mode: 0644]

index 11b391dab8e6ed0c55bdd801e25ad4677fecfb1d..24e3925e521e90c837dd81e41e6adc7228120685 100644 (file)
@@ -534,8 +534,8 @@ var events = module.requireNative('events');
 // Signal Handlers
 (function() {
   var signalWatchers = {};
-    addListener = process.addListener,
-    removeListener = process.removeListener;
+  var addListener = process.addListener;
+  var removeListener = process.removeListener;
 
   function isSignal (event) {
     return event.slice(0, 3) === 'SIG' && process.hasOwnProperty(event);
diff --git a/test/simple/test-global-leak.js b/test/simple/test-global-leak.js
new file mode 100644 (file)
index 0000000..8406d1e
--- /dev/null
@@ -0,0 +1,32 @@
+var assert = require('assert');
+
+var knownGlobals = [ setTimeout
+                   , setInterval
+                   , clearTimeout
+                   , clearInterval
+                   , console
+                   , Buffer
+                   , process
+                   , global
+                   , __module
+                   , include
+                   , puts
+                   , print
+                   , p
+                   ];
+
+for (var x in global) {
+  var found = false;
+
+  for (var y in knownGlobals) {
+    if (global[x] === knownGlobals[y]) {
+      found = true;
+      break;
+    }
+  }
+
+  if (!found) {
+    console.error("Unknown global: %s", x);
+    assert.ok(false);
+  }
+}