Skip to content

Commit f886bfd

Browse files
authored
feat(ecmascript): Temporal.PlainTime.prototype.valueOf (#982)
1 parent 285a37e commit f886bfd

3 files changed

Lines changed: 28 additions & 7 deletions

File tree

nova_vm/src/ecmascript/builtins/temporal/plain_time/plain_time_prototype.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
use 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+
93100
impl 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())

tests/expectations.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4196,8 +4196,6 @@
41964196
"built-ins/Temporal/PlainTime/prototype/until/smallestunit-wrong-type.js": "FAIL",
41974197
"built-ins/Temporal/PlainTime/prototype/until/year-zero.js": "FAIL",
41984198
"built-ins/Temporal/PlainTime/prototype/valueOf/basic.js": "FAIL",
4199-
"built-ins/Temporal/PlainTime/prototype/valueOf/branding.js": "FAIL",
4200-
"built-ins/Temporal/PlainTime/prototype/valueOf/prop-desc.js": "FAIL",
42014199
"built-ins/Temporal/PlainTime/prototype/with/argument-not-object.js": "FAIL",
42024200
"built-ins/Temporal/PlainTime/prototype/with/basic.js": "FAIL",
42034201
"built-ins/Temporal/PlainTime/prototype/with/branding.js": "FAIL",

tests/metrics.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"results": {
33
"crash": 52,
4-
"fail": 6896,
5-
"pass": 40404,
4+
"fail": 6894,
5+
"pass": 40406,
66
"skip": 3326,
77
"timeout": 18,
88
"unresolved": 37

0 commit comments

Comments
 (0)