// SPDX-License-Identifier: LGPL-2.1-or-later const fs = require("fs"); const path = require("path"); const { pathToFileURL } = require("url"); const buildDirectory = path.resolve(process.argv[2] || "build-web/configure/bin"); async function main() { globalThis.__dirname = `${buildDirectory}${path.sep}`; globalThis.require = require; const moduleUrl = pathToFileURL(path.join(buildDirectory, "FreeCADWebSpreadsheetRuntimeProbe.js")).href; const module = await import(moduleUrl); const probe = await module.default({ wasmBinary: fs.readFileSync(path.join(buildDirectory, "FreeCADWebSpreadsheetRuntimeProbe.wasm")), }); const call = (name, returnType = "number", argTypes = [], args = []) => probe.ccall(name, returnType, argTypes, args); const result = { initialize: call("fc_web_spreadsheet_initialize"), initializeAgain: call("fc_web_spreadsheet_initialize"), initializationCalls: call("fc_web_spreadsheet_initialization_calls"), initializationRuns: call("fc_web_spreadsheet_initialization_runs"), moduleAvailable: call("fc_web_spreadsheet_module_available"), typeCount: call("fc_web_spreadsheet_type_count"), pythonApi: call("fc_web_spreadsheet_python_api"), createRecompute: call("fc_web_spreadsheet_create_recompute"), }; result.typeName = call("fc_web_spreadsheet_type_name", "string"); result.objectCount = call("fc_web_spreadsheet_object_count"); result.recomputeCount = call("fc_web_spreadsheet_recompute_count"); result.recomputeHasError = call("fc_web_spreadsheet_recompute_has_error"); result.cellA1 = call("fc_web_spreadsheet_cell_a1", "string"); result.cellB1 = call("fc_web_spreadsheet_cell_b1", "string"); result.persistence = call("fc_web_spreadsheet_save_reopen"); result.persistenceError = call("fc_web_spreadsheet_persistence_error", "string"); result.persistencePath = call("fc_web_spreadsheet_persistence_path", "string"); result.persistenceA1 = call("fc_web_spreadsheet_persistence_a1", "string"); result.persistenceB1 = call("fc_web_spreadsheet_persistence_b1", "string"); result.persistenceSize = call("fc_web_spreadsheet_persistence_size"); result.persistenceObjectCount = call("fc_web_spreadsheet_persistence_object_count"); result.persistenceRoundTrip = call("fc_web_spreadsheet_persistence_round_trip"); result.persistenceResourcesReleased = call("fc_web_spreadsheet_persistence_resources_released"); result.lastError = call("fc_web_spreadsheet_last_error", "string"); const valid = result.initialize === 1 && result.initializeAgain === 1 && result.initializationCalls === 2 && result.initializationRuns === 1 && result.moduleAvailable === 1 && result.typeCount === 1 && result.typeName === "Spreadsheet::Sheet" && result.pythonApi === 1 && result.createRecompute === 1 && result.objectCount === 1 && result.recomputeCount === 1 && result.recomputeHasError === 0 && result.cellA1 === "21" && result.cellB1 === "=A1*2" && result.persistence === 1 && result.persistenceError === "" && result.persistenceA1 === "21" && result.persistenceB1 === "=A1*2" && result.persistenceSize > 0 && result.persistenceObjectCount === 1 && result.persistenceRoundTrip === 1 && result.persistenceResourcesReleased === 1 && result.lastError === ""; if (!valid) { throw new Error(JSON.stringify(result)); } console.log(JSON.stringify(result)); } main().catch((error) => { console.error(error); process.exitCode = 1; });