From 5a8f191fdd5ec4389ef3af9d8ba3b4779528fecf Mon Sep 17 00:00:00 2001 From: Haled Odat Date: Sun, 23 Apr 2023 08:38:13 +0200 Subject: [PATCH] Fix `Date.prototype[Symbol.primitive]` incorrect attributes --- boa_engine/src/builtins/date/mod.rs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/boa_engine/src/builtins/date/mod.rs b/boa_engine/src/builtins/date/mod.rs index cad6ac3dd7d..c083a0e1c99 100644 --- a/boa_engine/src/builtins/date/mod.rs +++ b/boa_engine/src/builtins/date/mod.rs @@ -102,7 +102,16 @@ impl IntrinsicObject for Date { .length(0) .build(); + let to_primitive = BuiltInBuilder::new(realm) + .callable(Self::to_primitive) + .name("[Symbol.toPrimitive]") + .length(1) + .build(); + BuiltInBuilder::from_standard_constructor::(realm) + .static_method(Self::now, "now", 0) + .static_method(Self::parse, "parse", 1) + .static_method(Self::utc, "UTC", 7) .method(Self::get_date::, "getDate", 0) .method(Self::get_day::, "getDay", 0) .method(Self::get_full_year::, "getFullYear", 0) @@ -122,8 +131,6 @@ impl IntrinsicObject for Date { .method(Self::get_month::, "getUTCMonth", 0) .method(Self::get_seconds::, "getUTCSeconds", 0) .method(Self::get_year, "getYear", 0) - .static_method(Self::now, "now", 0) - .static_method(Self::parse, "parse", 1) .method(Self::set_date::, "setDate", 1) .method(Self::set_full_year::, "setFullYear", 3) .method(Self::set_hours::, "setHours", 4) @@ -148,22 +155,21 @@ impl IntrinsicObject for Date { .method(Self::to_locale_time_string, "toLocaleTimeString", 0) .method(Self::to_string, "toString", 0) .method(Self::to_time_string, "toTimeString", 0) + .method(Self::value_of, "valueOf", 0) .property( "toGMTString", to_utc_string.clone(), - Attribute::WRITABLE | Attribute::CONFIGURABLE, + Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE, ) .property( "toUTCString", to_utc_string, - Attribute::WRITABLE | Attribute::CONFIGURABLE, + Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE, ) - .static_method(Self::utc, "UTC", 7) - .method(Self::value_of, "valueOf", 0) - .method( - Self::to_primitive, - (JsSymbol::to_primitive(), "[Symbol.toPrimitive]"), - 1, + .property( + JsSymbol::to_primitive(), + to_primitive, + Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE, ) .build(); }