goto fail;
}
if (fd->has_parameter_expressions) {
+ if (js_parse_check_duplicate_parameter(s, name))
+ goto fail;
if (define_var(s, fd, name, JS_VAR_DEF_LET) < 0)
goto fail;
}
if (js_get_length32(ctx, &len, array_arg))
return NULL;
if (len > JS_MAX_LOCAL_VARS) {
- JS_ThrowInternalError(ctx, "too many arguments");
+ // XXX: check for stack overflow?
+ JS_ThrowRangeError(ctx, "too many arguments in function call (only %d allowed)",
+ JS_MAX_LOCAL_VARS);
return NULL;
}
/* avoid allocating 0 bytes */
idx = len + idx;
if (idx < 0 || idx >= len) {
- JS_ThrowRangeError(ctx, "out of bound");
+ JS_ThrowRangeError(ctx, "invalid array index: %" PRId64, idx);
goto exception;
}
ret = js_is_regexp(ctx, argv[0]);
if (ret) {
if (ret > 0)
- JS_ThrowTypeError(ctx, "regex not supported");
+ JS_ThrowTypeError(ctx, "regexp not supported");
goto fail;
}
v = JS_ToString(ctx, argv[0]);
}
}
if (n > JS_STRING_LEN_MAX) {
- JS_ThrowInternalError(ctx, "string too long");
+ JS_ThrowRangeError(ctx, "invalid string length");
goto fail2;
}
if (string_buffer_init(ctx, b, n))
len = p->len;
if (len == 0 || n == 1)
return str;
+ // XXX: potential arithmetic overflow
if (val * len > JS_STRING_LEN_MAX) {
- JS_ThrowInternalError(ctx, "string too long");
+ JS_ThrowRangeError(ctx, "invalid string length");
goto fail;
}
if (string_buffer_init2(ctx, b, n * len, p->is_wide_char))
JS_NewGlobalCConstructor2(ctx, obj1,
"Error", ctx->class_proto[JS_CLASS_ERROR]);
+ /* Used to squelch a -Wcast-function-type warning. */
+ JSCFunctionType ft = { .generic_magic = js_error_constructor };
for(i = 0; i < JS_NATIVE_ERROR_COUNT; i++) {
JSValue func_obj;
int n_args;
n_args = 1 + (i == JS_AGGREGATE_ERROR);
- func_obj = JS_NewCFunction3(ctx, (JSCFunction *)js_error_constructor,
+ func_obj = JS_NewCFunction3(ctx, ft.generic,
native_error_name[i], n_args,
JS_CFUNC_constructor_or_func_magic, i, obj1);
JS_NewGlobalCConstructor2(ctx, func_obj, native_error_name[i],
if (idx < 0)
idx = len + idx;
if (idx < 0 || idx >= len)
- return JS_ThrowRangeError(ctx, "out of bound");
+ return JS_ThrowRangeError(ctx, "invalid array index");
val = JS_ToPrimitive(ctx, argv[1], HINT_NUMBER);
if (JS_IsException(val))
countof(js_typed_array_base_funcs));
JS_SetConstructor(ctx, typed_array_base_func, typed_array_base_proto);
+ /* Used to squelch a -Wcast-function-type warning. */
+ JSCFunctionType ft = { .generic_magic = js_typed_array_constructor };
for(i = JS_CLASS_UINT8C_ARRAY; i < JS_CLASS_UINT8C_ARRAY + JS_TYPED_ARRAY_COUNT; i++) {
JSValue func_obj;
char buf[ATOM_GET_STR_BUF_SIZE];
0);
name = JS_AtomGetStr(ctx, buf, sizeof(buf),
JS_ATOM_Uint8ClampedArray + i - JS_CLASS_UINT8C_ARRAY);
- func_obj = JS_NewCFunction3(ctx, (JSCFunction *)js_typed_array_constructor,
+ func_obj = JS_NewCFunction3(ctx, ft.generic,
name, 3, JS_CFUNC_constructor_magic, i,
typed_array_base_func);
JS_NewGlobalCConstructor2(ctx, func_obj, name, ctx->class_proto[i]);