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