Skip to content

Commit

Permalink
src: include specific V8 headers in node_v8
Browse files Browse the repository at this point in the history
Also do it in all its dependencies.
This introduces the NODE_WANT_V8_SUBHEADERS macro to opt in
to only include specific V8 headers from our public ones (e.g. node.h).
  • Loading branch information
targos committed Oct 25, 2021
1 parent 2413283 commit c749170
Show file tree
Hide file tree
Showing 27 changed files with 129 additions and 37 deletions.
11 changes: 9 additions & 2 deletions src/aliased_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include <cinttypes>
#include "util-inl.h"
#include "v8.h"
#include "v8-forward.h"
#include "v8-array-buffer.h"
#include "v8-context.h"
#include "v8-local-handle.h"
#include "v8-persistent-handle.h"
#include "v8-snapshot.h"
#include "v8-typed-array.h"

#include <cinttypes>

namespace node {

Expand Down
9 changes: 5 additions & 4 deletions src/allocated_buffer-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

#include "allocated_buffer.h"
#include "base_object-inl.h"
#include "node_buffer.h"
#include "env-inl.h"
#include "uv.h"
#include "v8.h"
#include "util-inl.h"
#include "node_buffer.h"
#include "node_internals.h"
#include "util-inl.h"
#include "uv.h"
#include "v8-forward.h"
#include "v8-array-buffer.h"

namespace node {

Expand Down
5 changes: 3 additions & 2 deletions src/allocated_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include "base_object.h"
#include "uv.h"
#include "v8.h"
#include "env.h"
#include "uv.h"
#include "v8-forward.h"
#include "v8-array-buffer.h"

namespace node {

Expand Down
3 changes: 2 additions & 1 deletion src/async_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include "base_object.h"
#include "v8.h"
#include "v8-forward.h"
#include "v8-weak-callback-info.h"

#include <cstdint>

Expand Down
5 changes: 3 additions & 2 deletions src/base_object-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
#include "base_object.h"
#include "env-inl.h"
#include "util.h"

#include "v8.h"
#include "v8-forward.h"
#include "v8-object.h"
#include "v8-weak-callback-info.h"

namespace node {

Expand Down
8 changes: 6 additions & 2 deletions src/base_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include <type_traits> // std::remove_reference
#include "memory_tracker.h"
#include "v8.h"
#include "v8-forward.h"
#include "v8-maybe.h"
#include "v8-persistent-handle.h"
#include "v8-value-serializer.h"

#include <type_traits> // std::remove_reference

namespace node {

Expand Down
16 changes: 13 additions & 3 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,21 @@
#include "callback_queue-inl.h"
#include "env.h"
#include "node.h"
#include "util-inl.h"
#include "uv.h"
#include "v8.h"
#include "node_perf_common.h"
#include "node_context_data.h"
#include "util-inl.h"
#include "uv.h"
#include "v8-forward.h"
#include "v8-array-buffer.h"
#include "v8-container.h"
#include "v8-context.h"
#include "v8-exception.h"
#include "v8-function.h"
#include "v8-function-callback.h"
#include "v8-isolate.h"
#include "v8-object.h"
#include "v8-primitive.h"
#include "v8-template.h"

#include <cstddef>
#include <cstdint>
Expand Down
7 changes: 6 additions & 1 deletion src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@
#include "req_wrap.h"
#include "util.h"
#include "uv.h"
#include "v8.h"
#include "v8-forward.h"
#include "v8-array-buffer.h"
#include "v8-persistent-handle.h"
#include "v8-platform.h"
#include "v8-profiler.h"
#include "v8-snapshot.h"

#include <array>
#include <atomic>
Expand Down
2 changes: 1 addition & 1 deletion src/handle_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "async_wrap.h"
#include "util.h"
#include "uv.h"
#include "v8.h"
#include "v8-forward.h"

namespace node {

Expand Down
3 changes: 2 additions & 1 deletion src/inspector_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#endif

#include "node_options.h"
#include "v8.h"
#include "v8-forward.h"
#include "v8-message.h"

#include <cstddef>
#include <memory>
Expand Down
4 changes: 3 additions & 1 deletion src/inspector_profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
#error("This header can only be used when inspector is enabled")
#endif

#include <unordered_set>
#include "inspector_agent.h"
#include "v8-forward.h"

#include <unordered_set>

namespace node {
// Forward declaration to break recursive dependency chain with src/env.h.
Expand Down
4 changes: 4 additions & 0 deletions src/memory_tracker-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include "memory_tracker.h"
#include "v8-forward.h"
#include "v8-array-buffer.h"
#include "v8-persistent-handle.h"
#include "v8-profiler.h"

namespace node {

Expand Down
3 changes: 3 additions & 0 deletions src/memory_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include "aliased_buffer.h"
#include "v8-forward.h"
#include "v8-array-buffer.h"
#include "v8-persistent-handle.h"
#include "v8-profiler.h"

#include <uv.h>
Expand Down
17 changes: 15 additions & 2 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,22 @@
# define SIGKILL 9
#endif

#include "v8.h" // NOLINT(build/include_order)
#ifndef NODE_WANT_V8_SUBHEADERS
#include "v8.h"
#else
#include "v8-forward.h"
#include "v8-callbacks.h"
#include "v8-date.h"
#include "v8-exception.h"
#include "v8-function.h"
#include "v8-isolate.h"
#include "v8-maybe.h"
#include "v8-microtask.h"
#include "v8-persistent-handle.h"
#include "v8-platform.h"
#include "v8-template.h"
#endif // NODE_WANT_V8_SUBHEADERS

#include "v8-platform.h" // NOLINT(build/include_order)
#include "node_version.h" // NODE_MODULE_VERSION

#include <memory>
Expand Down
1 change: 1 addition & 0 deletions src/node_binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define NAPI_EXPERIMENTAL
#include "node_api.h"
#include "uv.h"
#include "v8-forward.h"

enum {
NM_F_BUILTIN = 1 << 0, // Unused.
Expand Down
4 changes: 4 additions & 0 deletions src/node_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
#define SRC_NODE_BUFFER_H_

#include "node.h"
#ifndef NODE_WANT_V8_SUBHEADERS
#include "v8.h"
#else
#include "v8-forward.h"
#endif // NODE_WANT_V8_SUBHEADERS

namespace node {

Expand Down
2 changes: 1 addition & 1 deletion src/node_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include "node.h"
#include "v8.h"
#include "v8-forward.h"

#if HAVE_OPENSSL

Expand Down
6 changes: 5 additions & 1 deletion src/node_external_reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include "v8-forward.h"
#include "v8-function-callback.h"
#include "v8-object.h"
#include "v8-template.h"

#include <cinttypes>
#include <vector>
#include "v8.h"

namespace node {

Expand Down
7 changes: 6 additions & 1 deletion src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@
#include "tracing/trace_event.h"
#include "util.h"
#include "uv.h"
#include "v8.h"
#include "v8-forward.h"
#include "v8-debug.h"
#include "v8-exception.h"
#include "v8-isolate.h"
#include "v8-maybe.h"
#include "v8-profiler.h"

#include <cstdint>
#include <cstdlib>
Expand Down
9 changes: 5 additions & 4 deletions src/node_main_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include <cstddef>
#include <memory>

#include "node.h"
#include "util.h"
#include "uv.h"
#include "v8.h"
#include "v8-forward.h"
#include "v8-snapshot.h"

#include <cstddef>
#include <memory>

namespace node {

Expand Down
3 changes: 2 additions & 1 deletion src/node_perf_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#include "aliased_buffer.h"
#include "node.h"
#include "uv.h"
#include "v8.h"
#include "v8-forward.h"
#include "v8-snapshot.h"

#include <algorithm>
#include <iostream>
Expand Down
2 changes: 2 additions & 0 deletions src/node_snapshotable.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "base_object.h"
#include "util.h"
#include "v8-forward.h"
#include "v8-snapshot.h"

namespace node {

Expand Down
20 changes: 17 additions & 3 deletions src/node_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,27 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

#define NODE_WANT_V8_SUBHEADERS 1

#include "node_v8.h"
#include "base_object-inl.h"
#include "env-inl.h"
#include "memory_tracker-inl.h"
#include "node.h"
#include "node_external_reference.h"
#include "util-inl.h"
#include "v8.h"
#include "v8-forward.h"
#include "v8-container.h"
#include "v8-context.h"
#include "v8-function-callback.h"
#include "v8-initialization.h"
#include "v8-isolate.h"
#include "v8-object.h"
#include "v8-primitive.h"
#include "v8-script.h"
#include "v8-snapshot.h"
#include "v8-statistics.h"
#include "v8-value.h"

namespace node {
namespace v8_utils {
Expand All @@ -42,6 +55,7 @@ using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::ScriptCompiler;
using v8::SnapshotCreator;
using v8::String;
using v8::Uint32;
using v8::V8;
Expand Down Expand Up @@ -109,7 +123,7 @@ BindingData::BindingData(Environment* env, Local<Object> obj)
}

void BindingData::PrepareForSerialization(Local<Context> context,
v8::SnapshotCreator* creator) {
SnapshotCreator* creator) {
// We'll just re-initialize the buffers in the constructor since their
// contents can be thrown away once consumed in the previous call.
heap_statistics_buffer.Release();
Expand Down Expand Up @@ -169,7 +183,7 @@ void UpdateHeapSpaceStatisticsBuffer(const FunctionCallbackInfo<Value>& args) {
HeapSpaceStatistics s;
Isolate* const isolate = args.GetIsolate();
CHECK(args[0]->IsUint32());
size_t space_index = static_cast<size_t>(args[0].As<v8::Uint32>()->Value());
size_t space_index = static_cast<size_t>(args[0].As<Uint32>()->Value());
isolate->GetHeapSpaceStatistics(&s, space_index);

AliasedFloat64Array& buffer = data->heap_space_statistics_buffer;
Expand Down
2 changes: 1 addition & 1 deletion src/node_v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "base_object.h"
#include "node_snapshotable.h"
#include "util.h"
#include "v8.h"
#include "v8-forward.h"

namespace node {
class Environment;
Expand Down
2 changes: 1 addition & 1 deletion src/req_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "async_wrap.h"
#include "util.h"
#include "v8.h"
#include "v8-forward.h"

namespace node {

Expand Down
7 changes: 6 additions & 1 deletion src/util-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include "util.h"
#include "v8-forward.h"
#include "v8-container.h"
#include "v8-context.h"
#include "v8-function-callback.h"

#include <cmath>
#include <cstring>
#include <locale>
#include "util.h"

// These are defined by <sys/byteorder.h> or <netinet/in.h> on some systems.
// To avoid warnings, undefine them before redefining them.
Expand Down
Loading

0 comments on commit c749170

Please sign in to comment.