UNPKG

microvium

Version:

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

43 lines 2.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const decode_snapshot_1 = require("../../lib/decode-snapshot"); const filenames_1 = require("./filenames"); const common_1 = require("../common"); const encode_snapshot_1 = require("../../lib/encode-snapshot"); const virtual_machine_friendly_1 = require("../../lib/virtual-machine-friendly"); const snapshot_il_1 = require("../../lib/snapshot-il"); suite('decodeSnapshot', function () { test('decodeSnapshot', () => { const filenames = filenames_1.decodeSnapshotTestFilenames["decode-snapshot"]; const importMap = { 100: () => { } }; const vm = new virtual_machine_friendly_1.VirtualMachineFriendly(undefined, importMap); vm.globalThis.print = vm.vmImport(100); vm.globalThis.vmExport = vm.vmExport; const sourceText = ` const o = { x: 'Hello, World!', y: { z: 'Hello, World!' } }; const a = []; vmExport(42, run); function run() { print(o.x); print(a[0]); } `; vm.evaluateModule({ sourceText }); vm.garbageCollect(); const testResults = new common_1.TestResults(); const snapshotToSave = vm.createSnapshotIL(); const snapshotToSaveStr = (0, snapshot_il_1.stringifySnapshotIL)(snapshotToSave); const snapshot = (0, encode_snapshot_1.encodeSnapshot)(snapshotToSave, false, false).snapshot; const decoded = (0, decode_snapshot_1.decodeSnapshot)(snapshot); const snapshotLoaded = (0, snapshot_il_1.stringifySnapshotIL)(decoded.snapshotInfo); const disassemblyString = decoded.disassembly; testResults.push(snapshotToSaveStr, filenames.snapshotToSave); testResults.push(snapshotLoaded, filenames.snapshotLoaded); testResults.push(disassemblyString, filenames.disassembly); testResults.checkAll(); (0, common_1.assertSameCode)(snapshotToSaveStr, snapshotLoaded); }); }); //# sourceMappingURL=decode-snapshot.test.js.map