bhscript
v4.0.4
Published
Safely execute JS code. SAFELY!
Downloads
59
Readme
Installation
npm i bhscript
let bhscript = require("bhscript");
or:
<script src="bhscript.web.js"></script>
Basic usage:
let sandbox = bhscript({
onError: function(isCore, error) {}, // isCore ? bhscript error : provided script error
pure: true, // whether internal scopes inherit parent scope variables (pure by default doesn't)
maxOps: -1, // max amount of ops triggers
opTriggers: [], // ops that trigger ops count
noOpTriggers: [], // ops that don't trigger ops count
debug: false, // displays debugging information as it parses and runs through a script
cleanEnv: false, // true if you dont want to expose basic properties/methods, (isNaN, Array, Object, etc...)
globals: {}, // global variables provided for inside the sandbox (functions, objects, anything...)
});
sandbox.run(scriptName, scriptCode); // run a script
sandbox.global; // global scope inside sandbox
sandbox.ops; /* {
current, // view the current op count
limit, // view/set the op limit
clear, // clear the op counter
} */
sandbox.types; // Array of op trigger types
Op triggers:
[
ThisExpression,
Identifier,
Literal,
ArrayExpression,
ObjectExpression,
FunctionExpression,
ArrowFunctionExpression,
ClassExpression, // Unsupported
TaggedTemplateExpression, // Unsupported
MemberExpression,
Super, // Unsupported
MetaProperty, // Unsupported
CallExpression,
NewExpression,
UpdateExpression,
AwaitExpression, // Unsupported
UnaryExpression,
BinaryExpression,
LogicalExpression,
ConditionalExpression,
YieldExpression, // Unsupported
AssignmentExpression,
SequenceExpression,
BlockStatement,
BreakStatement,
ClassDeclaration, // Unsupported
ContinueStatement,
DebuggerStatement, // Unsupported
DoWhileStatement,
EmptyStatement,
ExpressionStatement,
ForStatement,
ForInStatement,
ForOfStatement,
FunctionDeclaration,
IfStatement,
LabelledStatement, // Unsupported
ReturnStatement,
SwitchStatement,
ThrowStatement,
TryStatement,
VariableDeclaration,
WhileStatement,
WithStatement,
Program,
ImportDeclaration, // Unsupported
ExportAllDeclaration, // Unsupported
ExportDefaultDeclaration, // Unsupported
ExportNamedDeclaration, // Unsupported
TemplateLiteral,
]