Skip to content

Commit

Permalink
don't use undefined if String ctor is invoked with no arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
y21 committed Mar 18, 2024
1 parent 9b2f9ba commit 5b84a12
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/dash_vm/src/js_std/string.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use dash_middle::interner::sym;

use crate::localscope::LocalScope;
use crate::throw;
use crate::value::array::{Array, ArrayIterator};
Expand All @@ -9,7 +11,10 @@ use crate::value::{Value, ValueContext};
use std::fmt::Write;

pub fn constructor(cx: CallContext) -> Result<Value, Value> {
let value = cx.args.first().unwrap_or_undefined().to_js_string(cx.scope)?;
let value = match cx.args.first() {
Some(arg) => arg.to_js_string(cx.scope)?,
None => sym::empty.into(),
};
if cx.is_constructor_call {
let boxed = BoxedString::new(cx.scope, value);
Ok(Value::Object(cx.scope.register(boxed)))
Expand Down

0 comments on commit 5b84a12

Please sign in to comment.