@@ -68,6 +68,7 @@ A number of concepts are involved in putting together Node.js on top of V8 and
68
68
libuv. This section aims to explain some of them and how they work together.
69
69
70
70
<a id =" isolate " ></a >
71
+
71
72
### ` Isolate `
72
73
73
74
The ` v8::Isolate ` class represents a single JavaScript engine instance, in
@@ -102,6 +103,7 @@ subclasses such as `v8::Number` (which in turn has subclasses like `v8::Int32`),
102
103
of ` v8::Object ` , e.g. ` v8::Uint8Array ` or ` v8::Date ` .
103
104
104
105
<a id =" internal-fields " ></a >
106
+
105
107
### Internal fields
106
108
107
109
V8 provides the ability to store data in so-called “internal fields” inside
@@ -128,12 +130,14 @@ Typical ways of working with internal fields are:
128
130
[ ` Context ` ] [ ] s provide the same feature under the name “embedder data”.
129
131
130
132
<a id =" js-handles " ></a >
133
+
131
134
### JavaScript value handles
132
135
133
136
All JavaScript values are accessed through the V8 API through so-called handles,
134
137
of which there are two types: [ ` Local ` ] [ ] s and [ ` Global ` ] [ ] s.
135
138
136
139
<a id =" local-handles " ></a >
140
+
137
141
#### ` Local ` handles
138
142
139
143
A ` v8::Local ` handle is a temporary pointer to a JavaScript object, where
@@ -210,6 +214,7 @@ any functions that are called from the event loop and want to run or access
210
214
JavaScript code to create ` HandleScope ` s.
211
215
212
216
<a id =" global-handles " ></a >
217
+
213
218
#### ` Global ` handles
214
219
215
220
A ` v8::Global ` handle (sometimes also referred to by the name of its parent
@@ -246,6 +251,7 @@ the `v8::Eternal` itself is destroyed at some point. This type of handle
246
251
is rarely used.
247
252
248
253
<a id="context"></a>
254
+
249
255
### `Context`
250
256
251
257
JavaScript allows multiple global objects and sets of built-in JavaScript
@@ -270,6 +276,7 @@ Typical ways of accessing the current `Context` in the Node.js code are:
270
276
main context.
271
277
272
278
<a id="event-loop"></a>
279
+
273
280
### Event loop
274
281
275
282
The main abstraction for an event loop inside Node.js is the `uv_loop_t` struct.
@@ -284,6 +291,7 @@ could restructure Node.js to provide e.g. the ability to run parts of Node.js
284
291
inside an event loop separate from the active thread’s event loop.
285
292
286
293
<a id="environment"></a>
294
+
287
295
### `Environment`
288
296
289
297
Node.js instances are represented by the `Environment` class.
@@ -315,6 +323,7 @@ Typical ways of accessing the current `Environment` in the Node.js code are:
315
323
up the current [`Context`][] and then uses that.
316
324
317
325
<a id="isolate-data"></a>
326
+
318
327
### `IsolateData`
319
328
320
329
Every Node.js instance ([`Environment`][]) is associated with one `IsolateData`
@@ -346,6 +355,7 @@ The platform can be accessed through `isolate_data->platform()` given an
346
355
and who passed this to Node.js.
347
356
348
357
<a id="binding-functions"></a>
358
+
349
359
### Binding functions
350
360
351
361
C++ functions exposed to JS follow a specific signature. The following example
@@ -463,6 +473,7 @@ Which explains that the unregistered external reference is
463
473
` node::util::GetHiddenValue ` defined in ` node_util.cc ` .
464
474
465
475
<a id =" per-binding-state " ></a >
476
+
466
477
#### Per-binding state
467
478
468
479
Some internal bindings, such as the HTTP parser, maintain internal state that
@@ -519,6 +530,7 @@ of `SnapshotableObject` on how to implement its serialization and
519
530
deserialization.
520
531
521
532
<a id="exception-handling"></a>
533
+
522
534
### Exception handling
523
535
524
536
The V8 engine provides multiple features to work with JavaScript exceptions,
@@ -554,7 +566,7 @@ The most common reasons for this are:
554
566
* Calls to functions like `object->Get(...)` or `object->Set(...)` may fail on
555
567
most objects, if the `Object.prototype` object has been modified from userland
556
568
code that added getters or setters.
557
- * Calls that invoke *any* JavaScript code, including JavaScript code that is
569
+ * Calls that invoke _any_ JavaScript code, including JavaScript code that is
558
570
provided from Node.js internals or V8 internals, will fail when JavaScript
559
571
execution is being terminated. This typically happens inside Workers when
560
572
`worker.terminate()` is called, but it can also affect the main thread when
@@ -661,6 +673,7 @@ and the exception object will not be a meaningful JavaScript value.
661
673
`try_catch.ReThrow()` should not be used in this case .
662
674
663
675
<a id=" libuv-handles-and-requests" ></a>
676
+
664
677
### libuv handles and requests
665
678
666
679
Two central concepts when working with libuv are handles and requests.
@@ -682,6 +695,7 @@ When a Node.js [`Environment`][] is destroyed, it generally needs to clean up
682
695
any resources owned by it, e.g. memory or libuv requests/handles.
683
696
684
697
<a id="cleanup-hooks"></a >
698
+
685
699
#### Cleanup hooks
686
700
687
701
Cleanup hooks are provided that run before the [ ` Environment ` ] [ ]
@@ -690,7 +704,7 @@ is destroyed. They can be added and removed through by using
690
704
` env->RemoveCleanupHook(callback, hint); ` , where callback takes a ` void* hint `
691
705
argument.
692
706
693
- Inside these cleanup hooks, new asynchronous operations * may * be started on the
707
+ Inside these cleanup hooks, new asynchronous operations _ may _ be started on the
694
708
event loop, although ideally that is avoided as much as possible.
695
709
696
710
Every [ ` BaseObject ` ] [ ] has its own cleanup hook that deletes it. For
@@ -742,6 +756,7 @@ This can be useful for debugging memory leaks.
742
756
The [ ` memory_tracker.h ` ] [ ] header file explains how to use this class.
743
757
744
758
<a id="baseobject"></a >
759
+
745
760
### ` BaseObject `
746
761
747
762
A frequently recurring situation is that a JavaScript object and a C++ object
@@ -819,6 +834,7 @@ called. This can be useful when one `BaseObject` fully owns another
819
834
`BaseObject`.
820
835
821
836
<a id="asyncwrap"></a>
837
+
822
838
### `AsyncWrap`
823
839
824
840
`AsyncWrap` is a subclass of `BaseObject` that additionally provides tracking
@@ -837,6 +853,7 @@ See the [`async_hooks` module][] documentation for more information about how
837
853
this information is provided to async tracking tools.
838
854
839
855
<a id="makecallback"></a>
856
+
840
857
#### `MakeCallback`
841
858
842
859
The `AsyncWrap` class has a set of methods called `MakeCallback()`, with the
@@ -876,6 +893,7 @@ void StatWatcher::Callback(uv_fs_poll_t* handle,
876
893
See [ Callback scopes] [ ] for more information.
877
894
878
895
<a id =" handlewrap " ></a >
896
+
879
897
### ` HandleWrap `
880
898
881
899
` HandleWrap ` is a subclass of ` AsyncWrap ` specifically designed to make working
@@ -890,6 +908,7 @@ current Node.js [`Environment`][] is destroyed, e.g. when a Worker thread stops.
890
908
overview over libuv handles managed by Node.js.
891
909
892
910
<a id =" reqwrap " ></a >
911
+
893
912
### ` ReqWrap `
894
913
895
914
` ReqWrap ` is a subclass of ` AsyncWrap ` specifically designed to make working
@@ -902,6 +921,7 @@ track of the current count of active libuv requests.
902
921
overview over libuv handles managed by Node.js.
903
922
904
923
<a id =" callback-scopes " ></a >
924
+
905
925
### Callback scopes
906
926
907
927
The public ` CallbackScope ` and the internally used ` InternalCallbackScope `
0 commit comments