-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
src,doc: add C++ internals documentation #30552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d3d23cd
src,doc: add C++ internals documentation
addaleax cbc4152
fixup! src,doc: add C++ internals documentation
addaleax 09386ef
fixup! src,doc: add C++ internals documentation
addaleax 4ef7a31
fixup! src,doc: add C++ internals documentation
addaleax 130ef12
fixup! src,doc: add C++ internals documentation
addaleax 2445c17
fixup! src,doc: add C++ internals documentation
addaleax e1ca24c
fixup! src,doc: add C++ internals documentation
addaleax 309fab4
fixup! src,doc: add C++ internals documentation
addaleax f50f971
fixup! src,doc: add C++ internals documentation
addaleax 9848ba5
fixup! fixup! src,doc: add C++ internals documentation
addaleax 5a5f9e3
fixup! fixup! fixup! src,doc: add C++ internals documentation
addaleax 7d32e28
fixup! src,doc: add C++ internals documentation
addaleax b49430d
fixup! src,doc: add C++ internals documentation
addaleax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fixup! src,doc: add C++ internals documentation
Co-Authored-By: Colin Ihrig <cjihrig@gmail.com>
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,6 +77,32 @@ subclasses such as `v8::Number` (which in turn has subclasses like `v8::Int32`), | |
| `v8::Boolean` or `v8::Object`. Most types are represented by subclasses | ||
| of `v8::Object`, e.g. `v8::Uint8Array` or `v8::Date`. | ||
|
|
||
| <a id="internal-fields"></a> | ||
| ### Internal fields | ||
|
|
||
| V8 provides the ability to store data in so-called “internal fields” inside | ||
| `v8::Object`s that were created as instances of C++-backed classes. The number | ||
| of fields needs to be defined when creating that class. | ||
|
|
||
| Both JavaScript values and `void*` pointers may be stored in such fields. | ||
| In most native Node.js objects, the first internal field is used to store a | ||
| pointer to a [`BaseObject`][] subclass, which then contains all relevant | ||
| information associated with the JavaScript object. | ||
|
|
||
| The most typical way of working internal fields are: | ||
|
|
||
| * `obj->InternalFieldCount()` to look up the number of internal fields for an | ||
| object (`0` for regular JavaScript objects). | ||
| * `obj->GetInternalField(i)` to get a JavaScript value from an internal field. | ||
| * `obj->SetInternalField(i, v)` to store a JavaScript value in an | ||
| internal field. | ||
| * `obj->GetAlignedPointerFromInternalField(i)` to get a `void*` pointer from an | ||
| internal field. | ||
| * `obj->SetAlignedPointerInInternalField(i, p)` to store a `void*` pointer in an | ||
| internal field. | ||
|
|
||
| [`Context`][]s provide the same feature under the name “embedder data”. | ||
|
|
||
| <a id="js-handles"></a> | ||
| ### JavaScript value handles | ||
|
|
||
|
|
@@ -315,7 +341,9 @@ Node.js source code.) | |
|
|
||
|
|
||
| `args[n]` is a `Local<Value>` that represents the n-th argument passed to the | ||
| function. `args.This()` is the `this` value inside this function call. | ||
| function. `args.This()` is the `this` value inside this function call, | ||
| and `args.Holder()` which is equivalent to `args.This()` in all use cases inside | ||
| of Node.js. | ||
|
|
||
| `args.GetReturnValue()` is a placeholder for the return value of the function, | ||
| and provides a `.Set()` method that can be called with a boolean, integer, | ||
|
|
@@ -577,7 +605,7 @@ Node.js, and most classes that are associated with JavaScript objects are | |
| subclasses of it. It is defined in [`base_object.h`][]. | ||
|
|
||
| Every `BaseObject` is associated with one [`Environment`][] and one | ||
| `v8::Object`. The `v8::Object` needs to have at least one “internal field” | ||
| `v8::Object`. The `v8::Object` needs to have at least one [internal field][] | ||
| that is used for storing the pointer to the C++ object. In order to ensure this, | ||
| the V8 `SetInternalFieldCount()` function is usually used when setting up the | ||
| class from C++. | ||
|
|
@@ -861,6 +889,7 @@ static void GetUserInfo(const FunctionCallbackInfo<Value>& args) { | |
| [cleanup hooks]: #cleanup-hooks | ||
| [event loop]: #event-loop | ||
| [exception handling]: #exception-handling | ||
| [internal field]: #internal-field | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. - [internal field]: #internal-field
+ [internal field]: #internal-fields |
||
| [introduction for V8 embedders]: https://v8.dev/docs/embed | ||
| [libuv handles]: #libuv-handles-and-requests | ||
| [libuv requests]: #libuv-handles-and-requests | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.