Browse Source

String wasn't defaulting to empty when called as String() with no argument (#407)

pull/396/head
Jason Williams 5 years ago committed by GitHub
parent
commit
05f220d38d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      boa/src/builtins/string/mod.rs

6
boa/src/builtins/string/mod.rs

@ -32,13 +32,11 @@ use std::{
/// [[Construct]] - Creates a new instance `this`
///
/// [[Call]] - Returns a new native `string`
/// <https://tc39.es/ecma262/#sec-string-constructor-string-value>
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));

Loading…
Cancel
Save