Contextify shim inneffective #456

JoshuaGross opened this Issue Jun 11, 2012 · 4 comments


None yet
5 participants

It appears that the Contextify Shim is broken.

I'm using jsdom through Zombie 1.3.1 on Mac OS X Lion and Node 0.6.11. Normally Contextify has issues compiling but I've resolved that; jsdom works but /not/ the Contextify shim.

In lib/jsdom/browser/index.js I am forcing usage of the shim:

 11 try {
 12   Contextify = require('contextify-blah');
 13 } catch (e) {

I am using this test code:

 35 describe('Register and access restricted page', function(){
 36   var browser = new Browser();
 37   it('/', function(done){ 
 38     browser.visit('/', function (err) {
 39       browser.fill('#registerForm .email', '')
 40       .fill('#registerForm .password', 'test')
 41       .fill('#registerForm .name', 'Test')
 42       .pressButton('#registerForm .register', function (value) {
 43         expect(browser.html()).to.match(/Your account was created successfully/);
 44         done();
 45       });
 46     });
 47   });
 48 });

And this is the error I get (again, totally fine when not using the shim):

  1) Register and access restricted page /:
     TypeError: Cannot call method 'dispatchEvent' of undefined
      at Object._dispatchSubmitEvent (/Users/joshuagross/Sites/projects/Spandex/node_modules/zombie/lib/zombie/forms.js:111:50)
      at (/Users/joshuagross/Sites/projects/Spandex/node_modules/zombie/lib/zombie/forms.js:136:23)
      at Object.dispatchEvent (/Users/joshuagross/Sites/projects/Spandex/node_modules/zombie/node_modules/jsdom/lib/jsdom/level2/html.js:480:47)
      at /Users/joshuagross/Sites/projects/Spandex/node_modules/zombie/lib/zombie/eventloop.js:135:40
      at Object._evaluate (/Users/joshuagross/Sites/projects/Spandex/node_modules/zombie/lib/zombie/windows.js:271:23)
      at /Users/joshuagross/Sites/projects/Spandex/node_modules/zombie/lib/zombie/eventloop.js:134:14
      at EventLoop.perform (/Users/joshuagross/Sites/projects/Spandex/node_modules/zombie/lib/zombie/eventloop.js:120:5)
      at EventLoop.dispatch (/Users/joshuagross/Sites/projects/Spandex/node_modules/zombie/lib/zombie/eventloop.js:131:10)
      at Browser.dispatchEvent (/Users/joshuagross/Sites/projects/Spandex/node_modules/zombie/lib/zombie/browser.js:207:28)
      at (/Users/joshuagross/Sites/projects/Spandex/node_modules/zombie/lib/zombie/browser.js:201:10)
      at Browser.pressButton (/Users/joshuagross/Sites/projects/Spandex/node_modules/zombie/lib/zombie/browser.js:681:17)
      at /Users/joshuagross/Sites/projects/Spandex/test/authtest.js:42:8
      at /Users/joshuagross/Sites/projects/Spandex/node_modules/zombie/lib/zombie/browser.js:327:16
      at /Users/joshuagross/Sites/projects/Spandex/node_modules/zombie/lib/zombie/browser.js:188:16
      at Array.0 (/Users/joshuagross/Sites/projects/Spandex/node_modules/zombie/lib/zombie/eventloop.js:177:18)
      at EventEmitter._tickCallback (node.js:192:40)

Later on in browser/index.js I am checking to see that Contextify does what it should:

303   var window = new DOMWindow(options);
304   console.log(window)
306   Contextify(window);
308   // We need to set up self references using Contextify's getGlobal() so that
309   // the global object identity is correct (window === this).
310   // See Contextify README for more info.
311   var global = window.getGlobal();
312   console.log(global)

The first console.log call reports a big fat object, the second one reports a blank dictionary {}.

Am I missing something? It appears that the shim is broken, yes?

I was running into this same issue as others have. I found a way around it, though might not be the correct way. I'm still pretty new to Node in general.

I simply npm install contextify in node_modules/zombie/node_modules/jsdom/ which skips the shim. I verified this by adding in some basic console.log() in node_modules/zombie/node_modules/jsdom/lib/jsdom/browser/index.js telling me when Contextify is being loaded or being shimmed.


@masteinhauser - yes, doing that certainly works (for certain environments). I think, though, that there are certain architectures or environments that contextify will not run on, which is what the shim is for. I'm just commenting that, at present, the shim doesn't seem to be doing its job if we have to manually install contextify for jsdom to work. The shim should either be removed, with documentation to describe how to get contextify working, or the shim should be fixed.

The shim doesn't work because the call to vm.runInContext('this', context) at will always return {}. See

Related to #458 and #436

tricknotes added a commit to tricknotes/mocha-ci-driver that referenced this issue Oct 14, 2012

Downgrade zombie version to 1.3.1
'mocha-ci-driver' doesn't work in zombie 1.4.1
Because of the following issues.
- tmpvar/jsdom#456
- assaf/zombie#406

When these issue is fixed, I will upgrade zombie version.

@domenic domenic closed this in e87cb1c Feb 13, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment