@jsprismarine/script-host 0.0.0 → 0.23.0-unstable-20261120210452

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (440) hide show
  1. package/CHANGELOG.md +99 -0
  2. package/LICENSE +21 -0
  3. package/README.md +667 -28
  4. package/dist/ScriptEngine.d.ts +250 -0
  5. package/dist/ScriptEngine.d.ts.map +1 -0
  6. package/dist/ScriptEngine.js +427 -0
  7. package/dist/ScriptEngine.js.map +1 -0
  8. package/dist/absentGlobals.d.ts +29 -0
  9. package/dist/absentGlobals.d.ts.map +1 -0
  10. package/dist/absentGlobals.js +94 -0
  11. package/dist/absentGlobals.js.map +1 -0
  12. package/dist/debugger/DebugSession.d.ts +189 -0
  13. package/dist/debugger/DebugSession.d.ts.map +1 -0
  14. package/dist/debugger/DebugSession.js +588 -0
  15. package/dist/debugger/DebugSession.js.map +1 -0
  16. package/dist/debugger/EngineDebugger.d.ts +158 -0
  17. package/dist/debugger/EngineDebugger.d.ts.map +1 -0
  18. package/dist/debugger/EngineDebugger.js +174 -0
  19. package/dist/debugger/EngineDebugger.js.map +1 -0
  20. package/dist/debugger/channel.d.ts +67 -0
  21. package/dist/debugger/channel.d.ts.map +1 -0
  22. package/dist/debugger/channel.js +120 -0
  23. package/dist/debugger/channel.js.map +1 -0
  24. package/dist/debugger/connectionWorker.d.ts +2 -0
  25. package/dist/debugger/connectionWorker.d.ts.map +1 -0
  26. package/dist/debugger/connectionWorker.js +98 -0
  27. package/dist/debugger/connectionWorker.js.map +1 -0
  28. package/dist/debugger/framing.d.ts +46 -0
  29. package/dist/debugger/framing.d.ts.map +1 -0
  30. package/dist/debugger/framing.js +106 -0
  31. package/dist/debugger/framing.js.map +1 -0
  32. package/dist/debugger/profiler.d.ts +72 -0
  33. package/dist/debugger/profiler.d.ts.map +1 -0
  34. package/dist/debugger/profiler.js +92 -0
  35. package/dist/debugger/profiler.js.map +1 -0
  36. package/dist/debugger/protocol.d.ts +170 -0
  37. package/dist/debugger/protocol.d.ts.map +1 -0
  38. package/dist/debugger/protocol.js +141 -0
  39. package/dist/debugger/protocol.js.map +1 -0
  40. package/dist/debugger/thread.d.ts +85 -0
  41. package/dist/debugger/thread.d.ts.map +1 -0
  42. package/dist/debugger/thread.js +134 -0
  43. package/dist/debugger/thread.js.map +1 -0
  44. package/dist/debugger/transport.d.ts +80 -0
  45. package/dist/debugger/transport.d.ts.map +1 -0
  46. package/dist/debugger/transport.js +150 -0
  47. package/dist/debugger/transport.js.map +1 -0
  48. package/dist/engineSource.d.ts +14 -0
  49. package/dist/engineSource.d.ts.map +1 -0
  50. package/dist/engineSource.js +17 -0
  51. package/dist/engineSource.js.map +1 -0
  52. package/dist/errors.d.ts +62 -0
  53. package/dist/errors.d.ts.map +1 -0
  54. package/dist/errors.js +62 -0
  55. package/dist/errors.js.map +1 -0
  56. package/dist/ffi.d.ts +63 -0
  57. package/dist/ffi.d.ts.map +1 -0
  58. package/dist/ffi.js +156 -0
  59. package/dist/ffi.js.map +1 -0
  60. package/dist/generated/script-modules/common.d.ts +2 -0
  61. package/dist/generated/script-modules/common.js +262 -0
  62. package/dist/generated/script-modules/common.js.map +1 -0
  63. package/dist/generated/script-modules/common.json.d.ts +2 -0
  64. package/dist/generated/script-modules/debug-utilities.d.ts +2 -0
  65. package/dist/generated/script-modules/debug-utilities.js +23 -0
  66. package/dist/generated/script-modules/debug-utilities.js.map +1 -0
  67. package/dist/generated/script-modules/debug-utilities.json.d.ts +2 -0
  68. package/dist/generated/script-modules/diagnostics.d.ts +2 -0
  69. package/dist/generated/script-modules/diagnostics.js +281 -0
  70. package/dist/generated/script-modules/diagnostics.js.map +1 -0
  71. package/dist/generated/script-modules/diagnostics.json.d.ts +2 -0
  72. package/dist/generated/script-modules/server-admin.d.ts +2 -0
  73. package/dist/generated/script-modules/server-admin.js +23 -0
  74. package/dist/generated/script-modules/server-admin.js.map +1 -0
  75. package/dist/generated/script-modules/server-admin.json.d.ts +2 -0
  76. package/dist/generated/script-modules/server-gametest.d.ts +2 -0
  77. package/dist/generated/script-modules/server-gametest.js +23 -0
  78. package/dist/generated/script-modules/server-gametest.js.map +1 -0
  79. package/dist/generated/script-modules/server-gametest.json.d.ts +2 -0
  80. package/dist/generated/script-modules/server-graphics.d.ts +2 -0
  81. package/dist/generated/script-modules/server-graphics.js +30 -0
  82. package/dist/generated/script-modules/server-graphics.js.map +1 -0
  83. package/dist/generated/script-modules/server-graphics.json.d.ts +2 -0
  84. package/dist/generated/script-modules/server-net.d.ts +2 -0
  85. package/dist/generated/script-modules/server-net.js +24 -0
  86. package/dist/generated/script-modules/server-net.js.map +1 -0
  87. package/dist/generated/script-modules/server-net.json.d.ts +2 -0
  88. package/dist/generated/script-modules/server-ui.d.ts +2 -0
  89. package/dist/generated/script-modules/server-ui.js +110 -0
  90. package/dist/generated/script-modules/server-ui.js.map +1 -0
  91. package/dist/generated/script-modules/server-ui.json.d.ts +2 -0
  92. package/dist/generated/script-modules/server.d.ts +2 -0
  93. package/dist/generated/script-modules/server.js +251 -0
  94. package/dist/generated/script-modules/server.js.map +1 -0
  95. package/dist/generated/script-modules/server.json.d.ts +2 -0
  96. package/dist/generated/scriptApi.d.ts +3233 -0
  97. package/dist/generated/scriptApi.d.ts.map +1 -0
  98. package/dist/generated/scriptApi.js +0 -0
  99. package/dist/generated/scriptModules.d.ts +13 -0
  100. package/dist/generated/scriptModules.d.ts.map +1 -0
  101. package/dist/generated/scriptModules.js +34 -0
  102. package/dist/generated/scriptModules.js.map +1 -0
  103. package/dist/host/PackForms.d.ts +71 -0
  104. package/dist/host/PackForms.d.ts.map +1 -0
  105. package/dist/host/PackForms.js +164 -0
  106. package/dist/host/PackForms.js.map +1 -0
  107. package/dist/host/ScriptForms.d.ts +51 -0
  108. package/dist/host/ScriptForms.d.ts.map +1 -0
  109. package/dist/host/ScriptForms.js +103 -0
  110. package/dist/host/ScriptForms.js.map +1 -0
  111. package/dist/host/ScriptHttp.d.ts +54 -0
  112. package/dist/host/ScriptHttp.d.ts.map +1 -0
  113. package/dist/host/ScriptHttp.js +82 -0
  114. package/dist/host/ScriptHttp.js.map +1 -0
  115. package/dist/host/WorldScripts.d.ts +350 -0
  116. package/dist/host/WorldScripts.d.ts.map +1 -0
  117. package/dist/host/WorldScripts.js +1421 -0
  118. package/dist/host/WorldScripts.js.map +1 -0
  119. package/dist/host/blocksItems/blockComponents.d.ts +27 -0
  120. package/dist/host/blocksItems/blockComponents.d.ts.map +1 -0
  121. package/dist/host/blocksItems/blockComponents.js +73 -0
  122. package/dist/host/blocksItems/blockComponents.js.map +1 -0
  123. package/dist/host/blocksItems/blocks.d.ts +12 -0
  124. package/dist/host/blocksItems/blocks.d.ts.map +1 -0
  125. package/dist/host/blocksItems/blocks.js +247 -0
  126. package/dist/host/blocksItems/blocks.js.map +1 -0
  127. package/dist/host/blocksItems/componentFacts.d.ts +14 -0
  128. package/dist/host/blocksItems/componentFacts.d.ts.map +1 -0
  129. package/dist/host/blocksItems/componentFacts.js +34 -0
  130. package/dist/host/blocksItems/componentFacts.js.map +1 -0
  131. package/dist/host/blocksItems/containers.d.ts +18 -0
  132. package/dist/host/blocksItems/containers.d.ts.map +1 -0
  133. package/dist/host/blocksItems/containers.js +128 -0
  134. package/dist/host/blocksItems/containers.js.map +1 -0
  135. package/dist/host/blocksItems/handles.d.ts +10 -0
  136. package/dist/host/blocksItems/handles.d.ts.map +1 -0
  137. package/dist/host/blocksItems/handles.js +30 -0
  138. package/dist/host/blocksItems/handles.js.map +1 -0
  139. package/dist/host/blocksItems/implement.d.ts +22 -0
  140. package/dist/host/blocksItems/implement.d.ts.map +1 -0
  141. package/dist/host/blocksItems/implement.js +23 -0
  142. package/dist/host/blocksItems/implement.js.map +1 -0
  143. package/dist/host/blocksItems/itemExtras.d.ts +8 -0
  144. package/dist/host/blocksItems/itemExtras.d.ts.map +1 -0
  145. package/dist/host/blocksItems/itemExtras.js +106 -0
  146. package/dist/host/blocksItems/itemExtras.js.map +1 -0
  147. package/dist/host/blocksItems/itemLink.d.ts +12 -0
  148. package/dist/host/blocksItems/itemLink.d.ts.map +1 -0
  149. package/dist/host/blocksItems/itemLink.js +38 -0
  150. package/dist/host/blocksItems/itemLink.js.map +1 -0
  151. package/dist/host/blocksItems/items.d.ts +25 -0
  152. package/dist/host/blocksItems/items.d.ts.map +1 -0
  153. package/dist/host/blocksItems/items.js +427 -0
  154. package/dist/host/blocksItems/items.js.map +1 -0
  155. package/dist/host/blocksItems/tags.d.ts +24 -0
  156. package/dist/host/blocksItems/tags.d.ts.map +1 -0
  157. package/dist/host/blocksItems/tags.js +27 -0
  158. package/dist/host/blocksItems/tags.js.map +1 -0
  159. package/dist/host/blocksItems/types.d.ts +13 -0
  160. package/dist/host/blocksItems/types.d.ts.map +1 -0
  161. package/dist/host/blocksItems/types.js +83 -0
  162. package/dist/host/blocksItems/types.js.map +1 -0
  163. package/dist/host/blocksItems/volumes.d.ts +37 -0
  164. package/dist/host/blocksItems/volumes.d.ts.map +1 -0
  165. package/dist/host/blocksItems/volumes.js +361 -0
  166. package/dist/host/blocksItems/volumes.js.map +1 -0
  167. package/dist/host/coverage.d.ts +28 -0
  168. package/dist/host/coverage.d.ts.map +1 -0
  169. package/dist/host/coverage.js +45 -0
  170. package/dist/host/coverage.js.map +1 -0
  171. package/dist/host/customContent.d.ts +81 -0
  172. package/dist/host/customContent.d.ts.map +1 -0
  173. package/dist/host/customContent.js +213 -0
  174. package/dist/host/customContent.js.map +1 -0
  175. package/dist/host/debugUtilities.d.ts +192 -0
  176. package/dist/host/debugUtilities.d.ts.map +1 -0
  177. package/dist/host/debugUtilities.js +503 -0
  178. package/dist/host/debugUtilities.js.map +1 -0
  179. package/dist/host/entities/aimAssist.d.ts +11 -0
  180. package/dist/host/entities/aimAssist.d.ts.map +1 -0
  181. package/dist/host/entities/aimAssist.js +195 -0
  182. package/dist/host/entities/aimAssist.js.map +1 -0
  183. package/dist/host/entities/area.d.ts +14 -0
  184. package/dist/host/entities/area.d.ts.map +1 -0
  185. package/dist/host/entities/area.js +19 -0
  186. package/dist/host/entities/area.js.map +1 -0
  187. package/dist/host/entities/components.d.ts +61 -0
  188. package/dist/host/entities/components.d.ts.map +1 -0
  189. package/dist/host/entities/components.js +642 -0
  190. package/dist/host/entities/components.js.map +1 -0
  191. package/dist/host/entities/entityMembers.d.ts +35 -0
  192. package/dist/host/entities/entityMembers.d.ts.map +1 -0
  193. package/dist/host/entities/entityMembers.js +494 -0
  194. package/dist/host/entities/entityMembers.js.map +1 -0
  195. package/dist/host/entities/playerMembers.d.ts +23 -0
  196. package/dist/host/entities/playerMembers.d.ts.map +1 -0
  197. package/dist/host/entities/playerMembers.js +576 -0
  198. package/dist/host/entities/playerMembers.js.map +1 -0
  199. package/dist/host/entities/world.d.ts +315 -0
  200. package/dist/host/entities/world.d.ts.map +1 -0
  201. package/dist/host/entities/world.js +0 -0
  202. package/dist/host/events/componentEvents.d.ts +11 -0
  203. package/dist/host/events/componentEvents.d.ts.map +1 -0
  204. package/dist/host/events/componentEvents.js +23 -0
  205. package/dist/host/events/componentEvents.js.map +1 -0
  206. package/dist/host/events/eventOptions.d.ts +14 -0
  207. package/dist/host/events/eventOptions.d.ts.map +1 -0
  208. package/dist/host/events/eventOptions.js +224 -0
  209. package/dist/host/events/eventOptions.js.map +1 -0
  210. package/dist/host/events/eventValues.d.ts +41 -0
  211. package/dist/host/events/eventValues.d.ts.map +1 -0
  212. package/dist/host/events/eventValues.js +89 -0
  213. package/dist/host/events/eventValues.js.map +1 -0
  214. package/dist/host/events/worldEvents.d.ts +30 -0
  215. package/dist/host/events/worldEvents.d.ts.map +1 -0
  216. package/dist/host/events/worldEvents.js +207 -0
  217. package/dist/host/events/worldEvents.js.map +1 -0
  218. package/dist/host/formJson.d.ts +35 -0
  219. package/dist/host/formJson.d.ts.map +1 -0
  220. package/dist/host/formJson.js +84 -0
  221. package/dist/host/formJson.js.map +1 -0
  222. package/dist/host/formKit.d.ts +40 -0
  223. package/dist/host/formKit.d.ts.map +1 -0
  224. package/dist/host/formKit.js +124 -0
  225. package/dist/host/formKit.js.map +1 -0
  226. package/dist/host/forms.d.ts +92 -0
  227. package/dist/host/forms.d.ts.map +1 -0
  228. package/dist/host/forms.js +361 -0
  229. package/dist/host/forms.js.map +1 -0
  230. package/dist/host/gametest.d.ts +202 -0
  231. package/dist/host/gametest.d.ts.map +1 -0
  232. package/dist/host/gametest.js +316 -0
  233. package/dist/host/gametest.js.map +1 -0
  234. package/dist/host/inputs.d.ts +29 -0
  235. package/dist/host/inputs.d.ts.map +1 -0
  236. package/dist/host/inputs.js +110 -0
  237. package/dist/host/inputs.js.map +1 -0
  238. package/dist/host/jobs.d.ts +48 -0
  239. package/dist/host/jobs.d.ts.map +1 -0
  240. package/dist/host/jobs.js +62 -0
  241. package/dist/host/jobs.js.map +1 -0
  242. package/dist/host/jsprismarineServer.d.ts +65 -0
  243. package/dist/host/jsprismarineServer.d.ts.map +1 -0
  244. package/dist/host/jsprismarineServer.js +83 -0
  245. package/dist/host/jsprismarineServer.js.map +1 -0
  246. package/dist/host/minecraftServer.d.ts +229 -0
  247. package/dist/host/minecraftServer.d.ts.map +1 -0
  248. package/dist/host/minecraftServer.js +304 -0
  249. package/dist/host/minecraftServer.js.map +1 -0
  250. package/dist/host/minecraftServerUi.d.ts +30 -0
  251. package/dist/host/minecraftServerUi.d.ts.map +1 -0
  252. package/dist/host/minecraftServerUi.js +89 -0
  253. package/dist/host/minecraftServerUi.js.map +1 -0
  254. package/dist/host/netKit.d.ts +44 -0
  255. package/dist/host/netKit.d.ts.map +1 -0
  256. package/dist/host/netKit.js +87 -0
  257. package/dist/host/netKit.js.map +1 -0
  258. package/dist/host/pack.d.ts +71 -0
  259. package/dist/host/pack.d.ts.map +1 -0
  260. package/dist/host/pack.js +157 -0
  261. package/dist/host/pack.js.map +1 -0
  262. package/dist/host/serverAdmin.d.ts +44 -0
  263. package/dist/host/serverAdmin.d.ts.map +1 -0
  264. package/dist/host/serverAdmin.js +96 -0
  265. package/dist/host/serverAdmin.js.map +1 -0
  266. package/dist/host/serverBlocks.d.ts +32 -0
  267. package/dist/host/serverBlocks.d.ts.map +1 -0
  268. package/dist/host/serverBlocks.js +93 -0
  269. package/dist/host/serverBlocks.js.map +1 -0
  270. package/dist/host/serverComponents.d.ts +46 -0
  271. package/dist/host/serverComponents.d.ts.map +1 -0
  272. package/dist/host/serverComponents.js +297 -0
  273. package/dist/host/serverComponents.js.map +1 -0
  274. package/dist/host/serverCustom.d.ts +16 -0
  275. package/dist/host/serverCustom.d.ts.map +1 -0
  276. package/dist/host/serverCustom.js +161 -0
  277. package/dist/host/serverCustom.js.map +1 -0
  278. package/dist/host/serverEntities.d.ts +49 -0
  279. package/dist/host/serverEntities.d.ts.map +1 -0
  280. package/dist/host/serverEntities.js +358 -0
  281. package/dist/host/serverEntities.js.map +1 -0
  282. package/dist/host/serverFeedback.d.ts +15 -0
  283. package/dist/host/serverFeedback.d.ts.map +1 -0
  284. package/dist/host/serverFeedback.js +413 -0
  285. package/dist/host/serverFeedback.js.map +1 -0
  286. package/dist/host/serverGametest.d.ts +43 -0
  287. package/dist/host/serverGametest.d.ts.map +1 -0
  288. package/dist/host/serverGametest.js +246 -0
  289. package/dist/host/serverGametest.js.map +1 -0
  290. package/dist/host/serverItems.d.ts +17 -0
  291. package/dist/host/serverItems.d.ts.map +1 -0
  292. package/dist/host/serverItems.js +71 -0
  293. package/dist/host/serverItems.js.map +1 -0
  294. package/dist/host/serverNet.d.ts +41 -0
  295. package/dist/host/serverNet.d.ts.map +1 -0
  296. package/dist/host/serverNet.js +289 -0
  297. package/dist/host/serverNet.js.map +1 -0
  298. package/dist/host/serverObjects.d.ts +142 -0
  299. package/dist/host/serverObjects.d.ts.map +1 -0
  300. package/dist/host/serverObjects.js +326 -0
  301. package/dist/host/serverObjects.js.map +1 -0
  302. package/dist/host/serverProperties.d.ts +48 -0
  303. package/dist/host/serverProperties.d.ts.map +1 -0
  304. package/dist/host/serverProperties.js +193 -0
  305. package/dist/host/serverProperties.js.map +1 -0
  306. package/dist/host/serverScoreboard.d.ts +9 -0
  307. package/dist/host/serverScoreboard.d.ts.map +1 -0
  308. package/dist/host/serverScoreboard.js +198 -0
  309. package/dist/host/serverScoreboard.js.map +1 -0
  310. package/dist/host/serverStructures.d.ts +9 -0
  311. package/dist/host/serverStructures.d.ts.map +1 -0
  312. package/dist/host/serverStructures.js +243 -0
  313. package/dist/host/serverStructures.js.map +1 -0
  314. package/dist/host/tasks.d.ts +66 -0
  315. package/dist/host/tasks.d.ts.map +1 -0
  316. package/dist/host/tasks.js +107 -0
  317. package/dist/host/tasks.js.map +1 -0
  318. package/dist/host/world.d.ts +1359 -0
  319. package/dist/host/world.d.ts.map +1 -0
  320. package/dist/host/world.js +10 -0
  321. package/dist/host/world.js.map +1 -0
  322. package/dist/host/worldsystem/gameRules.d.ts +189 -0
  323. package/dist/host/worldsystem/gameRules.d.ts.map +1 -0
  324. package/dist/host/worldsystem/gameRules.js +86 -0
  325. package/dist/host/worldsystem/gameRules.js.map +1 -0
  326. package/dist/host/worldsystem/memoryWorldSystem.d.ts +18 -0
  327. package/dist/host/worldsystem/memoryWorldSystem.d.ts.map +1 -0
  328. package/dist/host/worldsystem/memoryWorldSystem.js +223 -0
  329. package/dist/host/worldsystem/memoryWorldSystem.js.map +1 -0
  330. package/dist/host/worldsystem/seam.d.ts +163 -0
  331. package/dist/host/worldsystem/seam.d.ts.map +1 -0
  332. package/dist/host/worldsystem/seam.js +0 -0
  333. package/dist/host/worldsystem/serverClocks.d.ts +18 -0
  334. package/dist/host/worldsystem/serverClocks.d.ts.map +1 -0
  335. package/dist/host/worldsystem/serverClocks.js +166 -0
  336. package/dist/host/worldsystem/serverClocks.js.map +1 -0
  337. package/dist/host/worldsystem/serverDimension.d.ts +10 -0
  338. package/dist/host/worldsystem/serverDimension.d.ts.map +1 -0
  339. package/dist/host/worldsystem/serverDimension.js +388 -0
  340. package/dist/host/worldsystem/serverDimension.js.map +1 -0
  341. package/dist/host/worldsystem/serverFog.d.ts +15 -0
  342. package/dist/host/worldsystem/serverFog.d.ts.map +1 -0
  343. package/dist/host/worldsystem/serverFog.js +66 -0
  344. package/dist/host/worldsystem/serverFog.js.map +1 -0
  345. package/dist/host/worldsystem/serverLoot.d.ts +9 -0
  346. package/dist/host/worldsystem/serverLoot.d.ts.map +1 -0
  347. package/dist/host/worldsystem/serverLoot.js +255 -0
  348. package/dist/host/worldsystem/serverLoot.js.map +1 -0
  349. package/dist/host/worldsystem/serverPrimitiveShapes.d.ts +9 -0
  350. package/dist/host/worldsystem/serverPrimitiveShapes.d.ts.map +1 -0
  351. package/dist/host/worldsystem/serverPrimitiveShapes.js +149 -0
  352. package/dist/host/worldsystem/serverPrimitiveShapes.js.map +1 -0
  353. package/dist/host/worldsystem/serverTickingAreas.d.ts +11 -0
  354. package/dist/host/worldsystem/serverTickingAreas.d.ts.map +1 -0
  355. package/dist/host/worldsystem/serverTickingAreas.js +176 -0
  356. package/dist/host/worldsystem/serverTickingAreas.js.map +1 -0
  357. package/dist/host/worldsystem/serverVolumes.d.ts +9 -0
  358. package/dist/host/worldsystem/serverVolumes.d.ts.map +1 -0
  359. package/dist/host/worldsystem/serverVolumes.js +248 -0
  360. package/dist/host/worldsystem/serverVolumes.js.map +1 -0
  361. package/dist/host/worldsystem/serverWorld.d.ts +18 -0
  362. package/dist/host/worldsystem/serverWorld.d.ts.map +1 -0
  363. package/dist/host/worldsystem/serverWorld.js +199 -0
  364. package/dist/host/worldsystem/serverWorld.js.map +1 -0
  365. package/dist/host/worldsystem/tags.d.ts +40 -0
  366. package/dist/host/worldsystem/tags.d.ts.map +1 -0
  367. package/dist/host/worldsystem/tags.js +43 -0
  368. package/dist/host/worldsystem/tags.js.map +1 -0
  369. package/dist/install.d.ts +39 -0
  370. package/dist/install.d.ts.map +1 -0
  371. package/dist/install.js +83 -0
  372. package/dist/install.js.map +1 -0
  373. package/dist/isRecord.d.ts +3 -0
  374. package/dist/isRecord.d.ts.map +1 -0
  375. package/dist/isRecord.js +6 -0
  376. package/dist/isRecord.js.map +1 -0
  377. package/dist/library.d.ts +40 -0
  378. package/dist/library.d.ts.map +1 -0
  379. package/dist/library.js +101 -0
  380. package/dist/library.js.map +1 -0
  381. package/dist/manifest.d.ts +37 -0
  382. package/dist/manifest.d.ts.map +1 -0
  383. package/dist/manifest.js +40 -0
  384. package/dist/manifest.js.map +1 -0
  385. package/dist/native/manifest.json.js +45 -0
  386. package/dist/native/manifest.json.js.map +1 -0
  387. package/dist/nativeHash.d.ts +16 -0
  388. package/dist/nativeHash.d.ts.map +1 -0
  389. package/dist/nativeHash.js +52 -0
  390. package/dist/nativeHash.js.map +1 -0
  391. package/dist/platform.d.ts +50 -0
  392. package/dist/platform.d.ts.map +1 -0
  393. package/dist/platform.js +77 -0
  394. package/dist/platform.js.map +1 -0
  395. package/dist/shape/binding.d.ts +112 -0
  396. package/dist/shape/binding.d.ts.map +1 -0
  397. package/dist/shape/binding.js +558 -0
  398. package/dist/shape/binding.js.map +1 -0
  399. package/dist/shape/engineRuntime.d.ts +55 -0
  400. package/dist/shape/engineRuntime.d.ts.map +1 -0
  401. package/dist/shape/engineRuntime.js +451 -0
  402. package/dist/shape/engineRuntime.js.map +1 -0
  403. package/dist/shape/format.d.ts +249 -0
  404. package/dist/shape/format.d.ts.map +1 -0
  405. package/dist/shape/format.js +43 -0
  406. package/dist/shape/format.js.map +1 -0
  407. package/dist/shape/history.d.ts +24 -0
  408. package/dist/shape/history.d.ts.map +1 -0
  409. package/dist/shape/history.js +65 -0
  410. package/dist/shape/history.js.map +1 -0
  411. package/dist/shape/implementations.d.ts +105 -0
  412. package/dist/shape/implementations.d.ts.map +1 -0
  413. package/dist/shape/implementations.js +62 -0
  414. package/dist/shape/implementations.js.map +1 -0
  415. package/dist/shape/plan.d.ts +138 -0
  416. package/dist/shape/plan.d.ts.map +1 -0
  417. package/dist/shape/plan.js +0 -0
  418. package/dist/shape/resolve.d.ts +56 -0
  419. package/dist/shape/resolve.d.ts.map +1 -0
  420. package/dist/shape/resolve.js +78 -0
  421. package/dist/shape/resolve.js.map +1 -0
  422. package/dist/shape/version.d.ts +15 -0
  423. package/dist/shape/version.d.ts.map +1 -0
  424. package/dist/shape/version.js +35 -0
  425. package/dist/shape/version.js.map +1 -0
  426. package/dist/testing/debuggerWorker.d.ts +15 -0
  427. package/dist/testing/debuggerWorker.d.ts.map +1 -0
  428. package/dist/testing/debuggerWorker.js +29 -0
  429. package/dist/testing/debuggerWorker.js.map +1 -0
  430. package/dist/testing/engineWorker.d.ts +7 -0
  431. package/dist/testing/engineWorker.d.ts.map +1 -0
  432. package/dist/testing/engineWorker.js +31 -0
  433. package/dist/testing/engineWorker.js.map +1 -0
  434. package/dist/values.d.ts +94 -0
  435. package/dist/values.d.ts.map +1 -0
  436. package/dist/values.js +204 -0
  437. package/dist/values.js.map +1 -0
  438. package/native/manifest.json +49 -0
  439. package/package.json +177 -6
  440. package/scripts/postinstall.mjs +54 -0
@@ -0,0 +1,250 @@
1
+ import { EngineDebugger } from './debugger/EngineDebugger.js';
2
+ import type { DebuggerListener } from './debugger/EngineDebugger.js';
3
+ import type { BoundLibrary } from './ffi.js';
4
+ import { ScriptHandle } from './values.js';
5
+ import type { ScriptValue } from './values.js';
6
+ /** The C interface version this binding speaks, `JSH_ABI_VERSION` in the header. */
7
+ export declare const ABI_VERSION = 3;
8
+ /** The `jsh_stat` counters, by the field of {@link EngineStats} each fills. */
9
+ declare const Stat: {
10
+ readonly steps: 0;
11
+ readonly callbackSteps: 1;
12
+ readonly tickSteps: 2;
13
+ readonly hostCalls: 3;
14
+ readonly bytesToHost: 4;
15
+ readonly bytesFromHost: 5;
16
+ readonly stackOverflows: 6;
17
+ readonly memoryLimitHits: 7;
18
+ readonly memoryUsed: 8;
19
+ readonly handles: 9;
20
+ };
21
+ /**
22
+ * An engine's counters. A step is one call of QuickJS's interrupt handler, which QuickJS makes once
23
+ * every 10,000 of its polls at backward jumps and calls, so the same script takes the same steps on
24
+ * every machine.
25
+ */
26
+ export type EngineStats = {
27
+ -readonly [Key in keyof typeof Stat]: number;
28
+ };
29
+ /** The bytes a new engine's transfer buffer starts with. It grows when a value needs more. */
30
+ export declare const DEFAULT_BUFFER_SIZE: number;
31
+ /**
32
+ * The native stack a new engine's scripts may use, in bytes. A host callback runs on the same
33
+ * stack, so this leaves room for Node.js's own frames under QuickJS's.
34
+ */
35
+ export declare const DEFAULT_STACK_SIZE: number;
36
+ /** A function scripts call to reach the host. It runs synchronously and must not return a promise. */
37
+ export type HostFunction = (...args: ScriptValue[]) => ScriptValue;
38
+ /**
39
+ * Returns a module for its normalized name: its source, or an object whose own enumerable
40
+ * properties become its exports. Undefined when there is none.
41
+ * @param name - The normalized module name.
42
+ * @param context - The id of the context that imports it.
43
+ */
44
+ export type ModuleLoader = (name: string, context: ScriptContextId) => string | ScriptHandle | undefined;
45
+ /** A context's id in its engine. The context an engine is created with is {@link DEFAULT_CONTEXT}. */
46
+ export type ScriptContextId = number;
47
+ /** The context an engine is created with. */
48
+ export declare const DEFAULT_CONTEXT: ScriptContextId;
49
+ /** How {@link ScriptHostLibrary.createEngine} sets up an engine. */
50
+ export interface ScriptEngineOptions {
51
+ /** The bytes the engine may allocate; going over stops the script. Unlimited when absent. */
52
+ readonly memoryLimit?: number;
53
+ /** The native stack, in bytes, past which a script gets `InternalError: stack overflow`. */
54
+ readonly stackSize?: number;
55
+ /** The transfer buffer's first size in bytes. */
56
+ readonly bufferSize?: number;
57
+ /** Supplies the source of each module a script imports. */
58
+ readonly loadModule?: ModuleLoader;
59
+ }
60
+ /** How {@link ScriptEngine.attachDebugger} attaches a debugger. */
61
+ export interface DebuggerOptions {
62
+ /**
63
+ * The context the debugger watches, {@link DEFAULT_CONTEXT} when absent. Only its scripts stop
64
+ * and poll; the other contexts' scripts run as if no debugger were attached, even in a file
65
+ * with a breakpoint. A stop's frames still include every context's, each queried in its own.
66
+ */
67
+ readonly context?: ScriptContextId;
68
+ /**
69
+ * How many lines a running script runs between {@link DebuggerListener.poll} calls, which let a
70
+ * debugger pause a script that never ends. A count of lines, not a time, so a script polls at
71
+ * the same lines every run. No polling when 0.
72
+ */
73
+ readonly pollLines?: number;
74
+ }
75
+ /** The lines between polls when {@link DebuggerOptions.pollLines} is absent. */
76
+ export declare const DEFAULT_POLL_LINES = 10000;
77
+ /** How many steps one entry from the host, and one tick, may take. Unlimited when absent. */
78
+ export interface StepBudget {
79
+ readonly perCallback?: number;
80
+ readonly perTick?: number;
81
+ }
82
+ /** The script host's native library, bound for this thread. Engines run on the thread that loaded it. */
83
+ export declare class ScriptHostLibrary {
84
+ private readonly bound;
85
+ private constructor();
86
+ /**
87
+ * Loads the library and checks that it speaks this binding's interface.
88
+ * @param path - The library's file; {@link locateLibrary} finds it when absent.
89
+ * @returns The bound library.
90
+ * @throws {NativeLibraryError} When there is no library, or it speaks another interface.
91
+ */
92
+ static load(path?: string): ScriptHostLibrary;
93
+ /**
94
+ * Creates an engine: one QuickJS runtime and context, with the globals BDS lacks removed and
95
+ * `Function` from a string refused.
96
+ * @param options - Its limits and module loader.
97
+ * @returns The engine.
98
+ * @throws {Error} When the engine cannot be created.
99
+ */
100
+ createEngine(options?: ScriptEngineOptions): ScriptEngine;
101
+ /** Unloads the library. Destroy its engines first. */
102
+ close(): void;
103
+ }
104
+ /**
105
+ * One script engine: a QuickJS runtime and context in native memory, its values held by handle.
106
+ * Every method runs synchronously on the thread that created the engine.
107
+ */
108
+ export declare class ScriptEngine {
109
+ private readonly bound;
110
+ private readonly native;
111
+ private readonly pointer;
112
+ private readonly callback;
113
+ private readonly buffer;
114
+ private readonly functions;
115
+ private readonly loadModule;
116
+ private nextFunctionId;
117
+ private debuggerListener;
118
+ /** How many callbacks from the engine are running. */
119
+ private active;
120
+ /** Handles host functions returned, each with the depth of the host call, until the engine has read them. */
121
+ private readonly released;
122
+ private destroyed;
123
+ /** Use {@link ScriptHostLibrary.createEngine}. */
124
+ constructor(bound: BoundLibrary, options: ScriptEngineOptions);
125
+ /**
126
+ * Runs a classic script.
127
+ * @param source - The script's text.
128
+ * @param name - The file name its stack traces show.
129
+ * @returns Its completion value. A handle in it belongs to the caller, who frees it.
130
+ * @throws {ScriptError} When the script throws, runs out of steps or goes over the memory limit.
131
+ */
132
+ evaluate(source: string, name?: string): ScriptValue;
133
+ /**
134
+ * Runs a module, loading each module it imports through the engine's module loader.
135
+ * @param name - The module's name, which relative imports resolve against.
136
+ * @param source - The module's text.
137
+ * @returns A handle to the module's namespace, which the caller frees.
138
+ * @throws {ScriptError} When the module or one it imports throws, or does not load.
139
+ */
140
+ evaluateModule(name: string, source: string): ScriptHandle;
141
+ /**
142
+ * Runs pending promise jobs until none is left, in the order they were queued.
143
+ * @param context - Runs only this context's jobs, leaving the others queued. Every context's when absent.
144
+ * @returns How many jobs ran.
145
+ * @throws {ScriptError} When a job throws; the jobs after it stay pending.
146
+ */
147
+ runJobs(context?: ScriptContextId): number;
148
+ /**
149
+ * Creates another context in the engine: a global object of its own, with the same limits as
150
+ * the first. The current context stays as it was.
151
+ * @returns The new context's id.
152
+ * @throws {ScriptOutOfMemoryError} When the engine cannot make it.
153
+ */
154
+ createContext(): ScriptContextId;
155
+ /**
156
+ * Makes a context current, so evaluations, the global object and new host functions are its.
157
+ * While a script calls the host, the calling script's context is current.
158
+ * @returns The context that was current before.
159
+ * @throws {RangeError} When the engine has no such context.
160
+ */
161
+ useContext(context: ScriptContextId): ScriptContextId;
162
+ /**
163
+ * Runs a function with a context current, and makes the one before current again after it.
164
+ * @returns What the function returned.
165
+ */
166
+ inContext<Result>(context: ScriptContextId, run: () => Result): Result;
167
+ /**
168
+ * Calls a script function.
169
+ * @param fn - The function.
170
+ * @param thisValue - Its `this`, or undefined.
171
+ * @param args - Its arguments.
172
+ * @returns What it returned. A handle in it belongs to the caller, who frees it.
173
+ * @throws {ScriptError} When the function throws, runs out of steps or goes over the memory limit.
174
+ */
175
+ call(fn: ScriptHandle, thisValue: ScriptHandle | undefined, ...args: ScriptValue[]): ScriptValue;
176
+ /**
177
+ * Frees a handle that a host function returns, once the engine has read the result. A host
178
+ * function cannot free a handle it made for its result before it returns, and the engine
179
+ * takes its own reference when it reads one.
180
+ * @returns The handle, for the host function to return.
181
+ */
182
+ release(handle: ScriptHandle): ScriptHandle;
183
+ /** Returns a handle to the global object, which the caller frees. */
184
+ global(): ScriptHandle;
185
+ /**
186
+ * Reads a property, running a getter if it has one.
187
+ * @returns The value. A handle in it belongs to the caller, who frees it.
188
+ */
189
+ get(object: ScriptHandle, key: string): ScriptValue;
190
+ /** Writes a property, running a setter if it has one. */
191
+ set(object: ScriptHandle, key: string, value: ScriptValue): void;
192
+ /**
193
+ * Makes a script function that calls `fn` synchronously. Every call crosses into the host
194
+ * once. A handle among its arguments lasts until `fn` returns; {@link duplicate} keeps one.
195
+ * @param name - The function's `name`.
196
+ * @param fn - What runs. An error it throws reaches the script with the same name and message.
197
+ * @returns A handle to the function, which the caller frees.
198
+ */
199
+ hostFunction(name: string, fn: HostFunction): ScriptHandle;
200
+ /** Makes a host function and sets it on the global object under its name. */
201
+ defineGlobalFunction(name: string, fn: HostFunction): void;
202
+ /** Returns a second handle to the same value, which outlives the first. */
203
+ duplicate(handle: ScriptHandle): ScriptHandle;
204
+ /**
205
+ * Frees the released handles of host calls at `depth` or deeper, whose results the engine has
206
+ * read: a host call that starts at a depth has seen the calls before it at that depth return.
207
+ */
208
+ private freeReleased;
209
+ /** Runs one call into the engine, then frees what host functions released, once no host call is running. */
210
+ private settle;
211
+ /** Releases a handle. The value lives on while the script still refers to it. */
212
+ free(handle: ScriptHandle): void;
213
+ /** Sets the step budget; the step past it stops the script with an uncatchable error. */
214
+ setBudget(budget: StepBudget): void;
215
+ /** Starts a tick, so the per-tick budget counts from 0 again. */
216
+ beginTick(): void;
217
+ /**
218
+ * Attaches a debugger to one context. Functions the engine enters from now on report their
219
+ * lines; those already running do not, so attach between calls into the engine. A replay
220
+ * never attaches one. While the listener handles a stop or a poll, the watched context is current.
221
+ * @param listener - Handles each stop and poll, on this thread.
222
+ * @returns The debugger, which detaches with {@link EngineDebugger.detach}.
223
+ * @throws {Error} When a debugger is already attached.
224
+ * @throws {RangeError} When the engine has no such context.
225
+ */
226
+ attachDebugger(listener: DebuggerListener, options?: DebuggerOptions): EngineDebugger;
227
+ /** Reads the engine's counters. */
228
+ stats(): EngineStats;
229
+ /**
230
+ * Frees the engine, its handles and its callback.
231
+ * @throws {Error} When called from inside one of the engine's host functions.
232
+ */
233
+ destroy(): void;
234
+ private live;
235
+ /** Turns a negative status into the error the engine described. */
236
+ private check;
237
+ /** Reads a result handle's value, freeing the handle unless the value is an object. */
238
+ private take;
239
+ /** Makes a handle for a value from its bytes. */
240
+ private make;
241
+ /** The engine's one callback. It never throws: `node:ffi` callbacks must not. */
242
+ private onHost;
243
+ private dispatch;
244
+ private paused;
245
+ private load;
246
+ /** Writes an error's name and message for the engine to throw, and returns the status for it. */
247
+ private describe;
248
+ }
249
+ export {};
250
+ //# sourceMappingURL=ScriptEngine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ScriptEngine.d.ts","sources":["../src/ScriptEngine.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAe,MAAM,2BAA2B,CAAC;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,KAAK,EAAE,YAAY,EAAgC,MAAM,OAAO,CAAC;AAExE,OAAO,EAAE,YAAY,EAA4C,MAAM,UAAU,CAAC;AAClF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,oFAAoF;AACpF,eAAO,MAAM,WAAW,IAAI,CAAC;AAQ7B,+EAA+E;AAC/E,QAAA,MAAM,IAAI;aACN,KAAK,EAAE,CAAC;aACR,aAAa,EAAE,CAAC;aAChB,SAAS,EAAE,CAAC;aACZ,SAAS,EAAE,CAAC;aACZ,WAAW,EAAE,CAAC;aACd,aAAa,EAAE,CAAC;aAChB,cAAc,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AG,IAAI,CAEzC;IAED,iEAAiE;IAC1D,SAAS,IAAI,IAAI,CAEvB;IAED;;;;;;;;OAQG;IACI,cAAc,CAAC,QAAQ,EAAE,gBAAgB,EAAE,OAAO,GAAE,eAAoB,GAAG,cAAc,CAoB/F;IAED,mCAAmC;IAC5B,KAAK,IAAI,WAAW,CAe1B;IAED;;;OAGG;IACI,OAAO,IAAI,IAAI,CAQrB;IAED,OAAO,CAAC,IAAI;IAKZ,mEAAmE;IACnE,OAAO,CAAC,KAAK;IAcb,uFAAuF;IACvF,OAAO,CAAC,IAAI;IAOZ,iDAAiD;IACjD,OAAO,CAAC,IAAI;IAKZ,iFAAiF;IACjF,OAAO,CAAC,MAAM;IAuBd,OAAO,CAAC,QAAQ;IAShB,OAAO,CAAC,MAAM;IAMd,OAAO,CAAC,IAAI;IAOZ,iGAAiG;IACjG,OAAO,CAAC,QAAQ;CAUnB"}
@@ -0,0 +1,427 @@
1
+ import { EngineDebugger, PauseReason } from "./debugger/EngineDebugger.js";
2
+ import { scriptErrorParams } from "./errors.js";
3
+ import { bindLibrary } from "./ffi.js";
4
+ import { locateLibrary } from "./library.js";
5
+ import { ScriptHandle, TransferBuffer, ValueReader, ValueWriter } from "./values.js";
6
+ import { ScriptHostErrors } from "@jsprismarine/errors/script-host";
7
+ // src/ScriptEngine.ts
8
+ /** The C interface version this binding speaks, `JSH_ABI_VERSION` in the header. */
9
+ var ABI_VERSION = 3;
10
+ /** The `jsh_status` codes an entry returns instead of a handle or a count. */
11
+ var Status = {
12
+ Thrown: -1,
13
+ Terminated: -2,
14
+ OutOfMemory: -3,
15
+ Invalid: -4
16
+ };
17
+ /** The `jsh_op` requests the engine sends its callback. */
18
+ var Op = {
19
+ Call: 0,
20
+ LoadModule: 1,
21
+ Grow: 2,
22
+ DebugPaused: 3,
23
+ DebugPoll: 4
24
+ };
25
+ /** The `jsh_stat` counters, by the field of {@link EngineStats} each fills. */
26
+ var Stat = {
27
+ steps: 0,
28
+ callbackSteps: 1,
29
+ tickSteps: 2,
30
+ hostCalls: 3,
31
+ bytesToHost: 4,
32
+ bytesFromHost: 5,
33
+ stackOverflows: 6,
34
+ memoryLimitHits: 7,
35
+ memoryUsed: 8,
36
+ handles: 9
37
+ };
38
+ /** The bytes a new engine's transfer buffer starts with. It grows when a value needs more. */
39
+ var DEFAULT_BUFFER_SIZE = 65536;
40
+ /**
41
+ * The native stack a new engine's scripts may use, in bytes. A host callback runs on the same
42
+ * stack, so this leaves room for Node.js's own frames under QuickJS's.
43
+ */
44
+ var DEFAULT_STACK_SIZE = 262144;
45
+ /** The context an engine is created with. */
46
+ var DEFAULT_CONTEXT = 0;
47
+ /** The lines between polls when {@link DebuggerOptions.pollLines} is absent. */
48
+ var DEFAULT_POLL_LINES = 1e4;
49
+ /** The script host's native library, bound for this thread. Engines run on the thread that loaded it. */
50
+ var ScriptHostLibrary = class ScriptHostLibrary {
51
+ bound;
52
+ constructor(bound) {
53
+ this.bound = bound;
54
+ }
55
+ /**
56
+ * Loads the library and checks that it speaks this binding's interface.
57
+ * @param path - The library's file; {@link locateLibrary} finds it when absent.
58
+ * @returns The bound library.
59
+ * @throws {NativeLibraryError} When there is no library, or it speaks another interface.
60
+ */
61
+ static load(path = locateLibrary()) {
62
+ const bound = bindLibrary(path);
63
+ const version = bound.symbols.jsh_abi_version();
64
+ if (version !== 3) {
65
+ bound.close();
66
+ throw new ScriptHostErrors.LibraryInterfaceMismatch({
67
+ path,
68
+ version,
69
+ abiVersion: 3
70
+ });
71
+ }
72
+ return new ScriptHostLibrary(bound);
73
+ }
74
+ /**
75
+ * Creates an engine: one QuickJS runtime and context, with the globals BDS lacks removed and
76
+ * `Function` from a string refused.
77
+ * @param options - Its limits and module loader.
78
+ * @returns The engine.
79
+ * @throws {Error} When the engine cannot be created.
80
+ */
81
+ createEngine(options = {}) {
82
+ return new ScriptEngine(this.bound, options);
83
+ }
84
+ /** Unloads the library. Destroy its engines first. */
85
+ close() {
86
+ this.bound.close();
87
+ }
88
+ };
89
+ /**
90
+ * One script engine: a QuickJS runtime and context in native memory, its values held by handle.
91
+ * Every method runs synchronously on the thread that created the engine.
92
+ */
93
+ var ScriptEngine = class {
94
+ bound;
95
+ native;
96
+ pointer;
97
+ callback;
98
+ buffer;
99
+ functions = /* @__PURE__ */ new Map();
100
+ loadModule;
101
+ nextFunctionId = 1;
102
+ debuggerListener;
103
+ /** How many callbacks from the engine are running. */
104
+ active = 0;
105
+ /** Handles host functions returned, each with the depth of the host call, until the engine has read them. */
106
+ released = [];
107
+ destroyed = false;
108
+ /** Use {@link ScriptHostLibrary.createEngine}. */
109
+ constructor(bound, options) {
110
+ this.bound = bound;
111
+ this.native = bound.symbols;
112
+ this.loadModule = options.loadModule;
113
+ let engine = 0n;
114
+ this.buffer = new TransferBuffer(options.bufferSize ?? 65536, (memory) => this.native.jsh_engine_set_buffer(engine, bound.pointerOf(memory), memory.byteLength));
115
+ this.callback = bound.registerHostCallback((op, id, length) => this.onHost(op, id, length));
116
+ engine = this.native.jsh_engine_create(this.callback, bound.pointerOf(this.buffer.memory), this.buffer.capacity, options.memoryLimit ?? 0, options.stackSize ?? 262144);
117
+ if (engine === 0n) {
118
+ bound.unregisterHostCallback(this.callback);
119
+ throw new ScriptHostErrors.EngineNotCreated();
120
+ }
121
+ this.pointer = engine;
122
+ }
123
+ /**
124
+ * Runs a classic script.
125
+ * @param source - The script's text.
126
+ * @param name - The file name its stack traces show.
127
+ * @returns Its completion value. A handle in it belongs to the caller, who frees it.
128
+ * @throws {ScriptError} When the script throws, runs out of steps or goes over the memory limit.
129
+ */
130
+ evaluate(source, name = "<eval>") {
131
+ const text = Buffer.from(`${source}\0`, "utf8");
132
+ return this.settle(() => this.take(this.check(this.native.jsh_eval_script(this.live(), name, text, text.length - 1))));
133
+ }
134
+ /**
135
+ * Runs a module, loading each module it imports through the engine's module loader.
136
+ * @param name - The module's name, which relative imports resolve against.
137
+ * @param source - The module's text.
138
+ * @returns A handle to the module's namespace, which the caller frees.
139
+ * @throws {ScriptError} When the module or one it imports throws, or does not load.
140
+ */
141
+ evaluateModule(name, source) {
142
+ const text = Buffer.from(`${source}\0`, "utf8");
143
+ return this.settle(() => new ScriptHandle(this.check(this.native.jsh_eval_module(this.live(), name, text, text.length - 1))));
144
+ }
145
+ /**
146
+ * Runs pending promise jobs until none is left, in the order they were queued.
147
+ * @param context - Runs only this context's jobs, leaving the others queued. Every context's when absent.
148
+ * @returns How many jobs ran.
149
+ * @throws {ScriptError} When a job throws; the jobs after it stay pending.
150
+ */
151
+ runJobs(context) {
152
+ return this.settle(() => this.check(this.native.jsh_run_jobs(this.live(), context ?? -1)));
153
+ }
154
+ /**
155
+ * Creates another context in the engine: a global object of its own, with the same limits as
156
+ * the first. The current context stays as it was.
157
+ * @returns The new context's id.
158
+ * @throws {ScriptOutOfMemoryError} When the engine cannot make it.
159
+ */
160
+ createContext() {
161
+ return this.check(this.native.jsh_context_create(this.live()));
162
+ }
163
+ /**
164
+ * Makes a context current, so evaluations, the global object and new host functions are its.
165
+ * While a script calls the host, the calling script's context is current.
166
+ * @returns The context that was current before.
167
+ * @throws {RangeError} When the engine has no such context.
168
+ */
169
+ useContext(context) {
170
+ return this.check(this.native.jsh_context_select(this.live(), context));
171
+ }
172
+ /**
173
+ * Runs a function with a context current, and makes the one before current again after it.
174
+ * @returns What the function returned.
175
+ */
176
+ inContext(context, run) {
177
+ const previous = this.useContext(context);
178
+ try {
179
+ return run();
180
+ } finally {
181
+ this.useContext(previous);
182
+ }
183
+ }
184
+ /**
185
+ * Calls a script function.
186
+ * @param fn - The function.
187
+ * @param thisValue - Its `this`, or undefined.
188
+ * @param args - Its arguments.
189
+ * @returns What it returned. A handle in it belongs to the caller, who frees it.
190
+ * @throws {ScriptError} When the function throws, runs out of steps or goes over the memory limit.
191
+ */
192
+ call(fn, thisValue, ...args) {
193
+ const writer = new ValueWriter(this.buffer).list(args);
194
+ return this.settle(() => this.take(this.check(this.native.jsh_call(this.live(), fn.id, thisValue?.id ?? 0, writer.length))));
195
+ }
196
+ /**
197
+ * Frees a handle that a host function returns, once the engine has read the result. A host
198
+ * function cannot free a handle it made for its result before it returns, and the engine
199
+ * takes its own reference when it reads one.
200
+ * @returns The handle, for the host function to return.
201
+ */
202
+ release(handle) {
203
+ this.released.push({
204
+ handle,
205
+ depth: this.active
206
+ });
207
+ return handle;
208
+ }
209
+ /** Returns a handle to the global object, which the caller frees. */
210
+ global() {
211
+ return new ScriptHandle(this.check(this.native.jsh_global(this.live())));
212
+ }
213
+ /**
214
+ * Reads a property, running a getter if it has one.
215
+ * @returns The value. A handle in it belongs to the caller, who frees it.
216
+ */
217
+ get(object, key) {
218
+ return this.take(this.check(this.native.jsh_get(this.live(), object.id, key)));
219
+ }
220
+ /** Writes a property, running a setter if it has one. */
221
+ set(object, key, value) {
222
+ const handle = value instanceof ScriptHandle ? value : this.make(value);
223
+ try {
224
+ this.check(this.native.jsh_set(this.live(), object.id, key, handle.id));
225
+ } finally {
226
+ if (handle !== value) this.free(handle);
227
+ }
228
+ }
229
+ /**
230
+ * Makes a script function that calls `fn` synchronously. Every call crosses into the host
231
+ * once. A handle among its arguments lasts until `fn` returns; {@link duplicate} keeps one.
232
+ * @param name - The function's `name`.
233
+ * @param fn - What runs. An error it throws reaches the script with the same name and message.
234
+ * @returns A handle to the function, which the caller frees.
235
+ */
236
+ hostFunction(name, fn) {
237
+ const id = this.nextFunctionId++;
238
+ this.functions.set(id, fn);
239
+ return new ScriptHandle(this.check(this.native.jsh_host_function(this.live(), id, name, fn.length)));
240
+ }
241
+ /** Makes a host function and sets it on the global object under its name. */
242
+ defineGlobalFunction(name, fn) {
243
+ const global = this.global();
244
+ const handle = this.hostFunction(name, fn);
245
+ try {
246
+ this.set(global, name, handle);
247
+ } finally {
248
+ this.free(handle);
249
+ this.free(global);
250
+ }
251
+ }
252
+ /** Returns a second handle to the same value, which outlives the first. */
253
+ duplicate(handle) {
254
+ return new ScriptHandle(this.check(this.native.jsh_dup(this.live(), handle.id)));
255
+ }
256
+ /**
257
+ * Frees the released handles of host calls at `depth` or deeper, whose results the engine has
258
+ * read: a host call that starts at a depth has seen the calls before it at that depth return.
259
+ */
260
+ freeReleased(depth) {
261
+ for (let index = this.released.length - 1; index >= 0; index--) {
262
+ const entry = this.released[index];
263
+ if (entry === void 0 || entry.depth < depth) continue;
264
+ this.released.splice(index, 1);
265
+ this.native.jsh_free(this.pointer, entry.handle.id);
266
+ }
267
+ }
268
+ /** Runs one call into the engine, then frees what host functions released, once no host call is running. */
269
+ settle(run) {
270
+ try {
271
+ return run();
272
+ } finally {
273
+ if (this.active === 0 && !this.destroyed) this.freeReleased(1);
274
+ }
275
+ }
276
+ /** Releases a handle. The value lives on while the script still refers to it. */
277
+ free(handle) {
278
+ this.native.jsh_free(this.live(), handle.id);
279
+ }
280
+ /** Sets the step budget; the step past it stops the script with an uncatchable error. */
281
+ setBudget(budget) {
282
+ this.native.jsh_engine_set_budget(this.live(), budget.perCallback ?? 0, budget.perTick ?? 0);
283
+ }
284
+ /** Starts a tick, so the per-tick budget counts from 0 again. */
285
+ beginTick() {
286
+ this.native.jsh_engine_begin_tick(this.live());
287
+ }
288
+ /**
289
+ * Attaches a debugger to one context. Functions the engine enters from now on report their
290
+ * lines; those already running do not, so attach between calls into the engine. A replay
291
+ * never attaches one. While the listener handles a stop or a poll, the watched context is current.
292
+ * @param listener - Handles each stop and poll, on this thread.
293
+ * @returns The debugger, which detaches with {@link EngineDebugger.detach}.
294
+ * @throws {Error} When a debugger is already attached.
295
+ * @throws {RangeError} When the engine has no such context.
296
+ */
297
+ attachDebugger(listener, options = {}) {
298
+ if (this.debuggerListener !== void 0) throw new ScriptHostErrors.DebuggerAlreadyAttached();
299
+ this.check(this.native.jsh_debug_attach(this.live(), options.context ?? 0, options.pollLines ?? 1e4));
300
+ this.debuggerListener = listener;
301
+ return new EngineDebugger({
302
+ native: this.native,
303
+ buffer: this.buffer,
304
+ pointer: () => this.live(),
305
+ check: (result) => this.check(result),
306
+ take: (handle) => this.take(handle),
307
+ detached: () => {
308
+ this.debuggerListener = void 0;
309
+ }
310
+ });
311
+ }
312
+ /** Reads the engine's counters. */
313
+ stats() {
314
+ const pointer = this.live();
315
+ const read = (stat) => this.native.jsh_engine_stat(pointer, stat);
316
+ return {
317
+ steps: read(Stat.steps),
318
+ callbackSteps: read(Stat.callbackSteps),
319
+ tickSteps: read(Stat.tickSteps),
320
+ hostCalls: read(Stat.hostCalls),
321
+ bytesToHost: read(Stat.bytesToHost),
322
+ bytesFromHost: read(Stat.bytesFromHost),
323
+ stackOverflows: read(Stat.stackOverflows),
324
+ memoryLimitHits: read(Stat.memoryLimitHits),
325
+ memoryUsed: read(Stat.memoryUsed),
326
+ handles: read(Stat.handles)
327
+ };
328
+ }
329
+ /**
330
+ * Frees the engine, its handles and its callback.
331
+ * @throws {Error} When called from inside one of the engine's host functions.
332
+ */
333
+ destroy() {
334
+ if (this.destroyed) return;
335
+ if (this.active > 0) throw new ScriptHostErrors.EngineDestroyedDuringHostCall();
336
+ this.destroyed = true;
337
+ this.native.jsh_engine_destroy(this.pointer);
338
+ this.bound.unregisterHostCallback(this.callback);
339
+ this.functions.clear();
340
+ this.released.length = 0;
341
+ }
342
+ live() {
343
+ if (this.destroyed) throw new ScriptHostErrors.EngineDestroyed();
344
+ return this.pointer;
345
+ }
346
+ /** Turns a negative status into the error the engine described. */
347
+ check(result) {
348
+ if (result >= 0) return result;
349
+ if (result === Status.Invalid) throw new ScriptHostErrors.EngineRejectedValue();
350
+ const reader = new ValueReader(this.buffer.bytes, this.buffer.capacity);
351
+ const params = scriptErrorParams({
352
+ scriptName: reader.string(),
353
+ scriptMessage: reader.string(),
354
+ scriptStack: reader.string()
355
+ });
356
+ if (result === Status.Terminated) throw new ScriptHostErrors.ScriptTerminated(params);
357
+ if (result === Status.OutOfMemory) throw new ScriptHostErrors.ScriptOutOfMemory(params);
358
+ throw new ScriptHostErrors.ScriptThrew(params);
359
+ }
360
+ /** Reads a result handle's value, freeing the handle unless the value is an object. */
361
+ take(handle) {
362
+ const length = this.check(this.native.jsh_encode(this.pointer, handle));
363
+ const value = new ValueReader(this.buffer.bytes, length).value();
364
+ if (!(value instanceof ScriptHandle)) this.native.jsh_free(this.pointer, handle);
365
+ return value;
366
+ }
367
+ /** Makes a handle for a value from its bytes. */
368
+ make(value) {
369
+ const writer = new ValueWriter(this.buffer).value(value);
370
+ return new ScriptHandle(this.check(this.native.jsh_decode(this.pointer, writer.length)));
371
+ }
372
+ /** The engine's one callback. It never throws: `node:ffi` callbacks must not. */
373
+ onHost(op, id, length) {
374
+ this.active++;
375
+ try {
376
+ this.freeReleased(this.active);
377
+ if (op === Op.Grow) {
378
+ this.buffer.reserve(length);
379
+ return 0;
380
+ }
381
+ if (op === Op.Call) return this.dispatch(id, length);
382
+ if (op === Op.LoadModule) return this.load(id, length);
383
+ if (op === Op.DebugPaused) return this.paused(id);
384
+ if (op === Op.DebugPoll) {
385
+ this.debuggerListener?.poll();
386
+ return 0;
387
+ }
388
+ throw new ScriptHostErrors.UnknownEngineRequest({ op });
389
+ } catch (error) {
390
+ return this.describe(error);
391
+ } finally {
392
+ this.active--;
393
+ }
394
+ }
395
+ dispatch(id, length) {
396
+ const args = new ValueReader(this.buffer.bytes, length).list();
397
+ const fn = this.functions.get(id);
398
+ if (fn === void 0) throw new ScriptHostErrors.UnknownHostFunction({ id });
399
+ const result = fn(...args);
400
+ return new ValueWriter(this.buffer).value(result).length;
401
+ }
402
+ paused(code) {
403
+ const reason = PauseReason[code];
404
+ if (reason === void 0) throw new ScriptHostErrors.UnknownPauseReason({ code });
405
+ return this.debuggerListener?.paused(reason) === "terminate" ? -1 : 0;
406
+ }
407
+ load(context, length) {
408
+ const name = this.buffer.bytes.toString("utf8", 0, length);
409
+ const module = this.loadModule?.(name, context);
410
+ if (module === void 0) throw new ScriptHostErrors.ModuleNotFound({ name });
411
+ return new ValueWriter(this.buffer).value(module).length;
412
+ }
413
+ /** Writes an error's name and message for the engine to throw, and returns the status for it. */
414
+ describe(error) {
415
+ try {
416
+ const name = error instanceof Error ? error.name : "Error";
417
+ const message = error instanceof Error ? error.message : String(error);
418
+ new ValueWriter(this.buffer).string(name).string(message);
419
+ return -1;
420
+ } catch {
421
+ return -2;
422
+ }
423
+ }
424
+ };
425
+ export { ABI_VERSION, DEFAULT_BUFFER_SIZE, DEFAULT_CONTEXT, DEFAULT_POLL_LINES, DEFAULT_STACK_SIZE, ScriptEngine, ScriptHostLibrary };
426
+
427
+ //# sourceMappingURL=ScriptEngine.js.map