Closed venkateshatgit closed 2 years ago
The console is not part of the JavaScript spec, so it doesn't exist in the interpreter. You can create a console API using this code:
var myCode = 'console.log("Hello world");';
var initFunc = function(interpreter, globalObject) {
// Create 'console' global object.
var pseudoConsole = interpreter.nativeToPseudo({});
interpreter.setProperty(globalObject, 'console', pseudoConsole);
// Define 'console.log' function.
var wrapper = function log(value) {
return console.log(value);
};
interpreter.setProperty(pseudoConsole, 'log',
interpreter.createNativeFunction(wrapper));
};
var myInterpreter = new Interpreter(myCode, initFunc);
myInterpreter.run();
Interpreter gives error for console.log()
console.log(6);
Uncaught ReferenceError: console is not definedI would love to contribute in solving this issue.