GT2/GT2-iOS/node_modules/nan/doc/v8_internals.md

7.2 KiB

V8 internals

The hooks to access V8 internals—including GC and statistics—are different across the supported versions of V8, therefore NAN provides its own hooks that call the appropriate V8 methods.

NAN_GC_CALLBACK(callbackname)

Use NAN_GC_CALLBACK to declare your callbacks for Nan::AddGCPrologueCallback() and Nan::AddGCEpilogueCallback(). Your new method receives the arguments v8::GCType type and v8::GCCallbackFlags flags.

static Nan::Persistent<Function> callback;

NAN_GC_CALLBACK(gcPrologueCallback) {
  v8::Local<Value> argv[] = { Nan::New("prologue").ToLocalChecked() };
  Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(callback), 1, argv);
}

NAN_METHOD(Hook) {
  callback.Reset(To<Function>(args[0]).ToLocalChecked());
  Nan::AddGCPrologueCallback(gcPrologueCallback);
  info.GetReturnValue().Set(info.Holder());
}

Nan::AddGCEpilogueCallback()

Signature:

void Nan::AddGCEpilogueCallback(v8::Isolate::GCEpilogueCallback callback, v8::GCType gc_type_filter = v8::kGCTypeAll)

Calls V8's AddGCEpilogueCallback().

Nan::RemoveGCEpilogueCallback()

Signature:

void Nan::RemoveGCEpilogueCallback(v8::Isolate::GCEpilogueCallback callback)

Calls V8's RemoveGCEpilogueCallback().

Nan::AddGCPrologueCallback()

Signature:

void Nan::AddGCPrologueCallback(v8::Isolate::GCPrologueCallback, v8::GCType gc_type_filter callback)

Calls V8's AddGCPrologueCallback().

Nan::RemoveGCPrologueCallback()

Signature:

void Nan::RemoveGCPrologueCallback(v8::Isolate::GCPrologueCallback callback)

Calls V8's RemoveGCEpilogueCallback().

Nan::GetHeapStatistics()

Signature:

void Nan::GetHeapStatistics(v8::HeapStatistics *heap_statistics)

Calls V8's GetHeapStatistics().

Nan::SetCounterFunction()

Signature:

void Nan::SetCounterFunction(v8::CounterLookupCallback cb)

Calls V8's SetCounterFunction().

Nan::SetCreateHistogramFunction()

Signature:

void Nan::SetCreateHistogramFunction(v8::CreateHistogramCallback cb) 

Calls V8's SetCreateHistogramFunction().

Nan::SetAddHistogramSampleFunction()

Signature:

void Nan::SetAddHistogramSampleFunction(v8::AddHistogramSampleCallback cb) 

Calls V8's SetAddHistogramSampleFunction().

Nan::IdleNotification()

Signature:

void Nan::IdleNotification(v8::HeapStatistics *heap_statistics)

Calls V8's IdleNotification() or IdleNotificationDeadline() depending on V8 version.

Nan::LowMemoryNotification()

Signature:

void Nan::LowMemoryNotification() 

Calls V8's LowMemoryNotification().

Nan::ContextDisposedNotification()

Signature:

void Nan::ContextDisposedNotification()

Calls V8's ContextDisposedNotification().

Nan::GetInternalFieldPointer()

Gets a pointer to the internal field with at index from a V8 Object handle.

Signature:

void* Nan::GetInternalFieldPointer(v8::Local<v8::Object> object, int index) 

Calls the Object's GetAlignedPointerFromInternalField() or GetPointerFromInternalField() depending on the version of V8.

Nan::SetInternalFieldPointer()

Sets the value of the internal field at index on a V8 Object handle.

Signature:

void Nan::SetInternalFieldPointer(v8::Local<v8::Object> object, int index, void* value)

Calls the Object's SetAlignedPointerInInternalField() or SetPointerInInternalField() depending on the version of V8.

Nan::AdjustExternalMemory()

Signature:

int Nan::AdjustExternalMemory(int bytesChange)

Calls V8's AdjustAmountOfExternalAllocatedMemory().