arc-lang 0.6.13 → 0.6.14
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/dist/interpreter.js +8 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/interpreter.js
CHANGED
|
@@ -236,13 +236,15 @@ function makePrelude(env) {
|
|
|
236
236
|
return null;
|
|
237
237
|
},
|
|
238
238
|
len: (v) => {
|
|
239
|
+
if (v === undefined || v === null)
|
|
240
|
+
throw new Error("len() requires an argument — pass a string, list, or map");
|
|
239
241
|
if (typeof v === "string")
|
|
240
242
|
return [...v].length; // codepoint count, not UTF-16
|
|
241
243
|
if (Array.isArray(v))
|
|
242
244
|
return v.length;
|
|
243
245
|
if (v && typeof v === "object" && "__map" in v)
|
|
244
246
|
return v.entries.size;
|
|
245
|
-
|
|
247
|
+
throw new Error("len() expects a string, list, or map — got " + typeof v);
|
|
246
248
|
},
|
|
247
249
|
map: (list, fn) => {
|
|
248
250
|
if (!Array.isArray(list))
|
|
@@ -2792,10 +2794,14 @@ function evalExpr(expr, env) {
|
|
|
2792
2794
|
if (idx !== Math.floor(idx))
|
|
2793
2795
|
throw new ArcRuntimeError("String index must be an integer");
|
|
2794
2796
|
let i = idx < 0 ? obj.length + idx : idx;
|
|
2795
|
-
|
|
2797
|
+
if (i < 0 || i >= obj.length)
|
|
2798
|
+
throw new ArcRuntimeError(`String index out of bounds: index ${idx} but length is ${obj.length}`);
|
|
2799
|
+
return obj.charAt(i);
|
|
2796
2800
|
}
|
|
2797
2801
|
if (Array.isArray(obj) && typeof idx === "number") {
|
|
2798
2802
|
let i = idx < 0 ? obj.length + idx : idx;
|
|
2803
|
+
if (i < 0 || i >= obj.length)
|
|
2804
|
+
throw new ArcRuntimeError(`Index out of bounds: index ${idx} but length is ${obj.length}`);
|
|
2799
2805
|
return obj[i] ?? null;
|
|
2800
2806
|
}
|
|
2801
2807
|
if (obj && typeof obj === "object" && "__map" in obj) {
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED