Skip to content

Commit 151518c

Browse files
author
Lucas
committed
better error management with DOMException
1 parent c1f807a commit 151518c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

quickjs.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58162,7 +58162,8 @@ static JSValue js_btoa(JSContext *ctx, JSValueConst this_val, int argc, JSValueC
5816258162
if (unlikely(c > 0xFF)) {
5816358163
js_free(ctx, tmp);
5816458164
JS_FreeValue(ctx, val);
58165-
return JS_ThrowTypeError(ctx, "character out of range (>255) at %zu", i);
58165+
return JS_ThrowDOMException(ctx, "InvalidCharacterError",
58166+
"String contains an invalid character");
5816658167
}
5816758168
tmp[i] = (uint8_t)c;
5816858169
}
@@ -58215,7 +58216,8 @@ static JSValue js_atob(JSContext *ctx, JSValueConst this_val, int argc, JSValueC
5821558216
for (size_t i = 0; i < slen; i++) {
5821658217
if (unlikely(p[i] & 0x80)) {
5821758218
JS_FreeValue(ctx, val);
58218-
return JS_ThrowTypeError(ctx, "non-ASCII input");
58219+
return JS_ThrowDOMException(ctx, "InvalidCharacterError",
58220+
"The string to be decoded is not correctly encoded");
5821958221
}
5822058222
}
5822158223
in = p;
@@ -58230,7 +58232,8 @@ static JSValue js_atob(JSContext *ctx, JSValueConst this_val, int argc, JSValueC
5823058232
if (unlikely(src[i] > 0x7F)) {
5823158233
js_free(ctx, tmp);
5823258234
JS_FreeValue(ctx, val);
58233-
return JS_ThrowTypeError(ctx, "non-ASCII input at %zu", i);
58235+
return JS_ThrowDOMException(ctx, "InvalidCharacterError",
58236+
"The string to be decoded is not correctly encoded");
5823458237
}
5823558238
tmp[i] = (uint8_t)src[i];
5823658239
}
@@ -58266,7 +58269,9 @@ static JSValue js_atob(JSContext *ctx, JSValueConst this_val, int argc, JSValueC
5826658269

5826758270
if (unlikely(err)) {
5826858271
js_free(ctx, ostr);
58269-
return JS_ThrowTypeError(ctx, "invalid base64 input");
58272+
return JS_ThrowDOMException(ctx, "InvalidCharacterError",
58273+
"The string to be decoded is not correctly encoded");
58274+
5827058275
}
5827158276

5827258277
ostr->len = out_len;

0 commit comments

Comments
 (0)