I posted this on StackOverflow, but I want to parrot the post here. I worked on this issue all weekend and didn’t get anywhere, so I’d like to get a little more exposure on it. Hopefully somebody out there can help. Here’s the link to the original question. And here’s the content:
Moving from Ember 1.5.1 to 1.6.0, I’ve run into an issue with __nextSuper
(which has been changing in the last few versions). You can see the offending code here.
And here’s the relevant Ember code:
function wrap(func, superFunc) {
function superWrapper() {
var ret, sup = this.__nextSuper; // THIS LINE
this.__nextSuper = superFunc;
ret = apply(this, func, arguments);
this.__nextSuper = sup;
return ret;
}
superWrapper.wrappedFunction = func;
superWrapper.wrappedFunction.__ember_arity__ = func.length;
superWrapper.__ember_observes__ = func.__ember_observes__;
superWrapper.__ember_observesBefore__ = func.__ember_observesBefore__;
superWrapper.__ember_listens__ = func.__ember_listens__;
return superWrapper;
};
What happens is, at some point, the superWrapper
function gets called with window
as the this
value. So when I reach the line marked above, this.__nextSuper
comes out to be undefined
. But rather than sup
simply being undefined, it throws the following error:
TypeError: Cannot read property '__nextSuper' of undefined
The thing is, when I pause in the debugger, this
is defined (it’s the window object). And when I paste var ret, sup = this.__nextSuper;
into the console, it works as expected. And, if I go up the stack frame and check the this
value, it’s exactly what I expect. So I have no idea why superWrapper
suddenly has a bad this
value.
Finally, the most interesting part, this only happens in the browser; it works fine in PhantomJS. The changelog didn’t seem to list anything to do with __nextSuper
as a breaking bugfix, but obviously something has changed. How can I solve this issue?