return JS_EXCEPTION;
}
+/* never use except where 'obj' is an Array or a string */
static __exception int js_get_length32(JSContext *ctx, uint32_t *pres,
JSValueConst obj)
{
typedef struct JSArrayIteratorData {
JSValue obj;
JSIteratorKindEnum kind;
- uint32_t idx;
+ int64_t idx;
} JSArrayIteratorData;
static void js_array_iterator_finalizer(JSRuntime *rt, JSValue val)
BOOL *pdone, int magic)
{
JSArrayIteratorData *it;
- uint32_t len, idx;
+ int64_t len, idx;
JSValue val, obj;
JSObject *p;
}
len = p->u.array.count;
} else {
- if (js_get_length32(ctx, &len, it->obj)) {
+ if (js_get_length64(ctx, &len, it->obj)) {
fail1:
*pdone = FALSE;
return JS_EXCEPTION;
it->idx = idx + 1;
*pdone = FALSE;
if (it->kind == JS_ITERATOR_KIND_KEY) {
- return JS_NewUint32(ctx, idx);
+ return JS_NewInt64(ctx, idx);
} else {
- val = JS_GetPropertyUint32(ctx, it->obj, idx);
+ val = JS_GetPropertyInt64(ctx, it->obj, idx);
if (JS_IsException(val))
return JS_EXCEPTION;
if (it->kind == JS_ITERATOR_KIND_VALUE) {
} else {
JSValueConst args[2];
JSValue num;
- num = JS_NewUint32(ctx, idx);
+ num = JS_NewInt64(ctx, idx);
args[0] = num;
args[1] = val;
obj = js_create_array(ctx, 2, args);
return result;
}
-/* if captures != NULL, captures_val and matched are ignored. Otherwise,
- captures_len is ignored */
+/* if captures != NULL, captures_val and matched are
+ ignored. Otherwise, captures_len is ignored. 'matched' is
+ JS_UNDEFINED or a string. 'captures_val' is JS_UNDEFINED or an
+ array. */
static int js_string_GetSubstitution(JSContext *ctx,
StringBuffer *b,
JSValueConst matched,
} else {
captures_len = 0;
if (!JS_IsUndefined(captures_val)) {
+ /* captures_val is always an Array if not undefined */
if (js_get_length32(ctx, &captures_len, captures_val))
goto exception;
}
+ /* 'matched' is a string */
if (js_get_length32(ctx, &matched_len, matched))
goto exception;
}
JSString *p, *sp;
StringBuffer b_s, *b = &b_s;
ValueBuffer v_b, *results = &v_b;
- int nextSourcePosition, n, j, functionalReplace, is_global, fullUnicode;
- uint32_t nCaptures;
- int64_t position;
+ int nextSourcePosition, j, functionalReplace, is_global, fullUnicode;
+ int64_t nCaptures, n, position;
if (!JS_IsObject(rx))
return JS_ThrowTypeErrorNotAnObject(ctx);
for(j = 0; j < results->len; j++) {
JSValueConst result;
result = results->arr[j];
- if (js_get_length32(ctx, &nCaptures, result) < 0)
+ if (js_get_length64(ctx, &nCaptures, result) < 0)
goto exception;
JS_FreeValue(ctx, matched);
matched = JS_ToStringFree(ctx, JS_GetPropertyInt64(ctx, result, 0));
{
JSProxyData *s;
JSValue method, prop_array, val;
+ int64_t len64;
uint32_t len, i, len2;
JSPropertyEnum *tab, *tab2;
JSAtom atom;
len = 0;
tab2 = NULL;
len2 = 0;
- if (js_get_length32(ctx, &len, prop_array))
+ if (js_get_length64(ctx, &len64, prop_array))
goto fail;
+ if (len64 > INT32_MAX) {
+ JS_ThrowOutOfMemory(ctx);
+ goto fail;
+ }
+ len = len64;
if (len > 0) {
tab = js_mallocz(ctx, sizeof(tab[0]) * len);
if (!tab)