Hi!
I have found out this.callSuper() throws an uncontrolled exception if the base class does not implement the method.
While I think it makes sense that this call throws some exception if the base class does not implement the method, when coming to modules, well, the module implementer may be does not know if the base class the module will be included in will implement that method.
Therefore, I have modified core.js this way:
JS.Method.keyword('callSuper', function (method, env, receiver, args)
{
var methods = env.lookup(method.name),
stackIndex = methods.length - 1,
params = JS.array(args);
return function ()
{
var i = arguments.length;
while (i--) params[i] = arguments[i];
if (stackIndex==0)
return null;
stackIndex -= 1;
var returnValue = methods[stackIndex].apply(receiver, params);
stackIndex += 1;
return returnValue;
};
});
This way, if someone attempts to use this.callSuper() when there is no function upwards, it just returns null and that’s it.
Anyway, the error thrown was cryptic, since it would try to call methods[-1].apply(), and the array would return undefined, thus crashing.
Cheers,
/j
Hi!
I have found out this.callSuper() throws an uncontrolled exception if the base class does not implement the method.
While I think it makes sense that this call throws some exception if the base class does not implement the method, when coming to modules, well, the module implementer may be does not know if the base class the module will be included in will implement that method.
Nevertheless, I think core.js should not throw an Index out of bounds exception, but rather a "no parent method to call" exception.