Comparing version 1.0.5 to 1.0.6
import { MessageItem } from "./messages"; | ||
import { Node, ESTree } from "./nodes"; | ||
declare type Getter = () => any; | ||
declare type BaseClosure = (pNode?: Node) => any; | ||
interface BaseClosure { | ||
(pNode?: Node): any; | ||
isFunctionDeclareClosure?: boolean; | ||
} | ||
declare type CaseItem = { | ||
@@ -84,3 +87,3 @@ testClosure: BaseClosure; | ||
end?: number; | ||
})): () => (...args: any[]) => any; | ||
})): BaseClosure; | ||
newExpressionHandler(node: ESTree.NewExpression): BaseClosure; | ||
@@ -121,2 +124,3 @@ memberExpressionHandler(node: ESTree.MemberExpression): BaseClosure; | ||
labeledStatementHandler(node: ESTree.LabeledStatement): BaseClosure; | ||
debuggerStatementHandler(node: ESTree.DebuggerStatement): BaseClosure; | ||
createParamNameGetter(node: ESTree.Pattern): ReturnStringClosure; | ||
@@ -123,0 +127,0 @@ createObjectKeyGetter(node: ESTree.Expression): Getter; |
import _construct from "@babel/runtime/helpers/construct"; | ||
import { parse } from "acorn"; | ||
import { Messages, InterruptThrowError, InterruptThrowReferenceError, InterruptThrowSyntaxError } from "./messages"; | ||
function defineFunctionName(func, name) { | ||
Object.defineProperty(func, "name", { | ||
value: name, | ||
writable: false, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
} | ||
var hasOwnProperty = Object.prototype.hasOwnProperty; | ||
@@ -355,2 +365,6 @@ var FunctionNameSymbol = Symbol("name"); | ||
case "DebuggerStatement": | ||
closure = this.debuggerStatementHandler(node); | ||
break; | ||
default: | ||
@@ -590,12 +604,2 @@ throw this.createInternalThrowError(Messages.NodeTypeSyntaxError, node.type, node); | ||
properties[key] = {}; | ||
} // set function.name | ||
// var d = { test(){} } | ||
// var d = { test: function(){} } | ||
if (property.key.type === "Identifier" && property.value.type === "FunctionExpression" && kind === "init" && !property.value.id) { | ||
property.value.id = { | ||
type: "Identifier", | ||
name: property.key.name | ||
}; | ||
} | ||
@@ -605,3 +609,4 @@ | ||
items.push({ | ||
key: key | ||
key: key, | ||
property: property | ||
}); | ||
@@ -630,2 +635,11 @@ }); | ||
} else { | ||
var property = item.property; | ||
var kind = property.kind; // set function.name | ||
// var d = { test(){} } | ||
// var d = { test: function(){} } | ||
if (property.key.type === "Identifier" && property.value.type === "FunctionExpression" && kind === "init" && !property.value.id) { | ||
defineFunctionName(value, property.key.name); | ||
} | ||
result[key] = value; | ||
@@ -758,4 +772,13 @@ } | ||
self.setCurrentScope(currentScope); | ||
self.addDeclarationsToScope(declarations, currentScope); // init arguments var | ||
self.addDeclarationsToScope(declarations, currentScope); // var t = function(){ typeof t } // function | ||
// t = function(){ typeof t } // function | ||
// z = function tx(){ typeof tx } // function | ||
// but | ||
// d = { say: function(){ typeof say } } // undefined | ||
if (name) { | ||
currentScope.data[name] = func; | ||
} // init arguments var | ||
currentScope.data["arguments"] = arguments; | ||
@@ -780,8 +803,9 @@ paramsGetter.forEach(function (getter, i) { | ||
Object.defineProperty(func, "name", { | ||
value: name, | ||
writable: false, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
defineFunctionName(func, name); // Object.defineProperty(func, "name", { | ||
// value: name, | ||
// writable: false, | ||
// enumerable: false, | ||
// configurable: true, | ||
// }); | ||
Object.defineProperty(func, "length", { | ||
@@ -1023,3 +1047,10 @@ value: paramLength, | ||
if (node.id) { | ||
this.funcDeclaration(node.id.name, this.functionExpressionHandler(node)); | ||
var functionClosure = this.functionExpressionHandler(node); | ||
Object.defineProperty(functionClosure, "isFunctionDeclareClosure", { | ||
value: true, | ||
writable: false, | ||
configurable: false, | ||
enumerable: false | ||
}); | ||
this.funcDeclaration(node.id.name, functionClosure); | ||
} | ||
@@ -1170,3 +1201,3 @@ | ||
initClosure = node.init ? this.createClosure(node.init) : initClosure; | ||
updateClosure = node.update ? this.createClosure(node.update) : initClosure; | ||
updateClosure = node.update ? this.createClosure(node.update) : noop; | ||
} | ||
@@ -1331,2 +1362,4 @@ | ||
var currentContext = _this21.getCurrentContext(); | ||
var labelStack = currentScope.labelStack.concat([]); | ||
@@ -1339,2 +1372,14 @@ | ||
var throwError; | ||
var reset = function reset() { | ||
_this21.setCurrentScope(currentScope); //reset scope | ||
_this21.setCurrentContext(currentContext); //reset context | ||
currentScope.labelStack = labelStack; //reset label stack | ||
_this21.callStack = callStack; //reset call stack | ||
}; | ||
/** | ||
@@ -1351,2 +1396,3 @@ * try{...}catch(e){...}finally{...} execution sequence: | ||
try { | ||
@@ -1359,4 +1405,3 @@ result = _this21.setValue(blockClosure()); | ||
} catch (err) { | ||
currentScope.labelStack = labelStack; | ||
_this21.callStack = callStack; | ||
reset(); | ||
@@ -1375,3 +1420,4 @@ if (_this21.isInterruptThrow(err)) { | ||
} catch (e) { | ||
// save catch throw error | ||
reset(); // save catch throw error | ||
throwError = e; | ||
@@ -1393,3 +1439,4 @@ } | ||
} catch (e) { | ||
// save finally throw error | ||
reset(); // save finally throw error | ||
throwError = e; | ||
@@ -1549,2 +1596,9 @@ } // if (finalReturn instanceof Return) { | ||
}; | ||
}; | ||
_proto.debuggerStatementHandler = function debuggerStatementHandler(node) { | ||
return function () { | ||
debugger; | ||
return EmptyStatementReturn; | ||
}; | ||
} // get es3/5 param name | ||
@@ -1630,5 +1684,7 @@ ; | ||
_proto.funcDeclaration = function funcDeclaration(name, func) { | ||
var _a; | ||
var context = this.collectDeclarations; | ||
if (!hasOwnProperty.call(context, name) || context[name] === undefined) { | ||
if (!hasOwnProperty.call(context, name) || context[name] === undefined || ((_a = context[name]) === null || _a === void 0 ? void 0 : _a.isFunctionDeclareClosure)) { | ||
context[name] = func; | ||
@@ -1635,0 +1691,0 @@ } |
import * as ESTree from "estree"; | ||
export { ESTree }; | ||
export declare type Node = ESTree.Node | ESTree.BinaryExpression | ESTree.LogicalExpression | ESTree.UnaryExpression | ESTree.UpdateExpression | ESTree.ObjectExpression | ESTree.ArrayExpression | ESTree.CallExpression | ESTree.NewExpression | ESTree.MemberExpression | ESTree.ThisExpression | ESTree.SequenceExpression | ESTree.Literal | ESTree.Identifier | ESTree.AssignmentExpression | ESTree.FunctionDeclaration | ESTree.VariableDeclaration | ESTree.BlockStatement | ESTree.Program | ESTree.ExpressionStatement | ESTree.EmptyStatement | ESTree.ReturnStatement | ESTree.FunctionExpression | ESTree.IfStatement | ESTree.ConditionalExpression | ESTree.ForStatement | ESTree.WhileStatement | ESTree.DoWhileStatement | ESTree.ForInStatement | ESTree.WithStatement | ESTree.ThrowStatement | ESTree.TryStatement | ESTree.ContinueStatement | ESTree.BreakStatement | ESTree.SwitchStatement | ESTree.SwitchCase | ESTree.LabeledStatement; | ||
export declare type Node = ESTree.Node | ESTree.BinaryExpression | ESTree.LogicalExpression | ESTree.UnaryExpression | ESTree.UpdateExpression | ESTree.ObjectExpression | ESTree.ArrayExpression | ESTree.CallExpression | ESTree.NewExpression | ESTree.MemberExpression | ESTree.ThisExpression | ESTree.SequenceExpression | ESTree.Literal | ESTree.Identifier | ESTree.AssignmentExpression | ESTree.FunctionDeclaration | ESTree.VariableDeclaration | ESTree.BlockStatement | ESTree.Program | ESTree.ExpressionStatement | ESTree.EmptyStatement | ESTree.ReturnStatement | ESTree.FunctionExpression | ESTree.IfStatement | ESTree.ConditionalExpression | ESTree.ForStatement | ESTree.WhileStatement | ESTree.DoWhileStatement | ESTree.ForInStatement | ESTree.WithStatement | ESTree.ThrowStatement | ESTree.TryStatement | ESTree.ContinueStatement | ESTree.BreakStatement | ESTree.SwitchStatement | ESTree.SwitchCase | ESTree.LabeledStatement | ESTree.DebuggerStatement; |
import { MessageItem } from "./messages"; | ||
import { Node, ESTree } from "./nodes"; | ||
declare type Getter = () => any; | ||
declare type BaseClosure = (pNode?: Node) => any; | ||
interface BaseClosure { | ||
(pNode?: Node): any; | ||
isFunctionDeclareClosure?: boolean; | ||
} | ||
declare type CaseItem = { | ||
@@ -84,3 +87,3 @@ testClosure: BaseClosure; | ||
end?: number; | ||
})): () => (...args: any[]) => any; | ||
})): BaseClosure; | ||
newExpressionHandler(node: ESTree.NewExpression): BaseClosure; | ||
@@ -121,2 +124,3 @@ memberExpressionHandler(node: ESTree.MemberExpression): BaseClosure; | ||
labeledStatementHandler(node: ESTree.LabeledStatement): BaseClosure; | ||
debuggerStatementHandler(node: ESTree.DebuggerStatement): BaseClosure; | ||
createParamNameGetter(node: ESTree.Pattern): ReturnStringClosure; | ||
@@ -123,0 +127,0 @@ createObjectKeyGetter(node: ESTree.Expression): Getter; |
@@ -16,2 +16,11 @@ "use strict"; | ||
function defineFunctionName(func, name) { | ||
Object.defineProperty(func, "name", { | ||
value: name, | ||
writable: false, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
} | ||
var hasOwnProperty = Object.prototype.hasOwnProperty; | ||
@@ -368,2 +377,6 @@ var FunctionNameSymbol = Symbol("name"); | ||
case "DebuggerStatement": | ||
closure = this.debuggerStatementHandler(node); | ||
break; | ||
default: | ||
@@ -603,12 +616,2 @@ throw this.createInternalThrowError(_messages.Messages.NodeTypeSyntaxError, node.type, node); | ||
properties[key] = {}; | ||
} // set function.name | ||
// var d = { test(){} } | ||
// var d = { test: function(){} } | ||
if (property.key.type === "Identifier" && property.value.type === "FunctionExpression" && kind === "init" && !property.value.id) { | ||
property.value.id = { | ||
type: "Identifier", | ||
name: property.key.name | ||
}; | ||
} | ||
@@ -618,3 +621,4 @@ | ||
items.push({ | ||
key: key | ||
key: key, | ||
property: property | ||
}); | ||
@@ -643,2 +647,11 @@ }); | ||
} else { | ||
var property = item.property; | ||
var kind = property.kind; // set function.name | ||
// var d = { test(){} } | ||
// var d = { test: function(){} } | ||
if (property.key.type === "Identifier" && property.value.type === "FunctionExpression" && kind === "init" && !property.value.id) { | ||
defineFunctionName(value, property.key.name); | ||
} | ||
result[key] = value; | ||
@@ -771,4 +784,13 @@ } | ||
self.setCurrentScope(currentScope); | ||
self.addDeclarationsToScope(declarations, currentScope); // init arguments var | ||
self.addDeclarationsToScope(declarations, currentScope); // var t = function(){ typeof t } // function | ||
// t = function(){ typeof t } // function | ||
// z = function tx(){ typeof tx } // function | ||
// but | ||
// d = { say: function(){ typeof say } } // undefined | ||
if (name) { | ||
currentScope.data[name] = func; | ||
} // init arguments var | ||
currentScope.data["arguments"] = arguments; | ||
@@ -793,8 +815,9 @@ paramsGetter.forEach(function (getter, i) { | ||
Object.defineProperty(func, "name", { | ||
value: name, | ||
writable: false, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
defineFunctionName(func, name); // Object.defineProperty(func, "name", { | ||
// value: name, | ||
// writable: false, | ||
// enumerable: false, | ||
// configurable: true, | ||
// }); | ||
Object.defineProperty(func, "length", { | ||
@@ -1036,3 +1059,10 @@ value: paramLength, | ||
if (node.id) { | ||
this.funcDeclaration(node.id.name, this.functionExpressionHandler(node)); | ||
var functionClosure = this.functionExpressionHandler(node); | ||
Object.defineProperty(functionClosure, "isFunctionDeclareClosure", { | ||
value: true, | ||
writable: false, | ||
configurable: false, | ||
enumerable: false | ||
}); | ||
this.funcDeclaration(node.id.name, functionClosure); | ||
} | ||
@@ -1183,3 +1213,3 @@ | ||
initClosure = node.init ? this.createClosure(node.init) : initClosure; | ||
updateClosure = node.update ? this.createClosure(node.update) : initClosure; | ||
updateClosure = node.update ? this.createClosure(node.update) : noop; | ||
} | ||
@@ -1344,2 +1374,4 @@ | ||
var currentContext = _this21.getCurrentContext(); | ||
var labelStack = currentScope.labelStack.concat([]); | ||
@@ -1352,2 +1384,14 @@ | ||
var throwError; | ||
var reset = function reset() { | ||
_this21.setCurrentScope(currentScope); //reset scope | ||
_this21.setCurrentContext(currentContext); //reset context | ||
currentScope.labelStack = labelStack; //reset label stack | ||
_this21.callStack = callStack; //reset call stack | ||
}; | ||
/** | ||
@@ -1364,2 +1408,3 @@ * try{...}catch(e){...}finally{...} execution sequence: | ||
try { | ||
@@ -1372,4 +1417,3 @@ result = _this21.setValue(blockClosure()); | ||
} catch (err) { | ||
currentScope.labelStack = labelStack; | ||
_this21.callStack = callStack; | ||
reset(); | ||
@@ -1388,3 +1432,4 @@ if (_this21.isInterruptThrow(err)) { | ||
} catch (e) { | ||
// save catch throw error | ||
reset(); // save catch throw error | ||
throwError = e; | ||
@@ -1406,3 +1451,4 @@ } | ||
} catch (e) { | ||
// save finally throw error | ||
reset(); // save finally throw error | ||
throwError = e; | ||
@@ -1562,2 +1608,9 @@ } // if (finalReturn instanceof Return) { | ||
}; | ||
}; | ||
_proto.debuggerStatementHandler = function debuggerStatementHandler(node) { | ||
return function () { | ||
debugger; | ||
return EmptyStatementReturn; | ||
}; | ||
} // get es3/5 param name | ||
@@ -1643,5 +1696,7 @@ ; | ||
_proto.funcDeclaration = function funcDeclaration(name, func) { | ||
var _a; | ||
var context = this.collectDeclarations; | ||
if (!hasOwnProperty.call(context, name) || context[name] === undefined) { | ||
if (!hasOwnProperty.call(context, name) || context[name] === undefined || ((_a = context[name]) === null || _a === void 0 ? void 0 : _a.isFunctionDeclareClosure)) { | ||
context[name] = func; | ||
@@ -1648,0 +1703,0 @@ } |
import * as ESTree from "estree"; | ||
export { ESTree }; | ||
export declare type Node = ESTree.Node | ESTree.BinaryExpression | ESTree.LogicalExpression | ESTree.UnaryExpression | ESTree.UpdateExpression | ESTree.ObjectExpression | ESTree.ArrayExpression | ESTree.CallExpression | ESTree.NewExpression | ESTree.MemberExpression | ESTree.ThisExpression | ESTree.SequenceExpression | ESTree.Literal | ESTree.Identifier | ESTree.AssignmentExpression | ESTree.FunctionDeclaration | ESTree.VariableDeclaration | ESTree.BlockStatement | ESTree.Program | ESTree.ExpressionStatement | ESTree.EmptyStatement | ESTree.ReturnStatement | ESTree.FunctionExpression | ESTree.IfStatement | ESTree.ConditionalExpression | ESTree.ForStatement | ESTree.WhileStatement | ESTree.DoWhileStatement | ESTree.ForInStatement | ESTree.WithStatement | ESTree.ThrowStatement | ESTree.TryStatement | ESTree.ContinueStatement | ESTree.BreakStatement | ESTree.SwitchStatement | ESTree.SwitchCase | ESTree.LabeledStatement; | ||
export declare type Node = ESTree.Node | ESTree.BinaryExpression | ESTree.LogicalExpression | ESTree.UnaryExpression | ESTree.UpdateExpression | ESTree.ObjectExpression | ESTree.ArrayExpression | ESTree.CallExpression | ESTree.NewExpression | ESTree.MemberExpression | ESTree.ThisExpression | ESTree.SequenceExpression | ESTree.Literal | ESTree.Identifier | ESTree.AssignmentExpression | ESTree.FunctionDeclaration | ESTree.VariableDeclaration | ESTree.BlockStatement | ESTree.Program | ESTree.ExpressionStatement | ESTree.EmptyStatement | ESTree.ReturnStatement | ESTree.FunctionExpression | ESTree.IfStatement | ESTree.ConditionalExpression | ESTree.ForStatement | ESTree.WhileStatement | ESTree.DoWhileStatement | ESTree.ForInStatement | ESTree.WithStatement | ESTree.ThrowStatement | ESTree.TryStatement | ESTree.ContinueStatement | ESTree.BreakStatement | ESTree.SwitchStatement | ESTree.SwitchCase | ESTree.LabeledStatement | ESTree.DebuggerStatement; |
{ | ||
"name": "eval5", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "A JavaScript interpreter, written completely in JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
674807
9838