Skip to content

Commit c16cd5a

Browse files
committed
pkg
1 parent bf45d85 commit c16cd5a

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "libpg-query",
3-
"version": "17.3.1",
3+
"version": "17.3.3",
44
"description": "The real PostgreSQL query parser",
55
"homepage": "https://github.com/launchql/libpg-query-node",
66
"main": "./wasm/index.cjs",

src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ function awaitInit<T extends (...args: any[]) => Promise<any>>(fn: T): T {
6262

6363
function stringToPtr(str: string): number {
6464
ensureLoaded();
65+
if (typeof str !== 'string') {
66+
throw new TypeError(`Expected a string, got ${typeof str}`);
67+
}
6568
const len = wasmModule.lengthBytesUTF8(str) + 1;
6669
const ptr = wasmModule._malloc(len);
6770
try {
@@ -75,6 +78,9 @@ function stringToPtr(str: string): number {
7578

7679
function ptrToString(ptr: number): string {
7780
ensureLoaded();
81+
if (typeof ptr !== 'number') {
82+
throw new TypeError(`Expected a number, got ${typeof ptr}`);
83+
}
7884
return wasmModule.UTF8ToString(ptr);
7985
}
8086

wasm/index.cjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ function awaitInit(fn) {
5151
}
5252
function stringToPtr(str) {
5353
ensureLoaded();
54+
if (typeof str !== 'string') {
55+
throw new TypeError(`Expected a string, got ${typeof str}`);
56+
}
5457
const len = wasmModule.lengthBytesUTF8(str) + 1;
5558
const ptr = wasmModule._malloc(len);
5659
try {
@@ -64,6 +67,9 @@ function stringToPtr(str) {
6467
}
6568
function ptrToString(ptr) {
6669
ensureLoaded();
70+
if (typeof ptr !== 'number') {
71+
throw new TypeError(`Expected a number, got ${typeof ptr}`);
72+
}
6773
return wasmModule.UTF8ToString(ptr);
6874
}
6975
exports.parse = awaitInit(async (query) => {

wasm/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ function awaitInit(fn) {
2424
}
2525
function stringToPtr(str) {
2626
ensureLoaded();
27+
if (typeof str !== 'string') {
28+
throw new TypeError(`Expected a string, got ${typeof str}`);
29+
}
2730
const len = wasmModule.lengthBytesUTF8(str) + 1;
2831
const ptr = wasmModule._malloc(len);
2932
try {
@@ -37,6 +40,9 @@ function stringToPtr(str) {
3740
}
3841
function ptrToString(ptr) {
3942
ensureLoaded();
43+
if (typeof ptr !== 'number') {
44+
throw new TypeError(`Expected a number, got ${typeof ptr}`);
45+
}
4046
return wasmModule.UTF8ToString(ptr);
4147
}
4248
export const parse = awaitInit(async (query) => {

0 commit comments

Comments
 (0)