@@ -471,11 +471,17 @@ BindingData::BindingData(Environment* env, v8::Local<v8::Object> object)
471
471
472
472
v8::CFunction BindingData::fast_number_ (v8::CFunction::Make(FastNumber));
473
473
v8::CFunction BindingData::fast_bigint_ (v8::CFunction::Make(FastBigInt));
474
+ v8::CFunction BindingData::fast_get_constrained_memory_ =
475
+ v8::CFunction::Make (FastGetConstrainedMemory);
474
476
475
477
void BindingData::AddMethods () {
476
478
Local<Context> ctx = env ()->context ();
477
479
SetFastMethod (ctx, object (), " hrtime" , SlowNumber, &fast_number_);
478
480
SetFastMethod (ctx, object (), " hrtimeBigInt" , SlowBigInt, &fast_bigint_);
481
+ SetFastMethod (ctx, object (),
482
+ " constrainedMemory" ,
483
+ SlowGetConstrainedMemory,
484
+ &fast_get_constrained_memory_);
479
485
}
480
486
481
487
void BindingData::RegisterExternalReferences (
@@ -486,6 +492,9 @@ void BindingData::RegisterExternalReferences(
486
492
registry->Register (FastBigInt);
487
493
registry->Register (fast_number_.GetTypeInfo ());
488
494
registry->Register (fast_bigint_.GetTypeInfo ());
495
+ registry->Register (SlowGetConstrainedMemory);
496
+ registry->Register (FastGetConstrainedMemory);
497
+ registry->Register (fast_get_constrained_memory_.GetTypeInfo ());
489
498
}
490
499
491
500
BindingData* BindingData::FromV8Value (Local<Value> value) {
@@ -533,6 +542,23 @@ void BindingData::SlowNumber(const v8::FunctionCallbackInfo<v8::Value>& args) {
533
542
NumberImpl (FromJSObject<BindingData>(args.Holder ()));
534
543
}
535
544
545
+ void BindingData::ConstrainedMemoryImpl (BindingData* receiver) {
546
+ // Make sure we don't accidentally access buffers wiped for snapshot.
547
+ CHECK (!receiver->array_buffer_ .IsEmpty ());
548
+ uint64_t t = uv_get_constrained_memory ();
549
+ uint64_t * fields = static_cast <uint64_t *>(receiver->backing_store_ ->Data ());
550
+ fields[0 ] = t;
551
+ }
552
+
553
+ void BindingData::SlowGetConstrainedMemory (
554
+ const FunctionCallbackInfo<Value>& args) {
555
+ ConstrainedMemoryImpl (FromJSObject<BindingData>(args.Holder ()));
556
+ }
557
+
558
+ void BindingData::FastGetConstrainedMemory (v8::Local<v8::Value> receiver) {
559
+ ConstrainedMemoryImpl (FromV8Value (receiver));
560
+ }
561
+
536
562
bool BindingData::PrepareForSerialization (Local<Context> context,
537
563
v8::SnapshotCreator* creator) {
538
564
// It's not worth keeping.
0 commit comments