}
if (!name) {
+ JSValue v;
if (!strcmp(s->fallback, "none")) {
JS_FreeCString(ctx, code);
return JS_UNDEFINED;
}
/* fallback "code": return the code itself */
- if (!strcmp(s->type, "currency")) {
- JS_FreeCString(ctx, code);
- return JS_NewString(ctx, code);
- }
+ v = JS_NewString(ctx, code);
JS_FreeCString(ctx, code);
- return JS_NewString(ctx, code);
+ return v;
}
JS_FreeCString(ctx, code);
JSValue iter = JS_UNDEFINED;
JSValue next_method = JS_UNDEFINED;
JSValue r = JS_UNDEFINED;
- JSValue v = JS_UNDEFINED;
+ JSValue v;
BOOL done;
int64_t k;
for (k = 0;; k++) {
v = JS_IteratorNext(ctx, iter, next_method, &done);
if (JS_IsException(v))
- goto exception_close;
- if (done)
+ goto exception;
+ if (done) {
+ JS_FreeValue(ctx, v);
break;
+ }
if (!JS_IsString(v)) {
JS_FreeValue(ctx, v);
JS_ThrowTypeError(ctx, "iterable yielded non-string value");
exception:
JS_FreeValue(ctx, r);
r = JS_EXCEPTION;
- JS_FreeValue(ctx, v);
goto done;
}
if (!s)
return JS_EXCEPTION;
- arr = string_list_from_iterable(ctx, argc > 0 ? argv[0] : JS_UNDEFINED);
+ arr = string_list_from_iterable(ctx, argv[0]);
if (JS_IsException(arr))
return JS_EXCEPTION;
if (!s)
return JS_EXCEPTION;
- arr = string_list_from_iterable(ctx, argc > 0 ? argv[0] : JS_UNDEFINED);
+ arr = string_list_from_iterable(ctx, argv[0]);
if (JS_IsException(arr))
return JS_EXCEPTION;
/* For scale < 0, drop last k zeros (result is multiple of 10^k) */
if (k > 0) {
scaled_len -= k;
+ scaled_len = max_int(scaled_len, 0); /* XXX: fail safe */
scaled_digits[scaled_len] = '\0';
}
/* Drop the last 'drop' zeros */
scaled_len -= drop;
+ scaled_len = max_int(scaled_len, 0); /* XXX: fail safe */
scaled_digits[scaled_len] = '\0';
js_free(ctx, mv->digits);
remaining -= first;
while (remaining > 0) {
int g = remaining > gs2 ? gs2 : remaining;
+ if (num_groups >= countof(groups))
+ break; /* XXX: return an error or dynamic groups alloc ? */
groups[num_groups++] = g;
remaining -= g;
}
remaining -= first;
while (remaining > 0) {
int g = remaining > gs2 ? gs2 : remaining;
+ if (num_groups >= countof(groups))
+ break; /* XXX: return an error or dynamic groups alloc ? */
groups[num_groups++] = g;
remaining -= g;
}
/* Returns 1 if c is "word-like" (letter, digit, non-ASCII, or some punct) */
static int is_word_char(int c)
{
- return isalnum(c) || c > 127 ||
+ return c > 127 || isalnum(c) ||
c == '.' || c == '-' || c == '+' ||
c == '%' || c == '$' || c == '_' || c == '\'';
}