fix(bindings/wasm): fix Parser.getIncludedRanges()
This commit is contained in:
parent
ad07fa8a9e
commit
5c2f80ebb0
6 changed files with 71 additions and 10 deletions
|
|
@ -1,3 +1,8 @@
|
|||
/* eslint-disable-next-line spaced-comment */
|
||||
/// <reference types="emscripten" />
|
||||
/* eslint-disable-next-line spaced-comment */
|
||||
/// <reference path="tree-sitter-web.d.ts"/>
|
||||
|
||||
const C = Module;
|
||||
const INTERNAL = {};
|
||||
const SIZE_OF_INT = 4;
|
||||
|
|
@ -121,17 +126,19 @@ class ParserImpl {
|
|||
}
|
||||
|
||||
getIncludedRanges() {
|
||||
const count = C._malloc(SIZE_OF_INT);
|
||||
const rangeAddress = C._ts_parser_included_ranges(this[0], count);
|
||||
count = getValue(count, 'i32');
|
||||
C._ts_parser_included_ranges_wasm(this[0]);
|
||||
const count = getValue(TRANSFER_BUFFER, 'i32');
|
||||
const buffer = getValue(TRANSFER_BUFFER + SIZE_OF_INT, 'i32');
|
||||
const result = new Array(count);
|
||||
if (count > 0) {
|
||||
let address = rangeAddress;
|
||||
let address = buffer;
|
||||
for (let i = 0; i < count; i++) {
|
||||
result[i] = unmarshalRange(address);
|
||||
address += SIZE_OF_RANGE;
|
||||
}
|
||||
C._free(buffer);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
getTimeoutMicros() {
|
||||
|
|
@ -1500,10 +1507,11 @@ function marshalPoint(address, point) {
|
|||
}
|
||||
|
||||
function unmarshalPoint(address) {
|
||||
return {
|
||||
row: getValue(address, 'i32'),
|
||||
column: getValue(address + SIZE_OF_INT, 'i32'),
|
||||
const result = {
|
||||
row: getValue(address, 'i32') >>> 0,
|
||||
column: getValue(address + SIZE_OF_INT, 'i32') >>> 0,
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
function marshalRange(address, range) {
|
||||
|
|
@ -1517,8 +1525,8 @@ function unmarshalRange(address) {
|
|||
const result = {};
|
||||
result.startPosition = unmarshalPoint(address); address += SIZE_OF_POINT;
|
||||
result.endPosition = unmarshalPoint(address); address += SIZE_OF_POINT;
|
||||
result.startIndex = getValue(address, 'i32'); address += SIZE_OF_INT;
|
||||
result.endIndex = getValue(address, 'i32');
|
||||
result.startIndex = getValue(address, 'i32') >>> 0; address += SIZE_OF_INT;
|
||||
result.endIndex = getValue(address, 'i32') >>> 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue