From 05f220d38d2db4bc8330eaeaf221f1a686edc0f8 Mon Sep 17 00:00:00 2001 From: Jason Williams <936006+jasonwilliams@users.noreply.github.com> Date: Wed, 20 May 2020 23:04:45 +0100 Subject: [PATCH] String wasn't defaulting to empty when called as String() with no argument (#407) --- boa/src/builtins/string/mod.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/boa/src/builtins/string/mod.rs b/boa/src/builtins/string/mod.rs index d332f852f6..e3c1a665ca 100644 --- a/boa/src/builtins/string/mod.rs +++ b/boa/src/builtins/string/mod.rs @@ -32,13 +32,11 @@ use std::{ /// [[Construct]] - Creates a new instance `this` /// /// [[Call]] - Returns a new native `string` +/// pub fn make_string(this: &mut Value, args: &[Value], _: &mut Interpreter) -> ResultValue { // This value is used by console.log and other routines to match Obexpecty"failed to parse argument for String method"pe // to its Javascript Identifier (global constructor method name) - let s = args - .get(0) - .expect("failed to get StringData for make_string()") - .clone(); + let s = args.get(0).unwrap_or(&Value::string("")).clone(); let length_str = s.to_string().chars().count(); this.set_field_slice("length", Value::from(length_str as i32));