UNPKG

microvium

Version:

A compact, embeddable scripting engine for microcontrollers for executing small scripts written in a subset of JavaScript.

30 lines 1.49 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.addBuiltinGlobals = void 0; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); function addBuiltinGlobals(vm, noLib = false) { // Note: There is also a VirtualMachine.addBuiltinGlobals which can be used // when a global requires custom IL. // Note: even with noLib, we can add these globals because they're pretty // important but also the garbage collector will remove these if they aren't // used (which not true of Array.prototype since it's dynamically accessible) const runtimeLibText = fs_1.default.readFileSync(path_1.default.join(__dirname, './runtime-library.mvm.js'), 'utf8'); const runtimeLib = vm.evaluateModule({ sourceText: runtimeLibText, debugFilename: '<builtin>' }); const global = vm.globalThis; global.Infinity = Infinity; global.NaN = NaN; global.undefined = undefined; const Number = global.Number = vm.newObject(); Number.isNaN = runtimeLib.Number_isNaN; if (!noLib) { const arrayPrototype = vm.newObject(); arrayPrototype.push = runtimeLib.Array_push; vm.setArrayPrototype(arrayPrototype); } } exports.addBuiltinGlobals = addBuiltinGlobals; //# sourceMappingURL=builtin-globals.js.map