Skip to content

Commit f9340a5

Browse files
committed
add BigInt::from_i128, and add skeleton methods for Seb
1 parent bb8f5d8 commit f9340a5

File tree

3 files changed

+83
-3
lines changed

3 files changed

+83
-3
lines changed

nova_vm/src/builtin_strings

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ __proto__
2828
#[cfg(feature = "math")]abs
2929
#[cfg(feature = "math")]acos
3030
#[cfg(feature = "math")]acosh
31-
#[cfg(any(feature = "atomics", feature = "set", feature = "weak-refs"))]add
31+
#[cfg(any(feature = "atomics", feature = "set", feature = "weak-refs", feature = "temporal"))]add
3232
AggregateError
3333
all
3434
allSettled
@@ -389,6 +389,7 @@ setPrototypeOf
389389
shift
390390
#[cfg(feature = "math")]sign
391391
#[cfg(feature = "math")]sin
392+
#[cfg(feature = "temporal")]since
392393
#[cfg(feature = "math")]sinh
393394
size
394395
slice
@@ -414,6 +415,7 @@ String Iterator
414415
#[cfg(feature = "array-buffer")]subarray
415416
#[cfg(feature = "annex-b-string")]substr
416417
substring
418+
#[cfg(feature = "temporal")]subtract
417419
#[cfg(feature = "proposal-math-sum")]sumPrecise
418420
#[cfg(feature = "annex-b-string")]sup
419421
symbol
@@ -485,6 +487,7 @@ undefined
485487
unregister
486488
unscopables
487489
unshift
490+
#[cfg(feature = "temporal")]until
488491
URIError
489492
#[cfg(feature = "date")]UTC
490493
value

nova_vm/src/ecmascript/builtins/temporal/instant.rs

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,34 @@ impl Builtin for TemporalInstantPrototypeGetEpochNanoSeconds {
361361
Behaviour::Regular(TemporalInstantPrototype::get_epoch_nanoseconds);
362362
}
363363

364+
struct TemporalInstantPrototypeAdd;
365+
impl Builtin for TemporalInstantPrototypeAdd {
366+
const NAME: String<'static> = BUILTIN_STRING_MEMORY.add;
367+
const LENGTH: u8 = 1;
368+
const BEHAVIOUR: Behaviour = Behaviour::Regular(TemporalInstantPrototype::add);
369+
}
370+
371+
struct TemporalInstantPrototypeSubtract;
372+
impl Builtin for TemporalInstantPrototypeSubtract {
373+
const NAME: String<'static> = BUILTIN_STRING_MEMORY.subtract;
374+
const LENGTH: u8 = 1;
375+
const BEHAVIOUR: Behaviour = Behaviour::Regular(TemporalInstantPrototype::subtract);
376+
}
377+
378+
struct TemporalInstantPrototypeUntil;
379+
impl Builtin for TemporalInstantPrototypeUntil {
380+
const NAME: String<'static> = BUILTIN_STRING_MEMORY.until;
381+
const LENGTH: u8 = 1;
382+
const BEHAVIOUR: Behaviour = Behaviour::Regular(TemporalInstantPrototype::until);
383+
}
384+
385+
struct TemporalInstantPrototypeSince;
386+
impl Builtin for TemporalInstantPrototypeSince {
387+
const NAME: String<'static> = BUILTIN_STRING_MEMORY.since;
388+
const LENGTH: u8 = 1;
389+
const BEHAVIOUR: Behaviour = Behaviour::Regular(TemporalInstantPrototype::since);
390+
}
391+
364392
impl TemporalInstantPrototype {
365393
pub fn create_intrinsic(agent: &mut Agent, realm: Realm<'static>, _: NoGcScope) {
366394
let intrinsics = agent.get_realm_record_by_id(realm).intrinsics();
@@ -369,11 +397,15 @@ impl TemporalInstantPrototype {
369397
let instant_constructor = intrinsics.temporal_instant();
370398

371399
OrdinaryObjectBuilder::new_intrinsic_object(agent, realm, this)
372-
.with_property_capacity(3)
400+
.with_property_capacity(7)
373401
.with_prototype(object_prototype)
374402
.with_constructor_property(instant_constructor)
375403
.with_builtin_function_property::<TemporalInstantPrototypeGetEpochMilliseconds>()
376404
.with_builtin_function_property::<TemporalInstantPrototypeGetEpochNanoSeconds>()
405+
.with_builtin_function_property::<TemporalInstantPrototypeAdd>()
406+
.with_builtin_function_property::<TemporalInstantPrototypeSubtract>()
407+
.with_builtin_function_property::<TemporalInstantPrototypeUntil>()
408+
.with_builtin_function_property::<TemporalInstantPrototypeSince>()
377409
.build();
378410
}
379411

@@ -410,7 +442,43 @@ impl TemporalInstantPrototype {
410442
.bind(gc.nogc());
411443
// 3. Return instant.[[EpochNanoseconds]].
412444
let value = instant.inner_instant(agent).epoch_nanoseconds().as_i128();
413-
todo!()
445+
Ok(BigInt::from_i128(agent, value).into())
446+
}
447+
448+
fn add<'gc>(
449+
_agent: &mut Agent,
450+
_this_value: Value,
451+
_args: ArgumentsList,
452+
mut _gc: GcScope<'gc, '_>,
453+
) -> JsResult<'gc, Value<'gc>> {
454+
unimplemented!()
455+
}
456+
457+
fn subtract<'gc>(
458+
_agent: &mut Agent,
459+
_this_value: Value,
460+
_args: ArgumentsList,
461+
mut _gc: GcScope<'gc, '_>,
462+
) -> JsResult<'gc, Value<'gc>> {
463+
unimplemented!()
464+
}
465+
466+
fn until<'gc>(
467+
_agent: &mut Agent,
468+
_this_value: Value,
469+
_args: ArgumentsList,
470+
mut _gc: GcScope<'gc, '_>,
471+
) -> JsResult<'gc, Value<'gc>> {
472+
unimplemented!()
473+
}
474+
475+
fn since<'gc>(
476+
_agent: &mut Agent,
477+
_this_value: Value,
478+
_args: ArgumentsList,
479+
mut _gc: GcScope<'gc, '_>,
480+
) -> JsResult<'gc, Value<'gc>> {
481+
unimplemented!()
414482
}
415483
}
416484

nova_vm/src/ecmascript/types/language/bigint.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,15 @@ impl<'a> BigInt<'a> {
207207
}
208208
}
209209

210+
#[inline]
211+
pub fn from_i128(agent: &mut Agent, value: i128) -> Self {
212+
if let Ok(result) = SmallBigInt::try_from(value) {
213+
Self::SmallBigInt(result)
214+
} else {
215+
agent.heap.create(BigIntHeapData { data: value.into() })
216+
}
217+
}
218+
210219
#[inline]
211220
pub(crate) fn from_num_bigint(agent: &mut Agent, value: num_bigint::BigInt) -> Self {
212221
if let Ok(result) = SmallBigInt::try_from(&value) {

0 commit comments

Comments
 (0)