UNPKG

hakojs

Version:

A secure, embeddable JavaScript engine that runs untrusted code inside WebAssembly sandboxes with fine-grained permissions and resource limits

220 lines (218 loc) 7.64 kB
// src/etc/types.ts import { PrimJSError } from "../etc/errors"; var LEPUS_EXCEPTION = -1; var LEPUS_FALSE = 0; var LEPUS_TRUE = 1; function LEPUS_BOOLToBoolean(value) { switch (value) { case LEPUS_FALSE: return false; case LEPUS_TRUE: return true; default: throw new PrimJSError(`Invalid LEPUS_BOOL value: ${value}`); } } var Intrinsic; ((Intrinsic2) => { Intrinsic2[Intrinsic2["BaseObjects"] = 1] = "BaseObjects"; Intrinsic2[Intrinsic2["Date"] = 2] = "Date"; Intrinsic2[Intrinsic2["Eval"] = 4] = "Eval"; Intrinsic2[Intrinsic2["StringNormalize"] = 8] = "StringNormalize"; Intrinsic2[Intrinsic2["RegExp"] = 16] = "RegExp"; Intrinsic2[Intrinsic2["RegExpCompiler"] = 32] = "RegExpCompiler"; Intrinsic2[Intrinsic2["JSON"] = 64] = "JSON"; Intrinsic2[Intrinsic2["Proxy"] = 128] = "Proxy"; Intrinsic2[Intrinsic2["MapSet"] = 256] = "MapSet"; Intrinsic2[Intrinsic2["TypedArrays"] = 512] = "TypedArrays"; Intrinsic2[Intrinsic2["Promise"] = 1024] = "Promise"; Intrinsic2[Intrinsic2["BigInt"] = 2048] = "BigInt"; Intrinsic2[Intrinsic2["BigFloat"] = 4096] = "BigFloat"; Intrinsic2[Intrinsic2["BigDecimal"] = 8192] = "BigDecimal"; Intrinsic2[Intrinsic2["OperatorOverloading"] = 16384] = "OperatorOverloading"; Intrinsic2[Intrinsic2["BignumExt"] = 32768] = "BignumExt"; Intrinsic2[Intrinsic2["Performance"] = 65536] = "Performance"; Intrinsic2[Intrinsic2["Default"] = 3935] = "Default"; Intrinsic2[Intrinsic2["Basic"] = 1] = "Basic"; Intrinsic2[Intrinsic2["All"] = 1048575] = "All"; })(Intrinsic ||= {}); var DefaultIntrinsics = Object.freeze({ BaseObjects: true, Date: true, Eval: true, StringNormalize: true, RegExp: true, JSON: true, Proxy: true, MapSet: true, TypedArrays: true, Promise: true }); function intrinsicsToFlags(intrinsics) { let result = 0; if (intrinsics.BaseObjects) result |= 1 /* BaseObjects */; if (intrinsics.Date) result |= 2 /* Date */; if (intrinsics.Eval) result |= 4 /* Eval */; if (intrinsics.StringNormalize) result |= 8 /* StringNormalize */; if (intrinsics.RegExp) result |= 16 /* RegExp */; if (intrinsics.RegExpCompiler) result |= 32 /* RegExpCompiler */; if (intrinsics.JSON) result |= 64 /* JSON */; if (intrinsics.Proxy) result |= 128 /* Proxy */; if (intrinsics.MapSet) result |= 256 /* MapSet */; if (intrinsics.TypedArrays) result |= 512 /* TypedArrays */; if (intrinsics.Promise) result |= 1024 /* Promise */; if (intrinsics.BigInt) result |= 2048 /* BigInt */; if (intrinsics.BigFloat) result |= 4096 /* BigFloat */; if (intrinsics.BigDecimal) result |= 8192 /* BigDecimal */; if (intrinsics.OperatorOverloading) result |= 16384 /* OperatorOverloading */; if (intrinsics.BignumExt) result |= 32768 /* BignumExt */; if (intrinsics.Performance) result |= 65536 /* Performance */; return result; } var EvalFlag; ((EvalFlag2) => { EvalFlag2[EvalFlag2["Global"] = 0] = "Global"; EvalFlag2[EvalFlag2["Module"] = 1] = "Module"; EvalFlag2[EvalFlag2["Direct"] = 2] = "Direct"; EvalFlag2[EvalFlag2["Indirect"] = 3] = "Indirect"; EvalFlag2[EvalFlag2["TypeMask"] = 3] = "TypeMask"; EvalFlag2[EvalFlag2["Strict"] = 8] = "Strict"; EvalFlag2[EvalFlag2["Reserved"] = 16] = "Reserved"; EvalFlag2[EvalFlag2["CompileOnly"] = 32] = "CompileOnly"; EvalFlag2[EvalFlag2["DebuggerNoPersistScript"] = 64] = "DebuggerNoPersistScript"; })(EvalFlag ||= {}); var JS_STRIP_SOURCE = 1 << 0; var JS_STRIP_DEBUG = 1 << 1; function evalOptionsToFlags(evalOptions) { if (typeof evalOptions === "number") { return evalOptions; } if (evalOptions === undefined) { return 0 /* Global */; } if (evalOptions.type !== undefined && evalOptions.type !== "global" && evalOptions.type !== "module") { throw new PrimJSError(`Invalid eval type: ${evalOptions.type}. Must be "global" or "module".`); } const { type, strict, compileOnly, noPersist } = evalOptions; let flags = 0; if (type === "global") flags |= 0 /* Global */; if (type === "module") flags |= 1 /* Module */; if (strict) flags |= 8 /* Strict */; if (compileOnly) flags |= 32 /* CompileOnly */; if (noPersist) flags |= 64 /* DebuggerNoPersistScript */; return flags; } var EqualOp; ((EqualOp2) => { EqualOp2[EqualOp2["StrictEquals"] = 0] = "StrictEquals"; EqualOp2[EqualOp2["SameValue"] = 1] = "SameValue"; EqualOp2[EqualOp2["SameValueZero"] = 2] = "SameValueZero"; })(EqualOp ||= {}); var PropertyEnumFlags; ((PropertyEnumFlags2) => { PropertyEnumFlags2[PropertyEnumFlags2["String"] = 1] = "String"; PropertyEnumFlags2[PropertyEnumFlags2["Symbol"] = 2] = "Symbol"; PropertyEnumFlags2[PropertyEnumFlags2["Private"] = 4] = "Private"; PropertyEnumFlags2[PropertyEnumFlags2["Enumerable"] = 16] = "Enumerable"; PropertyEnumFlags2[PropertyEnumFlags2["NonEnumerable"] = 32] = "NonEnumerable"; PropertyEnumFlags2[PropertyEnumFlags2["Configurable"] = 64] = "Configurable"; PropertyEnumFlags2[PropertyEnumFlags2["NonConfigurable"] = 128] = "NonConfigurable"; PropertyEnumFlags2[PropertyEnumFlags2["Number"] = 16384] = "Number"; PropertyEnumFlags2[PropertyEnumFlags2["Compliant"] = 32768] = "Compliant"; })(PropertyEnumFlags ||= {}); var ABIJSType; ((ABIJSType2) => { ABIJSType2[ABIJSType2["Null"] = 0] = "Null"; ABIJSType2[ABIJSType2["Undefined"] = 1] = "Undefined"; ABIJSType2[ABIJSType2["Boolean"] = 2] = "Boolean"; ABIJSType2[ABIJSType2["Number"] = 3] = "Number"; ABIJSType2[ABIJSType2["String"] = 4] = "String"; ABIJSType2[ABIJSType2["Object"] = 5] = "Object"; ABIJSType2[ABIJSType2["Function"] = 6] = "Function"; ABIJSType2[ABIJSType2["Symbol"] = 7] = "Symbol"; ABIJSType2[ABIJSType2["BigInt"] = 8] = "BigInt"; ABIJSType2[ABIJSType2["Module"] = 9] = "Module"; ABIJSType2[ABIJSType2["Unknown"] = -1] = "Unknown"; })(ABIJSType ||= {}); var ValueLifecycle; ((ValueLifecycle2) => { ValueLifecycle2[ValueLifecycle2["Owned"] = 0] = "Owned"; ValueLifecycle2[ValueLifecycle2["Borrowed"] = 1] = "Borrowed"; ValueLifecycle2[ValueLifecycle2["Temporary"] = 2] = "Temporary"; })(ValueLifecycle ||= {}); var IsEqualOp; ((IsEqualOp2) => { IsEqualOp2[IsEqualOp2["IsStrictlyEqual"] = 0] = "IsStrictlyEqual"; IsEqualOp2[IsEqualOp2["IsSameValue"] = 1] = "IsSameValue"; IsEqualOp2[IsEqualOp2["IsSameValueZero"] = 2] = "IsSameValueZero"; })(IsEqualOp ||= {}); function hasOptionsWithCause(error) { return "options" in error && error.options !== null && typeof error.options === "object" && "cause" in error.options; } function detectCircularReferences(obj, path = "root") { const seen = new Set; function traverse(value, currentPath) { if (typeof value !== "object" || value === null) { return; } if (seen.has(value)) { throw new TypeError(`Circular reference detected at ${currentPath}`); } seen.add(value); if (Array.isArray(value)) { for (let i = 0;i < value.length; i++) { traverse(value[i], `${currentPath}[${i}]`); } } else { for (const key of Object.keys(value)) { traverse(value[key], `${currentPath}.${key}`); } } seen.delete(value); } traverse(obj, path); } export { intrinsicsToFlags, hasOptionsWithCause, evalOptionsToFlags, detectCircularReferences, ValueLifecycle, PropertyEnumFlags, LEPUS_TRUE, LEPUS_FALSE, LEPUS_EXCEPTION, LEPUS_BOOLToBoolean, JS_STRIP_SOURCE, JS_STRIP_DEBUG, IsEqualOp, Intrinsic, EvalFlag, EqualOp, DefaultIntrinsics, ABIJSType }; //# debugId=72512B37139E194D64756E2164756E21 //# sourceMappingURL=types.js.map