@lynx-js/tasm 0.0.20 → 0.0.21

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.
package/ChangeLog.md CHANGED
@@ -1,3 +1,8 @@
1
+ # CHANGELOG
2
+
3
+ # 0.0.21
4
+ * supports to resolve `compilerOption` in a tasm file.
5
+
1
6
  # 0.0.20
2
7
  * support LEPUS_Eval with filename for sourcemap.
3
8
 
Binary file
Binary file
package/index.js CHANGED
@@ -126,6 +126,27 @@ function decode_wasm(buffer) {
126
126
  return JSON.parse(res.result);
127
127
  }
128
128
 
129
+ function decode_wasm(buffer) {
130
+ const Module = loadModule();
131
+ // console.log(templateJs);
132
+ // const uint8array = new Uint8Array(templateJs.size());
133
+ // const res = m._decode(uint8array);
134
+ const byteArray = new Uint8Array(buffer);
135
+ const byteArrayLength = byteArray.length;
136
+ // Allocate memory in the Emscripten heap
137
+ const byteArrayPtr = Module._malloc(byteArrayLength);
138
+ // Copy the data to the Emscripten heap
139
+ Module.HEAPU8.set(byteArray, byteArrayPtr);
140
+ // Call the C++ function
141
+ const res = Module._decode(byteArrayPtr, byteArrayLength);
142
+ // Free the allocated memory
143
+ Module._free(byteArrayPtr);
144
+ if (res.status !== 0) {
145
+ throw new Error(`decode error: ${res.result}`);
146
+ }
147
+ return res;
148
+ }
149
+
129
150
  let encode = encode_napi;
130
151
  module.exports = {
131
152
  supportNapi,
package/lepus.d.ts ADDED
@@ -0,0 +1,85 @@
1
+ // TypeScript bindings for emscripten-generated code. Automatically generated at compile time.
2
+ declare namespace RuntimeExports {
3
+ /**
4
+ * @param {string=} returnType
5
+ * @param {Array=} argTypes
6
+ * @param {Object=} opts
7
+ */
8
+ function cwrap(ident: any, returnType?: string, argTypes?: any[], opts?: any): any;
9
+ /**
10
+ * @param {string|null=} returnType
11
+ * @param {Array=} argTypes
12
+ * @param {Array=} args
13
+ * @param {Object=} opts
14
+ */
15
+ function ccall(ident: any, returnType?: string, argTypes?: any[], args?: any[], opts?: any): any;
16
+ function allocateUTF8(...args: any[]): any;
17
+ /**
18
+ * Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the
19
+ * emscripten HEAP, returns a copy of that string as a Javascript String object.
20
+ *
21
+ * @param {number} ptr
22
+ * @param {number=} maxBytesToRead - An optional length that specifies the
23
+ * maximum number of bytes to read. You can omit this parameter to scan the
24
+ * string until the first 0 byte. If maxBytesToRead is passed, and the string
25
+ * at [ptr, ptr+maxBytesToReadr[ contains a null byte in the middle, then the
26
+ * string will cut short at that byte index.
27
+ * @param {boolean=} ignoreNul - If true, the function will not stop on a NUL character.
28
+ * @return {string}
29
+ */
30
+ function UTF8ToString(ptr: number, maxBytesToRead?: number, ignoreNul?: boolean): string;
31
+ }
32
+ interface WasmModule {
33
+ _quickjsCheck(_0: number): void;
34
+ _createBufferPool(): number;
35
+ _dropBufferPool(_0: number): void;
36
+ _readBufferPool_data(_0: number, _1: number): number;
37
+ _readBufferPool_len(_0: number, _1: number): number;
38
+ _reencode_template_debug(_0: number, _1: number, _2: number, _3: number): number;
39
+ _lepusCheck(_0: number, _1: number, _2: number): number;
40
+ }
41
+
42
+ type EmbindString = ArrayBuffer|Uint8Array|Uint8ClampedArray|Int8Array|string;
43
+ export interface ClassHandle {
44
+ isAliasOf(other: ClassHandle): boolean;
45
+ delete(): void;
46
+ deleteLater(): this;
47
+ isDeleted(): boolean;
48
+ // @ts-ignore - If targeting lower than ESNext, this symbol might not exist.
49
+ [Symbol.dispose](): void;
50
+ clone(): this;
51
+ }
52
+ export interface VectorUInt8 extends ClassHandle {
53
+ push_back(_0: number): void;
54
+ resize(_0: number, _1: number): void;
55
+ size(): number;
56
+ get(_0: number): number | undefined;
57
+ set(_0: number, _1: number): boolean;
58
+ }
59
+
60
+ export type EncodeResult = {
61
+ status: number,
62
+ error_msg: EmbindString,
63
+ buffer: VectorUInt8,
64
+ lepus_code: EmbindString,
65
+ lepus_debug: EmbindString,
66
+ section_size: EmbindString
67
+ };
68
+
69
+ export type DecodeResult = {
70
+ status: number,
71
+ result: EmbindString
72
+ };
73
+
74
+ interface EmbindModule {
75
+ VectorUInt8: {
76
+ new(): VectorUInt8;
77
+ };
78
+ _encode(_0: EmbindString): EncodeResult;
79
+ _quickjsCheck(_0: EmbindString): string;
80
+ _encode_ssr(_0: number, _1: number, _2: EmbindString): EncodeResult;
81
+ _decode(_0: number, _1: number): DecodeResult;
82
+ }
83
+
84
+ export type MainModule = WasmModule & typeof RuntimeExports & EmbindModule;
85
+ export default function MainModuleFactory (options?: unknown): MainModule;