-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcfddlcjs_wasm_json.js
57 lines (52 loc) · 1.53 KB
/
cfddlcjs_wasm_json.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const cfddlcjsWasm = require('./dist/cfddlcjs_wasm.js');
const cfddlcjsWasmJsonApi = require('./cfddlcjs_wasm_jsonapi.js');
cfddlcjsWasm['preInit'] = function() {};
const wrappedModule = {};
cfddlcjsWasm['onRuntimeInitialized'] = async () => {
const funcNameResult = await cfddlcjsWasmJsonApi.ccallCfd(
cfddlcjsWasm,
cfddlcjsWasm._cfdjsGetJsonApiNames,
'string',
[],
[],
);
if (funcNameResult.indexOf('Error:') >= 0) {
throw new cfddlcjsWasmJsonApi.CfdError(
`cfdjsGetJsonApiNames internal error. ${funcNameResult}`,
);
}
const funcList = funcNameResult.split(',');
// register function list
funcList.forEach((requestName) => {
const hook = async function(...args) {
if (args.length > 1) {
throw new cfddlcjsWasmJsonApi.CfdError(
'ERROR: Invalid argument passed:' +
`func=[${requestName}], args=[${args}]`,
);
}
let arg = '';
if (typeof args === 'undefined') {
arg = '';
} else if (typeof args === 'string') {
arg = args;
} else if (args) {
arg = args[0];
}
return await cfddlcjsWasmJsonApi.callJsonApi(
cfddlcjsWasm,
requestName,
arg,
);
};
Object.defineProperty(wrappedModule, requestName, {
value: hook,
enumerable: true,
});
});
if ('onRuntimeInitialized' in wrappedModule) {
wrappedModule.onRuntimeInitialized();
}
};
module.exports = wrappedModule;
module.exports.CfdError = cfddlcjsWasmJsonApi.CfdError;