mirror of
https://github.com/denoland/deno.git
synced 2025-01-09 23:58:23 -05:00
fix(core): don't panic on invalid arguments for Deno.core.print (#9834)
This commit is contained in:
parent
dd12a668e7
commit
c00872c0c0
1 changed files with 7 additions and 4 deletions
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue