Skip to content

Instantly share code, notes, and snippets.

@halemmerich
Last active November 1, 2022 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halemmerich/a2e90fc2ea1aefd2bed8a20d3fb3bdf0 to your computer and use it in GitHub Desktop.
Save halemmerich/a2e90fc2ea1aefd2bed8a20d3fb3bdf0 to your computer and use it in GitHub Desktop.
Trying to autowrap function in Bangle.js
let app = "iconlaunch.app.js";
function wrap(name, levels, filter, parent){
if (levels == 0) return;
print("Level", levels, name);
let o = parent[name];
Object.keys(o).forEach((key)=>{
if (key == "wrap" || filter.includes(key)) return;
print("is array", Object.keys(o[key]));
if(typeof o[key] === "function" && Object.keys(o[key]).length == 0){
print("Wrapping", name + "." + key);
o[key] = (orig => (a,b,c,d,e,f,g,h,i,j,k,l) => {
print("called" , name + "." + key);
let time = Date.now();
if (orig.___accTime == undefined) orig.___accTime = 0;
let result = orig(a,b,c,d,e,f,g,h,i,j,k,l);
let diff = Date.now() - time;
orig.___accTime += diff;
print("finished", name + "." + key, "t:", diff.toFixed(0), "acc:", orig.___accTime.toFixed(0));
return result;
})(o[key]);
} else {
print("Descent", key);
wrap(key, levels - 1, filter, o);
}
});
}
wrap("Bangle",2,["Object"], global);
wrap("E",1,["Object"], global);
eval(require("Storage").read(app));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment