manuel / wat-js

Concurrency and Metaprogramming for JS
MIT License
259 stars 10 forks source link

Window.setTimeout JSFun apply method causes an Internet Explorer irreversible error #10

Open garata opened 10 years ago

garata commented 10 years ago

While executing "sleeping" demo on IE an error occurs. In fact, when using setTimeout as function reference within the "JSFun.wat_combine" method the "apply(null, list_to_array(o))" is not callable that way.

My purposed solution was to do the following, but I'd like to ear wat-js author opinion. Simply put I'm relying on my own function called "js_fn_apply" which is then called from "wat_combine" JSFun method.

function js_fn_apply(fn, ctx, args) { if (fn === setTimeout) { return setTimeout(args[0], args[1] || 250); } return fn.apply(ctx, args); }

JSFun.prototype.wat_combine = function(e, k, f, o) { return js_fn_apply(this.jsfun, null, list_to_array(o)); };

I'm not yet certain this is the best solution for the IE issue, but it solve the problematic instruction call and let the "sleeping.html" flow. (though, just to be completely honest about my IE experimentation, I should add that I've included these polyfills: "Array.prototype.indexOf", "Array.prototype.map" and "Object.create").