Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can do something like this: <a href="http://jsfiddle.net/g68NP/" rel="nofollow">http://jsfiddle.net/g68NP/</a></p> <p>Problem is that you'll have to add a lot of code to protect every property, every native method, etc. The meat of the code really comes down to using <code>__defineGetter__</code>, whose support is limited. Since you're probably not running this on IE, you should be fine.</p> <p>EDIT: <a href="http://jsfiddle.net/g68NP/1/" rel="nofollow">http://jsfiddle.net/g68NP/1/</a> This code will make all properties read-only. The use of <code>hasOwnProperty()</code> may or may not be desirable.</p> <p>In case JSFiddle goes down:</p> <pre><code>function safeEval(input) { // Remove eval and evalJS from the window: var e = [window.eval, window.evalJS, document.getElementById], a; window.eval = function(){}; window.evalJS = function(){}; document.getElementById = function (id) { var elem = (e[2]).call(document, id); for (var prop in elem) { if (elem.hasOwnProperty(prop)) { elem.__defineGetter__(prop, function () { return (function (val) { return val; }(elem[prop])); }); } } return elem; }; try { /* More sanition needed before being passed to eval */ // Eval the input, stuffed into an annonomous function // so the code to be evalued can not access the stored // eval functions: a = (e[0])("(function(){return " + input + "}())"); } catch(ex){} // Return eval and evalJS to the window: window.eval = e[0]; window.evalJS = e[1]; document.getElementById = e[2]; // Return the eval'd result return a; } </code></pre>
    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. 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