mix init options in the Module-global

This commit is contained in:
Johannes Rieken 2021-08-30 14:16:41 +02:00
parent 0926fad1e2
commit 12d727fd49
4 changed files with 48 additions and 29 deletions

View file

@ -17,24 +17,15 @@ var MIN_COMPATIBLE_VERSION;
var TRANSFER_BUFFER;
var currentParseCallback;
var currentLogCallback;
var initPromise = new Promise(resolve => {
Module.onRuntimeInitialized = resolve
}).then(() => {
TRANSFER_BUFFER = C._ts_init();
VERSION = getValue(TRANSFER_BUFFER, 'i32');
MIN_COMPATIBLE_VERSION = getValue(TRANSFER_BUFFER + SIZE_OF_INT, 'i32');
});
class Parser {
class ParserImpl {
static init() {
return initPromise;
TRANSFER_BUFFER = C._ts_init();
VERSION = getValue(TRANSFER_BUFFER, 'i32');
MIN_COMPATIBLE_VERSION = getValue(TRANSFER_BUFFER + SIZE_OF_INT, 'i32');
}
constructor() {
if (TRANSFER_BUFFER == null) {
throw new Error('You must first call Parser.init() and wait for it to resolve.');
}
initialize() {
C._ts_parser_new_wasm();
this[0] = getValue(TRANSFER_BUFFER, 'i32');
this[1] = getValue(TRANSFER_BUFFER + SIZE_OF_INT, 'i32');
@ -1203,6 +1194,3 @@ function marshalEdit(edit) {
setValue(address, edit.oldEndIndex, 'i32'); address += SIZE_OF_INT;
setValue(address, edit.newEndIndex, 'i32'); address += SIZE_OF_INT;
}
Parser.Language = Language;
Parser.Parser = Parser;