JSFiddle - React, Tailwind, and code Playground

by jongobar

HTML

<pre id="out"></pre>

JavaScript

if(0){//debug list of blocked global props.
    var dbg=quarantinedFunction(null)();
    dbg.sort(function(a,b){
        if(a.toLowerCase()<b.toLowerCase())return -1;
        if(a.toLowerCase()>b.toLowerCase())return 1;
        return 0;
    });
    document.getElementById("out").textContent=dbg.join("\n");
}
else{
    var tests = [
        null,    //note: null trigger debug output that lists the forbidden global properties (extracted from this and self.)
        "return 'string';",
        "return 8*8;",
        "return window;",
        "return console;",
        "return top;",
        "return location;",    //a bug?? typeof(location) returns "undefined" what's going on here?
        "var location; return location;",
        "try{return location.href;}catch(err){return err;}",
        "return typeof(location);",
        "return ['abc','-','xyz'].join('');",
        "return /^http:\\/\\/jsfiddle\.net$/.test('http://jsfiddle.net');",
        "return JSON", 
        "return document;",
        "return document && document.body;",
        "return eval('8*8')+eval('7*7');",
        "return JSON.stringify({a:0,b:1,c:2});",
        "return Date.now()",
        "return Date();",
        "return !!this;",
        "return !!self;",
        "return !!HTMLElement;",
        "return Object.getOwnPropertyNames(this).length.toString();",
    ];
    var results;
    try{
        results = tests.map(function (fnText) {
            return quarantinedFunction(fnText)() || "--";
        }).join("\n");
    }
    catch(err){
        results=err.toString();    
    }
    document.getElementById("out").textContent = results;
}

function quarantinedFunction(fnText) {
    var exceptionKeys = [
        "eval", "Object", //need exceptions for this else error. (ie, 'Exception: redefining eval is deprecated')
    "Number", "String", "Boolean", "RegExp", "JSON", "Date", ];
    var forbiddenKeys = [
        "Fn", "fnText", "forbiddenKeys", "exceptionKeys", "empty", "oForbiddenKeys", 
       ...