diff --git a/boa/src/builtins/object/mod.rs b/boa/src/builtins/object/mod.rs index 173df33f4f..7c53dd4c1d 100644 --- a/boa/src/builtins/object/mod.rs +++ b/boa/src/builtins/object/mod.rs @@ -131,7 +131,10 @@ impl Object { /// Define a property in an object pub fn define_property(_: &Value, args: &[Value], ctx: &mut Context) -> Result { let obj = args.get(0).expect("Cannot get object"); - let prop = args.get(1).expect("Cannot get object").to_string(ctx)?; + let prop = args + .get(1) + .expect("Cannot get object") + .to_property_key(ctx)?; let desc = Property::from(args.get(2).expect("Cannot get object")); obj.set_property(prop, desc); Ok(Value::undefined()) diff --git a/boa/src/builtins/object/tests.rs b/boa/src/builtins/object/tests.rs index 5c42f85fc9..a13abf1d9b 100644 --- a/boa/src/builtins/object/tests.rs +++ b/boa/src/builtins/object/tests.rs @@ -177,3 +177,17 @@ fn object_to_string() { assert_eq!(forward(&mut ctx, "re.toString()"), "\"[object RegExp]\""); assert_eq!(forward(&mut ctx, "o.toString()"), "\"[object Object]\""); } + +#[test] +fn define_symbol_property() { + let mut ctx = Context::new(); + + let init = r#" + let obj = {}; + let sym = Symbol("key"); + Object.defineProperty(obj, sym, { value: "val" }); + "#; + eprintln!("{}", forward(&mut ctx, init)); + + assert_eq!(forward(&mut ctx, "obj[sym]"), "\"val\""); +}