Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Could start with let gc = gc.into_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,
Expand All @@ -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::<TemporalPlainTimePrototypeGetHour>()
Expand All @@ -268,6 +299,7 @@ impl TemporalPlainTimePrototype {
.with_builtin_function_getter_property::<TemporalPlainTimePrototypeGetMillisecond>()
.with_builtin_function_property::<TemporalPlainTimePrototypeAdd>()
.with_builtin_function_property::<TemporalPlainTimePrototypeSubtract>()
.with_builtin_function_property::<TemporalPlainTimePrototypeToJSON>()
.with_builtin_function_property::<TemporalPlainTimePrototypeValueOf>()
.with_property(|builder| {
builder
Expand Down
6 changes: 0 additions & 6 deletions tests/expectations.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions tests/metrics.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"results": {
"crash": 52,
"fail": 6894,
"pass": 40406,
"fail": 6888,
"pass": 40412,
"skip": 3326,
"timeout": 18,
"unresolved": 37
Expand Down
Loading