-
Notifications
You must be signed in to change notification settings - Fork 28.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: add an ExternalReferenceRegistry class
- Loading branch information
1 parent
8ebf40e
commit 94335ab
Showing
7 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include "node_external_reference.h" | ||
#include <cinttypes> | ||
#include <vector> | ||
#include "util.h" | ||
|
||
namespace node { | ||
|
||
const std::vector<intptr_t>& ExternalReferenceRegistry::external_references() { | ||
CHECK(!is_finalized_); | ||
external_references_.push_back(reinterpret_cast<intptr_t>(nullptr)); | ||
is_finalized_ = true; | ||
return external_references_; | ||
} | ||
|
||
} // namespace node |
This file contains 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef SRC_NODE_EXTERNAL_REFERENCE_H_ | ||
#define SRC_NODE_EXTERNAL_REFERENCE_H_ | ||
|
||
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | ||
|
||
#include <cinttypes> | ||
#include <vector> | ||
|
||
namespace node { | ||
|
||
// This class manages the external references from the V8 heap | ||
// to the C++ addresses in Node.js. | ||
class ExternalReferenceRegistry { | ||
public: | ||
ExternalReferenceRegistry() {} | ||
|
||
template <typename T> | ||
void Register(T* address) { | ||
external_references_.push_back(reinterpret_cast<intptr_t>(address)); | ||
} | ||
|
||
// This can be called only once. | ||
const std::vector<intptr_t>& external_references(); | ||
|
||
bool is_empty() { return external_references_.empty(); } | ||
|
||
private: | ||
bool is_finalized_ = false; | ||
std::vector<intptr_t> external_references_; | ||
}; | ||
|
||
} // namespace node | ||
|
||
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | ||
#endif // SRC_NODE_EXTERNAL_REFERENCE_H_ |
This file contains 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
This file contains 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
This file contains 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