UNPKG

@huolala-tech/eval5

Version:

A JavaScript vm written in JavaScript. Forked from eval5

3 lines (2 loc) 25.3 kB
!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