Socket
Socket
Sign inDemoInstall

@huolala-tech/eval5

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@huolala-tech/eval5 - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

2

dist/cjs/index.js

@@ -1,2 +0,2 @@

"use strict";class e extends Error{}class t extends SyntaxError{}class r extends ReferenceError{}class n extends TypeError{}class a extends e{}class s extends t{}class o extends r{}const i={UnknownError:[3001,"%0",a],ExecutionTimeOutError:[3002,"Script execution timed out after %0ms",a],NodeTypeSyntaxError:[1001,"Unknown node type: %0",o],BinaryOperatorSyntaxError:[1002,"Unknown binary operator: %0",o],LogicalOperatorSyntaxError:[1003,"Unknown logical operator: %0",o],UnaryOperatorSyntaxError:[1004,"Unknown unary operator: %0",o],UpdateOperatorSyntaxError:[1005,"Unknown update operator: %0",o],ObjectStructureSyntaxError:[1006,"Unknown object structure: %0",o],AssignmentExpressionSyntaxError:[1007,"Unknown assignment expression: %0",o],VariableTypeSyntaxError:[1008,"Unknown variable type: %0",o],ParamTypeSyntaxError:[1009,"Unknown param type: %0",o],AssignmentTypeSyntaxError:[1010,"Unknown assignment type: %0",o],FunctionUndefinedReferenceError:[2001,"%0 is not a function",r],VariableUndefinedReferenceError:[2002,"%0 is not defined",r],IsNotConstructor:[2003,"%0 is not a constructor",n]};function c(e,t){Object.defineProperty(e,"name",{value:t,writable:!1,enumerable:!1,configurable:!0})}const l=Object.prototype.hasOwnProperty,u=Symbol("Break"),h=Symbol("Continue"),p=Symbol("DefaultCase"),d=Symbol("EmptyStatementReturn"),m=Symbol("WithScopeName"),f=Symbol("SuperScopeName"),b=Symbol("RootScopeName"),S=Symbol("GlobalScopeName");function y(e){return"function"==typeof e}class x{value;constructor(e){this.value=e}}class E{value;constructor(e){this.value=e}}class g{value;constructor(e){this.value=e}}class C{name;parent;data;labelStack;constructor(e,t=null,r){this.name=r,this.parent=t,this.data=e,this.labelStack=[]}}function w(){}const k={NaN:NaN,Infinity:1/0,undefined:void 0,Object:Object,Array:Array,String:String,Boolean:Boolean,Number:Number,Date:Date,RegExp:RegExp,Error:Error,URIError:URIError,TypeError:TypeError,RangeError:RangeError,SyntaxError:SyntaxError,ReferenceError:ReferenceError,Math:Math,parseInt:parseInt,parseFloat:parseFloat,isNaN:isNaN,isFinite:isFinite,decodeURI:decodeURI,decodeURIComponent:decodeURIComponent,encodeURI:encodeURI,encodeURIComponent:encodeURIComponent,escape:escape,unescape:unescape};"undefined"!=typeof JSON&&(k.JSON=JSON),"undefined"!=typeof Promise&&(k.Promise=Promise),"undefined"!=typeof Set&&(k.Set=Set),"undefined"!=typeof Map&&(k.Map=Map),"undefined"!=typeof Symbol&&(k.Symbol=Symbol),"undefined"!=typeof Proxy&&(k.Proxy=Proxy),"undefined"!=typeof WeakMap&&(k.WeakMap=WeakMap),"undefined"!=typeof WeakSet&&(k.WeakSet=WeakSet),"undefined"!=typeof Reflect&&(k.Reflect=Reflect);class H{static version="0.0.0";static ecmaVersion=5;static globalContextInFunction=void 0;static global=Object.create(null);value;context;globalContext;source;sourceList=[];currentScope;globalScope;currentContext;options;callStack;collectDeclVars=Object.create(null);collectDeclFuncs=Object.create(null);isVarDeclMode=!1;lastExecNode=null;isRunning=!1;execStartTime;execEndTime;constructor(e=H.global,t={}){this.options={timeout:t.timeout||0,rootContext:t.rootContext,globalContextInFunction:void 0===t.globalContextInFunction?H.globalContextInFunction:t.globalContextInFunction,_initEnv:t._initEnv},this.context=e||Object.create(null),this.callStack=[],this.initEnvironment(this.context)}initEnvironment(e){let t;if(e instanceof C)t=e;else{let n=null;const a=this.createSuperScope(e);this.options.rootContext&&(n=new C((r=this.options.rootContext,Object.create(r)),a,b)),t=new C(e,n||a,S)}var r;this.globalScope=t,this.currentScope=this.globalScope,this.globalContext=t.data,this.currentContext=t.data,this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null),this.execStartTime=Date.now(),this.execEndTime=this.execStartTime;const n=this.options._initEnv;n&&n.call(this)}getExecStartTime(){return this.execStartTime}getExecutionTime(){return this.execEndTime-this.execStartTime}setExecTimeout(e=0){this.options.timeout=e}getOptions(){return this.options}getCurrentScope(){return this.currentScope}getCurrentContext(){return this.currentContext}isInterruptThrow(e){return e instanceof a||e instanceof o||e instanceof s}createSuperScope(e){let t={...k};return Object.keys(t).forEach((r=>{r in e&&delete t[r]})),new C(t,null,f)}setCurrentContext(e){this.currentContext=e}setCurrentScope(e){this.currentScope=e}evaluateNode(e,t=""){this.value=void 0,this.source=t,this.sourceList.push(t),this.isRunning=!0,this.execStartTime=Date.now(),this.execEndTime=this.execStartTime,this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null);const r=this.getCurrentScope(),n=this.getCurrentContext(),a=r.labelStack.concat([]),s=this.callStack.concat([]),o=()=>{this.setCurrentScope(r),this.setCurrentContext(n),r.labelStack=a,this.callStack=s};try{const t=this.createClosure(e);this.addDeclarationsToScope(this.collectDeclVars,this.collectDeclFuncs,this.getCurrentScope()),t()}catch(e){throw e}finally{o(),this.execEndTime=Date.now()}return this.isRunning=!1,this.getValue()}createErrorMessage(e,t,r){let n=e[1].replace("%0",String(t));return null!==r&&(n+=this.getNodePosition(r||this.lastExecNode)),n}createError(e,t){return new t(e)}createThrowError(e,t){return this.createError(e,t)}createInternalThrowError(e,t,r){return this.createError(this.createErrorMessage(e,t,r),e[2])}checkTimeout(){if(!this.isRunning)return!1;const e=this.options.timeout||0;return Date.now()-this.execStartTime>e}getNodePosition(e){if(e){const t="";return e.loc?` [${e.loc.start.line}:${e.loc.start.column}]${t}`:""}return""}createClosure(e){let t;switch(e.type){case"BinaryExpression":t=this.binaryExpressionHandler(e);break;case"LogicalExpression":t=this.logicalExpressionHandler(e);break;case"UnaryExpression":t=this.unaryExpressionHandler(e);break;case"UpdateExpression":t=this.updateExpressionHandler(e);break;case"ObjectExpression":t=this.objectExpressionHandler(e);break;case"ArrayExpression":t=this.arrayExpressionHandler(e);break;case"CallExpression":t=this.callExpressionHandler(e);break;case"NewExpression":t=this.newExpressionHandler(e);break;case"MemberExpression":t=this.memberExpressionHandler(e);break;case"ThisExpression":t=this.thisExpressionHandler(e);break;case"SequenceExpression":t=this.sequenceExpressionHandler(e);break;case"Literal":t=this.literalHandler(e);break;case"Identifier":t=this.identifierHandler(e);break;case"AssignmentExpression":t=this.assignmentExpressionHandler(e);break;case"FunctionDeclaration":t=this.functionDeclarationHandler(e);break;case"VariableDeclaration":t=this.variableDeclarationHandler(e);break;case"BlockStatement":case"Program":t=this.programHandler(e);break;case"ExpressionStatement":t=this.expressionStatementHandler(e);break;case"EmptyStatement":t=this.emptyStatementHandler(e);break;case"ReturnStatement":t=this.returnStatementHandler(e);break;case"FunctionExpression":t=this.functionExpressionHandler(e);break;case"IfStatement":t=this.ifStatementHandler(e);break;case"ConditionalExpression":t=this.conditionalExpressionHandler(e);break;case"ForStatement":t=this.forStatementHandler(e);break;case"WhileStatement":t=this.whileStatementHandler(e);break;case"DoWhileStatement":t=this.doWhileStatementHandler(e);break;case"ForInStatement":t=this.forInStatementHandler(e);break;case"WithStatement":t=this.withStatementHandler(e);break;case"ThrowStatement":t=this.throwStatementHandler(e);break;case"TryStatement":t=this.tryStatementHandler(e);break;case"ContinueStatement":t=this.continueStatementHandler(e);break;case"BreakStatement":t=this.breakStatementHandler(e);break;case"SwitchStatement":t=this.switchStatementHandler(e);break;case"LabeledStatement":t=this.labeledStatementHandler(e);break;case"DebuggerStatement":t=this.debuggerStatementHandler(e);break;default:throw this.createInternalThrowError(i.NodeTypeSyntaxError,e.type,e)}return(...r)=>{const n=this.options.timeout;if(n&&n>0&&this.checkTimeout())throw this.createInternalThrowError(i.ExecutionTimeOutError,n,null);return this.lastExecNode=e,t(...r)}}binaryExpressionHandler(e){const t=this.createClosure(e.left),r=this.createClosure(e.right);return()=>{const n=t(),a=r();switch(e.operator){case"==":return n==a;case"!=":return n!=a;case"===":return n===a;case"!==":return n!==a;case"<":return n<a;case"<=":return n<=a;case">":return n>a;case">=":return n>=a;case"<<":return n<<a;case">>":return n>>a;case">>>":return n>>>a;case"+":return n+a;case"-":return n-a;case"*":return n*a;case"**":return Math.pow(n,a);case"/":return n/a;case"%":return n%a;case"|":return n|a;case"^":return n^a;case"&":return n&a;case"in":return n in a;case"instanceof":return n instanceof a;default:throw this.createInternalThrowError(i.BinaryOperatorSyntaxError,e.operator,e)}}}logicalExpressionHandler(e){const t=this.createClosure(e.left),r=this.createClosure(e.right);return()=>{switch(e.operator){case"||":return t()||r();case"&&":return t()&&r();default:throw this.createInternalThrowError(i.LogicalOperatorSyntaxError,e.operator,e)}}}unaryExpressionHandler(e){if("delete"===e.operator){const t=this.createObjectGetter(e.argument),r=this.createNameGetter(e.argument);return()=>delete t()[r()]}{let t;if("typeof"===e.operator&&"Identifier"===e.argument.type){const r=this.createObjectGetter(e.argument),n=this.createNameGetter(e.argument);t=()=>r()[n()]}else t=this.createClosure(e.argument);return()=>{const r=t();switch(e.operator){case"-":return-r;case"+":return+r;case"!":return!r;case"~":return~r;case"void":return;case"typeof":return typeof r;default:throw this.createInternalThrowError(i.UnaryOperatorSyntaxError,e.operator,e)}}}}updateExpressionHandler(e){const t=this.createObjectGetter(e.argument),r=this.createNameGetter(e.argument);return()=>{const n=t(),a=r();switch(this.assertVariable(n,a,e),e.operator){case"++":return e.prefix?++n[a]:n[a]++;case"--":return e.prefix?--n[a]:n[a]--;default:throw this.createInternalThrowError(i.UpdateOperatorSyntaxError,e.operator,e)}}}objectExpressionHandler(e){const t=[];const r=Object.create(null);return e.properties.forEach((e=>{const n=e.kind,a=function(e){return"Identifier"===e.type?e.name:"Literal"===e.type?e.value:this.throwError(i.ObjectStructureSyntaxError,e.type,e)}(e.key);r[a]&&"init"!==n||(r[a]={}),r[a][n]=this.createClosure(e.value),t.push({key:a,property:e})})),()=>{const e={},n=t.length;for(let a=0;a<n;a++){const n=t[a],s=n.key,o=r[s],i=o.init?o.init():void 0,l=o.get?o.get():function(){},u=o.set?o.set():function(e){};if("set"in o||"get"in o){const t={configurable:!0,enumerable:!0,get:l,set:u};Object.defineProperty(e,s,t)}else{const t=n.property,r=t.kind;"Identifier"!==t.key.type||"FunctionExpression"!==t.value.type||"init"!==r||t.value.id||c(i,t.key.name),e[s]=i}}return e}}arrayExpressionHandler(e){const t=e.elements.map((e=>e?this.createClosure(e):e));return()=>{const e=t.length,r=Array(e);for(let n=0;n<e;n++){const e=t[n];e&&(r[n]=e())}return r}}safeObjectGet(e,t,r){return e[t]}createCallFunctionGetter(e){if("MemberExpression"===e.type){const t=this.createClosure(e.object),r=this.createMemberKeyGetter(e),n=this.source;return()=>{const a=t(),s=r(),o=this.safeObjectGet(a,s,e);if(!o||!y(o)){const t=n.slice(e.start,e.end);throw this.createInternalThrowError(i.FunctionUndefinedReferenceError,t,e)}return o.bind(a)}}{const t=this.createClosure(e);return()=>{let r="";"Identifier"===e.type&&(r=e.name);const n=t();if(!n||!y(n))throw this.createInternalThrowError(i.FunctionUndefinedReferenceError,r,e);let a=this.options.globalContextInFunction;if("Identifier"===e.type){const t=this.getIdentifierScope(e);t.name===m&&(a=t.data)}return n.bind(a)}}}callExpressionHandler(e){const t=this.createCallFunctionGetter(e.callee),r=e.arguments.map((e=>this.createClosure(e)));return()=>t()(...r.map((e=>e())))}functionExpressionHandler(e){const t=this,r=this.source,n=this.collectDeclVars,a=this.collectDeclFuncs;this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null);const s=e.id?e.id.name:"",o=e.params.length,i=e.params.map((e=>this.createParamNameGetter(e))),l=this.createClosure(e.body),u=this.collectDeclVars,h=this.collectDeclFuncs;return this.collectDeclVars=n,this.collectDeclFuncs=a,()=>{const n=t.getCurrentScope(),a=function(...e){t.callStack.push(`${s}`);const r=t.getCurrentScope(),o=function(e=null,t){return new C(Object.create(null),e,t)}(n,`FunctionScope(${s})`);t.setCurrentScope(o),t.addDeclarationsToScope(u,h,o),s&&(o.data[s]=a),o.data.arguments=arguments,i.forEach(((t,r)=>{o.data[t()]=e[r]}));const c=t.getCurrentContext();t.setCurrentContext(this);const p=l();if(t.setCurrentContext(c),t.setCurrentScope(r),t.callStack.pop(),p instanceof x)return p.value};return c(a,s),Object.defineProperty(a,"length",{value:o,writable:!1,enumerable:!1,configurable:!0}),Object.defineProperty(a,"toString",{value:()=>r.slice(e.start,e.end),writable:!0,configurable:!0,enumerable:!1}),Object.defineProperty(a,"valueOf",{value:()=>r.slice(e.start,e.end),writable:!0,configurable:!0,enumerable:!1}),a}}newExpressionHandler(e){const t=this.source,r=this.createClosure(e.callee),n=e.arguments.map((e=>this.createClosure(e)));return()=>{const a=r();if(!y(a)||a.__IS_EVAL_FUNC){const r=e.callee,n=t.slice(r.start,r.end);throw this.createInternalThrowError(i.IsNotConstructor,n,e)}return new a(...n.map((e=>e())))}}memberExpressionHandler(e){const t=this.createClosure(e.object),r=this.createMemberKeyGetter(e);return()=>t()[r()]}thisExpressionHandler(e){return()=>this.getCurrentContext()}sequenceExpressionHandler(e){const t=e.expressions.map((e=>this.createClosure(e)));return()=>{let e;const r=t.length;for(let n=0;n<r;n++){e=(0,t[n])()}return e}}literalHandler(e){return()=>e.regex?new RegExp(e.regex.pattern,e.regex.flags):e.value}identifierHandler(e){return()=>{const t=this.getCurrentScope(),r=this.getScopeDataFromName(e.name,t);return this.assertVariable(r,e.name,e),r[e.name]}}getIdentifierScope(e){const t=this.getCurrentScope();return this.getScopeFromName(e.name,t)}assignmentExpressionHandler(e){"Identifier"!==e.left.type||"FunctionExpression"!==e.right.type||e.right.id||(e.right.id={type:"Identifier",name:e.left.name});const t=this.createObjectGetter(e.left),r=this.createNameGetter(e.left),n=this.createClosure(e.right);return()=>{const a=t(),s=r(),o=n();switch("="!==e.operator&&this.assertVariable(a,s,e),e.operator){case"=":return a[s]=o;case"+=":return a[s]+=o;case"-=":return a[s]-=o;case"*=":return a[s]*=o;case"**=":return a[s]=Math.pow(a[s],o);case"/=":return a[s]/=o;case"%=":return a[s]%=o;case"<<=":return a[s]<<=o;case">>=":return a[s]>>=o;case">>>=":return a[s]>>>=o;case"&=":return a[s]&=o;case"^=":return a[s]^=o;case"|=":return a[s]|=o;default:throw this.createInternalThrowError(i.AssignmentExpressionSyntaxError,e.type,e)}}}functionDeclarationHandler(e){if(e.id){const t=this.functionExpressionHandler(e);Object.defineProperty(t,"isFunctionDeclareClosure",{value:!0,writable:!1,configurable:!1,enumerable:!1}),this.funcDeclaration(e.id.name,t)}return()=>d}getVariableName(e){if("Identifier"===e.type)return e.name;throw this.createInternalThrowError(i.VariableTypeSyntaxError,e.type,e)}variableDeclarationHandler(e){let t;const r=[];for(let t=0;t<e.declarations.length;t++){const n=e.declarations[t];this.varDeclaration(this.getVariableName(n.id)),n.init&&r.push({type:"AssignmentExpression",operator:"=",left:n.id,right:n.init})}return r.length&&(t=this.createClosure({type:"BlockStatement",body:r})),()=>{if(t){const e=this.isVarDeclMode;this.isVarDeclMode=!0,t(),this.isVarDeclMode=e}return d}}assertVariable(e,t,r){if(e===this.globalScope.data&&!(t in e))throw this.createInternalThrowError(i.VariableUndefinedReferenceError,t,r)}programHandler(e){const t=e.body.map((e=>this.createClosure(e)));return()=>{let e=d;for(let r=0;r<t.length;r++){const n=t[r],a=this.setValue(n());if(a!==d&&(e=a,e instanceof x||e instanceof E||e instanceof g||e===u||e===h))break}return e}}expressionStatementHandler(e){return this.createClosure(e.expression)}emptyStatementHandler(e){return()=>d}returnStatementHandler(e){const t=e.argument?this.createClosure(e.argument):w;return()=>new x(t())}ifStatementHandler(e){const t=this.createClosure(e.test),r=this.createClosure(e.consequent),n=e.alternate?this.createClosure(e.alternate):/*!important*/()=>d;return()=>t()?r():n()}conditionalExpressionHandler(e){return this.ifStatementHandler(e)}forStatementHandler(e){let t=w,r=e.test?this.createClosure(e.test):()=>!0,n=w;const a=this.createClosure(e.body);return"ForStatement"===e.type&&(t=e.init?this.createClosure(e.init):t,n=e.update?this.createClosure(e.update):w),s=>{let o,i=d,c="DoWhileStatement"===e.type;for(s&&"LabeledStatement"===s.type&&(o=s.label.name),t();c||r();n()){c=!1;const e=this.setValue(a());if(e!==d&&e!==h){if(e===u)break;if(i=e,i instanceof g&&i.value===o)i=d;else if(i instanceof x||i instanceof E||i instanceof g)break}}return i}}whileStatementHandler(e){return this.forStatementHandler(e)}doWhileStatementHandler(e){return this.forStatementHandler(e)}forInStatementHandler(e){let t=e.left;const r=this.createClosure(e.right),n=this.createClosure(e.body);return"VariableDeclaration"===e.left.type&&(this.createClosure(e.left)(),t=e.left.declarations[0].id),e=>{let a,s,o=d;e&&"LabeledStatement"===e.type&&(a=e.label.name);const i=r();for(s in i){this.assignmentExpressionHandler({type:"AssignmentExpression",operator:"=",left:t,right:{type:"Literal",value:s}})();const e=this.setValue(n());if(e!==d&&e!==h){if(e===u)break;if(o=e,o instanceof g&&o.value===a)o=d;else if(o instanceof x||o instanceof E||o instanceof g)break}}return o}}withStatementHandler(e){const t=this.createClosure(e.object),r=this.createClosure(e.body);return()=>{const e=t(),n=this.getCurrentScope(),a=new C(e,n,m);this.setCurrentScope(a);const s=this.setValue(r());return this.setCurrentScope(n),s}}throwStatementHandler(e){const t=this.createClosure(e.argument);return()=>{throw this.setValue(void 0),t()}}tryStatementHandler(e){const t=this.createClosure(e.block),r=e.handler?this.catchClauseHandler(e.handler):null,n=e.finalizer?this.createClosure(e.finalizer):null;return()=>{const e=this.getCurrentScope(),a=this.getCurrentContext(),s=e.labelStack.concat([]),o=this.callStack.concat([]);let i,c,l=d;const u=()=>{this.setCurrentScope(e),this.setCurrentContext(a),e.labelStack=s,this.callStack=o};try{l=this.setValue(t()),l instanceof x&&(i=l)}catch(e){if(u(),this.isInterruptThrow(e))throw e;if(r)try{l=this.setValue(r(e)),l instanceof x&&(i=l)}catch(e){if(u(),this.isInterruptThrow(e))throw e;c=e}}if(n)try{l=n(),l instanceof x&&(i=l)}catch(e){if(u(),this.isInterruptThrow(e))throw e;c=e}if(c)throw c;return i||l}}catchClauseHandler(e){const t=this.createParamNameGetter(e.param),r=this.createClosure(e.body);return e=>{let n;const a=this.getCurrentScope().data,s=t(),o=l.call(a,s),i=a[s];return a[s]=e,n=r(),o?a[s]=i:delete a[s],n}}continueStatementHandler(e){return()=>e.label?new g(e.label.name):h}breakStatementHandler(e){return()=>e.label?new E(e.label.name):u}switchStatementHandler(e){const t=this.createClosure(e.discriminant),r=e.cases.map((e=>this.switchCaseHandler(e)));return()=>{const e=t();let n,a,s,o=!1;for(let t=0;t<r.length;t++){const i=r[t](),c=i.testClosure();if(c!==p){if(o||c===e){if(o=!0,a=this.setValue(i.bodyClosure()),a===d)continue;if(a===u)break;if(n=a,n instanceof x||n instanceof E||n instanceof g||n===h)break}}else s=i}if(!o&&s){a=this.setValue(s.bodyClosure());a===d||a===u||(n=a)}return n}}switchCaseHandler(e){const t=e.test?this.createClosure(e.test):()=>p,r=this.createClosure({type:"BlockStatement",body:e.consequent});return()=>({testClosure:t,bodyClosure:r})}labeledStatementHandler(e){const t=e.label.name,r=this.createClosure(e.body);return()=>{let n;const a=this.getCurrentScope();return a.labelStack.push(t),n=r(e),n instanceof E&&n.value===t&&(n=d),a.labelStack.pop(),n}}debuggerStatementHandler(e){return()=>d}createParamNameGetter(e){if("Identifier"===e.type)return()=>e.name;throw this.createInternalThrowError(i.ParamTypeSyntaxError,e.type,e)}createObjectKeyGetter(e){let t;return t="Identifier"===e.type?()=>e.name:this.createClosure(e),function(){return t()}}createMemberKeyGetter(e){return e.computed?this.createClosure(e.property):this.createObjectKeyGetter(e.property)}createObjectGetter(e){switch(e.type){case"Identifier":return()=>this.getScopeDataFromName(e.name,this.getCurrentScope());case"MemberExpression":return this.createClosure(e.object);default:throw this.createInternalThrowError(i.AssignmentTypeSyntaxError,e.type,e)}}createNameGetter(e){switch(e.type){case"Identifier":return()=>e.name;case"MemberExpression":return this.createMemberKeyGetter(e);default:throw this.createInternalThrowError(i.AssignmentTypeSyntaxError,e.type,e)}}varDeclaration(e){this.collectDeclVars[e]=void 0}funcDeclaration(e,t){this.collectDeclFuncs[e]=t}addDeclarationsToScope(e,t,r){const n=r.data;for(let e in t){const r=t[e];n[e]=r?r():r}for(let t in e)t in n||(n[t]=void 0)}getScopeValue(e,t){return this.getScopeFromName(e,t).data[e]}getScopeDataFromName(e,t){return this.getScopeFromName(e,t).data}getScopeFromName(e,t){let r=t;do{if(e in r.data)return r}while(r=r.parent);return this.globalScope}setValue(e){const t=this.callStack.length;return this.isVarDeclMode||t||e===d||e===u||e===h||e instanceof E||e instanceof g||(this.value=e instanceof x?e.value:e),e}getValue(){return this.value}}exports.Interpreter=H;
"use strict";var e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},e(t,r)};function t(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}var r=function(){return r=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var a in t=arguments[r])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e},r.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var n=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),r}(Error),a=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),r}(SyntaxError),o=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),r}(ReferenceError),i=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),r}(TypeError),c=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),r}(n),s=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),r}(a),u=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),r}(o),l={UnknownError:[3001,"%0",c],ExecutionTimeOutError:[3002,"Script execution timed out after %0ms",c],NodeTypeSyntaxError:[1001,"Unknown node type: %0",u],BinaryOperatorSyntaxError:[1002,"Unknown binary operator: %0",u],LogicalOperatorSyntaxError:[1003,"Unknown logical operator: %0",u],UnaryOperatorSyntaxError:[1004,"Unknown unary operator: %0",u],UpdateOperatorSyntaxError:[1005,"Unknown update operator: %0",u],ObjectStructureSyntaxError:[1006,"Unknown object structure: %0",u],AssignmentExpressionSyntaxError:[1007,"Unknown assignment expression: %0",u],VariableTypeSyntaxError:[1008,"Unknown variable type: %0",u],ParamTypeSyntaxError:[1009,"Unknown param type: %0",u],AssignmentTypeSyntaxError:[1010,"Unknown assignment type: %0",u],FunctionUndefinedReferenceError:[2001,"%0 is not a function",o],VariableUndefinedReferenceError:[2002,"%0 is not defined",o],IsNotConstructor:[2003,"%0 is not a constructor",i]};function p(e,t){Object.defineProperty(e,"name",{value:t,writable:!1,enumerable:!1,configurable:!0})}var f=Object.prototype.hasOwnProperty,h=Symbol("Break"),d=Symbol("Continue"),y=Symbol("DefaultCase"),m=Symbol("EmptyStatementReturn"),b=Symbol("WithScopeName"),S=Symbol("SuperScopeName"),v=Symbol("RootScopeName"),E=Symbol("GlobalScopeName");function g(e){return"function"==typeof e}var x=function(e){this.value=e},C=function(e){this.value=e},w=function(e){this.value=e},k=function(e,t,r){void 0===t&&(t=null),this.name=r,this.parent=t,this.data=e,this.labelStack=[]};function H(){}var I={NaN:NaN,Infinity:1/0,undefined:void 0,Object:Object,Array:Array,String:String,Boolean:Boolean,Number:Number,Date:Date,RegExp:RegExp,Error:Error,URIError:URIError,TypeError:TypeError,RangeError:RangeError,SyntaxError:SyntaxError,ReferenceError:ReferenceError,Math:Math,parseInt:parseInt,parseFloat:parseFloat,isNaN:isNaN,isFinite:isFinite,decodeURI:decodeURI,decodeURIComponent:decodeURIComponent,encodeURI:encodeURI,encodeURIComponent:encodeURIComponent,escape:escape,unescape:unescape};"undefined"!=typeof JSON&&(I.JSON=JSON),"undefined"!=typeof Promise&&(I.Promise=Promise),"undefined"!=typeof Set&&(I.Set=Set),"undefined"!=typeof Map&&(I.Map=Map),"undefined"!=typeof Symbol&&(I.Symbol=Symbol),"undefined"!=typeof Proxy&&(I.Proxy=Proxy),"undefined"!=typeof WeakMap&&(I.WeakMap=WeakMap),"undefined"!=typeof WeakSet&&(I.WeakSet=WeakSet),"undefined"!=typeof Reflect&&(I.Reflect=Reflect);var O=function(){function e(t,r){void 0===t&&(t=e.global),void 0===r&&(r={}),this.sourceList=[],this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null),this.isVarDeclMode=!1,this.lastExecNode=null,this.isRunning=!1,this.options={timeout:r.timeout||0,rootContext:r.rootContext,globalContextInFunction:void 0===r.globalContextInFunction?e.globalContextInFunction:r.globalContextInFunction,_initEnv:r._initEnv},this.context=t||Object.create(null),this.callStack=[],this.initEnvironment(this.context)}return e.prototype.initEnvironment=function(e){var t,r;if(e instanceof k)t=e;else{var n=null,a=this.createSuperScope(e);this.options.rootContext&&(n=new k((r=this.options.rootContext,Object.create(r)),a,v)),t=new k(e,n||a,E)}this.globalScope=t,this.currentScope=this.globalScope,this.globalContext=t.data,this.currentContext=t.data,this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null),this.execStartTime=Date.now(),this.execEndTime=this.execStartTime;var o=this.options._initEnv;o&&o.call(this)},e.prototype.getExecStartTime=function(){return this.execStartTime},e.prototype.getExecutionTime=function(){return this.execEndTime-this.execStartTime},e.prototype.setExecTimeout=function(e){void 0===e&&(e=0),this.options.timeout=e},e.prototype.getOptions=function(){return this.options},e.prototype.getCurrentScope=function(){return this.currentScope},e.prototype.getCurrentContext=function(){return this.currentContext},e.prototype.isInterruptThrow=function(e){return e instanceof c||e instanceof u||e instanceof s},e.prototype.createSuperScope=function(e){var t=r({},I);return Object.keys(t).forEach((function(r){r in e&&delete t[r]})),new k(t,null,S)},e.prototype.setCurrentContext=function(e){this.currentContext=e},e.prototype.setCurrentScope=function(e){this.currentScope=e},e.prototype.evaluateNode=function(e,t){var r=this;void 0===t&&(t=""),this.value=void 0,this.source=t,this.sourceList.push(t),this.isRunning=!0,this.execStartTime=Date.now(),this.execEndTime=this.execStartTime,this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null);var n=this.getCurrentScope(),a=this.getCurrentContext(),o=n.labelStack.concat([]),i=this.callStack.concat([]);try{var c=this.createClosure(e);this.addDeclarationsToScope(this.collectDeclVars,this.collectDeclFuncs,this.getCurrentScope()),c()}catch(e){throw e}finally{r.setCurrentScope(n),r.setCurrentContext(a),n.labelStack=o,r.callStack=i,this.execEndTime=Date.now()}return this.isRunning=!1,this.getValue()},e.prototype.createErrorMessage=function(e,t,r){var n=e[1].replace("%0",String(t));return null!==r&&(n+=this.getNodePosition(r||this.lastExecNode)),n},e.prototype.createError=function(e,t){return new t(e)},e.prototype.createThrowError=function(e,t){return this.createError(e,t)},e.prototype.createInternalThrowError=function(e,t,r){return this.createError(this.createErrorMessage(e,t,r),e[2])},e.prototype.checkTimeout=function(){if(!this.isRunning)return!1;var e=this.options.timeout||0;return Date.now()-this.execStartTime>e},e.prototype.getNodePosition=function(e){if(e){return e.loc?" [".concat(e.loc.start.line,":").concat(e.loc.start.column,"]").concat(""):""}return""},e.prototype.createClosure=function(e){var t,r=this;switch(e.type){case"BinaryExpression":t=this.binaryExpressionHandler(e);break;case"LogicalExpression":t=this.logicalExpressionHandler(e);break;case"UnaryExpression":t=this.unaryExpressionHandler(e);break;case"UpdateExpression":t=this.updateExpressionHandler(e);break;case"ObjectExpression":t=this.objectExpressionHandler(e);break;case"ArrayExpression":t=this.arrayExpressionHandler(e);break;case"CallExpression":t=this.callExpressionHandler(e);break;case"NewExpression":t=this.newExpressionHandler(e);break;case"MemberExpression":t=this.memberExpressionHandler(e);break;case"ThisExpression":t=this.thisExpressionHandler(e);break;case"SequenceExpression":t=this.sequenceExpressionHandler(e);break;case"Literal":t=this.literalHandler(e);break;case"Identifier":t=this.identifierHandler(e);break;case"AssignmentExpression":t=this.assignmentExpressionHandler(e);break;case"FunctionDeclaration":t=this.functionDeclarationHandler(e);break;case"VariableDeclaration":t=this.variableDeclarationHandler(e);break;case"BlockStatement":case"Program":t=this.programHandler(e);break;case"ExpressionStatement":t=this.expressionStatementHandler(e);break;case"EmptyStatement":t=this.emptyStatementHandler(e);break;case"ReturnStatement":t=this.returnStatementHandler(e);break;case"FunctionExpression":t=this.functionExpressionHandler(e);break;case"IfStatement":t=this.ifStatementHandler(e);break;case"ConditionalExpression":t=this.conditionalExpressionHandler(e);break;case"ForStatement":t=this.forStatementHandler(e);break;case"WhileStatement":t=this.whileStatementHandler(e);break;case"DoWhileStatement":t=this.doWhileStatementHandler(e);break;case"ForInStatement":t=this.forInStatementHandler(e);break;case"WithStatement":t=this.withStatementHandler(e);break;case"ThrowStatement":t=this.throwStatementHandler(e);break;case"TryStatement":t=this.tryStatementHandler(e);break;case"ContinueStatement":t=this.continueStatementHandler(e);break;case"BreakStatement":t=this.breakStatementHandler(e);break;case"SwitchStatement":t=this.switchStatementHandler(e);break;case"LabeledStatement":t=this.labeledStatementHandler(e);break;case"DebuggerStatement":t=this.debuggerStatementHandler(e);break;default:throw this.createInternalThrowError(l.NodeTypeSyntaxError,e.type,e)}return function(){for(var n=[],a=0;a<arguments.length;a++)n[a]=arguments[a];var o=r.options.timeout;if(o&&o>0&&r.checkTimeout())throw r.createInternalThrowError(l.ExecutionTimeOutError,o,null);return r.lastExecNode=e,t.apply(void 0,n)}},e.prototype.binaryExpressionHandler=function(e){var t=this,r=this.createClosure(e.left),n=this.createClosure(e.right);return function(){var a=r(),o=n();switch(e.operator){case"==":return a==o;case"!=":return a!=o;case"===":return a===o;case"!==":return a!==o;case"<":return a<o;case"<=":return a<=o;case">":return a>o;case">=":return a>=o;case"<<":return a<<o;case">>":return a>>o;case">>>":return a>>>o;case"+":return a+o;case"-":return a-o;case"*":return a*o;case"**":return Math.pow(a,o);case"/":return a/o;case"%":return a%o;case"|":return a|o;case"^":return a^o;case"&":return a&o;case"in":return a in o;case"instanceof":return a instanceof o;default:throw t.createInternalThrowError(l.BinaryOperatorSyntaxError,e.operator,e)}}},e.prototype.logicalExpressionHandler=function(e){var t=this,r=this.createClosure(e.left),n=this.createClosure(e.right);return function(){switch(e.operator){case"||":return r()||n();case"&&":return r()&&n();default:throw t.createInternalThrowError(l.LogicalOperatorSyntaxError,e.operator,e)}}},e.prototype.unaryExpressionHandler=function(e){var t,r=this;if("delete"===e.operator){var n=this.createObjectGetter(e.argument),a=this.createNameGetter(e.argument);return function(){return delete n()[a()]}}if("typeof"===e.operator&&"Identifier"===e.argument.type){var o=this.createObjectGetter(e.argument),i=this.createNameGetter(e.argument);t=function(){return o()[i()]}}else t=this.createClosure(e.argument);return function(){var n=t();switch(e.operator){case"-":return-n;case"+":return+n;case"!":return!n;case"~":return~n;case"void":return;case"typeof":return typeof n;default:throw r.createInternalThrowError(l.UnaryOperatorSyntaxError,e.operator,e)}}},e.prototype.updateExpressionHandler=function(e){var t=this,r=this.createObjectGetter(e.argument),n=this.createNameGetter(e.argument);return function(){var a=r(),o=n();switch(t.assertVariable(a,o,e),e.operator){case"++":return e.prefix?++a[o]:a[o]++;case"--":return e.prefix?--a[o]:a[o]--;default:throw t.createInternalThrowError(l.UpdateOperatorSyntaxError,e.operator,e)}}},e.prototype.objectExpressionHandler=function(e){var t=this,r=[];var n=Object.create(null);return e.properties.forEach((function(e){var a=e.kind,o=function(e){return"Identifier"===e.type?e.name:"Literal"===e.type?e.value:this.throwError(l.ObjectStructureSyntaxError,e.type,e)}(e.key);n[o]&&"init"!==a||(n[o]={}),n[o][a]=t.createClosure(e.value),r.push({key:o,property:e})})),function(){for(var e={},t=r.length,a=0;a<t;a++){var o=r[a],i=o.key,c=n[i],s=c.init?c.init():void 0,u=c.get?c.get():function(){},l=c.set?c.set():function(e){};if("set"in c||"get"in c){var f={configurable:!0,enumerable:!0,get:u,set:l};Object.defineProperty(e,i,f)}else{var h=o.property,d=h.kind;"Identifier"!==h.key.type||"FunctionExpression"!==h.value.type||"init"!==d||h.value.id||p(s,h.key.name),e[i]=s}}return e}},e.prototype.arrayExpressionHandler=function(e){var t=this,r=e.elements.map((function(e){return e?t.createClosure(e):e}));return function(){for(var e=r.length,t=Array(e),n=0;n<e;n++){var a=r[n];a&&(t[n]=a())}return t}},e.prototype.safeObjectGet=function(e,t,r){return e[t]},e.prototype.createCallFunctionGetter=function(e){var t=this;if("MemberExpression"===e.type){var r=this.createClosure(e.object),n=this.createMemberKeyGetter(e),a=this.source;return function(){var o=r(),i=n(),c=t.safeObjectGet(o,i,e);if(!c||!g(c)){var s=a.slice(e.start,e.end);throw t.createInternalThrowError(l.FunctionUndefinedReferenceError,s,e)}return c.bind(o)}}var o=this.createClosure(e);return function(){var r="";"Identifier"===e.type&&(r=e.name);var n=o();if(!n||!g(n))throw t.createInternalThrowError(l.FunctionUndefinedReferenceError,r,e);var a=t.options.globalContextInFunction;if("Identifier"===e.type){var i=t.getIdentifierScope(e);i.name===b&&(a=i.data)}return n.bind(a)}},e.prototype.callExpressionHandler=function(e){var t=this,r=this.createCallFunctionGetter(e.callee),n=e.arguments.map((function(e){return t.createClosure(e)}));return function(){return r().apply(void 0,n.map((function(e){return e()})))}},e.prototype.functionExpressionHandler=function(e){var t=this,r=this,n=this.source,a=this.collectDeclVars,o=this.collectDeclFuncs;this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null);var i=e.id?e.id.name:"",c=e.params.length,s=e.params.map((function(e){return t.createParamNameGetter(e)})),u=this.createClosure(e.body),l=this.collectDeclVars,f=this.collectDeclFuncs;return this.collectDeclVars=a,this.collectDeclFuncs=o,function(){var t=r.getCurrentScope(),a=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];r.callStack.push("".concat(i));var o=r.getCurrentScope(),c=function(e,t){return void 0===e&&(e=null),new k(Object.create(null),e,t)}(t,"FunctionScope(".concat(i,")"));r.setCurrentScope(c),r.addDeclarationsToScope(l,f,c),i&&(c.data[i]=a),c.data.arguments=arguments,s.forEach((function(t,r){c.data[t()]=e[r]}));var p=r.getCurrentContext();r.setCurrentContext(this);var h=u();if(r.setCurrentContext(p),r.setCurrentScope(o),r.callStack.pop(),h instanceof x)return h.value};return p(a,i),Object.defineProperty(a,"length",{value:c,writable:!1,enumerable:!1,configurable:!0}),Object.defineProperty(a,"toString",{value:function(){return n.slice(e.start,e.end)},writable:!0,configurable:!0,enumerable:!1}),Object.defineProperty(a,"valueOf",{value:function(){return n.slice(e.start,e.end)},writable:!0,configurable:!0,enumerable:!1}),a}},e.prototype.newExpressionHandler=function(e){var t=this,r=this.source,n=this.createClosure(e.callee),a=e.arguments.map((function(e){return t.createClosure(e)}));return function(){var o=n();if(!g(o)||o.__IS_EVAL_FUNC){var i=e.callee,c=r.slice(i.start,i.end);throw t.createInternalThrowError(l.IsNotConstructor,c,e)}return new(o.bind.apply(o,function(e,t,r){if(r||2===arguments.length)for(var n,a=0,o=t.length;a<o;a++)!n&&a in t||(n||(n=Array.prototype.slice.call(t,0,a)),n[a]=t[a]);return e.concat(n||Array.prototype.slice.call(t))}([void 0],a.map((function(e){return e()})),!1)))}},e.prototype.memberExpressionHandler=function(e){var t=this.createClosure(e.object),r=this.createMemberKeyGetter(e);return function(){return t()[r()]}},e.prototype.thisExpressionHandler=function(e){var t=this;return function(){return t.getCurrentContext()}},e.prototype.sequenceExpressionHandler=function(e){var t=this,r=e.expressions.map((function(e){return t.createClosure(e)}));return function(){for(var e,t=r.length,n=0;n<t;n++){e=(0,r[n])()}return e}},e.prototype.literalHandler=function(e){return function(){return e.regex?new RegExp(e.regex.pattern,e.regex.flags):e.value}},e.prototype.identifierHandler=function(e){var t=this;return function(){var r=t.getCurrentScope(),n=t.getScopeDataFromName(e.name,r);return t.assertVariable(n,e.name,e),n[e.name]}},e.prototype.getIdentifierScope=function(e){var t=this.getCurrentScope();return this.getScopeFromName(e.name,t)},e.prototype.assignmentExpressionHandler=function(e){var t=this;"Identifier"!==e.left.type||"FunctionExpression"!==e.right.type||e.right.id||(e.right.id={type:"Identifier",name:e.left.name});var r=this.createObjectGetter(e.left),n=this.createNameGetter(e.left),a=this.createClosure(e.right);return function(){var o=r(),i=n(),c=a();switch("="!==e.operator&&t.assertVariable(o,i,e),e.operator){case"=":return o[i]=c;case"+=":return o[i]+=c;case"-=":return o[i]-=c;case"*=":return o[i]*=c;case"**=":return o[i]=Math.pow(o[i],c);case"/=":return o[i]/=c;case"%=":return o[i]%=c;case"<<=":return o[i]<<=c;case">>=":return o[i]>>=c;case">>>=":return o[i]>>>=c;case"&=":return o[i]&=c;case"^=":return o[i]^=c;case"|=":return o[i]|=c;default:throw t.createInternalThrowError(l.AssignmentExpressionSyntaxError,e.type,e)}}},e.prototype.functionDeclarationHandler=function(e){if(e.id){var t=this.functionExpressionHandler(e);Object.defineProperty(t,"isFunctionDeclareClosure",{value:!0,writable:!1,configurable:!1,enumerable:!1}),this.funcDeclaration(e.id.name,t)}return function(){return m}},e.prototype.getVariableName=function(e){if("Identifier"===e.type)return e.name;throw this.createInternalThrowError(l.VariableTypeSyntaxError,e.type,e)},e.prototype.variableDeclarationHandler=function(e){for(var t,r=this,n=[],a=0;a<e.declarations.length;a++){var o=e.declarations[a];this.varDeclaration(this.getVariableName(o.id)),o.init&&n.push({type:"AssignmentExpression",operator:"=",left:o.id,right:o.init})}return n.length&&(t=this.createClosure({type:"BlockStatement",body:n})),function(){if(t){var e=r.isVarDeclMode;r.isVarDeclMode=!0,t(),r.isVarDeclMode=e}return m}},e.prototype.assertVariable=function(e,t,r){if(e===this.globalScope.data&&!(t in e))throw this.createInternalThrowError(l.VariableUndefinedReferenceError,t,r)},e.prototype.programHandler=function(e){var t=this,r=e.body.map((function(e){return t.createClosure(e)}));return function(){for(var e=m,n=0;n<r.length;n++){var a=r[n],o=t.setValue(a());if(o!==m&&((e=o)instanceof x||e instanceof C||e instanceof w||e===h||e===d))break}return e}},e.prototype.expressionStatementHandler=function(e){return this.createClosure(e.expression)},e.prototype.emptyStatementHandler=function(e){return function(){return m}},e.prototype.returnStatementHandler=function(e){var t=e.argument?this.createClosure(e.argument):H;return function(){return new x(t())}},e.prototype.ifStatementHandler=function(e){var t=this.createClosure(e.test),r=this.createClosure(e.consequent),n=e.alternate?this.createClosure(e.alternate):/*!important*/function(){return m};return function(){return t()?r():n()}},e.prototype.conditionalExpressionHandler=function(e){return this.ifStatementHandler(e)},e.prototype.forStatementHandler=function(e){var t=this,r=H,n=e.test?this.createClosure(e.test):function(){return!0},a=H,o=this.createClosure(e.body);return"ForStatement"===e.type&&(r=e.init?this.createClosure(e.init):r,a=e.update?this.createClosure(e.update):H),function(i){var c,s=m,u="DoWhileStatement"===e.type;for(i&&"LabeledStatement"===i.type&&(c=i.label.name),r();u||n();a()){u=!1;var l=t.setValue(o());if(l!==m&&l!==d){if(l===h)break;if((s=l)instanceof w&&s.value===c)s=m;else if(s instanceof x||s instanceof C||s instanceof w)break}}return s}},e.prototype.whileStatementHandler=function(e){return this.forStatementHandler(e)},e.prototype.doWhileStatementHandler=function(e){return this.forStatementHandler(e)},e.prototype.forInStatementHandler=function(e){var t=this,r=e.left,n=this.createClosure(e.right),a=this.createClosure(e.body);return"VariableDeclaration"===e.left.type&&(this.createClosure(e.left)(),r=e.left.declarations[0].id),function(e){var o,i,c=m;e&&"LabeledStatement"===e.type&&(o=e.label.name);var s=n();for(i in s){t.assignmentExpressionHandler({type:"AssignmentExpression",operator:"=",left:r,right:{type:"Literal",value:i}})();var u=t.setValue(a());if(u!==m&&u!==d){if(u===h)break;if((c=u)instanceof w&&c.value===o)c=m;else if(c instanceof x||c instanceof C||c instanceof w)break}}return c}},e.prototype.withStatementHandler=function(e){var t=this,r=this.createClosure(e.object),n=this.createClosure(e.body);return function(){var e=r(),a=t.getCurrentScope(),o=new k(e,a,b);t.setCurrentScope(o);var i=t.setValue(n());return t.setCurrentScope(a),i}},e.prototype.throwStatementHandler=function(e){var t=this,r=this.createClosure(e.argument);return function(){throw t.setValue(void 0),r()}},e.prototype.tryStatementHandler=function(e){var t=this,r=this.createClosure(e.block),n=e.handler?this.catchClauseHandler(e.handler):null,a=e.finalizer?this.createClosure(e.finalizer):null;return function(){var e,o,i=t.getCurrentScope(),c=t.getCurrentContext(),s=i.labelStack.concat([]),u=t.callStack.concat([]),l=m,p=function(){t.setCurrentScope(i),t.setCurrentContext(c),i.labelStack=s,t.callStack=u};try{(l=t.setValue(r()))instanceof x&&(e=l)}catch(r){if(p(),t.isInterruptThrow(r))throw r;if(n)try{(l=t.setValue(n(r)))instanceof x&&(e=l)}catch(e){if(p(),t.isInterruptThrow(e))throw e;o=e}}if(a)try{(l=a())instanceof x&&(e=l)}catch(e){if(p(),t.isInterruptThrow(e))throw e;o=e}if(o)throw o;return e||l}},e.prototype.catchClauseHandler=function(e){var t=this,r=this.createParamNameGetter(e.param),n=this.createClosure(e.body);return function(e){var a,o=t.getCurrentScope().data,i=r(),c=f.call(o,i),s=o[i];return o[i]=e,a=n(),c?o[i]=s:delete o[i],a}},e.prototype.continueStatementHandler=function(e){return function(){return e.label?new w(e.label.name):d}},e.prototype.breakStatementHandler=function(e){return function(){return e.label?new C(e.label.name):h}},e.prototype.switchStatementHandler=function(e){var t=this,r=this.createClosure(e.discriminant),n=e.cases.map((function(e){return t.switchCaseHandler(e)}));return function(){for(var e,a,o,i=r(),c=!1,s=0;s<n.length;s++){var u=n[s](),l=u.testClosure();if(l!==y){if(c||l===i){if(c=!0,(a=t.setValue(u.bodyClosure()))===m)continue;if(a===h)break;if((e=a)instanceof x||e instanceof C||e instanceof w||e===d)break}}else o=u}!c&&o&&((a=t.setValue(o.bodyClosure()))===m||a===h||(e=a));return e}},e.prototype.switchCaseHandler=function(e){var t=e.test?this.createClosure(e.test):function(){return y},r=this.createClosure({type:"BlockStatement",body:e.consequent});return function(){return{testClosure:t,bodyClosure:r}}},e.prototype.labeledStatementHandler=function(e){var t=this,r=e.label.name,n=this.createClosure(e.body);return function(){var a,o=t.getCurrentScope();return o.labelStack.push(r),(a=n(e))instanceof C&&a.value===r&&(a=m),o.labelStack.pop(),a}},e.prototype.debuggerStatementHandler=function(e){return function(){return m}},e.prototype.createParamNameGetter=function(e){if("Identifier"===e.type)return function(){return e.name};throw this.createInternalThrowError(l.ParamTypeSyntaxError,e.type,e)},e.prototype.createObjectKeyGetter=function(e){var t;return t="Identifier"===e.type?function(){return e.name}:this.createClosure(e),function(){return t()}},e.prototype.createMemberKeyGetter=function(e){return e.computed?this.createClosure(e.property):this.createObjectKeyGetter(e.property)},e.prototype.createObjectGetter=function(e){var t=this;switch(e.type){case"Identifier":return function(){return t.getScopeDataFromName(e.name,t.getCurrentScope())};case"MemberExpression":return this.createClosure(e.object);default:throw this.createInternalThrowError(l.AssignmentTypeSyntaxError,e.type,e)}},e.prototype.createNameGetter=function(e){switch(e.type){case"Identifier":return function(){return e.name};case"MemberExpression":return this.createMemberKeyGetter(e);default:throw this.createInternalThrowError(l.AssignmentTypeSyntaxError,e.type,e)}},e.prototype.varDeclaration=function(e){this.collectDeclVars[e]=void 0},e.prototype.funcDeclaration=function(e,t){this.collectDeclFuncs[e]=t},e.prototype.addDeclarationsToScope=function(e,t,r){var n=r.data;for(var a in t){var o=t[a];n[a]=o?o():o}for(var a in e)a in n||(n[a]=void 0)},e.prototype.getScopeValue=function(e,t){return this.getScopeFromName(e,t).data[e]},e.prototype.getScopeDataFromName=function(e,t){return this.getScopeFromName(e,t).data},e.prototype.getScopeFromName=function(e,t){var r=t;do{if(e in r.data)return r}while(r=r.parent);return this.globalScope},e.prototype.setValue=function(e){var t=this.callStack.length;return this.isVarDeclMode||t||e===m||e===h||e===d||e instanceof C||e instanceof w||(this.value=e instanceof x?e.value:e),e},e.prototype.getValue=function(){return this.value},e.version="0.0.2",e.ecmaVersion=5,e.globalContextInFunction=void 0,e.global=Object.create(null),e}();exports.Interpreter=O;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

class e extends Error{}class t extends SyntaxError{}class r extends ReferenceError{}class n extends TypeError{}class a extends e{}class s extends t{}class o extends r{}const i={UnknownError:[3001,"%0",a],ExecutionTimeOutError:[3002,"Script execution timed out after %0ms",a],NodeTypeSyntaxError:[1001,"Unknown node type: %0",o],BinaryOperatorSyntaxError:[1002,"Unknown binary operator: %0",o],LogicalOperatorSyntaxError:[1003,"Unknown logical operator: %0",o],UnaryOperatorSyntaxError:[1004,"Unknown unary operator: %0",o],UpdateOperatorSyntaxError:[1005,"Unknown update operator: %0",o],ObjectStructureSyntaxError:[1006,"Unknown object structure: %0",o],AssignmentExpressionSyntaxError:[1007,"Unknown assignment expression: %0",o],VariableTypeSyntaxError:[1008,"Unknown variable type: %0",o],ParamTypeSyntaxError:[1009,"Unknown param type: %0",o],AssignmentTypeSyntaxError:[1010,"Unknown assignment type: %0",o],FunctionUndefinedReferenceError:[2001,"%0 is not a function",r],VariableUndefinedReferenceError:[2002,"%0 is not defined",r],IsNotConstructor:[2003,"%0 is not a constructor",n]};function c(e,t){Object.defineProperty(e,"name",{value:t,writable:!1,enumerable:!1,configurable:!0})}const l=Object.prototype.hasOwnProperty,u=Symbol("Break"),h=Symbol("Continue"),p=Symbol("DefaultCase"),d=Symbol("EmptyStatementReturn"),m=Symbol("WithScopeName"),f=Symbol("SuperScopeName"),b=Symbol("RootScopeName"),S=Symbol("GlobalScopeName");function y(e){return"function"==typeof e}class x{value;constructor(e){this.value=e}}class E{value;constructor(e){this.value=e}}class g{value;constructor(e){this.value=e}}class C{name;parent;data;labelStack;constructor(e,t=null,r){this.name=r,this.parent=t,this.data=e,this.labelStack=[]}}function w(){}const k={NaN:NaN,Infinity:1/0,undefined:void 0,Object:Object,Array:Array,String:String,Boolean:Boolean,Number:Number,Date:Date,RegExp:RegExp,Error:Error,URIError:URIError,TypeError:TypeError,RangeError:RangeError,SyntaxError:SyntaxError,ReferenceError:ReferenceError,Math:Math,parseInt:parseInt,parseFloat:parseFloat,isNaN:isNaN,isFinite:isFinite,decodeURI:decodeURI,decodeURIComponent:decodeURIComponent,encodeURI:encodeURI,encodeURIComponent:encodeURIComponent,escape:escape,unescape:unescape};"undefined"!=typeof JSON&&(k.JSON=JSON),"undefined"!=typeof Promise&&(k.Promise=Promise),"undefined"!=typeof Set&&(k.Set=Set),"undefined"!=typeof Map&&(k.Map=Map),"undefined"!=typeof Symbol&&(k.Symbol=Symbol),"undefined"!=typeof Proxy&&(k.Proxy=Proxy),"undefined"!=typeof WeakMap&&(k.WeakMap=WeakMap),"undefined"!=typeof WeakSet&&(k.WeakSet=WeakSet),"undefined"!=typeof Reflect&&(k.Reflect=Reflect);class H{static version="0.0.0";static ecmaVersion=5;static globalContextInFunction=void 0;static global=Object.create(null);value;context;globalContext;source;sourceList=[];currentScope;globalScope;currentContext;options;callStack;collectDeclVars=Object.create(null);collectDeclFuncs=Object.create(null);isVarDeclMode=!1;lastExecNode=null;isRunning=!1;execStartTime;execEndTime;constructor(e=H.global,t={}){this.options={timeout:t.timeout||0,rootContext:t.rootContext,globalContextInFunction:void 0===t.globalContextInFunction?H.globalContextInFunction:t.globalContextInFunction,_initEnv:t._initEnv},this.context=e||Object.create(null),this.callStack=[],this.initEnvironment(this.context)}initEnvironment(e){let t;if(e instanceof C)t=e;else{let n=null;const a=this.createSuperScope(e);this.options.rootContext&&(n=new C((r=this.options.rootContext,Object.create(r)),a,b)),t=new C(e,n||a,S)}var r;this.globalScope=t,this.currentScope=this.globalScope,this.globalContext=t.data,this.currentContext=t.data,this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null),this.execStartTime=Date.now(),this.execEndTime=this.execStartTime;const n=this.options._initEnv;n&&n.call(this)}getExecStartTime(){return this.execStartTime}getExecutionTime(){return this.execEndTime-this.execStartTime}setExecTimeout(e=0){this.options.timeout=e}getOptions(){return this.options}getCurrentScope(){return this.currentScope}getCurrentContext(){return this.currentContext}isInterruptThrow(e){return e instanceof a||e instanceof o||e instanceof s}createSuperScope(e){let t={...k};return Object.keys(t).forEach((r=>{r in e&&delete t[r]})),new C(t,null,f)}setCurrentContext(e){this.currentContext=e}setCurrentScope(e){this.currentScope=e}evaluateNode(e,t=""){this.value=void 0,this.source=t,this.sourceList.push(t),this.isRunning=!0,this.execStartTime=Date.now(),this.execEndTime=this.execStartTime,this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null);const r=this.getCurrentScope(),n=this.getCurrentContext(),a=r.labelStack.concat([]),s=this.callStack.concat([]),o=()=>{this.setCurrentScope(r),this.setCurrentContext(n),r.labelStack=a,this.callStack=s};try{const t=this.createClosure(e);this.addDeclarationsToScope(this.collectDeclVars,this.collectDeclFuncs,this.getCurrentScope()),t()}catch(e){throw e}finally{o(),this.execEndTime=Date.now()}return this.isRunning=!1,this.getValue()}createErrorMessage(e,t,r){let n=e[1].replace("%0",String(t));return null!==r&&(n+=this.getNodePosition(r||this.lastExecNode)),n}createError(e,t){return new t(e)}createThrowError(e,t){return this.createError(e,t)}createInternalThrowError(e,t,r){return this.createError(this.createErrorMessage(e,t,r),e[2])}checkTimeout(){if(!this.isRunning)return!1;const e=this.options.timeout||0;return Date.now()-this.execStartTime>e}getNodePosition(e){if(e){const t="";return e.loc?` [${e.loc.start.line}:${e.loc.start.column}]${t}`:""}return""}createClosure(e){let t;switch(e.type){case"BinaryExpression":t=this.binaryExpressionHandler(e);break;case"LogicalExpression":t=this.logicalExpressionHandler(e);break;case"UnaryExpression":t=this.unaryExpressionHandler(e);break;case"UpdateExpression":t=this.updateExpressionHandler(e);break;case"ObjectExpression":t=this.objectExpressionHandler(e);break;case"ArrayExpression":t=this.arrayExpressionHandler(e);break;case"CallExpression":t=this.callExpressionHandler(e);break;case"NewExpression":t=this.newExpressionHandler(e);break;case"MemberExpression":t=this.memberExpressionHandler(e);break;case"ThisExpression":t=this.thisExpressionHandler(e);break;case"SequenceExpression":t=this.sequenceExpressionHandler(e);break;case"Literal":t=this.literalHandler(e);break;case"Identifier":t=this.identifierHandler(e);break;case"AssignmentExpression":t=this.assignmentExpressionHandler(e);break;case"FunctionDeclaration":t=this.functionDeclarationHandler(e);break;case"VariableDeclaration":t=this.variableDeclarationHandler(e);break;case"BlockStatement":case"Program":t=this.programHandler(e);break;case"ExpressionStatement":t=this.expressionStatementHandler(e);break;case"EmptyStatement":t=this.emptyStatementHandler(e);break;case"ReturnStatement":t=this.returnStatementHandler(e);break;case"FunctionExpression":t=this.functionExpressionHandler(e);break;case"IfStatement":t=this.ifStatementHandler(e);break;case"ConditionalExpression":t=this.conditionalExpressionHandler(e);break;case"ForStatement":t=this.forStatementHandler(e);break;case"WhileStatement":t=this.whileStatementHandler(e);break;case"DoWhileStatement":t=this.doWhileStatementHandler(e);break;case"ForInStatement":t=this.forInStatementHandler(e);break;case"WithStatement":t=this.withStatementHandler(e);break;case"ThrowStatement":t=this.throwStatementHandler(e);break;case"TryStatement":t=this.tryStatementHandler(e);break;case"ContinueStatement":t=this.continueStatementHandler(e);break;case"BreakStatement":t=this.breakStatementHandler(e);break;case"SwitchStatement":t=this.switchStatementHandler(e);break;case"LabeledStatement":t=this.labeledStatementHandler(e);break;case"DebuggerStatement":t=this.debuggerStatementHandler(e);break;default:throw this.createInternalThrowError(i.NodeTypeSyntaxError,e.type,e)}return(...r)=>{const n=this.options.timeout;if(n&&n>0&&this.checkTimeout())throw this.createInternalThrowError(i.ExecutionTimeOutError,n,null);return this.lastExecNode=e,t(...r)}}binaryExpressionHandler(e){const t=this.createClosure(e.left),r=this.createClosure(e.right);return()=>{const n=t(),a=r();switch(e.operator){case"==":return n==a;case"!=":return n!=a;case"===":return n===a;case"!==":return n!==a;case"<":return n<a;case"<=":return n<=a;case">":return n>a;case">=":return n>=a;case"<<":return n<<a;case">>":return n>>a;case">>>":return n>>>a;case"+":return n+a;case"-":return n-a;case"*":return n*a;case"**":return Math.pow(n,a);case"/":return n/a;case"%":return n%a;case"|":return n|a;case"^":return n^a;case"&":return n&a;case"in":return n in a;case"instanceof":return n instanceof a;default:throw this.createInternalThrowError(i.BinaryOperatorSyntaxError,e.operator,e)}}}logicalExpressionHandler(e){const t=this.createClosure(e.left),r=this.createClosure(e.right);return()=>{switch(e.operator){case"||":return t()||r();case"&&":return t()&&r();default:throw this.createInternalThrowError(i.LogicalOperatorSyntaxError,e.operator,e)}}}unaryExpressionHandler(e){if("delete"===e.operator){const t=this.createObjectGetter(e.argument),r=this.createNameGetter(e.argument);return()=>delete t()[r()]}{let t;if("typeof"===e.operator&&"Identifier"===e.argument.type){const r=this.createObjectGetter(e.argument),n=this.createNameGetter(e.argument);t=()=>r()[n()]}else t=this.createClosure(e.argument);return()=>{const r=t();switch(e.operator){case"-":return-r;case"+":return+r;case"!":return!r;case"~":return~r;case"void":return;case"typeof":return typeof r;default:throw this.createInternalThrowError(i.UnaryOperatorSyntaxError,e.operator,e)}}}}updateExpressionHandler(e){const t=this.createObjectGetter(e.argument),r=this.createNameGetter(e.argument);return()=>{const n=t(),a=r();switch(this.assertVariable(n,a,e),e.operator){case"++":return e.prefix?++n[a]:n[a]++;case"--":return e.prefix?--n[a]:n[a]--;default:throw this.createInternalThrowError(i.UpdateOperatorSyntaxError,e.operator,e)}}}objectExpressionHandler(e){const t=[];const r=Object.create(null);return e.properties.forEach((e=>{const n=e.kind,a=function(e){return"Identifier"===e.type?e.name:"Literal"===e.type?e.value:this.throwError(i.ObjectStructureSyntaxError,e.type,e)}(e.key);r[a]&&"init"!==n||(r[a]={}),r[a][n]=this.createClosure(e.value),t.push({key:a,property:e})})),()=>{const e={},n=t.length;for(let a=0;a<n;a++){const n=t[a],s=n.key,o=r[s],i=o.init?o.init():void 0,l=o.get?o.get():function(){},u=o.set?o.set():function(e){};if("set"in o||"get"in o){const t={configurable:!0,enumerable:!0,get:l,set:u};Object.defineProperty(e,s,t)}else{const t=n.property,r=t.kind;"Identifier"!==t.key.type||"FunctionExpression"!==t.value.type||"init"!==r||t.value.id||c(i,t.key.name),e[s]=i}}return e}}arrayExpressionHandler(e){const t=e.elements.map((e=>e?this.createClosure(e):e));return()=>{const e=t.length,r=Array(e);for(let n=0;n<e;n++){const e=t[n];e&&(r[n]=e())}return r}}safeObjectGet(e,t,r){return e[t]}createCallFunctionGetter(e){if("MemberExpression"===e.type){const t=this.createClosure(e.object),r=this.createMemberKeyGetter(e),n=this.source;return()=>{const a=t(),s=r(),o=this.safeObjectGet(a,s,e);if(!o||!y(o)){const t=n.slice(e.start,e.end);throw this.createInternalThrowError(i.FunctionUndefinedReferenceError,t,e)}return o.bind(a)}}{const t=this.createClosure(e);return()=>{let r="";"Identifier"===e.type&&(r=e.name);const n=t();if(!n||!y(n))throw this.createInternalThrowError(i.FunctionUndefinedReferenceError,r,e);let a=this.options.globalContextInFunction;if("Identifier"===e.type){const t=this.getIdentifierScope(e);t.name===m&&(a=t.data)}return n.bind(a)}}}callExpressionHandler(e){const t=this.createCallFunctionGetter(e.callee),r=e.arguments.map((e=>this.createClosure(e)));return()=>t()(...r.map((e=>e())))}functionExpressionHandler(e){const t=this,r=this.source,n=this.collectDeclVars,a=this.collectDeclFuncs;this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null);const s=e.id?e.id.name:"",o=e.params.length,i=e.params.map((e=>this.createParamNameGetter(e))),l=this.createClosure(e.body),u=this.collectDeclVars,h=this.collectDeclFuncs;return this.collectDeclVars=n,this.collectDeclFuncs=a,()=>{const n=t.getCurrentScope(),a=function(...e){t.callStack.push(`${s}`);const r=t.getCurrentScope(),o=function(e=null,t){return new C(Object.create(null),e,t)}(n,`FunctionScope(${s})`);t.setCurrentScope(o),t.addDeclarationsToScope(u,h,o),s&&(o.data[s]=a),o.data.arguments=arguments,i.forEach(((t,r)=>{o.data[t()]=e[r]}));const c=t.getCurrentContext();t.setCurrentContext(this);const p=l();if(t.setCurrentContext(c),t.setCurrentScope(r),t.callStack.pop(),p instanceof x)return p.value};return c(a,s),Object.defineProperty(a,"length",{value:o,writable:!1,enumerable:!1,configurable:!0}),Object.defineProperty(a,"toString",{value:()=>r.slice(e.start,e.end),writable:!0,configurable:!0,enumerable:!1}),Object.defineProperty(a,"valueOf",{value:()=>r.slice(e.start,e.end),writable:!0,configurable:!0,enumerable:!1}),a}}newExpressionHandler(e){const t=this.source,r=this.createClosure(e.callee),n=e.arguments.map((e=>this.createClosure(e)));return()=>{const a=r();if(!y(a)||a.__IS_EVAL_FUNC){const r=e.callee,n=t.slice(r.start,r.end);throw this.createInternalThrowError(i.IsNotConstructor,n,e)}return new a(...n.map((e=>e())))}}memberExpressionHandler(e){const t=this.createClosure(e.object),r=this.createMemberKeyGetter(e);return()=>t()[r()]}thisExpressionHandler(e){return()=>this.getCurrentContext()}sequenceExpressionHandler(e){const t=e.expressions.map((e=>this.createClosure(e)));return()=>{let e;const r=t.length;for(let n=0;n<r;n++){e=(0,t[n])()}return e}}literalHandler(e){return()=>e.regex?new RegExp(e.regex.pattern,e.regex.flags):e.value}identifierHandler(e){return()=>{const t=this.getCurrentScope(),r=this.getScopeDataFromName(e.name,t);return this.assertVariable(r,e.name,e),r[e.name]}}getIdentifierScope(e){const t=this.getCurrentScope();return this.getScopeFromName(e.name,t)}assignmentExpressionHandler(e){"Identifier"!==e.left.type||"FunctionExpression"!==e.right.type||e.right.id||(e.right.id={type:"Identifier",name:e.left.name});const t=this.createObjectGetter(e.left),r=this.createNameGetter(e.left),n=this.createClosure(e.right);return()=>{const a=t(),s=r(),o=n();switch("="!==e.operator&&this.assertVariable(a,s,e),e.operator){case"=":return a[s]=o;case"+=":return a[s]+=o;case"-=":return a[s]-=o;case"*=":return a[s]*=o;case"**=":return a[s]=Math.pow(a[s],o);case"/=":return a[s]/=o;case"%=":return a[s]%=o;case"<<=":return a[s]<<=o;case">>=":return a[s]>>=o;case">>>=":return a[s]>>>=o;case"&=":return a[s]&=o;case"^=":return a[s]^=o;case"|=":return a[s]|=o;default:throw this.createInternalThrowError(i.AssignmentExpressionSyntaxError,e.type,e)}}}functionDeclarationHandler(e){if(e.id){const t=this.functionExpressionHandler(e);Object.defineProperty(t,"isFunctionDeclareClosure",{value:!0,writable:!1,configurable:!1,enumerable:!1}),this.funcDeclaration(e.id.name,t)}return()=>d}getVariableName(e){if("Identifier"===e.type)return e.name;throw this.createInternalThrowError(i.VariableTypeSyntaxError,e.type,e)}variableDeclarationHandler(e){let t;const r=[];for(let t=0;t<e.declarations.length;t++){const n=e.declarations[t];this.varDeclaration(this.getVariableName(n.id)),n.init&&r.push({type:"AssignmentExpression",operator:"=",left:n.id,right:n.init})}return r.length&&(t=this.createClosure({type:"BlockStatement",body:r})),()=>{if(t){const e=this.isVarDeclMode;this.isVarDeclMode=!0,t(),this.isVarDeclMode=e}return d}}assertVariable(e,t,r){if(e===this.globalScope.data&&!(t in e))throw this.createInternalThrowError(i.VariableUndefinedReferenceError,t,r)}programHandler(e){const t=e.body.map((e=>this.createClosure(e)));return()=>{let e=d;for(let r=0;r<t.length;r++){const n=t[r],a=this.setValue(n());if(a!==d&&(e=a,e instanceof x||e instanceof E||e instanceof g||e===u||e===h))break}return e}}expressionStatementHandler(e){return this.createClosure(e.expression)}emptyStatementHandler(e){return()=>d}returnStatementHandler(e){const t=e.argument?this.createClosure(e.argument):w;return()=>new x(t())}ifStatementHandler(e){const t=this.createClosure(e.test),r=this.createClosure(e.consequent),n=e.alternate?this.createClosure(e.alternate):/*!important*/()=>d;return()=>t()?r():n()}conditionalExpressionHandler(e){return this.ifStatementHandler(e)}forStatementHandler(e){let t=w,r=e.test?this.createClosure(e.test):()=>!0,n=w;const a=this.createClosure(e.body);return"ForStatement"===e.type&&(t=e.init?this.createClosure(e.init):t,n=e.update?this.createClosure(e.update):w),s=>{let o,i=d,c="DoWhileStatement"===e.type;for(s&&"LabeledStatement"===s.type&&(o=s.label.name),t();c||r();n()){c=!1;const e=this.setValue(a());if(e!==d&&e!==h){if(e===u)break;if(i=e,i instanceof g&&i.value===o)i=d;else if(i instanceof x||i instanceof E||i instanceof g)break}}return i}}whileStatementHandler(e){return this.forStatementHandler(e)}doWhileStatementHandler(e){return this.forStatementHandler(e)}forInStatementHandler(e){let t=e.left;const r=this.createClosure(e.right),n=this.createClosure(e.body);return"VariableDeclaration"===e.left.type&&(this.createClosure(e.left)(),t=e.left.declarations[0].id),e=>{let a,s,o=d;e&&"LabeledStatement"===e.type&&(a=e.label.name);const i=r();for(s in i){this.assignmentExpressionHandler({type:"AssignmentExpression",operator:"=",left:t,right:{type:"Literal",value:s}})();const e=this.setValue(n());if(e!==d&&e!==h){if(e===u)break;if(o=e,o instanceof g&&o.value===a)o=d;else if(o instanceof x||o instanceof E||o instanceof g)break}}return o}}withStatementHandler(e){const t=this.createClosure(e.object),r=this.createClosure(e.body);return()=>{const e=t(),n=this.getCurrentScope(),a=new C(e,n,m);this.setCurrentScope(a);const s=this.setValue(r());return this.setCurrentScope(n),s}}throwStatementHandler(e){const t=this.createClosure(e.argument);return()=>{throw this.setValue(void 0),t()}}tryStatementHandler(e){const t=this.createClosure(e.block),r=e.handler?this.catchClauseHandler(e.handler):null,n=e.finalizer?this.createClosure(e.finalizer):null;return()=>{const e=this.getCurrentScope(),a=this.getCurrentContext(),s=e.labelStack.concat([]),o=this.callStack.concat([]);let i,c,l=d;const u=()=>{this.setCurrentScope(e),this.setCurrentContext(a),e.labelStack=s,this.callStack=o};try{l=this.setValue(t()),l instanceof x&&(i=l)}catch(e){if(u(),this.isInterruptThrow(e))throw e;if(r)try{l=this.setValue(r(e)),l instanceof x&&(i=l)}catch(e){if(u(),this.isInterruptThrow(e))throw e;c=e}}if(n)try{l=n(),l instanceof x&&(i=l)}catch(e){if(u(),this.isInterruptThrow(e))throw e;c=e}if(c)throw c;return i||l}}catchClauseHandler(e){const t=this.createParamNameGetter(e.param),r=this.createClosure(e.body);return e=>{let n;const a=this.getCurrentScope().data,s=t(),o=l.call(a,s),i=a[s];return a[s]=e,n=r(),o?a[s]=i:delete a[s],n}}continueStatementHandler(e){return()=>e.label?new g(e.label.name):h}breakStatementHandler(e){return()=>e.label?new E(e.label.name):u}switchStatementHandler(e){const t=this.createClosure(e.discriminant),r=e.cases.map((e=>this.switchCaseHandler(e)));return()=>{const e=t();let n,a,s,o=!1;for(let t=0;t<r.length;t++){const i=r[t](),c=i.testClosure();if(c!==p){if(o||c===e){if(o=!0,a=this.setValue(i.bodyClosure()),a===d)continue;if(a===u)break;if(n=a,n instanceof x||n instanceof E||n instanceof g||n===h)break}}else s=i}if(!o&&s){a=this.setValue(s.bodyClosure());a===d||a===u||(n=a)}return n}}switchCaseHandler(e){const t=e.test?this.createClosure(e.test):()=>p,r=this.createClosure({type:"BlockStatement",body:e.consequent});return()=>({testClosure:t,bodyClosure:r})}labeledStatementHandler(e){const t=e.label.name,r=this.createClosure(e.body);return()=>{let n;const a=this.getCurrentScope();return a.labelStack.push(t),n=r(e),n instanceof E&&n.value===t&&(n=d),a.labelStack.pop(),n}}debuggerStatementHandler(e){return()=>d}createParamNameGetter(e){if("Identifier"===e.type)return()=>e.name;throw this.createInternalThrowError(i.ParamTypeSyntaxError,e.type,e)}createObjectKeyGetter(e){let t;return t="Identifier"===e.type?()=>e.name:this.createClosure(e),function(){return t()}}createMemberKeyGetter(e){return e.computed?this.createClosure(e.property):this.createObjectKeyGetter(e.property)}createObjectGetter(e){switch(e.type){case"Identifier":return()=>this.getScopeDataFromName(e.name,this.getCurrentScope());case"MemberExpression":return this.createClosure(e.object);default:throw this.createInternalThrowError(i.AssignmentTypeSyntaxError,e.type,e)}}createNameGetter(e){switch(e.type){case"Identifier":return()=>e.name;case"MemberExpression":return this.createMemberKeyGetter(e);default:throw this.createInternalThrowError(i.AssignmentTypeSyntaxError,e.type,e)}}varDeclaration(e){this.collectDeclVars[e]=void 0}funcDeclaration(e,t){this.collectDeclFuncs[e]=t}addDeclarationsToScope(e,t,r){const n=r.data;for(let e in t){const r=t[e];n[e]=r?r():r}for(let t in e)t in n||(n[t]=void 0)}getScopeValue(e,t){return this.getScopeFromName(e,t).data[e]}getScopeDataFromName(e,t){return this.getScopeFromName(e,t).data}getScopeFromName(e,t){let r=t;do{if(e in r.data)return r}while(r=r.parent);return this.globalScope}setValue(e){const t=this.callStack.length;return this.isVarDeclMode||t||e===d||e===u||e===h||e instanceof E||e instanceof g||(this.value=e instanceof x?e.value:e),e}getValue(){return this.value}}export{H as Interpreter};
var e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},e(t,r)};function t(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}var r=function(){return r=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var a in t=arguments[r])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e},r.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var n=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),r}(Error),a=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),r}(SyntaxError),o=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),r}(ReferenceError),i=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),r}(TypeError),c=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),r}(n),s=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),r}(a),u=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),r}(o),l={UnknownError:[3001,"%0",c],ExecutionTimeOutError:[3002,"Script execution timed out after %0ms",c],NodeTypeSyntaxError:[1001,"Unknown node type: %0",u],BinaryOperatorSyntaxError:[1002,"Unknown binary operator: %0",u],LogicalOperatorSyntaxError:[1003,"Unknown logical operator: %0",u],UnaryOperatorSyntaxError:[1004,"Unknown unary operator: %0",u],UpdateOperatorSyntaxError:[1005,"Unknown update operator: %0",u],ObjectStructureSyntaxError:[1006,"Unknown object structure: %0",u],AssignmentExpressionSyntaxError:[1007,"Unknown assignment expression: %0",u],VariableTypeSyntaxError:[1008,"Unknown variable type: %0",u],ParamTypeSyntaxError:[1009,"Unknown param type: %0",u],AssignmentTypeSyntaxError:[1010,"Unknown assignment type: %0",u],FunctionUndefinedReferenceError:[2001,"%0 is not a function",o],VariableUndefinedReferenceError:[2002,"%0 is not defined",o],IsNotConstructor:[2003,"%0 is not a constructor",i]};function p(e,t){Object.defineProperty(e,"name",{value:t,writable:!1,enumerable:!1,configurable:!0})}var f=Object.prototype.hasOwnProperty,h=Symbol("Break"),d=Symbol("Continue"),y=Symbol("DefaultCase"),m=Symbol("EmptyStatementReturn"),b=Symbol("WithScopeName"),S=Symbol("SuperScopeName"),v=Symbol("RootScopeName"),E=Symbol("GlobalScopeName");function g(e){return"function"==typeof e}var x=function(e){this.value=e},C=function(e){this.value=e},w=function(e){this.value=e},k=function(e,t,r){void 0===t&&(t=null),this.name=r,this.parent=t,this.data=e,this.labelStack=[]};function H(){}var I={NaN:NaN,Infinity:1/0,undefined:void 0,Object:Object,Array:Array,String:String,Boolean:Boolean,Number:Number,Date:Date,RegExp:RegExp,Error:Error,URIError:URIError,TypeError:TypeError,RangeError:RangeError,SyntaxError:SyntaxError,ReferenceError:ReferenceError,Math:Math,parseInt:parseInt,parseFloat:parseFloat,isNaN:isNaN,isFinite:isFinite,decodeURI:decodeURI,decodeURIComponent:decodeURIComponent,encodeURI:encodeURI,encodeURIComponent:encodeURIComponent,escape:escape,unescape:unescape};"undefined"!=typeof JSON&&(I.JSON=JSON),"undefined"!=typeof Promise&&(I.Promise=Promise),"undefined"!=typeof Set&&(I.Set=Set),"undefined"!=typeof Map&&(I.Map=Map),"undefined"!=typeof Symbol&&(I.Symbol=Symbol),"undefined"!=typeof Proxy&&(I.Proxy=Proxy),"undefined"!=typeof WeakMap&&(I.WeakMap=WeakMap),"undefined"!=typeof WeakSet&&(I.WeakSet=WeakSet),"undefined"!=typeof Reflect&&(I.Reflect=Reflect);var O=function(){function e(t,r){void 0===t&&(t=e.global),void 0===r&&(r={}),this.sourceList=[],this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null),this.isVarDeclMode=!1,this.lastExecNode=null,this.isRunning=!1,this.options={timeout:r.timeout||0,rootContext:r.rootContext,globalContextInFunction:void 0===r.globalContextInFunction?e.globalContextInFunction:r.globalContextInFunction,_initEnv:r._initEnv},this.context=t||Object.create(null),this.callStack=[],this.initEnvironment(this.context)}return e.prototype.initEnvironment=function(e){var t,r;if(e instanceof k)t=e;else{var n=null,a=this.createSuperScope(e);this.options.rootContext&&(n=new k((r=this.options.rootContext,Object.create(r)),a,v)),t=new k(e,n||a,E)}this.globalScope=t,this.currentScope=this.globalScope,this.globalContext=t.data,this.currentContext=t.data,this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null),this.execStartTime=Date.now(),this.execEndTime=this.execStartTime;var o=this.options._initEnv;o&&o.call(this)},e.prototype.getExecStartTime=function(){return this.execStartTime},e.prototype.getExecutionTime=function(){return this.execEndTime-this.execStartTime},e.prototype.setExecTimeout=function(e){void 0===e&&(e=0),this.options.timeout=e},e.prototype.getOptions=function(){return this.options},e.prototype.getCurrentScope=function(){return this.currentScope},e.prototype.getCurrentContext=function(){return this.currentContext},e.prototype.isInterruptThrow=function(e){return e instanceof c||e instanceof u||e instanceof s},e.prototype.createSuperScope=function(e){var t=r({},I);return Object.keys(t).forEach((function(r){r in e&&delete t[r]})),new k(t,null,S)},e.prototype.setCurrentContext=function(e){this.currentContext=e},e.prototype.setCurrentScope=function(e){this.currentScope=e},e.prototype.evaluateNode=function(e,t){var r=this;void 0===t&&(t=""),this.value=void 0,this.source=t,this.sourceList.push(t),this.isRunning=!0,this.execStartTime=Date.now(),this.execEndTime=this.execStartTime,this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null);var n=this.getCurrentScope(),a=this.getCurrentContext(),o=n.labelStack.concat([]),i=this.callStack.concat([]);try{var c=this.createClosure(e);this.addDeclarationsToScope(this.collectDeclVars,this.collectDeclFuncs,this.getCurrentScope()),c()}catch(e){throw e}finally{r.setCurrentScope(n),r.setCurrentContext(a),n.labelStack=o,r.callStack=i,this.execEndTime=Date.now()}return this.isRunning=!1,this.getValue()},e.prototype.createErrorMessage=function(e,t,r){var n=e[1].replace("%0",String(t));return null!==r&&(n+=this.getNodePosition(r||this.lastExecNode)),n},e.prototype.createError=function(e,t){return new t(e)},e.prototype.createThrowError=function(e,t){return this.createError(e,t)},e.prototype.createInternalThrowError=function(e,t,r){return this.createError(this.createErrorMessage(e,t,r),e[2])},e.prototype.checkTimeout=function(){if(!this.isRunning)return!1;var e=this.options.timeout||0;return Date.now()-this.execStartTime>e},e.prototype.getNodePosition=function(e){if(e){return e.loc?" [".concat(e.loc.start.line,":").concat(e.loc.start.column,"]").concat(""):""}return""},e.prototype.createClosure=function(e){var t,r=this;switch(e.type){case"BinaryExpression":t=this.binaryExpressionHandler(e);break;case"LogicalExpression":t=this.logicalExpressionHandler(e);break;case"UnaryExpression":t=this.unaryExpressionHandler(e);break;case"UpdateExpression":t=this.updateExpressionHandler(e);break;case"ObjectExpression":t=this.objectExpressionHandler(e);break;case"ArrayExpression":t=this.arrayExpressionHandler(e);break;case"CallExpression":t=this.callExpressionHandler(e);break;case"NewExpression":t=this.newExpressionHandler(e);break;case"MemberExpression":t=this.memberExpressionHandler(e);break;case"ThisExpression":t=this.thisExpressionHandler(e);break;case"SequenceExpression":t=this.sequenceExpressionHandler(e);break;case"Literal":t=this.literalHandler(e);break;case"Identifier":t=this.identifierHandler(e);break;case"AssignmentExpression":t=this.assignmentExpressionHandler(e);break;case"FunctionDeclaration":t=this.functionDeclarationHandler(e);break;case"VariableDeclaration":t=this.variableDeclarationHandler(e);break;case"BlockStatement":case"Program":t=this.programHandler(e);break;case"ExpressionStatement":t=this.expressionStatementHandler(e);break;case"EmptyStatement":t=this.emptyStatementHandler(e);break;case"ReturnStatement":t=this.returnStatementHandler(e);break;case"FunctionExpression":t=this.functionExpressionHandler(e);break;case"IfStatement":t=this.ifStatementHandler(e);break;case"ConditionalExpression":t=this.conditionalExpressionHandler(e);break;case"ForStatement":t=this.forStatementHandler(e);break;case"WhileStatement":t=this.whileStatementHandler(e);break;case"DoWhileStatement":t=this.doWhileStatementHandler(e);break;case"ForInStatement":t=this.forInStatementHandler(e);break;case"WithStatement":t=this.withStatementHandler(e);break;case"ThrowStatement":t=this.throwStatementHandler(e);break;case"TryStatement":t=this.tryStatementHandler(e);break;case"ContinueStatement":t=this.continueStatementHandler(e);break;case"BreakStatement":t=this.breakStatementHandler(e);break;case"SwitchStatement":t=this.switchStatementHandler(e);break;case"LabeledStatement":t=this.labeledStatementHandler(e);break;case"DebuggerStatement":t=this.debuggerStatementHandler(e);break;default:throw this.createInternalThrowError(l.NodeTypeSyntaxError,e.type,e)}return function(){for(var n=[],a=0;a<arguments.length;a++)n[a]=arguments[a];var o=r.options.timeout;if(o&&o>0&&r.checkTimeout())throw r.createInternalThrowError(l.ExecutionTimeOutError,o,null);return r.lastExecNode=e,t.apply(void 0,n)}},e.prototype.binaryExpressionHandler=function(e){var t=this,r=this.createClosure(e.left),n=this.createClosure(e.right);return function(){var a=r(),o=n();switch(e.operator){case"==":return a==o;case"!=":return a!=o;case"===":return a===o;case"!==":return a!==o;case"<":return a<o;case"<=":return a<=o;case">":return a>o;case">=":return a>=o;case"<<":return a<<o;case">>":return a>>o;case">>>":return a>>>o;case"+":return a+o;case"-":return a-o;case"*":return a*o;case"**":return Math.pow(a,o);case"/":return a/o;case"%":return a%o;case"|":return a|o;case"^":return a^o;case"&":return a&o;case"in":return a in o;case"instanceof":return a instanceof o;default:throw t.createInternalThrowError(l.BinaryOperatorSyntaxError,e.operator,e)}}},e.prototype.logicalExpressionHandler=function(e){var t=this,r=this.createClosure(e.left),n=this.createClosure(e.right);return function(){switch(e.operator){case"||":return r()||n();case"&&":return r()&&n();default:throw t.createInternalThrowError(l.LogicalOperatorSyntaxError,e.operator,e)}}},e.prototype.unaryExpressionHandler=function(e){var t,r=this;if("delete"===e.operator){var n=this.createObjectGetter(e.argument),a=this.createNameGetter(e.argument);return function(){return delete n()[a()]}}if("typeof"===e.operator&&"Identifier"===e.argument.type){var o=this.createObjectGetter(e.argument),i=this.createNameGetter(e.argument);t=function(){return o()[i()]}}else t=this.createClosure(e.argument);return function(){var n=t();switch(e.operator){case"-":return-n;case"+":return+n;case"!":return!n;case"~":return~n;case"void":return;case"typeof":return typeof n;default:throw r.createInternalThrowError(l.UnaryOperatorSyntaxError,e.operator,e)}}},e.prototype.updateExpressionHandler=function(e){var t=this,r=this.createObjectGetter(e.argument),n=this.createNameGetter(e.argument);return function(){var a=r(),o=n();switch(t.assertVariable(a,o,e),e.operator){case"++":return e.prefix?++a[o]:a[o]++;case"--":return e.prefix?--a[o]:a[o]--;default:throw t.createInternalThrowError(l.UpdateOperatorSyntaxError,e.operator,e)}}},e.prototype.objectExpressionHandler=function(e){var t=this,r=[];var n=Object.create(null);return e.properties.forEach((function(e){var a=e.kind,o=function(e){return"Identifier"===e.type?e.name:"Literal"===e.type?e.value:this.throwError(l.ObjectStructureSyntaxError,e.type,e)}(e.key);n[o]&&"init"!==a||(n[o]={}),n[o][a]=t.createClosure(e.value),r.push({key:o,property:e})})),function(){for(var e={},t=r.length,a=0;a<t;a++){var o=r[a],i=o.key,c=n[i],s=c.init?c.init():void 0,u=c.get?c.get():function(){},l=c.set?c.set():function(e){};if("set"in c||"get"in c){var f={configurable:!0,enumerable:!0,get:u,set:l};Object.defineProperty(e,i,f)}else{var h=o.property,d=h.kind;"Identifier"!==h.key.type||"FunctionExpression"!==h.value.type||"init"!==d||h.value.id||p(s,h.key.name),e[i]=s}}return e}},e.prototype.arrayExpressionHandler=function(e){var t=this,r=e.elements.map((function(e){return e?t.createClosure(e):e}));return function(){for(var e=r.length,t=Array(e),n=0;n<e;n++){var a=r[n];a&&(t[n]=a())}return t}},e.prototype.safeObjectGet=function(e,t,r){return e[t]},e.prototype.createCallFunctionGetter=function(e){var t=this;if("MemberExpression"===e.type){var r=this.createClosure(e.object),n=this.createMemberKeyGetter(e),a=this.source;return function(){var o=r(),i=n(),c=t.safeObjectGet(o,i,e);if(!c||!g(c)){var s=a.slice(e.start,e.end);throw t.createInternalThrowError(l.FunctionUndefinedReferenceError,s,e)}return c.bind(o)}}var o=this.createClosure(e);return function(){var r="";"Identifier"===e.type&&(r=e.name);var n=o();if(!n||!g(n))throw t.createInternalThrowError(l.FunctionUndefinedReferenceError,r,e);var a=t.options.globalContextInFunction;if("Identifier"===e.type){var i=t.getIdentifierScope(e);i.name===b&&(a=i.data)}return n.bind(a)}},e.prototype.callExpressionHandler=function(e){var t=this,r=this.createCallFunctionGetter(e.callee),n=e.arguments.map((function(e){return t.createClosure(e)}));return function(){return r().apply(void 0,n.map((function(e){return e()})))}},e.prototype.functionExpressionHandler=function(e){var t=this,r=this,n=this.source,a=this.collectDeclVars,o=this.collectDeclFuncs;this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null);var i=e.id?e.id.name:"",c=e.params.length,s=e.params.map((function(e){return t.createParamNameGetter(e)})),u=this.createClosure(e.body),l=this.collectDeclVars,f=this.collectDeclFuncs;return this.collectDeclVars=a,this.collectDeclFuncs=o,function(){var t=r.getCurrentScope(),a=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];r.callStack.push("".concat(i));var o=r.getCurrentScope(),c=function(e,t){return void 0===e&&(e=null),new k(Object.create(null),e,t)}(t,"FunctionScope(".concat(i,")"));r.setCurrentScope(c),r.addDeclarationsToScope(l,f,c),i&&(c.data[i]=a),c.data.arguments=arguments,s.forEach((function(t,r){c.data[t()]=e[r]}));var p=r.getCurrentContext();r.setCurrentContext(this);var h=u();if(r.setCurrentContext(p),r.setCurrentScope(o),r.callStack.pop(),h instanceof x)return h.value};return p(a,i),Object.defineProperty(a,"length",{value:c,writable:!1,enumerable:!1,configurable:!0}),Object.defineProperty(a,"toString",{value:function(){return n.slice(e.start,e.end)},writable:!0,configurable:!0,enumerable:!1}),Object.defineProperty(a,"valueOf",{value:function(){return n.slice(e.start,e.end)},writable:!0,configurable:!0,enumerable:!1}),a}},e.prototype.newExpressionHandler=function(e){var t=this,r=this.source,n=this.createClosure(e.callee),a=e.arguments.map((function(e){return t.createClosure(e)}));return function(){var o=n();if(!g(o)||o.__IS_EVAL_FUNC){var i=e.callee,c=r.slice(i.start,i.end);throw t.createInternalThrowError(l.IsNotConstructor,c,e)}return new(o.bind.apply(o,function(e,t,r){if(r||2===arguments.length)for(var n,a=0,o=t.length;a<o;a++)!n&&a in t||(n||(n=Array.prototype.slice.call(t,0,a)),n[a]=t[a]);return e.concat(n||Array.prototype.slice.call(t))}([void 0],a.map((function(e){return e()})),!1)))}},e.prototype.memberExpressionHandler=function(e){var t=this.createClosure(e.object),r=this.createMemberKeyGetter(e);return function(){return t()[r()]}},e.prototype.thisExpressionHandler=function(e){var t=this;return function(){return t.getCurrentContext()}},e.prototype.sequenceExpressionHandler=function(e){var t=this,r=e.expressions.map((function(e){return t.createClosure(e)}));return function(){for(var e,t=r.length,n=0;n<t;n++){e=(0,r[n])()}return e}},e.prototype.literalHandler=function(e){return function(){return e.regex?new RegExp(e.regex.pattern,e.regex.flags):e.value}},e.prototype.identifierHandler=function(e){var t=this;return function(){var r=t.getCurrentScope(),n=t.getScopeDataFromName(e.name,r);return t.assertVariable(n,e.name,e),n[e.name]}},e.prototype.getIdentifierScope=function(e){var t=this.getCurrentScope();return this.getScopeFromName(e.name,t)},e.prototype.assignmentExpressionHandler=function(e){var t=this;"Identifier"!==e.left.type||"FunctionExpression"!==e.right.type||e.right.id||(e.right.id={type:"Identifier",name:e.left.name});var r=this.createObjectGetter(e.left),n=this.createNameGetter(e.left),a=this.createClosure(e.right);return function(){var o=r(),i=n(),c=a();switch("="!==e.operator&&t.assertVariable(o,i,e),e.operator){case"=":return o[i]=c;case"+=":return o[i]+=c;case"-=":return o[i]-=c;case"*=":return o[i]*=c;case"**=":return o[i]=Math.pow(o[i],c);case"/=":return o[i]/=c;case"%=":return o[i]%=c;case"<<=":return o[i]<<=c;case">>=":return o[i]>>=c;case">>>=":return o[i]>>>=c;case"&=":return o[i]&=c;case"^=":return o[i]^=c;case"|=":return o[i]|=c;default:throw t.createInternalThrowError(l.AssignmentExpressionSyntaxError,e.type,e)}}},e.prototype.functionDeclarationHandler=function(e){if(e.id){var t=this.functionExpressionHandler(e);Object.defineProperty(t,"isFunctionDeclareClosure",{value:!0,writable:!1,configurable:!1,enumerable:!1}),this.funcDeclaration(e.id.name,t)}return function(){return m}},e.prototype.getVariableName=function(e){if("Identifier"===e.type)return e.name;throw this.createInternalThrowError(l.VariableTypeSyntaxError,e.type,e)},e.prototype.variableDeclarationHandler=function(e){for(var t,r=this,n=[],a=0;a<e.declarations.length;a++){var o=e.declarations[a];this.varDeclaration(this.getVariableName(o.id)),o.init&&n.push({type:"AssignmentExpression",operator:"=",left:o.id,right:o.init})}return n.length&&(t=this.createClosure({type:"BlockStatement",body:n})),function(){if(t){var e=r.isVarDeclMode;r.isVarDeclMode=!0,t(),r.isVarDeclMode=e}return m}},e.prototype.assertVariable=function(e,t,r){if(e===this.globalScope.data&&!(t in e))throw this.createInternalThrowError(l.VariableUndefinedReferenceError,t,r)},e.prototype.programHandler=function(e){var t=this,r=e.body.map((function(e){return t.createClosure(e)}));return function(){for(var e=m,n=0;n<r.length;n++){var a=r[n],o=t.setValue(a());if(o!==m&&((e=o)instanceof x||e instanceof C||e instanceof w||e===h||e===d))break}return e}},e.prototype.expressionStatementHandler=function(e){return this.createClosure(e.expression)},e.prototype.emptyStatementHandler=function(e){return function(){return m}},e.prototype.returnStatementHandler=function(e){var t=e.argument?this.createClosure(e.argument):H;return function(){return new x(t())}},e.prototype.ifStatementHandler=function(e){var t=this.createClosure(e.test),r=this.createClosure(e.consequent),n=e.alternate?this.createClosure(e.alternate):/*!important*/function(){return m};return function(){return t()?r():n()}},e.prototype.conditionalExpressionHandler=function(e){return this.ifStatementHandler(e)},e.prototype.forStatementHandler=function(e){var t=this,r=H,n=e.test?this.createClosure(e.test):function(){return!0},a=H,o=this.createClosure(e.body);return"ForStatement"===e.type&&(r=e.init?this.createClosure(e.init):r,a=e.update?this.createClosure(e.update):H),function(i){var c,s=m,u="DoWhileStatement"===e.type;for(i&&"LabeledStatement"===i.type&&(c=i.label.name),r();u||n();a()){u=!1;var l=t.setValue(o());if(l!==m&&l!==d){if(l===h)break;if((s=l)instanceof w&&s.value===c)s=m;else if(s instanceof x||s instanceof C||s instanceof w)break}}return s}},e.prototype.whileStatementHandler=function(e){return this.forStatementHandler(e)},e.prototype.doWhileStatementHandler=function(e){return this.forStatementHandler(e)},e.prototype.forInStatementHandler=function(e){var t=this,r=e.left,n=this.createClosure(e.right),a=this.createClosure(e.body);return"VariableDeclaration"===e.left.type&&(this.createClosure(e.left)(),r=e.left.declarations[0].id),function(e){var o,i,c=m;e&&"LabeledStatement"===e.type&&(o=e.label.name);var s=n();for(i in s){t.assignmentExpressionHandler({type:"AssignmentExpression",operator:"=",left:r,right:{type:"Literal",value:i}})();var u=t.setValue(a());if(u!==m&&u!==d){if(u===h)break;if((c=u)instanceof w&&c.value===o)c=m;else if(c instanceof x||c instanceof C||c instanceof w)break}}return c}},e.prototype.withStatementHandler=function(e){var t=this,r=this.createClosure(e.object),n=this.createClosure(e.body);return function(){var e=r(),a=t.getCurrentScope(),o=new k(e,a,b);t.setCurrentScope(o);var i=t.setValue(n());return t.setCurrentScope(a),i}},e.prototype.throwStatementHandler=function(e){var t=this,r=this.createClosure(e.argument);return function(){throw t.setValue(void 0),r()}},e.prototype.tryStatementHandler=function(e){var t=this,r=this.createClosure(e.block),n=e.handler?this.catchClauseHandler(e.handler):null,a=e.finalizer?this.createClosure(e.finalizer):null;return function(){var e,o,i=t.getCurrentScope(),c=t.getCurrentContext(),s=i.labelStack.concat([]),u=t.callStack.concat([]),l=m,p=function(){t.setCurrentScope(i),t.setCurrentContext(c),i.labelStack=s,t.callStack=u};try{(l=t.setValue(r()))instanceof x&&(e=l)}catch(r){if(p(),t.isInterruptThrow(r))throw r;if(n)try{(l=t.setValue(n(r)))instanceof x&&(e=l)}catch(e){if(p(),t.isInterruptThrow(e))throw e;o=e}}if(a)try{(l=a())instanceof x&&(e=l)}catch(e){if(p(),t.isInterruptThrow(e))throw e;o=e}if(o)throw o;return e||l}},e.prototype.catchClauseHandler=function(e){var t=this,r=this.createParamNameGetter(e.param),n=this.createClosure(e.body);return function(e){var a,o=t.getCurrentScope().data,i=r(),c=f.call(o,i),s=o[i];return o[i]=e,a=n(),c?o[i]=s:delete o[i],a}},e.prototype.continueStatementHandler=function(e){return function(){return e.label?new w(e.label.name):d}},e.prototype.breakStatementHandler=function(e){return function(){return e.label?new C(e.label.name):h}},e.prototype.switchStatementHandler=function(e){var t=this,r=this.createClosure(e.discriminant),n=e.cases.map((function(e){return t.switchCaseHandler(e)}));return function(){for(var e,a,o,i=r(),c=!1,s=0;s<n.length;s++){var u=n[s](),l=u.testClosure();if(l!==y){if(c||l===i){if(c=!0,(a=t.setValue(u.bodyClosure()))===m)continue;if(a===h)break;if((e=a)instanceof x||e instanceof C||e instanceof w||e===d)break}}else o=u}!c&&o&&((a=t.setValue(o.bodyClosure()))===m||a===h||(e=a));return e}},e.prototype.switchCaseHandler=function(e){var t=e.test?this.createClosure(e.test):function(){return y},r=this.createClosure({type:"BlockStatement",body:e.consequent});return function(){return{testClosure:t,bodyClosure:r}}},e.prototype.labeledStatementHandler=function(e){var t=this,r=e.label.name,n=this.createClosure(e.body);return function(){var a,o=t.getCurrentScope();return o.labelStack.push(r),(a=n(e))instanceof C&&a.value===r&&(a=m),o.labelStack.pop(),a}},e.prototype.debuggerStatementHandler=function(e){return function(){return m}},e.prototype.createParamNameGetter=function(e){if("Identifier"===e.type)return function(){return e.name};throw this.createInternalThrowError(l.ParamTypeSyntaxError,e.type,e)},e.prototype.createObjectKeyGetter=function(e){var t;return t="Identifier"===e.type?function(){return e.name}:this.createClosure(e),function(){return t()}},e.prototype.createMemberKeyGetter=function(e){return e.computed?this.createClosure(e.property):this.createObjectKeyGetter(e.property)},e.prototype.createObjectGetter=function(e){var t=this;switch(e.type){case"Identifier":return function(){return t.getScopeDataFromName(e.name,t.getCurrentScope())};case"MemberExpression":return this.createClosure(e.object);default:throw this.createInternalThrowError(l.AssignmentTypeSyntaxError,e.type,e)}},e.prototype.createNameGetter=function(e){switch(e.type){case"Identifier":return function(){return e.name};case"MemberExpression":return this.createMemberKeyGetter(e);default:throw this.createInternalThrowError(l.AssignmentTypeSyntaxError,e.type,e)}},e.prototype.varDeclaration=function(e){this.collectDeclVars[e]=void 0},e.prototype.funcDeclaration=function(e,t){this.collectDeclFuncs[e]=t},e.prototype.addDeclarationsToScope=function(e,t,r){var n=r.data;for(var a in t){var o=t[a];n[a]=o?o():o}for(var a in e)a in n||(n[a]=void 0)},e.prototype.getScopeValue=function(e,t){return this.getScopeFromName(e,t).data[e]},e.prototype.getScopeDataFromName=function(e,t){return this.getScopeFromName(e,t).data},e.prototype.getScopeFromName=function(e,t){var r=t;do{if(e in r.data)return r}while(r=r.parent);return this.globalScope},e.prototype.setValue=function(e){var t=this.callStack.length;return this.isVarDeclMode||t||e===m||e===h||e===d||e instanceof C||e instanceof w||(this.value=e instanceof x?e.value:e),e},e.prototype.getValue=function(){return this.value},e.version="0.0.2",e.ecmaVersion=5,e.globalContextInFunction=void 0,e.global=Object.create(null),e}();export{O as Interpreter};
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).eval5={})}(this,(function(e){"use strict";class t extends Error{}class r extends SyntaxError{}class n extends ReferenceError{}class a extends TypeError{}class s extends t{}class o extends r{}class i extends n{}const c={UnknownError:[3001,"%0",s],ExecutionTimeOutError:[3002,"Script execution timed out after %0ms",s],NodeTypeSyntaxError:[1001,"Unknown node type: %0",i],BinaryOperatorSyntaxError:[1002,"Unknown binary operator: %0",i],LogicalOperatorSyntaxError:[1003,"Unknown logical operator: %0",i],UnaryOperatorSyntaxError:[1004,"Unknown unary operator: %0",i],UpdateOperatorSyntaxError:[1005,"Unknown update operator: %0",i],ObjectStructureSyntaxError:[1006,"Unknown object structure: %0",i],AssignmentExpressionSyntaxError:[1007,"Unknown assignment expression: %0",i],VariableTypeSyntaxError:[1008,"Unknown variable type: %0",i],ParamTypeSyntaxError:[1009,"Unknown param type: %0",i],AssignmentTypeSyntaxError:[1010,"Unknown assignment type: %0",i],FunctionUndefinedReferenceError:[2001,"%0 is not a function",n],VariableUndefinedReferenceError:[2002,"%0 is not defined",n],IsNotConstructor:[2003,"%0 is not a constructor",a]};function l(e,t){Object.defineProperty(e,"name",{value:t,writable:!1,enumerable:!1,configurable:!0})}const u=Object.prototype.hasOwnProperty,h=Symbol("Break"),p=Symbol("Continue"),d=Symbol("DefaultCase"),m=Symbol("EmptyStatementReturn"),f=Symbol("WithScopeName"),b=Symbol("SuperScopeName"),S=Symbol("RootScopeName"),y=Symbol("GlobalScopeName");function x(e){return"function"==typeof e}class E{value;constructor(e){this.value=e}}class g{value;constructor(e){this.value=e}}class C{value;constructor(e){this.value=e}}class w{name;parent;data;labelStack;constructor(e,t=null,r){this.name=r,this.parent=t,this.data=e,this.labelStack=[]}}function k(){}const H={NaN:NaN,Infinity:1/0,undefined:void 0,Object:Object,Array:Array,String:String,Boolean:Boolean,Number:Number,Date:Date,RegExp:RegExp,Error:Error,URIError:URIError,TypeError:TypeError,RangeError:RangeError,SyntaxError:SyntaxError,ReferenceError:ReferenceError,Math:Math,parseInt:parseInt,parseFloat:parseFloat,isNaN:isNaN,isFinite:isFinite,decodeURI:decodeURI,decodeURIComponent:decodeURIComponent,encodeURI:encodeURI,encodeURIComponent:encodeURIComponent,escape:escape,unescape:unescape};"undefined"!=typeof JSON&&(H.JSON=JSON),"undefined"!=typeof Promise&&(H.Promise=Promise),"undefined"!=typeof Set&&(H.Set=Set),"undefined"!=typeof Map&&(H.Map=Map),"undefined"!=typeof Symbol&&(H.Symbol=Symbol),"undefined"!=typeof Proxy&&(H.Proxy=Proxy),"undefined"!=typeof WeakMap&&(H.WeakMap=WeakMap),"undefined"!=typeof WeakSet&&(H.WeakSet=WeakSet),"undefined"!=typeof Reflect&&(H.Reflect=Reflect);class I{static version="0.0.0";static ecmaVersion=5;static globalContextInFunction=void 0;static global=Object.create(null);value;context;globalContext;source;sourceList=[];currentScope;globalScope;currentContext;options;callStack;collectDeclVars=Object.create(null);collectDeclFuncs=Object.create(null);isVarDeclMode=!1;lastExecNode=null;isRunning=!1;execStartTime;execEndTime;constructor(e=I.global,t={}){this.options={timeout:t.timeout||0,rootContext:t.rootContext,globalContextInFunction:void 0===t.globalContextInFunction?I.globalContextInFunction:t.globalContextInFunction,_initEnv:t._initEnv},this.context=e||Object.create(null),this.callStack=[],this.initEnvironment(this.context)}initEnvironment(e){let t;if(e instanceof w)t=e;else{let n=null;const a=this.createSuperScope(e);this.options.rootContext&&(n=new w((r=this.options.rootContext,Object.create(r)),a,S)),t=new w(e,n||a,y)}var r;this.globalScope=t,this.currentScope=this.globalScope,this.globalContext=t.data,this.currentContext=t.data,this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null),this.execStartTime=Date.now(),this.execEndTime=this.execStartTime;const n=this.options._initEnv;n&&n.call(this)}getExecStartTime(){return this.execStartTime}getExecutionTime(){return this.execEndTime-this.execStartTime}setExecTimeout(e=0){this.options.timeout=e}getOptions(){return this.options}getCurrentScope(){return this.currentScope}getCurrentContext(){return this.currentContext}isInterruptThrow(e){return e instanceof s||e instanceof i||e instanceof o}createSuperScope(e){let t={...H};return Object.keys(t).forEach((r=>{r in e&&delete t[r]})),new w(t,null,b)}setCurrentContext(e){this.currentContext=e}setCurrentScope(e){this.currentScope=e}evaluateNode(e,t=""){this.value=void 0,this.source=t,this.sourceList.push(t),this.isRunning=!0,this.execStartTime=Date.now(),this.execEndTime=this.execStartTime,this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null);const r=this.getCurrentScope(),n=this.getCurrentContext(),a=r.labelStack.concat([]),s=this.callStack.concat([]),o=()=>{this.setCurrentScope(r),this.setCurrentContext(n),r.labelStack=a,this.callStack=s};try{const t=this.createClosure(e);this.addDeclarationsToScope(this.collectDeclVars,this.collectDeclFuncs,this.getCurrentScope()),t()}catch(e){throw e}finally{o(),this.execEndTime=Date.now()}return this.isRunning=!1,this.getValue()}createErrorMessage(e,t,r){let n=e[1].replace("%0",String(t));return null!==r&&(n+=this.getNodePosition(r||this.lastExecNode)),n}createError(e,t){return new t(e)}createThrowError(e,t){return this.createError(e,t)}createInternalThrowError(e,t,r){return this.createError(this.createErrorMessage(e,t,r),e[2])}checkTimeout(){if(!this.isRunning)return!1;const e=this.options.timeout||0;return Date.now()-this.execStartTime>e}getNodePosition(e){if(e){const t="";return e.loc?` [${e.loc.start.line}:${e.loc.start.column}]${t}`:""}return""}createClosure(e){let t;switch(e.type){case"BinaryExpression":t=this.binaryExpressionHandler(e);break;case"LogicalExpression":t=this.logicalExpressionHandler(e);break;case"UnaryExpression":t=this.unaryExpressionHandler(e);break;case"UpdateExpression":t=this.updateExpressionHandler(e);break;case"ObjectExpression":t=this.objectExpressionHandler(e);break;case"ArrayExpression":t=this.arrayExpressionHandler(e);break;case"CallExpression":t=this.callExpressionHandler(e);break;case"NewExpression":t=this.newExpressionHandler(e);break;case"MemberExpression":t=this.memberExpressionHandler(e);break;case"ThisExpression":t=this.thisExpressionHandler(e);break;case"SequenceExpression":t=this.sequenceExpressionHandler(e);break;case"Literal":t=this.literalHandler(e);break;case"Identifier":t=this.identifierHandler(e);break;case"AssignmentExpression":t=this.assignmentExpressionHandler(e);break;case"FunctionDeclaration":t=this.functionDeclarationHandler(e);break;case"VariableDeclaration":t=this.variableDeclarationHandler(e);break;case"BlockStatement":case"Program":t=this.programHandler(e);break;case"ExpressionStatement":t=this.expressionStatementHandler(e);break;case"EmptyStatement":t=this.emptyStatementHandler(e);break;case"ReturnStatement":t=this.returnStatementHandler(e);break;case"FunctionExpression":t=this.functionExpressionHandler(e);break;case"IfStatement":t=this.ifStatementHandler(e);break;case"ConditionalExpression":t=this.conditionalExpressionHandler(e);break;case"ForStatement":t=this.forStatementHandler(e);break;case"WhileStatement":t=this.whileStatementHandler(e);break;case"DoWhileStatement":t=this.doWhileStatementHandler(e);break;case"ForInStatement":t=this.forInStatementHandler(e);break;case"WithStatement":t=this.withStatementHandler(e);break;case"ThrowStatement":t=this.throwStatementHandler(e);break;case"TryStatement":t=this.tryStatementHandler(e);break;case"ContinueStatement":t=this.continueStatementHandler(e);break;case"BreakStatement":t=this.breakStatementHandler(e);break;case"SwitchStatement":t=this.switchStatementHandler(e);break;case"LabeledStatement":t=this.labeledStatementHandler(e);break;case"DebuggerStatement":t=this.debuggerStatementHandler(e);break;default:throw this.createInternalThrowError(c.NodeTypeSyntaxError,e.type,e)}return(...r)=>{const n=this.options.timeout;if(n&&n>0&&this.checkTimeout())throw this.createInternalThrowError(c.ExecutionTimeOutError,n,null);return this.lastExecNode=e,t(...r)}}binaryExpressionHandler(e){const t=this.createClosure(e.left),r=this.createClosure(e.right);return()=>{const n=t(),a=r();switch(e.operator){case"==":return n==a;case"!=":return n!=a;case"===":return n===a;case"!==":return n!==a;case"<":return n<a;case"<=":return n<=a;case">":return n>a;case">=":return n>=a;case"<<":return n<<a;case">>":return n>>a;case">>>":return n>>>a;case"+":return n+a;case"-":return n-a;case"*":return n*a;case"**":return Math.pow(n,a);case"/":return n/a;case"%":return n%a;case"|":return n|a;case"^":return n^a;case"&":return n&a;case"in":return n in a;case"instanceof":return n instanceof a;default:throw this.createInternalThrowError(c.BinaryOperatorSyntaxError,e.operator,e)}}}logicalExpressionHandler(e){const t=this.createClosure(e.left),r=this.createClosure(e.right);return()=>{switch(e.operator){case"||":return t()||r();case"&&":return t()&&r();default:throw this.createInternalThrowError(c.LogicalOperatorSyntaxError,e.operator,e)}}}unaryExpressionHandler(e){if("delete"===e.operator){const t=this.createObjectGetter(e.argument),r=this.createNameGetter(e.argument);return()=>delete t()[r()]}{let t;if("typeof"===e.operator&&"Identifier"===e.argument.type){const r=this.createObjectGetter(e.argument),n=this.createNameGetter(e.argument);t=()=>r()[n()]}else t=this.createClosure(e.argument);return()=>{const r=t();switch(e.operator){case"-":return-r;case"+":return+r;case"!":return!r;case"~":return~r;case"void":return;case"typeof":return typeof r;default:throw this.createInternalThrowError(c.UnaryOperatorSyntaxError,e.operator,e)}}}}updateExpressionHandler(e){const t=this.createObjectGetter(e.argument),r=this.createNameGetter(e.argument);return()=>{const n=t(),a=r();switch(this.assertVariable(n,a,e),e.operator){case"++":return e.prefix?++n[a]:n[a]++;case"--":return e.prefix?--n[a]:n[a]--;default:throw this.createInternalThrowError(c.UpdateOperatorSyntaxError,e.operator,e)}}}objectExpressionHandler(e){const t=[];const r=Object.create(null);return e.properties.forEach((e=>{const n=e.kind,a=function(e){return"Identifier"===e.type?e.name:"Literal"===e.type?e.value:this.throwError(c.ObjectStructureSyntaxError,e.type,e)}(e.key);r[a]&&"init"!==n||(r[a]={}),r[a][n]=this.createClosure(e.value),t.push({key:a,property:e})})),()=>{const e={},n=t.length;for(let a=0;a<n;a++){const n=t[a],s=n.key,o=r[s],i=o.init?o.init():void 0,c=o.get?o.get():function(){},u=o.set?o.set():function(e){};if("set"in o||"get"in o){const t={configurable:!0,enumerable:!0,get:c,set:u};Object.defineProperty(e,s,t)}else{const t=n.property,r=t.kind;"Identifier"!==t.key.type||"FunctionExpression"!==t.value.type||"init"!==r||t.value.id||l(i,t.key.name),e[s]=i}}return e}}arrayExpressionHandler(e){const t=e.elements.map((e=>e?this.createClosure(e):e));return()=>{const e=t.length,r=Array(e);for(let n=0;n<e;n++){const e=t[n];e&&(r[n]=e())}return r}}safeObjectGet(e,t,r){return e[t]}createCallFunctionGetter(e){if("MemberExpression"===e.type){const t=this.createClosure(e.object),r=this.createMemberKeyGetter(e),n=this.source;return()=>{const a=t(),s=r(),o=this.safeObjectGet(a,s,e);if(!o||!x(o)){const t=n.slice(e.start,e.end);throw this.createInternalThrowError(c.FunctionUndefinedReferenceError,t,e)}return o.bind(a)}}{const t=this.createClosure(e);return()=>{let r="";"Identifier"===e.type&&(r=e.name);const n=t();if(!n||!x(n))throw this.createInternalThrowError(c.FunctionUndefinedReferenceError,r,e);let a=this.options.globalContextInFunction;if("Identifier"===e.type){const t=this.getIdentifierScope(e);t.name===f&&(a=t.data)}return n.bind(a)}}}callExpressionHandler(e){const t=this.createCallFunctionGetter(e.callee),r=e.arguments.map((e=>this.createClosure(e)));return()=>t()(...r.map((e=>e())))}functionExpressionHandler(e){const t=this,r=this.source,n=this.collectDeclVars,a=this.collectDeclFuncs;this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null);const s=e.id?e.id.name:"",o=e.params.length,i=e.params.map((e=>this.createParamNameGetter(e))),c=this.createClosure(e.body),u=this.collectDeclVars,h=this.collectDeclFuncs;return this.collectDeclVars=n,this.collectDeclFuncs=a,()=>{const n=t.getCurrentScope(),a=function(...e){t.callStack.push(`${s}`);const r=t.getCurrentScope(),o=function(e=null,t){return new w(Object.create(null),e,t)}(n,`FunctionScope(${s})`);t.setCurrentScope(o),t.addDeclarationsToScope(u,h,o),s&&(o.data[s]=a),o.data.arguments=arguments,i.forEach(((t,r)=>{o.data[t()]=e[r]}));const l=t.getCurrentContext();t.setCurrentContext(this);const p=c();if(t.setCurrentContext(l),t.setCurrentScope(r),t.callStack.pop(),p instanceof E)return p.value};return l(a,s),Object.defineProperty(a,"length",{value:o,writable:!1,enumerable:!1,configurable:!0}),Object.defineProperty(a,"toString",{value:()=>r.slice(e.start,e.end),writable:!0,configurable:!0,enumerable:!1}),Object.defineProperty(a,"valueOf",{value:()=>r.slice(e.start,e.end),writable:!0,configurable:!0,enumerable:!1}),a}}newExpressionHandler(e){const t=this.source,r=this.createClosure(e.callee),n=e.arguments.map((e=>this.createClosure(e)));return()=>{const a=r();if(!x(a)||a.__IS_EVAL_FUNC){const r=e.callee,n=t.slice(r.start,r.end);throw this.createInternalThrowError(c.IsNotConstructor,n,e)}return new a(...n.map((e=>e())))}}memberExpressionHandler(e){const t=this.createClosure(e.object),r=this.createMemberKeyGetter(e);return()=>t()[r()]}thisExpressionHandler(e){return()=>this.getCurrentContext()}sequenceExpressionHandler(e){const t=e.expressions.map((e=>this.createClosure(e)));return()=>{let e;const r=t.length;for(let n=0;n<r;n++){e=(0,t[n])()}return e}}literalHandler(e){return()=>e.regex?new RegExp(e.regex.pattern,e.regex.flags):e.value}identifierHandler(e){return()=>{const t=this.getCurrentScope(),r=this.getScopeDataFromName(e.name,t);return this.assertVariable(r,e.name,e),r[e.name]}}getIdentifierScope(e){const t=this.getCurrentScope();return this.getScopeFromName(e.name,t)}assignmentExpressionHandler(e){"Identifier"!==e.left.type||"FunctionExpression"!==e.right.type||e.right.id||(e.right.id={type:"Identifier",name:e.left.name});const t=this.createObjectGetter(e.left),r=this.createNameGetter(e.left),n=this.createClosure(e.right);return()=>{const a=t(),s=r(),o=n();switch("="!==e.operator&&this.assertVariable(a,s,e),e.operator){case"=":return a[s]=o;case"+=":return a[s]+=o;case"-=":return a[s]-=o;case"*=":return a[s]*=o;case"**=":return a[s]=Math.pow(a[s],o);case"/=":return a[s]/=o;case"%=":return a[s]%=o;case"<<=":return a[s]<<=o;case">>=":return a[s]>>=o;case">>>=":return a[s]>>>=o;case"&=":return a[s]&=o;case"^=":return a[s]^=o;case"|=":return a[s]|=o;default:throw this.createInternalThrowError(c.AssignmentExpressionSyntaxError,e.type,e)}}}functionDeclarationHandler(e){if(e.id){const t=this.functionExpressionHandler(e);Object.defineProperty(t,"isFunctionDeclareClosure",{value:!0,writable:!1,configurable:!1,enumerable:!1}),this.funcDeclaration(e.id.name,t)}return()=>m}getVariableName(e){if("Identifier"===e.type)return e.name;throw this.createInternalThrowError(c.VariableTypeSyntaxError,e.type,e)}variableDeclarationHandler(e){let t;const r=[];for(let t=0;t<e.declarations.length;t++){const n=e.declarations[t];this.varDeclaration(this.getVariableName(n.id)),n.init&&r.push({type:"AssignmentExpression",operator:"=",left:n.id,right:n.init})}return r.length&&(t=this.createClosure({type:"BlockStatement",body:r})),()=>{if(t){const e=this.isVarDeclMode;this.isVarDeclMode=!0,t(),this.isVarDeclMode=e}return m}}assertVariable(e,t,r){if(e===this.globalScope.data&&!(t in e))throw this.createInternalThrowError(c.VariableUndefinedReferenceError,t,r)}programHandler(e){const t=e.body.map((e=>this.createClosure(e)));return()=>{let e=m;for(let r=0;r<t.length;r++){const n=t[r],a=this.setValue(n());if(a!==m&&(e=a,e instanceof E||e instanceof g||e instanceof C||e===h||e===p))break}return e}}expressionStatementHandler(e){return this.createClosure(e.expression)}emptyStatementHandler(e){return()=>m}returnStatementHandler(e){const t=e.argument?this.createClosure(e.argument):k;return()=>new E(t())}ifStatementHandler(e){const t=this.createClosure(e.test),r=this.createClosure(e.consequent),n=e.alternate?this.createClosure(e.alternate):/*!important*/()=>m;return()=>t()?r():n()}conditionalExpressionHandler(e){return this.ifStatementHandler(e)}forStatementHandler(e){let t=k,r=e.test?this.createClosure(e.test):()=>!0,n=k;const a=this.createClosure(e.body);return"ForStatement"===e.type&&(t=e.init?this.createClosure(e.init):t,n=e.update?this.createClosure(e.update):k),s=>{let o,i=m,c="DoWhileStatement"===e.type;for(s&&"LabeledStatement"===s.type&&(o=s.label.name),t();c||r();n()){c=!1;const e=this.setValue(a());if(e!==m&&e!==p){if(e===h)break;if(i=e,i instanceof C&&i.value===o)i=m;else if(i instanceof E||i instanceof g||i instanceof C)break}}return i}}whileStatementHandler(e){return this.forStatementHandler(e)}doWhileStatementHandler(e){return this.forStatementHandler(e)}forInStatementHandler(e){let t=e.left;const r=this.createClosure(e.right),n=this.createClosure(e.body);return"VariableDeclaration"===e.left.type&&(this.createClosure(e.left)(),t=e.left.declarations[0].id),e=>{let a,s,o=m;e&&"LabeledStatement"===e.type&&(a=e.label.name);const i=r();for(s in i){this.assignmentExpressionHandler({type:"AssignmentExpression",operator:"=",left:t,right:{type:"Literal",value:s}})();const e=this.setValue(n());if(e!==m&&e!==p){if(e===h)break;if(o=e,o instanceof C&&o.value===a)o=m;else if(o instanceof E||o instanceof g||o instanceof C)break}}return o}}withStatementHandler(e){const t=this.createClosure(e.object),r=this.createClosure(e.body);return()=>{const e=t(),n=this.getCurrentScope(),a=new w(e,n,f);this.setCurrentScope(a);const s=this.setValue(r());return this.setCurrentScope(n),s}}throwStatementHandler(e){const t=this.createClosure(e.argument);return()=>{throw this.setValue(void 0),t()}}tryStatementHandler(e){const t=this.createClosure(e.block),r=e.handler?this.catchClauseHandler(e.handler):null,n=e.finalizer?this.createClosure(e.finalizer):null;return()=>{const e=this.getCurrentScope(),a=this.getCurrentContext(),s=e.labelStack.concat([]),o=this.callStack.concat([]);let i,c,l=m;const u=()=>{this.setCurrentScope(e),this.setCurrentContext(a),e.labelStack=s,this.callStack=o};try{l=this.setValue(t()),l instanceof E&&(i=l)}catch(e){if(u(),this.isInterruptThrow(e))throw e;if(r)try{l=this.setValue(r(e)),l instanceof E&&(i=l)}catch(e){if(u(),this.isInterruptThrow(e))throw e;c=e}}if(n)try{l=n(),l instanceof E&&(i=l)}catch(e){if(u(),this.isInterruptThrow(e))throw e;c=e}if(c)throw c;return i||l}}catchClauseHandler(e){const t=this.createParamNameGetter(e.param),r=this.createClosure(e.body);return e=>{let n;const a=this.getCurrentScope().data,s=t(),o=u.call(a,s),i=a[s];return a[s]=e,n=r(),o?a[s]=i:delete a[s],n}}continueStatementHandler(e){return()=>e.label?new C(e.label.name):p}breakStatementHandler(e){return()=>e.label?new g(e.label.name):h}switchStatementHandler(e){const t=this.createClosure(e.discriminant),r=e.cases.map((e=>this.switchCaseHandler(e)));return()=>{const e=t();let n,a,s,o=!1;for(let t=0;t<r.length;t++){const i=r[t](),c=i.testClosure();if(c!==d){if(o||c===e){if(o=!0,a=this.setValue(i.bodyClosure()),a===m)continue;if(a===h)break;if(n=a,n instanceof E||n instanceof g||n instanceof C||n===p)break}}else s=i}if(!o&&s){a=this.setValue(s.bodyClosure());a===m||a===h||(n=a)}return n}}switchCaseHandler(e){const t=e.test?this.createClosure(e.test):()=>d,r=this.createClosure({type:"BlockStatement",body:e.consequent});return()=>({testClosure:t,bodyClosure:r})}labeledStatementHandler(e){const t=e.label.name,r=this.createClosure(e.body);return()=>{let n;const a=this.getCurrentScope();return a.labelStack.push(t),n=r(e),n instanceof g&&n.value===t&&(n=m),a.labelStack.pop(),n}}debuggerStatementHandler(e){return()=>m}createParamNameGetter(e){if("Identifier"===e.type)return()=>e.name;throw this.createInternalThrowError(c.ParamTypeSyntaxError,e.type,e)}createObjectKeyGetter(e){let t;return t="Identifier"===e.type?()=>e.name:this.createClosure(e),function(){return t()}}createMemberKeyGetter(e){return e.computed?this.createClosure(e.property):this.createObjectKeyGetter(e.property)}createObjectGetter(e){switch(e.type){case"Identifier":return()=>this.getScopeDataFromName(e.name,this.getCurrentScope());case"MemberExpression":return this.createClosure(e.object);default:throw this.createInternalThrowError(c.AssignmentTypeSyntaxError,e.type,e)}}createNameGetter(e){switch(e.type){case"Identifier":return()=>e.name;case"MemberExpression":return this.createMemberKeyGetter(e);default:throw this.createInternalThrowError(c.AssignmentTypeSyntaxError,e.type,e)}}varDeclaration(e){this.collectDeclVars[e]=void 0}funcDeclaration(e,t){this.collectDeclFuncs[e]=t}addDeclarationsToScope(e,t,r){const n=r.data;for(let e in t){const r=t[e];n[e]=r?r():r}for(let t in e)t in n||(n[t]=void 0)}getScopeValue(e,t){return this.getScopeFromName(e,t).data[e]}getScopeDataFromName(e,t){return this.getScopeFromName(e,t).data}getScopeFromName(e,t){let r=t;do{if(e in r.data)return r}while(r=r.parent);return this.globalScope}setValue(e){const t=this.callStack.length;return this.isVarDeclMode||t||e===m||e===h||e===p||e instanceof g||e instanceof C||(this.value=e instanceof E?e.value:e),e}getValue(){return this.value}}e.Interpreter=I}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).eval5={})}(this,(function(e){"use strict";var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},t(e,r)};function r(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}var n=function(){return n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},n.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var o=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t}(Error),a=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t}(SyntaxError),i=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t}(ReferenceError),c=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t}(TypeError),s=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t}(o),u=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t}(a),l=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t}(i),p={UnknownError:[3001,"%0",s],ExecutionTimeOutError:[3002,"Script execution timed out after %0ms",s],NodeTypeSyntaxError:[1001,"Unknown node type: %0",l],BinaryOperatorSyntaxError:[1002,"Unknown binary operator: %0",l],LogicalOperatorSyntaxError:[1003,"Unknown logical operator: %0",l],UnaryOperatorSyntaxError:[1004,"Unknown unary operator: %0",l],UpdateOperatorSyntaxError:[1005,"Unknown update operator: %0",l],ObjectStructureSyntaxError:[1006,"Unknown object structure: %0",l],AssignmentExpressionSyntaxError:[1007,"Unknown assignment expression: %0",l],VariableTypeSyntaxError:[1008,"Unknown variable type: %0",l],ParamTypeSyntaxError:[1009,"Unknown param type: %0",l],AssignmentTypeSyntaxError:[1010,"Unknown assignment type: %0",l],FunctionUndefinedReferenceError:[2001,"%0 is not a function",i],VariableUndefinedReferenceError:[2002,"%0 is not defined",i],IsNotConstructor:[2003,"%0 is not a constructor",c]};function f(e,t){Object.defineProperty(e,"name",{value:t,writable:!1,enumerable:!1,configurable:!0})}var h=Object.prototype.hasOwnProperty,d=Symbol("Break"),y=Symbol("Continue"),m=Symbol("DefaultCase"),b=Symbol("EmptyStatementReturn"),S=Symbol("WithScopeName"),v=Symbol("SuperScopeName"),E=Symbol("RootScopeName"),g=Symbol("GlobalScopeName");function x(e){return"function"==typeof e}var C=function(e){this.value=e},w=function(e){this.value=e},k=function(e){this.value=e},H=function(e,t,r){void 0===t&&(t=null),this.name=r,this.parent=t,this.data=e,this.labelStack=[]};function I(){}var T={NaN:NaN,Infinity:1/0,undefined:void 0,Object:Object,Array:Array,String:String,Boolean:Boolean,Number:Number,Date:Date,RegExp:RegExp,Error:Error,URIError:URIError,TypeError:TypeError,RangeError:RangeError,SyntaxError:SyntaxError,ReferenceError:ReferenceError,Math:Math,parseInt:parseInt,parseFloat:parseFloat,isNaN:isNaN,isFinite:isFinite,decodeURI:decodeURI,decodeURIComponent:decodeURIComponent,encodeURI:encodeURI,encodeURIComponent:encodeURIComponent,escape:escape,unescape:unescape};"undefined"!=typeof JSON&&(T.JSON=JSON),"undefined"!=typeof Promise&&(T.Promise=Promise),"undefined"!=typeof Set&&(T.Set=Set),"undefined"!=typeof Map&&(T.Map=Map),"undefined"!=typeof Symbol&&(T.Symbol=Symbol),"undefined"!=typeof Proxy&&(T.Proxy=Proxy),"undefined"!=typeof WeakMap&&(T.WeakMap=WeakMap),"undefined"!=typeof WeakSet&&(T.WeakSet=WeakSet),"undefined"!=typeof Reflect&&(T.Reflect=Reflect);var O=function(){function e(t,r){void 0===t&&(t=e.global),void 0===r&&(r={}),this.sourceList=[],this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null),this.isVarDeclMode=!1,this.lastExecNode=null,this.isRunning=!1,this.options={timeout:r.timeout||0,rootContext:r.rootContext,globalContextInFunction:void 0===r.globalContextInFunction?e.globalContextInFunction:r.globalContextInFunction,_initEnv:r._initEnv},this.context=t||Object.create(null),this.callStack=[],this.initEnvironment(this.context)}return e.prototype.initEnvironment=function(e){var t,r;if(e instanceof H)t=e;else{var n=null,o=this.createSuperScope(e);this.options.rootContext&&(n=new H((r=this.options.rootContext,Object.create(r)),o,E)),t=new H(e,n||o,g)}this.globalScope=t,this.currentScope=this.globalScope,this.globalContext=t.data,this.currentContext=t.data,this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null),this.execStartTime=Date.now(),this.execEndTime=this.execStartTime;var a=this.options._initEnv;a&&a.call(this)},e.prototype.getExecStartTime=function(){return this.execStartTime},e.prototype.getExecutionTime=function(){return this.execEndTime-this.execStartTime},e.prototype.setExecTimeout=function(e){void 0===e&&(e=0),this.options.timeout=e},e.prototype.getOptions=function(){return this.options},e.prototype.getCurrentScope=function(){return this.currentScope},e.prototype.getCurrentContext=function(){return this.currentContext},e.prototype.isInterruptThrow=function(e){return e instanceof s||e instanceof l||e instanceof u},e.prototype.createSuperScope=function(e){var t=n({},T);return Object.keys(t).forEach((function(r){r in e&&delete t[r]})),new H(t,null,v)},e.prototype.setCurrentContext=function(e){this.currentContext=e},e.prototype.setCurrentScope=function(e){this.currentScope=e},e.prototype.evaluateNode=function(e,t){var r=this;void 0===t&&(t=""),this.value=void 0,this.source=t,this.sourceList.push(t),this.isRunning=!0,this.execStartTime=Date.now(),this.execEndTime=this.execStartTime,this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null);var n=this.getCurrentScope(),o=this.getCurrentContext(),a=n.labelStack.concat([]),i=this.callStack.concat([]);try{var c=this.createClosure(e);this.addDeclarationsToScope(this.collectDeclVars,this.collectDeclFuncs,this.getCurrentScope()),c()}catch(e){throw e}finally{r.setCurrentScope(n),r.setCurrentContext(o),n.labelStack=a,r.callStack=i,this.execEndTime=Date.now()}return this.isRunning=!1,this.getValue()},e.prototype.createErrorMessage=function(e,t,r){var n=e[1].replace("%0",String(t));return null!==r&&(n+=this.getNodePosition(r||this.lastExecNode)),n},e.prototype.createError=function(e,t){return new t(e)},e.prototype.createThrowError=function(e,t){return this.createError(e,t)},e.prototype.createInternalThrowError=function(e,t,r){return this.createError(this.createErrorMessage(e,t,r),e[2])},e.prototype.checkTimeout=function(){if(!this.isRunning)return!1;var e=this.options.timeout||0;return Date.now()-this.execStartTime>e},e.prototype.getNodePosition=function(e){if(e){return e.loc?" [".concat(e.loc.start.line,":").concat(e.loc.start.column,"]").concat(""):""}return""},e.prototype.createClosure=function(e){var t,r=this;switch(e.type){case"BinaryExpression":t=this.binaryExpressionHandler(e);break;case"LogicalExpression":t=this.logicalExpressionHandler(e);break;case"UnaryExpression":t=this.unaryExpressionHandler(e);break;case"UpdateExpression":t=this.updateExpressionHandler(e);break;case"ObjectExpression":t=this.objectExpressionHandler(e);break;case"ArrayExpression":t=this.arrayExpressionHandler(e);break;case"CallExpression":t=this.callExpressionHandler(e);break;case"NewExpression":t=this.newExpressionHandler(e);break;case"MemberExpression":t=this.memberExpressionHandler(e);break;case"ThisExpression":t=this.thisExpressionHandler(e);break;case"SequenceExpression":t=this.sequenceExpressionHandler(e);break;case"Literal":t=this.literalHandler(e);break;case"Identifier":t=this.identifierHandler(e);break;case"AssignmentExpression":t=this.assignmentExpressionHandler(e);break;case"FunctionDeclaration":t=this.functionDeclarationHandler(e);break;case"VariableDeclaration":t=this.variableDeclarationHandler(e);break;case"BlockStatement":case"Program":t=this.programHandler(e);break;case"ExpressionStatement":t=this.expressionStatementHandler(e);break;case"EmptyStatement":t=this.emptyStatementHandler(e);break;case"ReturnStatement":t=this.returnStatementHandler(e);break;case"FunctionExpression":t=this.functionExpressionHandler(e);break;case"IfStatement":t=this.ifStatementHandler(e);break;case"ConditionalExpression":t=this.conditionalExpressionHandler(e);break;case"ForStatement":t=this.forStatementHandler(e);break;case"WhileStatement":t=this.whileStatementHandler(e);break;case"DoWhileStatement":t=this.doWhileStatementHandler(e);break;case"ForInStatement":t=this.forInStatementHandler(e);break;case"WithStatement":t=this.withStatementHandler(e);break;case"ThrowStatement":t=this.throwStatementHandler(e);break;case"TryStatement":t=this.tryStatementHandler(e);break;case"ContinueStatement":t=this.continueStatementHandler(e);break;case"BreakStatement":t=this.breakStatementHandler(e);break;case"SwitchStatement":t=this.switchStatementHandler(e);break;case"LabeledStatement":t=this.labeledStatementHandler(e);break;case"DebuggerStatement":t=this.debuggerStatementHandler(e);break;default:throw this.createInternalThrowError(p.NodeTypeSyntaxError,e.type,e)}return function(){for(var n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];var a=r.options.timeout;if(a&&a>0&&r.checkTimeout())throw r.createInternalThrowError(p.ExecutionTimeOutError,a,null);return r.lastExecNode=e,t.apply(void 0,n)}},e.prototype.binaryExpressionHandler=function(e){var t=this,r=this.createClosure(e.left),n=this.createClosure(e.right);return function(){var o=r(),a=n();switch(e.operator){case"==":return o==a;case"!=":return o!=a;case"===":return o===a;case"!==":return o!==a;case"<":return o<a;case"<=":return o<=a;case">":return o>a;case">=":return o>=a;case"<<":return o<<a;case">>":return o>>a;case">>>":return o>>>a;case"+":return o+a;case"-":return o-a;case"*":return o*a;case"**":return Math.pow(o,a);case"/":return o/a;case"%":return o%a;case"|":return o|a;case"^":return o^a;case"&":return o&a;case"in":return o in a;case"instanceof":return o instanceof a;default:throw t.createInternalThrowError(p.BinaryOperatorSyntaxError,e.operator,e)}}},e.prototype.logicalExpressionHandler=function(e){var t=this,r=this.createClosure(e.left),n=this.createClosure(e.right);return function(){switch(e.operator){case"||":return r()||n();case"&&":return r()&&n();default:throw t.createInternalThrowError(p.LogicalOperatorSyntaxError,e.operator,e)}}},e.prototype.unaryExpressionHandler=function(e){var t,r=this;if("delete"===e.operator){var n=this.createObjectGetter(e.argument),o=this.createNameGetter(e.argument);return function(){return delete n()[o()]}}if("typeof"===e.operator&&"Identifier"===e.argument.type){var a=this.createObjectGetter(e.argument),i=this.createNameGetter(e.argument);t=function(){return a()[i()]}}else t=this.createClosure(e.argument);return function(){var n=t();switch(e.operator){case"-":return-n;case"+":return+n;case"!":return!n;case"~":return~n;case"void":return;case"typeof":return typeof n;default:throw r.createInternalThrowError(p.UnaryOperatorSyntaxError,e.operator,e)}}},e.prototype.updateExpressionHandler=function(e){var t=this,r=this.createObjectGetter(e.argument),n=this.createNameGetter(e.argument);return function(){var o=r(),a=n();switch(t.assertVariable(o,a,e),e.operator){case"++":return e.prefix?++o[a]:o[a]++;case"--":return e.prefix?--o[a]:o[a]--;default:throw t.createInternalThrowError(p.UpdateOperatorSyntaxError,e.operator,e)}}},e.prototype.objectExpressionHandler=function(e){var t=this,r=[];var n=Object.create(null);return e.properties.forEach((function(e){var o=e.kind,a=function(e){return"Identifier"===e.type?e.name:"Literal"===e.type?e.value:this.throwError(p.ObjectStructureSyntaxError,e.type,e)}(e.key);n[a]&&"init"!==o||(n[a]={}),n[a][o]=t.createClosure(e.value),r.push({key:a,property:e})})),function(){for(var e={},t=r.length,o=0;o<t;o++){var a=r[o],i=a.key,c=n[i],s=c.init?c.init():void 0,u=c.get?c.get():function(){},l=c.set?c.set():function(e){};if("set"in c||"get"in c){var p={configurable:!0,enumerable:!0,get:u,set:l};Object.defineProperty(e,i,p)}else{var h=a.property,d=h.kind;"Identifier"!==h.key.type||"FunctionExpression"!==h.value.type||"init"!==d||h.value.id||f(s,h.key.name),e[i]=s}}return e}},e.prototype.arrayExpressionHandler=function(e){var t=this,r=e.elements.map((function(e){return e?t.createClosure(e):e}));return function(){for(var e=r.length,t=Array(e),n=0;n<e;n++){var o=r[n];o&&(t[n]=o())}return t}},e.prototype.safeObjectGet=function(e,t,r){return e[t]},e.prototype.createCallFunctionGetter=function(e){var t=this;if("MemberExpression"===e.type){var r=this.createClosure(e.object),n=this.createMemberKeyGetter(e),o=this.source;return function(){var a=r(),i=n(),c=t.safeObjectGet(a,i,e);if(!c||!x(c)){var s=o.slice(e.start,e.end);throw t.createInternalThrowError(p.FunctionUndefinedReferenceError,s,e)}return c.bind(a)}}var a=this.createClosure(e);return function(){var r="";"Identifier"===e.type&&(r=e.name);var n=a();if(!n||!x(n))throw t.createInternalThrowError(p.FunctionUndefinedReferenceError,r,e);var o=t.options.globalContextInFunction;if("Identifier"===e.type){var i=t.getIdentifierScope(e);i.name===S&&(o=i.data)}return n.bind(o)}},e.prototype.callExpressionHandler=function(e){var t=this,r=this.createCallFunctionGetter(e.callee),n=e.arguments.map((function(e){return t.createClosure(e)}));return function(){return r().apply(void 0,n.map((function(e){return e()})))}},e.prototype.functionExpressionHandler=function(e){var t=this,r=this,n=this.source,o=this.collectDeclVars,a=this.collectDeclFuncs;this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null);var i=e.id?e.id.name:"",c=e.params.length,s=e.params.map((function(e){return t.createParamNameGetter(e)})),u=this.createClosure(e.body),l=this.collectDeclVars,p=this.collectDeclFuncs;return this.collectDeclVars=o,this.collectDeclFuncs=a,function(){var t=r.getCurrentScope(),o=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];r.callStack.push("".concat(i));var a=r.getCurrentScope(),c=function(e,t){return void 0===e&&(e=null),new H(Object.create(null),e,t)}(t,"FunctionScope(".concat(i,")"));r.setCurrentScope(c),r.addDeclarationsToScope(l,p,c),i&&(c.data[i]=o),c.data.arguments=arguments,s.forEach((function(t,r){c.data[t()]=e[r]}));var f=r.getCurrentContext();r.setCurrentContext(this);var h=u();if(r.setCurrentContext(f),r.setCurrentScope(a),r.callStack.pop(),h instanceof C)return h.value};return f(o,i),Object.defineProperty(o,"length",{value:c,writable:!1,enumerable:!1,configurable:!0}),Object.defineProperty(o,"toString",{value:function(){return n.slice(e.start,e.end)},writable:!0,configurable:!0,enumerable:!1}),Object.defineProperty(o,"valueOf",{value:function(){return n.slice(e.start,e.end)},writable:!0,configurable:!0,enumerable:!1}),o}},e.prototype.newExpressionHandler=function(e){var t=this,r=this.source,n=this.createClosure(e.callee),o=e.arguments.map((function(e){return t.createClosure(e)}));return function(){var a=n();if(!x(a)||a.__IS_EVAL_FUNC){var i=e.callee,c=r.slice(i.start,i.end);throw t.createInternalThrowError(p.IsNotConstructor,c,e)}return new(a.bind.apply(a,function(e,t,r){if(r||2===arguments.length)for(var n,o=0,a=t.length;o<a;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}([void 0],o.map((function(e){return e()})),!1)))}},e.prototype.memberExpressionHandler=function(e){var t=this.createClosure(e.object),r=this.createMemberKeyGetter(e);return function(){return t()[r()]}},e.prototype.thisExpressionHandler=function(e){var t=this;return function(){return t.getCurrentContext()}},e.prototype.sequenceExpressionHandler=function(e){var t=this,r=e.expressions.map((function(e){return t.createClosure(e)}));return function(){for(var e,t=r.length,n=0;n<t;n++){e=(0,r[n])()}return e}},e.prototype.literalHandler=function(e){return function(){return e.regex?new RegExp(e.regex.pattern,e.regex.flags):e.value}},e.prototype.identifierHandler=function(e){var t=this;return function(){var r=t.getCurrentScope(),n=t.getScopeDataFromName(e.name,r);return t.assertVariable(n,e.name,e),n[e.name]}},e.prototype.getIdentifierScope=function(e){var t=this.getCurrentScope();return this.getScopeFromName(e.name,t)},e.prototype.assignmentExpressionHandler=function(e){var t=this;"Identifier"!==e.left.type||"FunctionExpression"!==e.right.type||e.right.id||(e.right.id={type:"Identifier",name:e.left.name});var r=this.createObjectGetter(e.left),n=this.createNameGetter(e.left),o=this.createClosure(e.right);return function(){var a=r(),i=n(),c=o();switch("="!==e.operator&&t.assertVariable(a,i,e),e.operator){case"=":return a[i]=c;case"+=":return a[i]+=c;case"-=":return a[i]-=c;case"*=":return a[i]*=c;case"**=":return a[i]=Math.pow(a[i],c);case"/=":return a[i]/=c;case"%=":return a[i]%=c;case"<<=":return a[i]<<=c;case">>=":return a[i]>>=c;case">>>=":return a[i]>>>=c;case"&=":return a[i]&=c;case"^=":return a[i]^=c;case"|=":return a[i]|=c;default:throw t.createInternalThrowError(p.AssignmentExpressionSyntaxError,e.type,e)}}},e.prototype.functionDeclarationHandler=function(e){if(e.id){var t=this.functionExpressionHandler(e);Object.defineProperty(t,"isFunctionDeclareClosure",{value:!0,writable:!1,configurable:!1,enumerable:!1}),this.funcDeclaration(e.id.name,t)}return function(){return b}},e.prototype.getVariableName=function(e){if("Identifier"===e.type)return e.name;throw this.createInternalThrowError(p.VariableTypeSyntaxError,e.type,e)},e.prototype.variableDeclarationHandler=function(e){for(var t,r=this,n=[],o=0;o<e.declarations.length;o++){var a=e.declarations[o];this.varDeclaration(this.getVariableName(a.id)),a.init&&n.push({type:"AssignmentExpression",operator:"=",left:a.id,right:a.init})}return n.length&&(t=this.createClosure({type:"BlockStatement",body:n})),function(){if(t){var e=r.isVarDeclMode;r.isVarDeclMode=!0,t(),r.isVarDeclMode=e}return b}},e.prototype.assertVariable=function(e,t,r){if(e===this.globalScope.data&&!(t in e))throw this.createInternalThrowError(p.VariableUndefinedReferenceError,t,r)},e.prototype.programHandler=function(e){var t=this,r=e.body.map((function(e){return t.createClosure(e)}));return function(){for(var e=b,n=0;n<r.length;n++){var o=r[n],a=t.setValue(o());if(a!==b&&((e=a)instanceof C||e instanceof w||e instanceof k||e===d||e===y))break}return e}},e.prototype.expressionStatementHandler=function(e){return this.createClosure(e.expression)},e.prototype.emptyStatementHandler=function(e){return function(){return b}},e.prototype.returnStatementHandler=function(e){var t=e.argument?this.createClosure(e.argument):I;return function(){return new C(t())}},e.prototype.ifStatementHandler=function(e){var t=this.createClosure(e.test),r=this.createClosure(e.consequent),n=e.alternate?this.createClosure(e.alternate):/*!important*/function(){return b};return function(){return t()?r():n()}},e.prototype.conditionalExpressionHandler=function(e){return this.ifStatementHandler(e)},e.prototype.forStatementHandler=function(e){var t=this,r=I,n=e.test?this.createClosure(e.test):function(){return!0},o=I,a=this.createClosure(e.body);return"ForStatement"===e.type&&(r=e.init?this.createClosure(e.init):r,o=e.update?this.createClosure(e.update):I),function(i){var c,s=b,u="DoWhileStatement"===e.type;for(i&&"LabeledStatement"===i.type&&(c=i.label.name),r();u||n();o()){u=!1;var l=t.setValue(a());if(l!==b&&l!==y){if(l===d)break;if((s=l)instanceof k&&s.value===c)s=b;else if(s instanceof C||s instanceof w||s instanceof k)break}}return s}},e.prototype.whileStatementHandler=function(e){return this.forStatementHandler(e)},e.prototype.doWhileStatementHandler=function(e){return this.forStatementHandler(e)},e.prototype.forInStatementHandler=function(e){var t=this,r=e.left,n=this.createClosure(e.right),o=this.createClosure(e.body);return"VariableDeclaration"===e.left.type&&(this.createClosure(e.left)(),r=e.left.declarations[0].id),function(e){var a,i,c=b;e&&"LabeledStatement"===e.type&&(a=e.label.name);var s=n();for(i in s){t.assignmentExpressionHandler({type:"AssignmentExpression",operator:"=",left:r,right:{type:"Literal",value:i}})();var u=t.setValue(o());if(u!==b&&u!==y){if(u===d)break;if((c=u)instanceof k&&c.value===a)c=b;else if(c instanceof C||c instanceof w||c instanceof k)break}}return c}},e.prototype.withStatementHandler=function(e){var t=this,r=this.createClosure(e.object),n=this.createClosure(e.body);return function(){var e=r(),o=t.getCurrentScope(),a=new H(e,o,S);t.setCurrentScope(a);var i=t.setValue(n());return t.setCurrentScope(o),i}},e.prototype.throwStatementHandler=function(e){var t=this,r=this.createClosure(e.argument);return function(){throw t.setValue(void 0),r()}},e.prototype.tryStatementHandler=function(e){var t=this,r=this.createClosure(e.block),n=e.handler?this.catchClauseHandler(e.handler):null,o=e.finalizer?this.createClosure(e.finalizer):null;return function(){var e,a,i=t.getCurrentScope(),c=t.getCurrentContext(),s=i.labelStack.concat([]),u=t.callStack.concat([]),l=b,p=function(){t.setCurrentScope(i),t.setCurrentContext(c),i.labelStack=s,t.callStack=u};try{(l=t.setValue(r()))instanceof C&&(e=l)}catch(r){if(p(),t.isInterruptThrow(r))throw r;if(n)try{(l=t.setValue(n(r)))instanceof C&&(e=l)}catch(e){if(p(),t.isInterruptThrow(e))throw e;a=e}}if(o)try{(l=o())instanceof C&&(e=l)}catch(e){if(p(),t.isInterruptThrow(e))throw e;a=e}if(a)throw a;return e||l}},e.prototype.catchClauseHandler=function(e){var t=this,r=this.createParamNameGetter(e.param),n=this.createClosure(e.body);return function(e){var o,a=t.getCurrentScope().data,i=r(),c=h.call(a,i),s=a[i];return a[i]=e,o=n(),c?a[i]=s:delete a[i],o}},e.prototype.continueStatementHandler=function(e){return function(){return e.label?new k(e.label.name):y}},e.prototype.breakStatementHandler=function(e){return function(){return e.label?new w(e.label.name):d}},e.prototype.switchStatementHandler=function(e){var t=this,r=this.createClosure(e.discriminant),n=e.cases.map((function(e){return t.switchCaseHandler(e)}));return function(){for(var e,o,a,i=r(),c=!1,s=0;s<n.length;s++){var u=n[s](),l=u.testClosure();if(l!==m){if(c||l===i){if(c=!0,(o=t.setValue(u.bodyClosure()))===b)continue;if(o===d)break;if((e=o)instanceof C||e instanceof w||e instanceof k||e===y)break}}else a=u}!c&&a&&((o=t.setValue(a.bodyClosure()))===b||o===d||(e=o));return e}},e.prototype.switchCaseHandler=function(e){var t=e.test?this.createClosure(e.test):function(){return m},r=this.createClosure({type:"BlockStatement",body:e.consequent});return function(){return{testClosure:t,bodyClosure:r}}},e.prototype.labeledStatementHandler=function(e){var t=this,r=e.label.name,n=this.createClosure(e.body);return function(){var o,a=t.getCurrentScope();return a.labelStack.push(r),(o=n(e))instanceof w&&o.value===r&&(o=b),a.labelStack.pop(),o}},e.prototype.debuggerStatementHandler=function(e){return function(){return b}},e.prototype.createParamNameGetter=function(e){if("Identifier"===e.type)return function(){return e.name};throw this.createInternalThrowError(p.ParamTypeSyntaxError,e.type,e)},e.prototype.createObjectKeyGetter=function(e){var t;return t="Identifier"===e.type?function(){return e.name}:this.createClosure(e),function(){return t()}},e.prototype.createMemberKeyGetter=function(e){return e.computed?this.createClosure(e.property):this.createObjectKeyGetter(e.property)},e.prototype.createObjectGetter=function(e){var t=this;switch(e.type){case"Identifier":return function(){return t.getScopeDataFromName(e.name,t.getCurrentScope())};case"MemberExpression":return this.createClosure(e.object);default:throw this.createInternalThrowError(p.AssignmentTypeSyntaxError,e.type,e)}},e.prototype.createNameGetter=function(e){switch(e.type){case"Identifier":return function(){return e.name};case"MemberExpression":return this.createMemberKeyGetter(e);default:throw this.createInternalThrowError(p.AssignmentTypeSyntaxError,e.type,e)}},e.prototype.varDeclaration=function(e){this.collectDeclVars[e]=void 0},e.prototype.funcDeclaration=function(e,t){this.collectDeclFuncs[e]=t},e.prototype.addDeclarationsToScope=function(e,t,r){var n=r.data;for(var o in t){var a=t[o];n[o]=a?a():a}for(var o in e)o in n||(n[o]=void 0)},e.prototype.getScopeValue=function(e,t){return this.getScopeFromName(e,t).data[e]},e.prototype.getScopeDataFromName=function(e,t){return this.getScopeFromName(e,t).data},e.prototype.getScopeFromName=function(e,t){var r=t;do{if(e in r.data)return r}while(r=r.parent);return this.globalScope},e.prototype.setValue=function(e){var t=this.callStack.length;return this.isVarDeclMode||t||e===b||e===d||e===y||e instanceof w||e instanceof k||(this.value=e instanceof C?e.value:e),e},e.prototype.getValue=function(){return this.value},e.version="0.0.2",e.ecmaVersion=5,e.globalContextInFunction=void 0,e.global=Object.create(null),e}();e.Interpreter=O}));
//# sourceMappingURL=index.min.js.map
{
"name": "@huolala-tech/eval5",
"version": "0.0.1",
"version": "0.0.2",
"description": "A JavaScript vm written in JavaScript. Forked from eval5",

@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js",

@@ -12,3 +12,3 @@ # eval5

> [!INFO]
> [!NOTE]
> Forked from [eval5](https://github.com/bplok20010/eval5)

@@ -15,0 +15,0 @@

@@ -12,3 +12,3 @@ # eval5

> [!INFO]
> [!NOTE]
> Forked from [eval5](https://github.com/bplok20010/eval5)

@@ -15,0 +15,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc