1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-09 15:48:16 -05:00

fix(core): don't panic on invalid arguments for Deno.core.print (#9834)

This commit is contained in:
Andrew Mitchell 2021-03-21 08:52:28 -04:00 committed by GitHub
parent dd12a668e7
commit c00872c0c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -315,16 +315,19 @@ fn print(
_rv: v8::ReturnValue, _rv: v8::ReturnValue,
) { ) {
let arg_len = args.length(); let arg_len = args.length();
assert!((0..=2).contains(&arg_len)); if !(0..=2).contains(&arg_len) {
return throw_type_error(scope, "Expected a maximum of 2 arguments.");
}
let obj = args.get(0); let obj = args.get(0);
let is_err_arg = args.get(1); let is_err_arg = args.get(1);
let mut is_err = false; let mut is_err = false;
if arg_len == 2 { if arg_len == 2 {
let int_val = is_err_arg let int_val = match is_err_arg.integer_value(scope) {
.integer_value(scope) Some(v) => v,
.expect("Unable to convert to integer"); None => return throw_type_error(scope, "Invalid arugment. Argument 2 should indicate wheter or not to print to stderr."),
};
is_err = int_val != 0; is_err = int_val != 0;
}; };
let tc_scope = &mut v8::TryCatch::new(scope); let tc_scope = &mut v8::TryCatch::new(scope);