Last active
August 29, 2015 14:25
Revisions
-
lewisje revised this gist
Jul 22, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ function functionize(func, arg) { switch (typeof func) { case 'string': return arg ? new Function(String(arg), func) : new Function(func); case 'function': return func; default: -
lewisje created this gist
Jul 22, 2015 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ // part of a pair of functions intended to isolate code that kills the optimizing compiler // https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#2-unsupported-syntax function functionize(func, arg) { switch (typeof func) { case 'string': return new Function(func, String(arg)); case 'function': return func; default: return function () {return func;}; } } // The first argument to the toCatch callback is the caught error; // if toCatch is passed as a string, this argument must be named `e`. function trial(toTry, toCatch, toFinal) { var try1 = functionize(toTry), catch1 = functionize(toCatch, 'e'), final1 = functionize(toFinal); try {try1();} catch (e) {catch1(e);} finally {final1();} } // This does not directly replace try/catch/finally blocks that // would break or continue from loops or return from the function: // Consider setting a variable indicating success or failure within // each callback and then deciding to break, continue, or return. // This is a reliable way to get a reference to the global object // even in strict mode, without deoptimizing the entire function. var global = function(){return this||(1,eval)('this');}();