diff --git a/common.gypi b/common.gypi index 7c9305aa2d9..cdac606f120 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 ##### @@ -569,6 +571,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