JSFiddle - React, Tailwind, and code Playground
HTML
<pre>LOOK IN FIREFOX, FOOL!
https://gist.github.com/jeremybanks/8b3735e482519cf23652
Sytnax error: NOT PRODDUCE
unterminated string: yup!
illegal character: yup!
JavaScript
window.ExternalInterface = { call: function(functionVal) {
var args = [].slice.call(arguments, 1);
var src = functionVal + "(" + args.map(function(arg) {
return "\"" + arg.replace(/\\/g, "\\\\") + "\"";
}).join(", ") + ")";
return eval(src);
} };
window.noop = function(){};
function expectErrorFromCall(argument, errorString) {
try {
ExternalInterface.call("noop", argument);
console.error("FAIL No error triggered with", argument, "expected", errorString);
} catch (error) {
if (String(error) === errorString) {
console.error("FAIL Triggered", String(error), "expected", argument);
} else {
console.log("++++ Correctly triggered", String(error), "with", argument);
}
}
}
expectErrorFromCall("\\", "some kind of syntax error");
expectErrorFromCall("\\\"' , \\\"", "SyntaxError: unterminated string literal");
expectErrorFromCall("\"\\\"\\\"\"" , "SyntaxError: illegal character");