cujojs / wire

A light, fast, flexible Javascript IOC container
Other
862 stars 71 forks source link

WireJS cannot run under PhantomJS! #138

Closed ouadi closed 10 years ago

ouadi commented 10 years ago

Dears,

PhantomJS doesn't implement 'Function.prototype.bind' yet. As such, WireJS fails to load under this headless browser (see http://stackoverflow.com/questions/19451808/running-a-requirejs-wirejs-app-using-phantomjs).

I have already mentioned to PhantomJS people this limitation (https://groups.google.com/forum/#!topic/phantomjs/xlGHp3Ycme4).

While waiting an outcome from them, is there a chance to put in place a workaround?

Cheers

briancavalier commented 10 years ago

Nice find, @ouadi. Have you tried using cujoJS poly to polyfill the ES5 env in phantomJS? I'm betting that would work. I agree that it'd sure be nice if phantom implemented F.p.bind in the near future :)

Let me know if poly works for you.

unscriptable commented 10 years ago

I suspect poly won't fix this in PhantomJS (but haven't tried it). I suspect that PhantomJS supports Function.prototype.bind, but doesn't support Function.prototype.call.bind. poly/function only checks for existence of Function.prototype.bind since in true js environments, Function.prototype.call is of type Function.

briancavalier commented 10 years ago

Ack, that's true. If call's prototype is not Function.prototype, then Function.prototype.call.bind wouldn't exist even if Function.prototype.bind does. However (Luckily???), it looks like F.p.bind simply isn't implemented:

phantomjs> Function.prototype.bind
undefined

I'll make some time today to try poly to see if it helps.

ouadi commented 10 years ago

Dears,

Sorry for the delay.

The CujoJS/PolyJS has solved my issue. Now, PhantomJS is happy with WireJS thanks to CujoJS/PolyJS. Well, thanks to you guys.

I will update the Stackoverflow and PhantomJS posts.

Cheers.

unscriptable commented 10 years ago

Hey @ouadi, I'll update the SO post. I was meaning to anyways. Thanks for trying poly.js! :) -- John

briancavalier commented 10 years ago

Ok, I did a quick test of using poly (via curl) to polyfill Function.prototype.bind and check to make sure that Function.prototype.call.bind works in the way that wire.js expects. That all seemed to work.

Here's a gist of my test. Please have a look and let me know if it looks like I got it right :)

briancavalier commented 10 years ago

Haha, looks like we all converged on the solution at the same time :) Thanks @ouadi!

ouadi commented 10 years ago

Yes, indeed. And you cannot image what a pain you have took away from me. Thank you to you Brian.

On Tue, Oct 22, 2013 at 3:05 PM, Brian Cavalier notifications@github.comwrote:

Haha, looks like we all converged on the solution at the same time :) Thanks @ouadi https://github.com/ouadi!

— Reply to this email directly or view it on GitHubhttps://github.com/cujojs/wire/issues/138#issuecomment-26811098 .