Commit 5b47a78cd32 for nodejs
commit 5b47a78cd32174a46504b42b9bb6dfa07dacc05c
Author: Chengzhong Wu <legendecas@gmail.com>
Date: Fri Oct 30 16:13:50 2026 +0100
src,build: configure V8_EMBEDDER_DATA_ARRAY_SIZE
Refs: https://issues.chromium.org/issues/570436596
Signed-off-by: Chengzhong Wu <cwu631@bloomberg.net>
PR-URL: https://github.com/nodejs/node/pull/67755
Refs: https://crrev.com/c/8687878
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
diff --git a/common.gypi b/common.gypi
index 5a7ab699e5c..df36122982b 100644
--- a/common.gypi
+++ b/common.gypi
@@ -96,6 +96,8 @@
'v8_enable_sandbox%': 0,
'v8_enable_v8_checks%': 0,
'v8_use_perfetto%': 0,
+ # Must be greater than NODE_CONTEXT_TAG in src/node_context_data.h.
+ 'v8_embedder_data_array_size%': 40,
'tsan%': 0,
##### end V8 defaults #####
@@ -570,6 +572,11 @@
['v8_use_perfetto == 1', {
'defines': ['V8_USE_PERFETTO',],
}],
+ ['v8_embedder_data_array_size != 0', {
+ 'defines': [
+ 'V8_EMBEDDER_DATA_ARRAY_SIZE=<(v8_embedder_data_array_size)',
+ ],
+ }],
['v8_enable_map_packing == 1', {
'defines': ['V8_MAP_PACKING',],
}],
diff --git a/src/node_context_data.h b/src/node_context_data.h
index 02eae73cb2c..befb8b5e1ee 100644
--- a/src/node_context_data.h
+++ b/src/node_context_data.h
@@ -10,9 +10,9 @@
namespace node {
// Pick an index that's hopefully out of the way when we're embedded inside
-// another application. Performance-wise or memory-wise it doesn't matter:
-// Context::SetAlignedPointerInEmbedderData() is backed by a FixedArray,
-// worst case we pay a one-time penalty for resizing the array.
+// another application. V8 allocates the context embedder data array with a
+// fixed size of V8_EMBEDDER_DATA_ARRAY_SIZE, which must cover every index
+// below.
#ifndef NODE_CONTEXT_EMBEDDER_DATA_INDEX
#define NODE_CONTEXT_EMBEDDER_DATA_INDEX 32
#endif
@@ -48,10 +48,14 @@ namespace node {
#define NODE_CONTEXT_TAG 39
#endif
+static_assert(NODE_CONTEXT_TAG < V8_EMBEDDER_DATA_ARRAY_SIZE,
+ "V8 must be built with v8_embedder_data_array_size greater than "
+ "NODE_CONTEXT_TAG");
+
/**
* These are indexes used to set Node.js-specific data in the V8 contexts
- * via v8::Context::SetAlignedPointerInEmbedderData() (for pointers) and
- * v8::Context::SetEmbedderData() (for v8::Values).
+ * via v8::Context::SetAlignedPointerInEmbedderDataV2() (for pointers) and
+ * v8::Context::SetEmbedderDataV3() (for v8::Values).
*
* There are five types of contexts in Node.js:
* 1. Default V8 context, with nothing Node.js-specific. This is normally only