When adding prototype
functions to the preloaded javascript, the content of the function can end up nuking the whole app.
How to reproduce:
- Add any amount of elements to the app;
- Add the following code to the Preloaded Javascript tab:
Object.prototype.nuke = function() {
const keys = Object.keys(this);
for (let i = 0; i < keys.length; i++) {
this[keys[i]]; // this nukes it
}
}
- Release a new version;
- Open the new version and see that every element is gone;
- Press the edit button on the app page and see that there are no elements to be edited, making the app completely blank.
About the code, what I noticed after some trial and error is that, when accessing the this
element via a keyed array (keys[i]
) is when the bug happens.
Another way to reproduce it is by doing the following:
function nuke() {
const keys = Object.keys(this);
for (let i = 0; i < keys.length; i++) {
this[keys[i]];
}
}
Object.prototype.nuke = nuke;
Workaround
Instead of using a prototyped function, simply make a function and give it, as an argument, what would be the this
element.
function wontNuke(obj) {
const keys = Object.keys(obj);
for (let i = 0; i < keys.length; i++) {
obj[keys[i]]; // Won't nuke
}
}
Which leads me to believe that there might be something going wrong with how prototyped functions are getting parsed or how they are being interpreted.
Video demonstration: Bug demonstration