Comparing version 1.4.3 to 1.4.4
@@ -16,3 +16,3 @@ "use strict"; | ||
var version = "1.4.3"; | ||
var version = "1.4.4"; | ||
@@ -396,2 +396,4 @@ function defineFunctionName(func, name) { | ||
_proto2.evaluateNode = function evaluateNode(node, source) { | ||
var _this = this; | ||
if (source === void 0) { | ||
@@ -404,14 +406,31 @@ source = ""; | ||
this.sourceList.push(source); | ||
this.isRunning = true; | ||
var bodyClosure = this.createClosure(node); //reset timeout | ||
this.isRunning = true; //reset timeout | ||
this.execStartTime = Date.now(); | ||
this.execEndTime = this.execStartTime; // add declares to data | ||
this.execEndTime = this.execStartTime; // reset | ||
this.addDeclarationsToScope(this.collectDeclVars, this.collectDeclFuncs, this.getCurrentScope()); // reset | ||
this.collectDeclVars = Object.create(null); | ||
this.collectDeclFuncs = Object.create(null); // start run | ||
this.collectDeclFuncs = Object.create(null); | ||
var currentScope = this.getCurrentScope(); | ||
var currentContext = this.getCurrentContext(); | ||
var labelStack = currentScope.labelStack.concat([]); | ||
var callStack = this.callStack.concat([]); | ||
var reset = function reset() { | ||
_this.setCurrentScope(currentScope); //reset scope | ||
_this.setCurrentContext(currentContext); //reset context | ||
currentScope.labelStack = labelStack; //reset label stack | ||
_this.callStack = callStack; //reset call stack | ||
}; // start run | ||
try { | ||
var bodyClosure = this.createClosure(node); // add declares to data | ||
this.addDeclarationsToScope(this.collectDeclVars, this.collectDeclFuncs, this.getCurrentScope()); | ||
bodyClosure(); | ||
@@ -421,2 +440,3 @@ } catch (e) { | ||
} finally { | ||
reset(); | ||
this.execEndTime = Date.now(); | ||
@@ -474,3 +494,3 @@ } | ||
_proto2.createClosure = function createClosure(node) { | ||
var _this = this; | ||
var _this2 = this; | ||
@@ -626,9 +646,9 @@ var closure; | ||
return function () { | ||
var timeout = _this.options.timeout; | ||
var timeout = _this2.options.timeout; | ||
if (timeout && timeout > 0 && _this.checkTimeout()) { | ||
throw _this.createInternalThrowError(_messages.Messages.ExecutionTimeOutError, timeout, null); | ||
if (timeout && timeout > 0 && _this2.checkTimeout()) { | ||
throw _this2.createInternalThrowError(_messages.Messages.ExecutionTimeOutError, timeout, null); | ||
} | ||
_this.lastExecNode = node; | ||
_this2.lastExecNode = node; | ||
return closure.apply(void 0, arguments); | ||
@@ -640,3 +660,3 @@ }; | ||
_proto2.binaryExpressionHandler = function binaryExpressionHandler(node) { | ||
var _this2 = this; | ||
var _this3 = this; | ||
@@ -717,3 +737,3 @@ var leftExpression = this.createClosure(node.left); | ||
default: | ||
throw _this2.createInternalThrowError(_messages.Messages.BinaryOperatorSyntaxError, node.operator, node); | ||
throw _this3.createInternalThrowError(_messages.Messages.BinaryOperatorSyntaxError, node.operator, node); | ||
} | ||
@@ -725,3 +745,3 @@ }; | ||
_proto2.logicalExpressionHandler = function logicalExpressionHandler(node) { | ||
var _this3 = this; | ||
var _this4 = this; | ||
@@ -739,3 +759,3 @@ var leftExpression = this.createClosure(node.left); | ||
default: | ||
throw _this3.createInternalThrowError(_messages.Messages.LogicalOperatorSyntaxError, node.operator, node); | ||
throw _this4.createInternalThrowError(_messages.Messages.LogicalOperatorSyntaxError, node.operator, node); | ||
} | ||
@@ -754,3 +774,3 @@ }; | ||
_proto2.unaryExpressionHandler = function unaryExpressionHandler(node) { | ||
var _this4 = this; | ||
var _this5 = this; | ||
@@ -811,3 +831,3 @@ switch (node.operator) { | ||
default: | ||
throw _this4.createInternalThrowError(_messages.Messages.UnaryOperatorSyntaxError, node.operator, node); | ||
throw _this5.createInternalThrowError(_messages.Messages.UnaryOperatorSyntaxError, node.operator, node); | ||
} | ||
@@ -820,3 +840,3 @@ }; | ||
_proto2.updateExpressionHandler = function updateExpressionHandler(node) { | ||
var _this5 = this; | ||
var _this6 = this; | ||
@@ -829,3 +849,3 @@ var objectGetter = this.createObjectGetter(node.argument); | ||
_this5.assertVariable(obj, name, node); | ||
_this6.assertVariable(obj, name, node); | ||
@@ -840,3 +860,3 @@ switch (node.operator) { | ||
default: | ||
throw _this5.createInternalThrowError(_messages.Messages.UpdateOperatorSyntaxError, node.operator, node); | ||
throw _this6.createInternalThrowError(_messages.Messages.UpdateOperatorSyntaxError, node.operator, node); | ||
} | ||
@@ -848,3 +868,3 @@ }; | ||
_proto2.objectExpressionHandler = function objectExpressionHandler(node) { | ||
var _this6 = this; | ||
var _this7 = this; | ||
@@ -875,3 +895,3 @@ var items = []; | ||
properties[key][kind] = _this6.createClosure(property.value); | ||
properties[key][kind] = _this7.createClosure(property.value); | ||
items.push({ | ||
@@ -922,7 +942,7 @@ key: key, | ||
_proto2.arrayExpressionHandler = function arrayExpressionHandler(node) { | ||
var _this7 = this; | ||
var _this8 = this; | ||
//fix: [,,,1,2] | ||
var items = node.elements.map(function (element) { | ||
return element ? _this7.createClosure(element) : element; | ||
return element ? _this8.createClosure(element) : element; | ||
}); | ||
@@ -950,3 +970,3 @@ return function () { | ||
_proto2.createCallFunctionGetter = function createCallFunctionGetter(node) { | ||
var _this8 = this; | ||
var _this9 = this; | ||
@@ -962,7 +982,7 @@ switch (node.type) { | ||
var func = _this8.safeObjectGet(obj, key, node); | ||
var func = _this9.safeObjectGet(obj, key, node); | ||
if (!func || !isFunction(func)) { | ||
var name = source.slice(node.start, node.end); | ||
throw _this8.createInternalThrowError(_messages.Messages.FunctionUndefinedReferenceError, name, node); | ||
throw _this9.createInternalThrowError(_messages.Messages.FunctionUndefinedReferenceError, name, node); | ||
} // obj.eval = eval | ||
@@ -974,3 +994,3 @@ // obj.eval(...) | ||
return function (code) { | ||
return func(new InternalInterpreterReflection(_this8), code, true); | ||
return func(new InternalInterpreterReflection(_this9), code, true); | ||
}; | ||
@@ -987,3 +1007,3 @@ } // obj.func = Function | ||
return func.apply(void 0, [new InternalInterpreterReflection(_this8)].concat(args)); | ||
return func.apply(void 0, [new InternalInterpreterReflection(_this9)].concat(args)); | ||
}; | ||
@@ -1021,3 +1041,3 @@ } // method call | ||
if (!func || !isFunction(func)) { | ||
throw _this8.createInternalThrowError(_messages.Messages.FunctionUndefinedReferenceError, name, node); | ||
throw _this9.createInternalThrowError(_messages.Messages.FunctionUndefinedReferenceError, name, node); | ||
} // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval | ||
@@ -1032,7 +1052,7 @@ // var eval = eval; | ||
return function (code) { | ||
var scope = _this8.getScopeFromName(name, _this8.getCurrentScope()); | ||
var scope = _this9.getScopeFromName(name, _this9.getCurrentScope()); | ||
var useGlobalScope = !scope.parent || _this8.globalScope === scope || scope.name === "rootScope"; // use local scope if calling eval in super scope | ||
var useGlobalScope = !scope.parent || _this9.globalScope === scope || scope.name === "rootScope"; // use local scope if calling eval in super scope | ||
return func(new InternalInterpreterReflection(_this8), code, !useGlobalScope); | ||
return func(new InternalInterpreterReflection(_this9), code, !useGlobalScope); | ||
}; | ||
@@ -1047,3 +1067,3 @@ } // use global scope | ||
return function (code) { | ||
return func(new InternalInterpreterReflection(_this8), code, true); | ||
return func(new InternalInterpreterReflection(_this9), code, true); | ||
}; | ||
@@ -1059,3 +1079,3 @@ } // Function('a', 'b', 'return a+b') | ||
return func.apply(void 0, [new InternalInterpreterReflection(_this8)].concat(args)); | ||
return func.apply(void 0, [new InternalInterpreterReflection(_this9)].concat(args)); | ||
}; | ||
@@ -1069,3 +1089,3 @@ } // function call | ||
return func.bind(_this8.options.globalContextInFunction); | ||
return func.bind(_this9.options.globalContextInFunction); | ||
}; | ||
@@ -1077,7 +1097,7 @@ } | ||
_proto2.callExpressionHandler = function callExpressionHandler(node) { | ||
var _this9 = this; | ||
var _this10 = this; | ||
var funcGetter = this.createCallFunctionGetter(node.callee); | ||
var argsGetter = node.arguments.map(function (arg) { | ||
return _this9.createClosure(arg); | ||
return _this10.createClosure(arg); | ||
}); | ||
@@ -1093,3 +1113,3 @@ return function () { | ||
_proto2.functionExpressionHandler = function functionExpressionHandler(node) { | ||
var _this10 = this; | ||
var _this11 = this; | ||
@@ -1107,3 +1127,3 @@ var self = this; | ||
var paramsGetter = node.params.map(function (param) { | ||
return _this10.createParamNameGetter(param); | ||
return _this11.createParamNameGetter(param); | ||
}); // set scope | ||
@@ -1188,3 +1208,3 @@ | ||
_proto2.newExpressionHandler = function newExpressionHandler(node) { | ||
var _this11 = this; | ||
var _this12 = this; | ||
@@ -1194,3 +1214,3 @@ var source = this.source; | ||
var args = node.arguments.map(function (arg) { | ||
return _this11.createClosure(arg); | ||
return _this12.createClosure(arg); | ||
}); | ||
@@ -1203,3 +1223,3 @@ return function () { | ||
var name = source.slice(callee.start, callee.end); | ||
throw _this11.createInternalThrowError(_messages.Messages.IsNotConstructor, name, node); | ||
throw _this12.createInternalThrowError(_messages.Messages.IsNotConstructor, name, node); | ||
} // new Function(...) | ||
@@ -1209,3 +1229,3 @@ | ||
if (construct.__IS_FUNCTION_FUNC) { | ||
return construct.apply(void 0, [new InternalInterpreterReflection(_this11)].concat(args.map(function (arg) { | ||
return construct.apply(void 0, [new InternalInterpreterReflection(_this12)].concat(args.map(function (arg) { | ||
return arg(); | ||
@@ -1234,6 +1254,6 @@ }))); | ||
_proto2.thisExpressionHandler = function thisExpressionHandler(node) { | ||
var _this12 = this; | ||
var _this13 = this; | ||
return function () { | ||
return _this12.getCurrentContext(); | ||
return _this13.getCurrentContext(); | ||
}; | ||
@@ -1244,6 +1264,6 @@ } // var1,var2,... | ||
_proto2.sequenceExpressionHandler = function sequenceExpressionHandler(node) { | ||
var _this13 = this; | ||
var _this14 = this; | ||
var expressions = node.expressions.map(function (item) { | ||
return _this13.createClosure(item); | ||
return _this14.createClosure(item); | ||
}); | ||
@@ -1276,10 +1296,10 @@ return function () { | ||
_proto2.identifierHandler = function identifierHandler(node) { | ||
var _this14 = this; | ||
var _this15 = this; | ||
return function () { | ||
var currentScope = _this14.getCurrentScope(); | ||
var currentScope = _this15.getCurrentScope(); | ||
var data = _this14.getScopeDataFromName(node.name, currentScope); | ||
var data = _this15.getScopeDataFromName(node.name, currentScope); | ||
_this14.assertVariable(data, node.name, node); | ||
_this15.assertVariable(data, node.name, node); | ||
@@ -1292,3 +1312,3 @@ return data[node.name]; | ||
_proto2.assignmentExpressionHandler = function assignmentExpressionHandler(node) { | ||
var _this15 = this; | ||
var _this16 = this; | ||
@@ -1315,3 +1335,3 @@ // var s = function(){} | ||
// a += 1 | ||
_this15.assertVariable(data, name, node); | ||
_this16.assertVariable(data, name, node); | ||
} | ||
@@ -1360,3 +1380,3 @@ | ||
default: | ||
throw _this15.createInternalThrowError(_messages.Messages.AssignmentExpressionSyntaxError, node.type, node); | ||
throw _this16.createInternalThrowError(_messages.Messages.AssignmentExpressionSyntaxError, node.type, node); | ||
} | ||
@@ -1395,3 +1415,3 @@ }; | ||
_proto2.variableDeclarationHandler = function variableDeclarationHandler(node) { | ||
var _this16 = this; | ||
var _this17 = this; | ||
@@ -1424,6 +1444,6 @@ var assignmentsClosure; | ||
if (assignmentsClosure) { | ||
var oldValue = _this16.isVarDeclMode; | ||
_this16.isVarDeclMode = true; | ||
var oldValue = _this17.isVarDeclMode; | ||
_this17.isVarDeclMode = true; | ||
assignmentsClosure(); | ||
_this16.isVarDeclMode = oldValue; | ||
_this17.isVarDeclMode = oldValue; | ||
} | ||
@@ -1443,3 +1463,3 @@ | ||
_proto2.programHandler = function programHandler(node) { | ||
var _this17 = this; | ||
var _this18 = this; | ||
@@ -1449,3 +1469,3 @@ // const currentScope = this.getCurrentScope(); | ||
// if (stmt.type === "EmptyStatement") return null; | ||
return _this17.createClosure(stmt); | ||
return _this18.createClosure(stmt); | ||
}); | ||
@@ -1458,3 +1478,3 @@ return function () { | ||
var ret = _this17.setValue(stmtClosure()); // if (!stmtClosure) continue; | ||
var ret = _this18.setValue(stmtClosure()); // if (!stmtClosure) continue; | ||
// EmptyStatement | ||
@@ -1517,3 +1537,3 @@ | ||
_proto2.forStatementHandler = function forStatementHandler(node) { | ||
var _this18 = this; | ||
var _this19 = this; | ||
@@ -1544,3 +1564,3 @@ var initClosure = noop; | ||
var ret = _this18.setValue(bodyClosure()); // notice: never return Break or Continue! | ||
var ret = _this19.setValue(bodyClosure()); // notice: never return Break or Continue! | ||
@@ -1580,3 +1600,3 @@ | ||
_proto2.forInStatementHandler = function forInStatementHandler(node) { | ||
var _this19 = this; | ||
var _this20 = this; | ||
@@ -1611,3 +1631,3 @@ // for( k in obj) or for(o.k in obj) ... | ||
// o.k = x | ||
_this19.assignmentExpressionHandler({ | ||
_this20.assignmentExpressionHandler({ | ||
type: "AssignmentExpression", | ||
@@ -1623,3 +1643,3 @@ operator: "=", | ||
var ret = _this19.setValue(bodyClosure()); // notice: never return Break or Continue! | ||
var ret = _this20.setValue(bodyClosure()); // notice: never return Break or Continue! | ||
@@ -1650,3 +1670,3 @@ | ||
_proto2.withStatementHandler = function withStatementHandler(node) { | ||
var _this20 = this; | ||
var _this21 = this; | ||
@@ -1658,3 +1678,3 @@ var objectClosure = this.createClosure(node.object); | ||
var currentScope = _this20.getCurrentScope(); | ||
var currentScope = _this21.getCurrentScope(); | ||
@@ -1667,8 +1687,8 @@ var newScope = new Scope(data, currentScope, "with"); // const data = objectClosure(); | ||
_this20.setCurrentScope(newScope); // save last value | ||
_this21.setCurrentScope(newScope); // save last value | ||
var result = _this20.setValue(bodyClosure()); | ||
var result = _this21.setValue(bodyClosure()); | ||
_this20.setCurrentScope(currentScope); | ||
_this21.setCurrentScope(currentScope); | ||
@@ -1680,7 +1700,7 @@ return result; | ||
_proto2.throwStatementHandler = function throwStatementHandler(node) { | ||
var _this21 = this; | ||
var _this22 = this; | ||
var argumentClosure = this.createClosure(node.argument); | ||
return function () { | ||
_this21.setValue(undefined); | ||
_this22.setValue(undefined); | ||
@@ -1693,3 +1713,3 @@ throw argumentClosure(); | ||
_proto2.tryStatementHandler = function tryStatementHandler(node) { | ||
var _this22 = this; | ||
var _this23 = this; | ||
@@ -1700,9 +1720,9 @@ var blockClosure = this.createClosure(node.block); | ||
return function () { | ||
var currentScope = _this22.getCurrentScope(); | ||
var currentScope = _this23.getCurrentScope(); | ||
var currentContext = _this22.getCurrentContext(); | ||
var currentContext = _this23.getCurrentContext(); | ||
var labelStack = currentScope.labelStack.concat([]); | ||
var callStack = _this22.callStack.concat([]); | ||
var callStack = _this23.callStack.concat([]); | ||
@@ -1714,6 +1734,6 @@ var result = EmptyStatementReturn; | ||
var reset = function reset() { | ||
_this22.setCurrentScope(currentScope); //reset scope | ||
_this23.setCurrentScope(currentScope); //reset scope | ||
_this22.setCurrentContext(currentContext); //reset context | ||
_this23.setCurrentContext(currentContext); //reset context | ||
@@ -1723,3 +1743,3 @@ | ||
_this22.callStack = callStack; //reset call stack | ||
_this23.callStack = callStack; //reset call stack | ||
}; | ||
@@ -1739,3 +1759,3 @@ /** | ||
try { | ||
result = _this22.setValue(blockClosure()); | ||
result = _this23.setValue(blockClosure()); | ||
@@ -1748,3 +1768,3 @@ if (result instanceof Return) { | ||
if (_this22.isInterruptThrow(err)) { | ||
if (_this23.isInterruptThrow(err)) { | ||
throw err; | ||
@@ -1755,3 +1775,3 @@ } | ||
try { | ||
result = _this22.setValue(handlerClosure(err)); | ||
result = _this23.setValue(handlerClosure(err)); | ||
@@ -1764,3 +1784,3 @@ if (result instanceof Return) { | ||
if (_this22.isInterruptThrow(err)) { | ||
if (_this23.isInterruptThrow(err)) { | ||
throw err; | ||
@@ -1788,3 +1808,3 @@ } // save catch throw error | ||
if (_this22.isInterruptThrow(err)) { | ||
if (_this23.isInterruptThrow(err)) { | ||
throw err; | ||
@@ -1814,3 +1834,3 @@ } // save finally throw error | ||
_proto2.catchClauseHandler = function catchClauseHandler(node) { | ||
var _this23 = this; | ||
var _this24 = this; | ||
@@ -1822,3 +1842,3 @@ var paramNameGetter = this.createParamNameGetter(node.param); | ||
var currentScope = _this23.getCurrentScope(); | ||
var currentScope = _this24.getCurrentScope(); | ||
@@ -1861,7 +1881,7 @@ var scopeData = currentScope.data; // get param name "e" | ||
_proto2.switchStatementHandler = function switchStatementHandler(node) { | ||
var _this24 = this; | ||
var _this25 = this; | ||
var discriminantClosure = this.createClosure(node.discriminant); | ||
var caseClosures = node.cases.map(function (item) { | ||
return _this24.switchCaseHandler(item); | ||
return _this25.switchCaseHandler(item); | ||
}); | ||
@@ -1885,3 +1905,3 @@ return function () { | ||
match = true; | ||
ret = _this24.setValue(item.bodyClosure()); // notice: never return Break! | ||
ret = _this25.setValue(item.bodyClosure()); // notice: never return Break! | ||
@@ -1903,3 +1923,3 @@ if (ret === EmptyStatementReturn) continue; | ||
if (!match && defaultCase) { | ||
ret = _this24.setValue(defaultCase.bodyClosure()); | ||
ret = _this25.setValue(defaultCase.bodyClosure()); | ||
var isEBC = ret === EmptyStatementReturn || ret === Break || ret === Continue; // notice: never return Break or Continue! | ||
@@ -1934,3 +1954,3 @@ | ||
_proto2.labeledStatementHandler = function labeledStatementHandler(node) { | ||
var _this25 = this; | ||
var _this26 = this; | ||
@@ -1942,3 +1962,3 @@ var labelName = node.label.name; | ||
var currentScope = _this25.getCurrentScope(); | ||
var currentScope = _this26.getCurrentScope(); | ||
@@ -2001,3 +2021,3 @@ currentScope.labelStack.push(labelName); | ||
_proto2.createObjectGetter = function createObjectGetter(node) { | ||
var _this26 = this; | ||
var _this27 = this; | ||
@@ -2007,3 +2027,3 @@ switch (node.type) { | ||
return function () { | ||
return _this26.getScopeDataFromName(node.name, _this26.getCurrentScope()); | ||
return _this27.getScopeDataFromName(node.name, _this27.getCurrentScope()); | ||
}; | ||
@@ -2010,0 +2030,0 @@ |
import _construct from "@babel/runtime/helpers/construct"; | ||
import { parse } from "acorn"; | ||
import { Messages, InterruptThrowError, InterruptThrowReferenceError, InterruptThrowSyntaxError } from "./messages"; | ||
var version = "1.4.3"; | ||
var version = "1.4.4"; | ||
@@ -383,2 +383,4 @@ function defineFunctionName(func, name) { | ||
_proto2.evaluateNode = function evaluateNode(node, source) { | ||
var _this = this; | ||
if (source === void 0) { | ||
@@ -391,14 +393,31 @@ source = ""; | ||
this.sourceList.push(source); | ||
this.isRunning = true; | ||
var bodyClosure = this.createClosure(node); //reset timeout | ||
this.isRunning = true; //reset timeout | ||
this.execStartTime = Date.now(); | ||
this.execEndTime = this.execStartTime; // add declares to data | ||
this.execEndTime = this.execStartTime; // reset | ||
this.addDeclarationsToScope(this.collectDeclVars, this.collectDeclFuncs, this.getCurrentScope()); // reset | ||
this.collectDeclVars = Object.create(null); | ||
this.collectDeclFuncs = Object.create(null); // start run | ||
this.collectDeclFuncs = Object.create(null); | ||
var currentScope = this.getCurrentScope(); | ||
var currentContext = this.getCurrentContext(); | ||
var labelStack = currentScope.labelStack.concat([]); | ||
var callStack = this.callStack.concat([]); | ||
var reset = function reset() { | ||
_this.setCurrentScope(currentScope); //reset scope | ||
_this.setCurrentContext(currentContext); //reset context | ||
currentScope.labelStack = labelStack; //reset label stack | ||
_this.callStack = callStack; //reset call stack | ||
}; // start run | ||
try { | ||
var bodyClosure = this.createClosure(node); // add declares to data | ||
this.addDeclarationsToScope(this.collectDeclVars, this.collectDeclFuncs, this.getCurrentScope()); | ||
bodyClosure(); | ||
@@ -408,2 +427,3 @@ } catch (e) { | ||
} finally { | ||
reset(); | ||
this.execEndTime = Date.now(); | ||
@@ -461,3 +481,3 @@ } | ||
_proto2.createClosure = function createClosure(node) { | ||
var _this = this; | ||
var _this2 = this; | ||
@@ -613,9 +633,9 @@ var closure; | ||
return function () { | ||
var timeout = _this.options.timeout; | ||
var timeout = _this2.options.timeout; | ||
if (timeout && timeout > 0 && _this.checkTimeout()) { | ||
throw _this.createInternalThrowError(Messages.ExecutionTimeOutError, timeout, null); | ||
if (timeout && timeout > 0 && _this2.checkTimeout()) { | ||
throw _this2.createInternalThrowError(Messages.ExecutionTimeOutError, timeout, null); | ||
} | ||
_this.lastExecNode = node; | ||
_this2.lastExecNode = node; | ||
return closure.apply(void 0, arguments); | ||
@@ -627,3 +647,3 @@ }; | ||
_proto2.binaryExpressionHandler = function binaryExpressionHandler(node) { | ||
var _this2 = this; | ||
var _this3 = this; | ||
@@ -704,3 +724,3 @@ var leftExpression = this.createClosure(node.left); | ||
default: | ||
throw _this2.createInternalThrowError(Messages.BinaryOperatorSyntaxError, node.operator, node); | ||
throw _this3.createInternalThrowError(Messages.BinaryOperatorSyntaxError, node.operator, node); | ||
} | ||
@@ -712,3 +732,3 @@ }; | ||
_proto2.logicalExpressionHandler = function logicalExpressionHandler(node) { | ||
var _this3 = this; | ||
var _this4 = this; | ||
@@ -726,3 +746,3 @@ var leftExpression = this.createClosure(node.left); | ||
default: | ||
throw _this3.createInternalThrowError(Messages.LogicalOperatorSyntaxError, node.operator, node); | ||
throw _this4.createInternalThrowError(Messages.LogicalOperatorSyntaxError, node.operator, node); | ||
} | ||
@@ -741,3 +761,3 @@ }; | ||
_proto2.unaryExpressionHandler = function unaryExpressionHandler(node) { | ||
var _this4 = this; | ||
var _this5 = this; | ||
@@ -798,3 +818,3 @@ switch (node.operator) { | ||
default: | ||
throw _this4.createInternalThrowError(Messages.UnaryOperatorSyntaxError, node.operator, node); | ||
throw _this5.createInternalThrowError(Messages.UnaryOperatorSyntaxError, node.operator, node); | ||
} | ||
@@ -807,3 +827,3 @@ }; | ||
_proto2.updateExpressionHandler = function updateExpressionHandler(node) { | ||
var _this5 = this; | ||
var _this6 = this; | ||
@@ -816,3 +836,3 @@ var objectGetter = this.createObjectGetter(node.argument); | ||
_this5.assertVariable(obj, name, node); | ||
_this6.assertVariable(obj, name, node); | ||
@@ -827,3 +847,3 @@ switch (node.operator) { | ||
default: | ||
throw _this5.createInternalThrowError(Messages.UpdateOperatorSyntaxError, node.operator, node); | ||
throw _this6.createInternalThrowError(Messages.UpdateOperatorSyntaxError, node.operator, node); | ||
} | ||
@@ -835,3 +855,3 @@ }; | ||
_proto2.objectExpressionHandler = function objectExpressionHandler(node) { | ||
var _this6 = this; | ||
var _this7 = this; | ||
@@ -862,3 +882,3 @@ var items = []; | ||
properties[key][kind] = _this6.createClosure(property.value); | ||
properties[key][kind] = _this7.createClosure(property.value); | ||
items.push({ | ||
@@ -909,7 +929,7 @@ key: key, | ||
_proto2.arrayExpressionHandler = function arrayExpressionHandler(node) { | ||
var _this7 = this; | ||
var _this8 = this; | ||
//fix: [,,,1,2] | ||
var items = node.elements.map(function (element) { | ||
return element ? _this7.createClosure(element) : element; | ||
return element ? _this8.createClosure(element) : element; | ||
}); | ||
@@ -937,3 +957,3 @@ return function () { | ||
_proto2.createCallFunctionGetter = function createCallFunctionGetter(node) { | ||
var _this8 = this; | ||
var _this9 = this; | ||
@@ -949,7 +969,7 @@ switch (node.type) { | ||
var func = _this8.safeObjectGet(obj, key, node); | ||
var func = _this9.safeObjectGet(obj, key, node); | ||
if (!func || !isFunction(func)) { | ||
var name = source.slice(node.start, node.end); | ||
throw _this8.createInternalThrowError(Messages.FunctionUndefinedReferenceError, name, node); | ||
throw _this9.createInternalThrowError(Messages.FunctionUndefinedReferenceError, name, node); | ||
} // obj.eval = eval | ||
@@ -961,3 +981,3 @@ // obj.eval(...) | ||
return function (code) { | ||
return func(new InternalInterpreterReflection(_this8), code, true); | ||
return func(new InternalInterpreterReflection(_this9), code, true); | ||
}; | ||
@@ -974,3 +994,3 @@ } // obj.func = Function | ||
return func.apply(void 0, [new InternalInterpreterReflection(_this8)].concat(args)); | ||
return func.apply(void 0, [new InternalInterpreterReflection(_this9)].concat(args)); | ||
}; | ||
@@ -1008,3 +1028,3 @@ } // method call | ||
if (!func || !isFunction(func)) { | ||
throw _this8.createInternalThrowError(Messages.FunctionUndefinedReferenceError, name, node); | ||
throw _this9.createInternalThrowError(Messages.FunctionUndefinedReferenceError, name, node); | ||
} // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval | ||
@@ -1019,7 +1039,7 @@ // var eval = eval; | ||
return function (code) { | ||
var scope = _this8.getScopeFromName(name, _this8.getCurrentScope()); | ||
var scope = _this9.getScopeFromName(name, _this9.getCurrentScope()); | ||
var useGlobalScope = !scope.parent || _this8.globalScope === scope || scope.name === "rootScope"; // use local scope if calling eval in super scope | ||
var useGlobalScope = !scope.parent || _this9.globalScope === scope || scope.name === "rootScope"; // use local scope if calling eval in super scope | ||
return func(new InternalInterpreterReflection(_this8), code, !useGlobalScope); | ||
return func(new InternalInterpreterReflection(_this9), code, !useGlobalScope); | ||
}; | ||
@@ -1034,3 +1054,3 @@ } // use global scope | ||
return function (code) { | ||
return func(new InternalInterpreterReflection(_this8), code, true); | ||
return func(new InternalInterpreterReflection(_this9), code, true); | ||
}; | ||
@@ -1046,3 +1066,3 @@ } // Function('a', 'b', 'return a+b') | ||
return func.apply(void 0, [new InternalInterpreterReflection(_this8)].concat(args)); | ||
return func.apply(void 0, [new InternalInterpreterReflection(_this9)].concat(args)); | ||
}; | ||
@@ -1056,3 +1076,3 @@ } // function call | ||
return func.bind(_this8.options.globalContextInFunction); | ||
return func.bind(_this9.options.globalContextInFunction); | ||
}; | ||
@@ -1064,7 +1084,7 @@ } | ||
_proto2.callExpressionHandler = function callExpressionHandler(node) { | ||
var _this9 = this; | ||
var _this10 = this; | ||
var funcGetter = this.createCallFunctionGetter(node.callee); | ||
var argsGetter = node.arguments.map(function (arg) { | ||
return _this9.createClosure(arg); | ||
return _this10.createClosure(arg); | ||
}); | ||
@@ -1080,3 +1100,3 @@ return function () { | ||
_proto2.functionExpressionHandler = function functionExpressionHandler(node) { | ||
var _this10 = this; | ||
var _this11 = this; | ||
@@ -1094,3 +1114,3 @@ var self = this; | ||
var paramsGetter = node.params.map(function (param) { | ||
return _this10.createParamNameGetter(param); | ||
return _this11.createParamNameGetter(param); | ||
}); // set scope | ||
@@ -1175,3 +1195,3 @@ | ||
_proto2.newExpressionHandler = function newExpressionHandler(node) { | ||
var _this11 = this; | ||
var _this12 = this; | ||
@@ -1181,3 +1201,3 @@ var source = this.source; | ||
var args = node.arguments.map(function (arg) { | ||
return _this11.createClosure(arg); | ||
return _this12.createClosure(arg); | ||
}); | ||
@@ -1190,3 +1210,3 @@ return function () { | ||
var name = source.slice(callee.start, callee.end); | ||
throw _this11.createInternalThrowError(Messages.IsNotConstructor, name, node); | ||
throw _this12.createInternalThrowError(Messages.IsNotConstructor, name, node); | ||
} // new Function(...) | ||
@@ -1196,3 +1216,3 @@ | ||
if (construct.__IS_FUNCTION_FUNC) { | ||
return construct.apply(void 0, [new InternalInterpreterReflection(_this11)].concat(args.map(function (arg) { | ||
return construct.apply(void 0, [new InternalInterpreterReflection(_this12)].concat(args.map(function (arg) { | ||
return arg(); | ||
@@ -1221,6 +1241,6 @@ }))); | ||
_proto2.thisExpressionHandler = function thisExpressionHandler(node) { | ||
var _this12 = this; | ||
var _this13 = this; | ||
return function () { | ||
return _this12.getCurrentContext(); | ||
return _this13.getCurrentContext(); | ||
}; | ||
@@ -1231,6 +1251,6 @@ } // var1,var2,... | ||
_proto2.sequenceExpressionHandler = function sequenceExpressionHandler(node) { | ||
var _this13 = this; | ||
var _this14 = this; | ||
var expressions = node.expressions.map(function (item) { | ||
return _this13.createClosure(item); | ||
return _this14.createClosure(item); | ||
}); | ||
@@ -1263,10 +1283,10 @@ return function () { | ||
_proto2.identifierHandler = function identifierHandler(node) { | ||
var _this14 = this; | ||
var _this15 = this; | ||
return function () { | ||
var currentScope = _this14.getCurrentScope(); | ||
var currentScope = _this15.getCurrentScope(); | ||
var data = _this14.getScopeDataFromName(node.name, currentScope); | ||
var data = _this15.getScopeDataFromName(node.name, currentScope); | ||
_this14.assertVariable(data, node.name, node); | ||
_this15.assertVariable(data, node.name, node); | ||
@@ -1279,3 +1299,3 @@ return data[node.name]; | ||
_proto2.assignmentExpressionHandler = function assignmentExpressionHandler(node) { | ||
var _this15 = this; | ||
var _this16 = this; | ||
@@ -1302,3 +1322,3 @@ // var s = function(){} | ||
// a += 1 | ||
_this15.assertVariable(data, name, node); | ||
_this16.assertVariable(data, name, node); | ||
} | ||
@@ -1347,3 +1367,3 @@ | ||
default: | ||
throw _this15.createInternalThrowError(Messages.AssignmentExpressionSyntaxError, node.type, node); | ||
throw _this16.createInternalThrowError(Messages.AssignmentExpressionSyntaxError, node.type, node); | ||
} | ||
@@ -1382,3 +1402,3 @@ }; | ||
_proto2.variableDeclarationHandler = function variableDeclarationHandler(node) { | ||
var _this16 = this; | ||
var _this17 = this; | ||
@@ -1411,6 +1431,6 @@ var assignmentsClosure; | ||
if (assignmentsClosure) { | ||
var oldValue = _this16.isVarDeclMode; | ||
_this16.isVarDeclMode = true; | ||
var oldValue = _this17.isVarDeclMode; | ||
_this17.isVarDeclMode = true; | ||
assignmentsClosure(); | ||
_this16.isVarDeclMode = oldValue; | ||
_this17.isVarDeclMode = oldValue; | ||
} | ||
@@ -1430,3 +1450,3 @@ | ||
_proto2.programHandler = function programHandler(node) { | ||
var _this17 = this; | ||
var _this18 = this; | ||
@@ -1436,3 +1456,3 @@ // const currentScope = this.getCurrentScope(); | ||
// if (stmt.type === "EmptyStatement") return null; | ||
return _this17.createClosure(stmt); | ||
return _this18.createClosure(stmt); | ||
}); | ||
@@ -1445,3 +1465,3 @@ return function () { | ||
var ret = _this17.setValue(stmtClosure()); // if (!stmtClosure) continue; | ||
var ret = _this18.setValue(stmtClosure()); // if (!stmtClosure) continue; | ||
// EmptyStatement | ||
@@ -1504,3 +1524,3 @@ | ||
_proto2.forStatementHandler = function forStatementHandler(node) { | ||
var _this18 = this; | ||
var _this19 = this; | ||
@@ -1531,3 +1551,3 @@ var initClosure = noop; | ||
var ret = _this18.setValue(bodyClosure()); // notice: never return Break or Continue! | ||
var ret = _this19.setValue(bodyClosure()); // notice: never return Break or Continue! | ||
@@ -1567,3 +1587,3 @@ | ||
_proto2.forInStatementHandler = function forInStatementHandler(node) { | ||
var _this19 = this; | ||
var _this20 = this; | ||
@@ -1598,3 +1618,3 @@ // for( k in obj) or for(o.k in obj) ... | ||
// o.k = x | ||
_this19.assignmentExpressionHandler({ | ||
_this20.assignmentExpressionHandler({ | ||
type: "AssignmentExpression", | ||
@@ -1610,3 +1630,3 @@ operator: "=", | ||
var ret = _this19.setValue(bodyClosure()); // notice: never return Break or Continue! | ||
var ret = _this20.setValue(bodyClosure()); // notice: never return Break or Continue! | ||
@@ -1637,3 +1657,3 @@ | ||
_proto2.withStatementHandler = function withStatementHandler(node) { | ||
var _this20 = this; | ||
var _this21 = this; | ||
@@ -1645,3 +1665,3 @@ var objectClosure = this.createClosure(node.object); | ||
var currentScope = _this20.getCurrentScope(); | ||
var currentScope = _this21.getCurrentScope(); | ||
@@ -1654,8 +1674,8 @@ var newScope = new Scope(data, currentScope, "with"); // const data = objectClosure(); | ||
_this20.setCurrentScope(newScope); // save last value | ||
_this21.setCurrentScope(newScope); // save last value | ||
var result = _this20.setValue(bodyClosure()); | ||
var result = _this21.setValue(bodyClosure()); | ||
_this20.setCurrentScope(currentScope); | ||
_this21.setCurrentScope(currentScope); | ||
@@ -1667,7 +1687,7 @@ return result; | ||
_proto2.throwStatementHandler = function throwStatementHandler(node) { | ||
var _this21 = this; | ||
var _this22 = this; | ||
var argumentClosure = this.createClosure(node.argument); | ||
return function () { | ||
_this21.setValue(undefined); | ||
_this22.setValue(undefined); | ||
@@ -1680,3 +1700,3 @@ throw argumentClosure(); | ||
_proto2.tryStatementHandler = function tryStatementHandler(node) { | ||
var _this22 = this; | ||
var _this23 = this; | ||
@@ -1687,9 +1707,9 @@ var blockClosure = this.createClosure(node.block); | ||
return function () { | ||
var currentScope = _this22.getCurrentScope(); | ||
var currentScope = _this23.getCurrentScope(); | ||
var currentContext = _this22.getCurrentContext(); | ||
var currentContext = _this23.getCurrentContext(); | ||
var labelStack = currentScope.labelStack.concat([]); | ||
var callStack = _this22.callStack.concat([]); | ||
var callStack = _this23.callStack.concat([]); | ||
@@ -1701,6 +1721,6 @@ var result = EmptyStatementReturn; | ||
var reset = function reset() { | ||
_this22.setCurrentScope(currentScope); //reset scope | ||
_this23.setCurrentScope(currentScope); //reset scope | ||
_this22.setCurrentContext(currentContext); //reset context | ||
_this23.setCurrentContext(currentContext); //reset context | ||
@@ -1710,3 +1730,3 @@ | ||
_this22.callStack = callStack; //reset call stack | ||
_this23.callStack = callStack; //reset call stack | ||
}; | ||
@@ -1726,3 +1746,3 @@ /** | ||
try { | ||
result = _this22.setValue(blockClosure()); | ||
result = _this23.setValue(blockClosure()); | ||
@@ -1735,3 +1755,3 @@ if (result instanceof Return) { | ||
if (_this22.isInterruptThrow(err)) { | ||
if (_this23.isInterruptThrow(err)) { | ||
throw err; | ||
@@ -1742,3 +1762,3 @@ } | ||
try { | ||
result = _this22.setValue(handlerClosure(err)); | ||
result = _this23.setValue(handlerClosure(err)); | ||
@@ -1751,3 +1771,3 @@ if (result instanceof Return) { | ||
if (_this22.isInterruptThrow(err)) { | ||
if (_this23.isInterruptThrow(err)) { | ||
throw err; | ||
@@ -1775,3 +1795,3 @@ } // save catch throw error | ||
if (_this22.isInterruptThrow(err)) { | ||
if (_this23.isInterruptThrow(err)) { | ||
throw err; | ||
@@ -1801,3 +1821,3 @@ } // save finally throw error | ||
_proto2.catchClauseHandler = function catchClauseHandler(node) { | ||
var _this23 = this; | ||
var _this24 = this; | ||
@@ -1809,3 +1829,3 @@ var paramNameGetter = this.createParamNameGetter(node.param); | ||
var currentScope = _this23.getCurrentScope(); | ||
var currentScope = _this24.getCurrentScope(); | ||
@@ -1848,7 +1868,7 @@ var scopeData = currentScope.data; // get param name "e" | ||
_proto2.switchStatementHandler = function switchStatementHandler(node) { | ||
var _this24 = this; | ||
var _this25 = this; | ||
var discriminantClosure = this.createClosure(node.discriminant); | ||
var caseClosures = node.cases.map(function (item) { | ||
return _this24.switchCaseHandler(item); | ||
return _this25.switchCaseHandler(item); | ||
}); | ||
@@ -1872,3 +1892,3 @@ return function () { | ||
match = true; | ||
ret = _this24.setValue(item.bodyClosure()); // notice: never return Break! | ||
ret = _this25.setValue(item.bodyClosure()); // notice: never return Break! | ||
@@ -1890,3 +1910,3 @@ if (ret === EmptyStatementReturn) continue; | ||
if (!match && defaultCase) { | ||
ret = _this24.setValue(defaultCase.bodyClosure()); | ||
ret = _this25.setValue(defaultCase.bodyClosure()); | ||
var isEBC = ret === EmptyStatementReturn || ret === Break || ret === Continue; // notice: never return Break or Continue! | ||
@@ -1921,3 +1941,3 @@ | ||
_proto2.labeledStatementHandler = function labeledStatementHandler(node) { | ||
var _this25 = this; | ||
var _this26 = this; | ||
@@ -1929,3 +1949,3 @@ var labelName = node.label.name; | ||
var currentScope = _this25.getCurrentScope(); | ||
var currentScope = _this26.getCurrentScope(); | ||
@@ -1988,3 +2008,3 @@ currentScope.labelStack.push(labelName); | ||
_proto2.createObjectGetter = function createObjectGetter(node) { | ||
var _this26 = this; | ||
var _this27 = this; | ||
@@ -1994,3 +2014,3 @@ switch (node.type) { | ||
return function () { | ||
return _this26.getScopeDataFromName(node.name, _this26.getCurrentScope()); | ||
return _this27.getScopeDataFromName(node.name, _this27.getCurrentScope()); | ||
}; | ||
@@ -1997,0 +2017,0 @@ |
@@ -312,13 +312,23 @@ import { parse } from "acorn"; | ||
this.isRunning = true; | ||
const bodyClosure = this.createClosure(node); | ||
//reset timeout | ||
this.execStartTime = Date.now(); | ||
this.execEndTime = this.execStartTime; | ||
// add declares to data | ||
this.addDeclarationsToScope(this.collectDeclVars, this.collectDeclFuncs, this.getCurrentScope()); | ||
// reset | ||
this.collectDeclVars = Object.create(null); | ||
this.collectDeclFuncs = Object.create(null); | ||
const currentScope = this.getCurrentScope(); | ||
const currentContext = this.getCurrentContext(); | ||
const labelStack = currentScope.labelStack.concat([]); | ||
const callStack = this.callStack.concat([]); | ||
const reset = () => { | ||
this.setCurrentScope(currentScope); //reset scope | ||
this.setCurrentContext(currentContext); //reset context | ||
currentScope.labelStack = labelStack; //reset label stack | ||
this.callStack = callStack; //reset call stack | ||
}; | ||
// start run | ||
try { | ||
const bodyClosure = this.createClosure(node); | ||
// add declares to data | ||
this.addDeclarationsToScope(this.collectDeclVars, this.collectDeclFuncs, this.getCurrentScope()); | ||
bodyClosure(); | ||
@@ -330,2 +340,3 @@ } | ||
finally { | ||
reset(); | ||
this.execEndTime = Date.now(); | ||
@@ -332,0 +343,0 @@ } |
{ | ||
"name": "eval5", | ||
"version": "1.4.3", | ||
"version": "1.4.4", | ||
"description": "A JavaScript interpreter written in JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "./dist/cjs/index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1068615
12663