diff --git a/nova_vm/src/ecmascript/builtins/temporal/plain_time/plain_time_prototype.rs b/nova_vm/src/ecmascript/builtins/temporal/plain_time/plain_time_prototype.rs index 5a70d75be..0369e1c6a 100644 --- a/nova_vm/src/ecmascript/builtins/temporal/plain_time/plain_time_prototype.rs +++ b/nova_vm/src/ecmascript/builtins/temporal/plain_time/plain_time_prototype.rs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +use temporal_rs::options::ToStringRoundingOptions; + use crate::{ ecmascript::{ Agent, ArgumentsList, BUILTIN_STRING_MEMORY, Behaviour, Builtin, BuiltinGetter, @@ -10,6 +12,7 @@ use crate::{ builtins::temporal::plain_time::{ add_duration_to_time, require_internal_slot_temporal_plain_time, }, + temporal_err_to_js_err, }, engine::{Bindable, GcScope, NoGcScope}, heap::WellKnownSymbols, @@ -90,6 +93,13 @@ impl Builtin for TemporalPlainTimePrototypeSubtract { const BEHAVIOUR: Behaviour = Behaviour::Regular(TemporalPlainTimePrototype::subtract); } +struct TemporalPlainTimePrototypeToJSON; +impl Builtin for TemporalPlainTimePrototypeToJSON { + const NAME: String<'static> = BUILTIN_STRING_MEMORY.toJSON; + const LENGTH: u8 = 0; + const BEHAVIOUR: Behaviour = Behaviour::Regular(TemporalPlainTimePrototype::to_json); +} + struct TemporalPlainTimePrototypeValueOf; impl Builtin for TemporalPlainTimePrototypeValueOf { const NAME: String<'static> = BUILTIN_STRING_MEMORY.valueOf; @@ -235,6 +245,27 @@ impl TemporalPlainTimePrototype { .map(Value::from) } + /// ### [4.3.18 Temporal.PlainTime.prototype.toJSON ( )](https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.tojson) + fn to_json<'gc>( + agent: &mut Agent, + this_value: Value, + _args: ArgumentsList, + gc: GcScope<'gc, '_>, + ) -> JsResult<'gc, Value<'gc>> { + // 1. Let plainTime be the this value. + let value = this_value.bind(gc.nogc()); + // 2. Perform ? RequireInternalSlot(plainTime, [[InitializedTemporalTime]]). + let instant = require_internal_slot_temporal_plain_time(agent, value.unbind(), gc.nogc()) + .unbind()? + .bind(gc.nogc()); + // 3. Return TimeRecordToString(plainTime.[[Time]], auto). + let options: ToStringRoundingOptions = ToStringRoundingOptions::default(); + match instant.inner_plain_time(agent).to_ixdtf_string(options) { + Ok(string) => Ok(Value::from_string(agent, string, gc.into_nogc())), + Err(err) => Err(temporal_err_to_js_err(agent, err, gc.into_nogc())), + } + } + /// ### [4.3.19 Temporal.PlainTime.prototype.valueOf](https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.valueof) fn value_of<'gc>( agent: &mut Agent, @@ -257,7 +288,7 @@ impl TemporalPlainTimePrototype { let plain_time_constructor = intrinsics.temporal_plain_time(); OrdinaryObjectBuilder::new_intrinsic_object(agent, realm, this) - .with_property_capacity(11) + .with_property_capacity(12) .with_prototype(object_prototype) .with_constructor_property(plain_time_constructor) .with_builtin_function_getter_property::() @@ -268,6 +299,7 @@ impl TemporalPlainTimePrototype { .with_builtin_function_getter_property::() .with_builtin_function_property::() .with_builtin_function_property::() + .with_builtin_function_property::() .with_builtin_function_property::() .with_property(|builder| { builder diff --git a/tests/expectations.json b/tests/expectations.json index be12ae643..f868501d5 100644 --- a/tests/expectations.json +++ b/tests/expectations.json @@ -4077,12 +4077,6 @@ "built-ins/Temporal/PlainTime/prototype/subtract/precision-exact-mathematical-values-2.js": "FAIL", "built-ins/Temporal/PlainTime/prototype/subtract/subclassing-ignored.js": "FAIL", "built-ins/Temporal/PlainTime/prototype/toJSON/basic.js": "FAIL", - "built-ins/Temporal/PlainTime/prototype/toJSON/branding.js": "FAIL", - "built-ins/Temporal/PlainTime/prototype/toJSON/builtin.js": "FAIL", - "built-ins/Temporal/PlainTime/prototype/toJSON/length.js": "FAIL", - "built-ins/Temporal/PlainTime/prototype/toJSON/name.js": "FAIL", - "built-ins/Temporal/PlainTime/prototype/toJSON/not-a-constructor.js": "FAIL", - "built-ins/Temporal/PlainTime/prototype/toJSON/prop-desc.js": "FAIL", "built-ins/Temporal/PlainTime/prototype/toLocaleString/branding.js": "FAIL", "built-ins/Temporal/PlainTime/prototype/toLocaleString/prop-desc.js": "FAIL", "built-ins/Temporal/PlainTime/prototype/toLocaleString/return-string.js": "FAIL", diff --git a/tests/metrics.json b/tests/metrics.json index 9a8547133..c7c123b0b 100644 --- a/tests/metrics.json +++ b/tests/metrics.json @@ -1,8 +1,8 @@ { "results": { "crash": 52, - "fail": 6894, - "pass": 40406, + "fail": 6888, + "pass": 40412, "skip": 3326, "timeout": 18, "unresolved": 37