nginx-lint-plugin 0.10.4 → 0.10.5
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/README.md +1 -1
- package/package.json +1 -1
- package/wasm/parser/parser.core.wasm +0 -0
- package/wasm/parser/parser.js +219 -8
package/README.md
CHANGED
|
@@ -122,7 +122,7 @@ The WIT definition file is bundled with this package, so `jco componentize` can
|
|
|
122
122
|
"test": "tsc && node --test dist/plugin.test.js"
|
|
123
123
|
},
|
|
124
124
|
"dependencies": {
|
|
125
|
-
"nginx-lint-plugin": "^0.10.
|
|
125
|
+
"nginx-lint-plugin": "^0.10.5"
|
|
126
126
|
},
|
|
127
127
|
"devDependencies": {
|
|
128
128
|
"@bytecodealliance/componentize-js": "^0.19",
|
package/package.json
CHANGED
|
Binary file
|
package/wasm/parser/parser.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use
|
|
1
|
+
"use components";
|
|
2
2
|
|
|
3
3
|
function promiseWithResolvers() {
|
|
4
4
|
if (Promise.withResolvers) {
|
|
@@ -13,8 +13,9 @@ function promiseWithResolvers() {
|
|
|
13
13
|
return { promise, resolve, reject };
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
|
|
17
16
|
const symbolDispose = Symbol.dispose || Symbol.for('dispose');
|
|
17
|
+
const symbolAsyncIterator = Symbol.asyncIterator;
|
|
18
|
+
const symbolIterator = Symbol.iterator;
|
|
18
19
|
|
|
19
20
|
const _debugLog = (...args) => {
|
|
20
21
|
if (!globalThis?.process?.env?.JCO_DEBUG) { return; }
|
|
@@ -109,7 +110,7 @@ async function _clearCurrentTask(args) {
|
|
|
109
110
|
const { taskID, componentIdx } = args;
|
|
110
111
|
|
|
111
112
|
const meta = CURRENT_TASK_META[componentIdx];
|
|
112
|
-
if (!meta) { throw new Error(`missing current task meta for component idx [${componentIdx}]`); }
|
|
113
|
+
if (!meta) { throw new Error(`missing current task meta for component idx [${componentIdx}]n`); }
|
|
113
114
|
|
|
114
115
|
if (meta.taskID !== taskID) {
|
|
115
116
|
throw new Error(`task ID [${meta.taskID}] != requested ID [${taskID}]`);
|
|
@@ -217,13 +218,54 @@ const _coinFlip = () => { return Math.random() > 0.5; };
|
|
|
217
218
|
let SCOPE_ID = 0;
|
|
218
219
|
const I32_MIN = -2_147_483_648;
|
|
219
220
|
const I32_MAX = 2_147_483_647;
|
|
221
|
+
|
|
222
|
+
function _isValidNumericPrimitive(ty, v) {
|
|
223
|
+
if (v === undefined || v === null) { return false; }
|
|
224
|
+
switch (ty) {
|
|
225
|
+
case 'bool':
|
|
226
|
+
return v === 0 || v === 1;
|
|
227
|
+
break;
|
|
228
|
+
case 'u8':
|
|
229
|
+
return v >= 0 && v <= 255;
|
|
230
|
+
break;
|
|
231
|
+
case 's8':
|
|
232
|
+
return v >= -128 && v <= 127;
|
|
233
|
+
break;
|
|
234
|
+
case 'u16':
|
|
235
|
+
return v >= 0 && v <= 65535;
|
|
236
|
+
break;
|
|
237
|
+
case 's16':
|
|
238
|
+
return v >= -32768 && v <= 32767;
|
|
239
|
+
case 'u32':
|
|
240
|
+
return v >= 0 && v <= 4_294_967_295;
|
|
241
|
+
case 's32':
|
|
242
|
+
return v >= -2_147_483_648 && v <= 2_147_483_647;
|
|
243
|
+
case 'u64':
|
|
244
|
+
return typeof v === 'bigint' && v >= 0 && v <= 18_446_744_073_709_551_615n;
|
|
245
|
+
case 's64':
|
|
246
|
+
return typeof v === 'bigint' && v >= -9223372036854775808n && v <= 9223372036854775807n;
|
|
247
|
+
break;
|
|
248
|
+
case 'f32':
|
|
249
|
+
case 'f64': return typeof v === 'number';
|
|
250
|
+
default:
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function _requireValidNumericPrimitive(ty, v) {
|
|
257
|
+
if (v === undefined || v === null || !_isValidNumericPrimitive(ty, v)) {
|
|
258
|
+
throw new TypeError(`invalid ${ty} value [${v}]`);
|
|
259
|
+
}
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
220
262
|
const _typeCheckValidI32 = (n) => typeof n === 'number' && n >= I32_MIN && n <= I32_MAX;
|
|
221
263
|
|
|
222
264
|
const _typeCheckAsyncFn= (f) => {
|
|
223
265
|
return f instanceof ASYNC_FN_CTOR;
|
|
224
266
|
};
|
|
225
267
|
|
|
226
|
-
const ASYNC_FN_CTOR = (async () => {}).constructor;
|
|
268
|
+
let RESOURCE_CALL_BORROWS = [];const ASYNC_FN_CTOR = (async () => {}).constructor;
|
|
227
269
|
|
|
228
270
|
function clearCurrentTask(componentIdx, taskID) {
|
|
229
271
|
_debugLog('[clearCurrentTask()] args', { componentIdx, taskID });
|
|
@@ -512,6 +554,7 @@ class AsyncSubtask {
|
|
|
512
554
|
realloc,
|
|
513
555
|
vals: [subtaskValue],
|
|
514
556
|
storagePtr: resultPtr,
|
|
557
|
+
stringEncoding: callMetadata.stringEncoding,
|
|
515
558
|
});
|
|
516
559
|
}
|
|
517
560
|
}
|
|
@@ -701,6 +744,7 @@ resultCountOrAsync,
|
|
|
701
744
|
resultPtr,
|
|
702
745
|
returnFn,
|
|
703
746
|
startFn,
|
|
747
|
+
stringEncoding,
|
|
704
748
|
}
|
|
705
749
|
});
|
|
706
750
|
|
|
@@ -866,7 +910,8 @@ function _asyncStartCall(args, callee, paramCount, resultCount, flags) {
|
|
|
866
910
|
memory: callerMemory,
|
|
867
911
|
vals: [res],
|
|
868
912
|
storagePtr: subtaskCallMeta.resultPtr,
|
|
869
|
-
componentIdx: callerComponentIdx
|
|
913
|
+
componentIdx: callerComponentIdx,
|
|
914
|
+
stringEncoding: subtaskCallMeta.stringEncoding,
|
|
870
915
|
});
|
|
871
916
|
|
|
872
917
|
});
|
|
@@ -2156,9 +2201,48 @@ class ComponentAsyncState {
|
|
|
2156
2201
|
return new Waitable({ target: args?.target, });
|
|
2157
2202
|
}
|
|
2158
2203
|
|
|
2204
|
+
createReadableStreamEnd(args) {
|
|
2205
|
+
_debugLog('[ComponentAsyncState#createStreamEnd()] args', args);
|
|
2206
|
+
const { tableIdx, elemMeta, hostInjectFn } = args;
|
|
2207
|
+
|
|
2208
|
+
const { table: localStreamTable, componentIdx } = STREAM_TABLES[tableIdx];
|
|
2209
|
+
if (!localStreamTable) {
|
|
2210
|
+
throw new Error(`missing global stream table lookup for table [${tableIdx}] while creating stream`);
|
|
2211
|
+
}
|
|
2212
|
+
if (componentIdx !== this.#componentIdx) {
|
|
2213
|
+
throw new Error('component idx mismatch while creating stream');
|
|
2214
|
+
}
|
|
2215
|
+
|
|
2216
|
+
const waitable = this.createWaitable();
|
|
2217
|
+
const streamEnd = new StreamReadableEnd({
|
|
2218
|
+
tableIdx,
|
|
2219
|
+
elemMeta,
|
|
2220
|
+
hostInjectFn,
|
|
2221
|
+
pendingBufferMeta: {},
|
|
2222
|
+
target: `stream read end (lowered, @init)`,
|
|
2223
|
+
waitable,
|
|
2224
|
+
});
|
|
2225
|
+
|
|
2226
|
+
streamEnd.setWaitableIdx(this.handles.insert(streamEnd));
|
|
2227
|
+
streamEnd.setHandle(localStreamTable.insert(streamEnd));
|
|
2228
|
+
if (streamEnd.streamTableIdx() !== tableIdx) {
|
|
2229
|
+
throw new Error("unexpectedly mismatched stream table");
|
|
2230
|
+
}
|
|
2231
|
+
const streamEndWaitableIdx = streamEnd.waitableIdx();
|
|
2232
|
+
const streamEndHandle = streamEnd.handle();
|
|
2233
|
+
waitable.setTarget(`waitable for stream read end (lowered, waitable [${streamEndWaitableIdx}])`);
|
|
2234
|
+
streamEnd.setTarget(`stream read end (lowered, waitable [${streamEndWaitableIdx}])`);
|
|
2235
|
+
|
|
2236
|
+
return {
|
|
2237
|
+
waitableIdx: streamEndWaitableIdx,
|
|
2238
|
+
handle: streamEndHandle,
|
|
2239
|
+
streamEnd,
|
|
2240
|
+
};
|
|
2241
|
+
}
|
|
2242
|
+
|
|
2159
2243
|
createStream(args) {
|
|
2160
2244
|
_debugLog('[ComponentAsyncState#createStream()] args', args);
|
|
2161
|
-
const { tableIdx, elemMeta } = args;
|
|
2245
|
+
const { tableIdx, elemMeta, hostInjectFn } = args;
|
|
2162
2246
|
if (tableIdx === undefined) { throw new Error("missing table idx while adding stream"); }
|
|
2163
2247
|
if (elemMeta === undefined) { throw new Error("missing element metadata while adding stream"); }
|
|
2164
2248
|
|
|
@@ -2175,10 +2259,10 @@ class ComponentAsyncState {
|
|
|
2175
2259
|
|
|
2176
2260
|
const stream = new InternalStream({
|
|
2177
2261
|
tableIdx,
|
|
2178
|
-
componentIdx: this.#componentIdx,
|
|
2179
2262
|
elemMeta,
|
|
2180
2263
|
readWaitable,
|
|
2181
2264
|
writeWaitable,
|
|
2265
|
+
hostInjectFn,
|
|
2182
2266
|
});
|
|
2183
2267
|
stream.setGlobalStreamMapRep(STREAMS.insert(stream));
|
|
2184
2268
|
|
|
@@ -2203,17 +2287,21 @@ class ComponentAsyncState {
|
|
|
2203
2287
|
readEnd.setTarget(`stream read end (waitable [${readEndWaitableIdx}])`);
|
|
2204
2288
|
|
|
2205
2289
|
return {
|
|
2290
|
+
writeEnd,
|
|
2206
2291
|
writeEndWaitableIdx,
|
|
2207
2292
|
writeEndHandle,
|
|
2208
2293
|
readEndWaitableIdx,
|
|
2209
2294
|
readEndHandle,
|
|
2295
|
+
readEnd,
|
|
2210
2296
|
};
|
|
2211
2297
|
}
|
|
2212
2298
|
|
|
2213
2299
|
getStreamEnd(args) {
|
|
2214
2300
|
_debugLog('[ComponentAsyncState#getStreamEnd()] args', args);
|
|
2215
2301
|
const { tableIdx, streamEndHandle, streamEndWaitableIdx } = args;
|
|
2216
|
-
if (tableIdx === undefined) {
|
|
2302
|
+
if (tableIdx === undefined) {
|
|
2303
|
+
throw new Error('missing table idx while getting stream end');
|
|
2304
|
+
}
|
|
2217
2305
|
|
|
2218
2306
|
const { table, componentIdx } = STREAM_TABLES[tableIdx];
|
|
2219
2307
|
const cstate = getOrCreateAsyncState(componentIdx);
|
|
@@ -2300,6 +2388,127 @@ class ComponentAsyncState {
|
|
|
2300
2388
|
|
|
2301
2389
|
return streamEnd;
|
|
2302
2390
|
}
|
|
2391
|
+
|
|
2392
|
+
createFuture(args) {
|
|
2393
|
+
_debugLog('[ComponentAsyncState#createFuture()] args', args);
|
|
2394
|
+
const { tableIdx, elemMeta, hostInjectFn } = args;
|
|
2395
|
+
if (tableIdx === undefined) { throw new Error("missing table idx while adding future"); }
|
|
2396
|
+
if (elemMeta === undefined) { throw new Error("missing element metadata while adding future"); }
|
|
2397
|
+
|
|
2398
|
+
const { table: futureTable, componentIdx } = FUTURE_TABLES[tableIdx];
|
|
2399
|
+
if (!futureTable) {
|
|
2400
|
+
throw new Error(`missing global future table lookup for table [${tableIdx}] while creating future`);
|
|
2401
|
+
}
|
|
2402
|
+
if (componentIdx !== this.#componentIdx) {
|
|
2403
|
+
throw new Error('component idx mismatch while creating future');
|
|
2404
|
+
}
|
|
2405
|
+
|
|
2406
|
+
const readWaitable = this.createWaitable();
|
|
2407
|
+
const writeWaitable = this.createWaitable();
|
|
2408
|
+
|
|
2409
|
+
const future = new InternalFuture({
|
|
2410
|
+
tableIdx,
|
|
2411
|
+
componentIdx: this.#componentIdx,
|
|
2412
|
+
elemMeta,
|
|
2413
|
+
readWaitable,
|
|
2414
|
+
writeWaitable,
|
|
2415
|
+
hostInjectFn,
|
|
2416
|
+
});
|
|
2417
|
+
future.setGlobalFutureMapRep(FUTURES.insert(future));
|
|
2418
|
+
|
|
2419
|
+
const writeEnd = future.writeEnd();
|
|
2420
|
+
writeEnd.setWaitableIdx(this.handles.insert(writeEnd));
|
|
2421
|
+
writeEnd.setHandle(futureTable.insert(writeEnd));
|
|
2422
|
+
if (writeEnd.futureTableIdx() !== tableIdx) { throw new Error("unexpectedly mismatched future table"); }
|
|
2423
|
+
|
|
2424
|
+
const writeEndWaitableIdx = writeEnd.waitableIdx();
|
|
2425
|
+
const writeEndHandle = writeEnd.handle();
|
|
2426
|
+
writeWaitable.setTarget(`waitable for future write end (waitable [${writeEndWaitableIdx}])`);
|
|
2427
|
+
writeEnd.setTarget(`future write end (waitable [${writeEndWaitableIdx}])`);
|
|
2428
|
+
|
|
2429
|
+
const readEnd = future.readEnd();
|
|
2430
|
+
readEnd.setWaitableIdx(this.handles.insert(readEnd));
|
|
2431
|
+
readEnd.setHandle(futureTable.insert(readEnd));
|
|
2432
|
+
if (readEnd.futureTableIdx() !== tableIdx) { throw new Error("unexpectedly mismatched future table"); }
|
|
2433
|
+
|
|
2434
|
+
const readEndWaitableIdx = readEnd.waitableIdx();
|
|
2435
|
+
const readEndHandle = readEnd.handle();
|
|
2436
|
+
readWaitable.setTarget(`waitable for read end (waitable [${readEndWaitableIdx}])`);
|
|
2437
|
+
readEnd.setTarget(`future read end (waitable [${readEndWaitableIdx}])`);
|
|
2438
|
+
|
|
2439
|
+
return {
|
|
2440
|
+
writeEnd,
|
|
2441
|
+
writeEndWaitableIdx,
|
|
2442
|
+
writeEndHandle,
|
|
2443
|
+
readEndWaitableIdx,
|
|
2444
|
+
readEndHandle,
|
|
2445
|
+
readEnd,
|
|
2446
|
+
};
|
|
2447
|
+
}
|
|
2448
|
+
|
|
2449
|
+
getFutureEnd(args) {
|
|
2450
|
+
_debugLog('[ComponentAsyncState#getFutureEnd()] args', args);
|
|
2451
|
+
const { tableIdx, futureEndHandle, futureEndWaitableIdx } = args;
|
|
2452
|
+
if (tableIdx === undefined) {
|
|
2453
|
+
throw new Error('missing table idx while getting future end');
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2456
|
+
const { table, componentIdx } = FUTURE_TABLES[tableIdx];
|
|
2457
|
+
const cstate = getOrCreateAsyncState(componentIdx);
|
|
2458
|
+
|
|
2459
|
+
let futureEnd;
|
|
2460
|
+
if (futureEndWaitableIdx !== undefined) {
|
|
2461
|
+
futureEnd = cstate.handles.get(futureEndWaitableIdx);
|
|
2462
|
+
} else if (futureEndHandle !== undefined) {
|
|
2463
|
+
if (!table) { throw new Error(`missing/invalid table [${tableIdx}] while getting future end`); }
|
|
2464
|
+
futureEnd = table.get(futureEndHandle);
|
|
2465
|
+
} else {
|
|
2466
|
+
throw new TypeError("must specify either waitable idx or handle to retrieve future");
|
|
2467
|
+
}
|
|
2468
|
+
|
|
2469
|
+
if (!futureEnd) {
|
|
2470
|
+
throw new Error(`missing future end (tableIdx [${tableIdx}], handle [${futureEndHandle}], waitableIdx [${futureEndWaitableIdx}])`);
|
|
2471
|
+
}
|
|
2472
|
+
if (tableIdx && futureEnd.futureTableIdx() !== tableIdx) {
|
|
2473
|
+
throw new Error(`future end table idx [${futureEnd.futureTableIdx()}] does not match [${tableIdx}]`);
|
|
2474
|
+
}
|
|
2475
|
+
|
|
2476
|
+
return futureEnd;
|
|
2477
|
+
}
|
|
2478
|
+
|
|
2479
|
+
removeFutureEndFromTable(args) {
|
|
2480
|
+
_debugLog('[ComponentAsyncState#removeFutureEndFromTable()] args', args);
|
|
2481
|
+
|
|
2482
|
+
const { tableIdx, futureWaitableIdx } = args;
|
|
2483
|
+
if (tableIdx === undefined) { throw new Error("missing table idx while removing future end"); }
|
|
2484
|
+
if (futureWaitableIdx === undefined) {
|
|
2485
|
+
throw new Error("missing future end waitable idx while removing future end");
|
|
2486
|
+
}
|
|
2487
|
+
|
|
2488
|
+
const { table, componentIdx } = FUTURE_TABLES[tableIdx];
|
|
2489
|
+
if (!table) { throw new Error(`missing/invalid table [${tableIdx}] while removing future end`); }
|
|
2490
|
+
|
|
2491
|
+
const cstate = getOrCreateAsyncState(componentIdx);
|
|
2492
|
+
|
|
2493
|
+
const futureEnd = cstate.handles.get(futureWaitableIdx);
|
|
2494
|
+
if (!futureEnd) {
|
|
2495
|
+
throw new Error(`missing future end (handle [${futureWaitableIdx}], table [${tableIdx}])`);
|
|
2496
|
+
}
|
|
2497
|
+
const handle = futureEnd.handle();
|
|
2498
|
+
|
|
2499
|
+
let removed = cstate.handles.remove(futureWaitableIdx);
|
|
2500
|
+
if (!removed) {
|
|
2501
|
+
throw new Error(`failed to remove futureEnd from handles (waitable idx [${futureWaitableIdx}]), component [${componentIdx}])`);
|
|
2502
|
+
}
|
|
2503
|
+
|
|
2504
|
+
removed = table.remove(handle);
|
|
2505
|
+
if (!removed) {
|
|
2506
|
+
throw new Error(`failed to remove futureEnd from table (handle [${handle}]), table [${tableIdx}], component [${componentIdx}])`);
|
|
2507
|
+
}
|
|
2508
|
+
|
|
2509
|
+
return futureEnd;
|
|
2510
|
+
}
|
|
2511
|
+
|
|
2303
2512
|
}
|
|
2304
2513
|
|
|
2305
2514
|
const isNode = typeof process !== 'undefined' && process.versions && process.versions.node;
|
|
@@ -2320,6 +2529,8 @@ class ComponentError extends Error {
|
|
|
2320
2529
|
}
|
|
2321
2530
|
}
|
|
2322
2531
|
|
|
2532
|
+
const isLE = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;
|
|
2533
|
+
|
|
2323
2534
|
function throwInvalidBool() {
|
|
2324
2535
|
throw new TypeError('invalid variant discriminant for bool');
|
|
2325
2536
|
}
|