44
55use crate :: {
66 ecmascript:: {
7- Agent , ArgumentsList , BUILTIN_STRING_MEMORY , Behaviour , Builtin , BuiltinGetter , JsResult ,
8- PropertyKey , Realm , String , Value ,
7+ Agent , ArgumentsList , BUILTIN_STRING_MEMORY , Behaviour , Builtin , BuiltinGetter ,
8+ ExceptionType , JsResult , PropertyKey , Realm , String , Value ,
99 builders:: OrdinaryObjectBuilder ,
1010 builtins:: temporal:: plain_time:: {
1111 add_duration_to_time, require_internal_slot_temporal_plain_time,
@@ -90,6 +90,13 @@ impl Builtin for TemporalPlainTimePrototypeSubtract {
9090 const BEHAVIOUR : Behaviour = Behaviour :: Regular ( TemporalPlainTimePrototype :: subtract) ;
9191}
9292
93+ struct TemporalPlainTimePrototypeValueOf ;
94+ impl Builtin for TemporalPlainTimePrototypeValueOf {
95+ const NAME : String < ' static > = BUILTIN_STRING_MEMORY . valueOf ;
96+ const LENGTH : u8 = 0 ;
97+ const BEHAVIOUR : Behaviour = Behaviour :: Regular ( TemporalPlainTimePrototype :: value_of) ;
98+ }
99+
93100impl TemporalPlainTimePrototype {
94101 /// ### [4.3.4 get Temporal.PlainTime.prototype.minute](https://tc39.es/proposal-temporal/#sec-get-temporal.plaintime.prototype.minute)
95102 pub ( crate ) fn get_minute < ' gc > (
@@ -228,14 +235,29 @@ impl TemporalPlainTimePrototype {
228235 . map ( Value :: from)
229236 }
230237
238+ /// ### [4.3.19 Temporal.PlainTime.prototype.valueOf](https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.valueof)
239+ fn value_of < ' gc > (
240+ agent : & mut Agent ,
241+ _: Value ,
242+ _: ArgumentsList ,
243+ gc : GcScope < ' gc , ' _ > ,
244+ ) -> JsResult < ' gc , Value < ' gc > > {
245+ // 1. Throw a TypeError exception.
246+ Err ( agent. throw_exception_with_static_message (
247+ ExceptionType :: TypeError ,
248+ "can't convert PlainTime to primitive type. Use PlainTime.prototype.equals() or PlainTime.compare() instead." ,
249+ gc. into_nogc ( ) ,
250+ ) )
251+ }
252+
231253 pub ( crate ) fn create_intrinsic ( agent : & mut Agent , realm : Realm < ' static > , _: NoGcScope ) {
232254 let intrinsics = agent. get_realm_record_by_id ( realm) . intrinsics ( ) ;
233255 let this = intrinsics. temporal_plain_time_prototype ( ) ;
234256 let object_prototype = intrinsics. object_prototype ( ) ;
235257 let plain_time_constructor = intrinsics. temporal_plain_time ( ) ;
236258
237259 OrdinaryObjectBuilder :: new_intrinsic_object ( agent, realm, this)
238- . with_property_capacity ( 10 )
260+ . with_property_capacity ( 11 )
239261 . with_prototype ( object_prototype)
240262 . with_constructor_property ( plain_time_constructor)
241263 . with_builtin_function_getter_property :: < TemporalPlainTimePrototypeGetHour > ( )
@@ -246,6 +268,7 @@ impl TemporalPlainTimePrototype {
246268 . with_builtin_function_getter_property :: < TemporalPlainTimePrototypeGetMillisecond > ( )
247269 . with_builtin_function_property :: < TemporalPlainTimePrototypeAdd > ( )
248270 . with_builtin_function_property :: < TemporalPlainTimePrototypeSubtract > ( )
271+ . with_builtin_function_property :: < TemporalPlainTimePrototypeValueOf > ( )
249272 . with_property ( |builder| {
250273 builder
251274 . with_key ( WellKnownSymbols :: ToStringTag . into ( ) )
0 commit comments