Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This could be a possible solution:</p> <ul> <li>wrap all the foreign code into a class</li> <li>make all the undeclared identifiers members of that class</li> <li>before invoking the messy code, make a copy of the built-in classes and name them differently <br/> (is this possible??).</li> </ul> <p>I think this should solve all the problems.</p> <p>With my suggestion, your sample</p> <pre><code>var badA = "hahaha"; this.badB = "hehehe"; badC = "hohoho"; String.prototype.star = function(){ return '***' + this + '***' } var somethingUseful = { doStuff: function () { alert((badA + badB + badC).star()); } } </code></pre> <p>should get like this</p> <pre><code>// Identifies the added properties to prototypes (ie String and Function) // for later filtering if you need a for-in loop. var stringAddons = []; var functionAddons = [] var _string = new String(); var _function = function() {}; for (var property in _string) { if (!_string.hasOwnProperty(property)) { stringAddons.push(property); }} for (var property in _function) { if (!_function.hasOwnProperty(property)) { functionAddons.push(property); }} // Wraps the undeclared identifiers var global = function() { this.badA = "hahaha"; this.badB = "hehehe"; this.badC = "hohoho"; String.prototype.star = function(){ return '***' + this + '***' } this.somethingUseful = { doStuff: function () { alert((global.badA + global.badB + global.badC).star()); } } } var global = new Global(); global.somethingUseful.doStuff(); </code></pre> <p>The tricky part is making ALL the undeclared identifiers <em>global</em> properties. Maybe a good regex script could make it. Im not that good with regex :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload