Skip to content

Commit

Permalink
fix(core): don't panic on invalid arguments for Deno.core.print (deno…
Browse files Browse the repository at this point in the history
  • Loading branch information
mitch292 committed Mar 21, 2021
1 parent dd12a66 commit c00872c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions core/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,19 @@ fn print(
_rv: v8::ReturnValue,
) {
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 is_err_arg = args.get(1);

let mut is_err = false;
if arg_len == 2 {
let int_val = is_err_arg
.integer_value(scope)
.expect("Unable to convert to integer");
let int_val = match is_err_arg.integer_value(scope) {
Some(v) => v,
None => return throw_type_error(scope, "Invalid arugment. Argument 2 should indicate wheter or not to print to stderr."),
};
is_err = int_val != 0;
};
let tc_scope = &mut v8::TryCatch::new(scope);
Expand Down

0 comments on commit c00872c

Please sign in to comment.