teptris 0.3.16 → 0.3.17
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/package.json +1 -1
- package/src/index.d.ts +8 -1
- package/src/index.js +11 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "teptris",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.17",
|
|
4
4
|
"description": "TOML for JavaScript/TypeScript at libteptris speed (WebAssembly, no fallback) - version tracks the engine ({engine}.{iteration}; npm semver is 3-part)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
package/src/index.d.ts
CHANGED
|
@@ -38,7 +38,14 @@ export interface TeptrisApi {
|
|
|
38
38
|
* integer literals beyond that round (9223372036854775807 reads
|
|
39
39
|
* back as 9223372036854776000). dump() never wraps: values past
|
|
40
40
|
* the int64 bounds emit as floats, and bigints outside int64
|
|
41
|
-
* throw.
|
|
41
|
+
* throw.
|
|
42
|
+
*
|
|
43
|
+
* Type floor: JSON numbers carry no int/float distinction, so an
|
|
44
|
+
* integral-valued float (-776571136.0) loads as a plain number and
|
|
45
|
+
* dump() re-emits it as an integer - the .0-ness is unrecoverable
|
|
46
|
+
* (py/ruby/rs keep it; their loads carry typed values). Nesting
|
|
47
|
+
* past the engine's 512 ceiling dumps with a named
|
|
48
|
+
* 'nesting too deep' error. */
|
|
42
49
|
loads(toml: string): TomlTable;
|
|
43
50
|
|
|
44
51
|
/** Serialize a table to canonical TOML via the engine builder.
|
package/src/index.js
CHANGED
|
@@ -327,7 +327,14 @@ export function initApi(mod) {
|
|
|
327
327
|
v !== null && (typeof v !== "object" || Array.isArray(v) === false &&
|
|
328
328
|
(typeof v === "string" || typeof v === "number" ||
|
|
329
329
|
typeof v === "boolean" || typeof v === "bigint"));
|
|
330
|
+
let depth = 0;
|
|
330
331
|
const members = (o, inline) => {
|
|
332
|
+
// name the engine's 512 ceiling: without this the JS stack
|
|
333
|
+
// RangeErrors somewhere host-opaque (ruby's binding names it)
|
|
334
|
+
if (++depth > 512) {
|
|
335
|
+
throw new Error("nesting too deep (> 512)");
|
|
336
|
+
}
|
|
337
|
+
try {
|
|
331
338
|
const keys = Object.keys(o);
|
|
332
339
|
for (let i = 0; i < keys.length; i++) {
|
|
333
340
|
const k = keys[i], v = o[k];
|
|
@@ -359,13 +366,17 @@ export function initApi(mod) {
|
|
|
359
366
|
byte(0x0C);
|
|
360
367
|
}
|
|
361
368
|
}
|
|
369
|
+
} finally { depth--; }
|
|
362
370
|
};
|
|
363
371
|
const arrayVal = (el) => {
|
|
364
372
|
if (isScalar(el)) { scalar(null, el); return; }
|
|
365
373
|
if (Array.isArray(el)) {
|
|
374
|
+
if (++depth > 512) throw new Error("nesting too deep (> 512)");
|
|
375
|
+
try {
|
|
366
376
|
byte(0x09);
|
|
367
377
|
for (const x of el) arrayVal(x);
|
|
368
378
|
byte(0x0C);
|
|
379
|
+
} finally { depth--; }
|
|
369
380
|
return;
|
|
370
381
|
}
|
|
371
382
|
if (el === null || el === undefined) {
|