Skip to content

Commit e60dc1d

Browse files
targosaddaleax
authored andcommitted
deps: patch V8 to be API/ABI compatible with 7.4 (from 7.7)
Co-authored-by: Anna Henningsen <[email protected]> Backport-PR-URL: #30109 PR-URL: #29241 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 887ca3b commit e60dc1d

File tree

4 files changed

+95
-80
lines changed

4 files changed

+95
-80
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
# Reset this number to 0 on major V8 upgrades.
4040
# Increment by one for each non-official patch applied to deps/v8.
41-
'v8_embedder_string': '-node.19',
41+
'v8_embedder_string': '-node.20',
4242

4343
##### V8 defaults for Node.js #####
4444

deps/v8/include/v8.h

+46-47
Original file line numberDiff line numberDiff line change
@@ -1819,8 +1819,14 @@ class V8_EXPORT ScriptCompiler {
18191819
Local<String> arguments[], size_t context_extension_count,
18201820
Local<Object> context_extensions[],
18211821
CompileOptions options = kNoCompileOptions,
1822-
NoCacheReason no_cache_reason = kNoCacheNoReason,
1823-
Local<ScriptOrModule>* script_or_module_out = nullptr);
1822+
NoCacheReason no_cache_reason = kNoCacheNoReason);
1823+
1824+
static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInContext(
1825+
Local<Context> context, Source* source, size_t arguments_count,
1826+
Local<String> arguments[], size_t context_extension_count,
1827+
Local<Object> context_extensions[], CompileOptions options,
1828+
NoCacheReason no_cache_reason,
1829+
Local<ScriptOrModule>* script_or_module_out);
18241830

18251831
/**
18261832
* Creates and returns code cache for the specified unbound_script.
@@ -3481,13 +3487,17 @@ enum class IntegrityLevel { kFrozen, kSealed };
34813487
*/
34823488
class V8_EXPORT Object : public Value {
34833489
public:
3490+
V8_DEPRECATED("Use maybe version",
3491+
bool Set(Local<Value> key, Local<Value> value));
34843492
/**
34853493
* Set only return Just(true) or Empty(), so if it should never fail, use
34863494
* result.Check().
34873495
*/
34883496
V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
34893497
Local<Value> key, Local<Value> value);
34903498

3499+
V8_DEPRECATED("Use maybe version",
3500+
bool Set(uint32_t index, Local<Value> value));
34913501
V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
34923502
Local<Value> value);
34933503

@@ -3532,9 +3542,11 @@ class V8_EXPORT Object : public Value {
35323542
Local<Context> context, Local<Name> key,
35333543
PropertyDescriptor& descriptor); // NOLINT(runtime/references)
35343544

3545+
V8_DEPRECATED("Use maybe version", Local<Value> Get(Local<Value> key));
35353546
V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
35363547
Local<Value> key);
35373548

3549+
V8_DEPRECATED("Use maybe version", Local<Value> Get(uint32_t index));
35383550
V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
35393551
uint32_t index);
35403552

@@ -6683,26 +6695,7 @@ V8_INLINE Local<Boolean> False(Isolate* isolate);
66836695
*/
66846696
class V8_EXPORT ResourceConstraints {
66856697
public:
6686-
/**
6687-
* Configures the constraints with reasonable default values based on the
6688-
* provided heap size limit. The heap size includes both the young and
6689-
* the old generation.
6690-
*
6691-
* \param initial_heap_size_in_bytes The initial heap size or zero.
6692-
* By default V8 starts with a small heap and dynamically grows it to
6693-
* match the set of live objects. This may lead to ineffective
6694-
* garbage collections at startup if the live set is large.
6695-
* Setting the initial heap size avoids such garbage collections.
6696-
* Note that this does not affect young generation garbage collections.
6697-
*
6698-
* \param maximum_heap_size_in_bytes The hard limit for the heap size.
6699-
* When the heap size approaches this limit, V8 will perform series of
6700-
* garbage collections and invoke the NearHeapLimitCallback. If the garbage
6701-
* collections do not help and the callback does not increase the limit,
6702-
* then V8 will crash with V8::FatalProcessOutOfMemory.
6703-
*/
6704-
void ConfigureDefaultsFromHeapSize(size_t initial_heap_size_in_bytes,
6705-
size_t maximum_heap_size_in_bytes);
6698+
ResourceConstraints();
67066699

67076700
/**
67086701
* Configures the constraints with reasonable default values based on the
@@ -6726,8 +6719,12 @@ class V8_EXPORT ResourceConstraints {
67266719
* The amount of virtual memory reserved for generated code. This is relevant
67276720
* for 64-bit architectures that rely on code range for calls in code.
67286721
*/
6729-
size_t code_range_size_in_bytes() const { return code_range_size_; }
6730-
void set_code_range_size_in_bytes(size_t limit) { code_range_size_ = limit; }
6722+
size_t code_range_size_in_bytes() const {
6723+
return code_range_size_ * kMB;
6724+
}
6725+
void set_code_range_size_in_bytes(size_t limit) {
6726+
code_range_size_ = limit / kMB;
6727+
}
67316728

67326729
/**
67336730
* The maximum size of the old generation.
@@ -6737,60 +6734,60 @@ class V8_EXPORT ResourceConstraints {
67376734
* increase the limit, then V8 will crash with V8::FatalProcessOutOfMemory.
67386735
*/
67396736
size_t max_old_generation_size_in_bytes() const {
6740-
return max_old_generation_size_;
6737+
return max_old_space_size_ * kMB;
67416738
}
67426739
void set_max_old_generation_size_in_bytes(size_t limit) {
6743-
max_old_generation_size_ = limit;
6740+
max_old_space_size_ = limit / kMB;
67446741
}
67456742

67466743
/**
67476744
* The maximum size of the young generation, which consists of two semi-spaces
67486745
* and a large object space. This affects frequency of Scavenge garbage
67496746
* collections and should be typically much smaller that the old generation.
67506747
*/
6751-
size_t max_young_generation_size_in_bytes() const {
6752-
return max_young_generation_size_;
6753-
}
6754-
void set_max_young_generation_size_in_bytes(size_t limit) {
6755-
max_young_generation_size_ = limit;
6756-
}
6748+
size_t max_young_generation_size_in_bytes() const;
6749+
void set_max_young_generation_size_in_bytes(size_t limit);
67576750

67586751
size_t initial_old_generation_size_in_bytes() const {
6759-
return initial_old_generation_size_;
6752+
return 0;
67606753
}
67616754
void set_initial_old_generation_size_in_bytes(size_t initial_size) {
6762-
initial_old_generation_size_ = initial_size;
6755+
// Not available on Node 12.
67636756
}
67646757

67656758
size_t initial_young_generation_size_in_bytes() const {
6766-
return initial_young_generation_size_;
6759+
return 0;
67676760
}
67686761
void set_initial_young_generation_size_in_bytes(size_t initial_size) {
6769-
initial_young_generation_size_ = initial_size;
6762+
// Not available on Node 12.
67706763
}
67716764

67726765
/**
67736766
* Deprecated functions. Do not use in new code.
67746767
*/
67756768
V8_DEPRECATE_SOON("Use code_range_size_in_bytes.",
67766769
size_t code_range_size() const) {
6777-
return code_range_size_ / kMB;
6770+
return code_range_size_;
67786771
}
67796772
V8_DEPRECATE_SOON("Use set_code_range_size_in_bytes.",
67806773
void set_code_range_size(size_t limit_in_mb)) {
6781-
code_range_size_ = limit_in_mb * kMB;
6774+
code_range_size_ = limit_in_mb;
67826775
}
67836776
V8_DEPRECATE_SOON("Use max_young_generation_size_in_bytes.",
6784-
size_t max_semi_space_size_in_kb() const);
6777+
size_t max_semi_space_size_in_kb() const) {
6778+
return max_semi_space_size_in_kb_;
6779+
}
67856780
V8_DEPRECATE_SOON("Use set_max_young_generation_size_in_bytes.",
6786-
void set_max_semi_space_size_in_kb(size_t limit_in_kb));
6781+
void set_max_semi_space_size_in_kb(size_t limit_in_kb)) {
6782+
max_semi_space_size_in_kb_ = limit_in_kb;
6783+
}
67876784
V8_DEPRECATE_SOON("Use max_old_generation_size_in_bytes.",
67886785
size_t max_old_space_size() const) {
6789-
return max_old_generation_size_ / kMB;
6786+
return max_old_space_size_;
67906787
}
67916788
V8_DEPRECATE_SOON("Use set_max_old_generation_size_in_bytes.",
67926789
void set_max_old_space_size(size_t limit_in_mb)) {
6793-
max_old_generation_size_ = limit_in_mb * kMB;
6790+
max_old_space_size_ = limit_in_mb;
67946791
}
67956792
V8_DEPRECATE_SOON("Zone does not pool memory any more.",
67966793
size_t max_zone_pool_size() const) {
@@ -6803,13 +6800,15 @@ class V8_EXPORT ResourceConstraints {
68036800

68046801
private:
68056802
static constexpr size_t kMB = 1048576u;
6803+
6804+
// max_semi_space_size_ is in KB
6805+
size_t max_semi_space_size_in_kb_ = 0;
6806+
6807+
// The remaining limits are in MB
6808+
size_t max_old_space_size_ = 0;
6809+
uint32_t* stack_limit_ = nullptr;
68066810
size_t code_range_size_ = 0;
6807-
size_t max_old_generation_size_ = 0;
6808-
size_t max_young_generation_size_ = 0;
68096811
size_t max_zone_pool_size_ = 0;
6810-
size_t initial_old_generation_size_ = 0;
6811-
size_t initial_young_generation_size_ = 0;
6812-
uint32_t* stack_limit_ = nullptr;
68136812
};
68146813

68156814

deps/v8/src/api/api.cc

+46-32
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,18 @@ namespace v8 {
238238
#define RETURN_ON_FAILED_EXECUTION_PRIMITIVE(T) \
239239
EXCEPTION_BAILOUT_CHECK_SCOPED_DO_NOT_USE(isolate, Nothing<T>())
240240

241+
#define RETURN_TO_LOCAL_UNCHECKED(maybe_local, T) \
242+
return maybe_local.FromMaybe(Local<T>());
243+
241244
#define RETURN_ESCAPED(value) return handle_scope.Escape(value);
242245

243246
namespace {
244247

248+
Local<Context> ContextFromNeverReadOnlySpaceObject(
249+
i::Handle<i::JSReceiver> obj) {
250+
return reinterpret_cast<v8::Isolate*>(obj->GetIsolate())->GetCurrentContext();
251+
}
252+
245253
class InternalEscapableScope : public v8::EscapableHandleScope {
246254
public:
247255
explicit inline InternalEscapableScope(i::Isolate* isolate)
@@ -964,31 +972,7 @@ Extension::Extension(const char* name, const char* source, int dep_count,
964972
CHECK(source != nullptr || source_length_ == 0);
965973
}
966974

967-
void ResourceConstraints::ConfigureDefaultsFromHeapSize(
968-
size_t initial_heap_size_in_bytes, size_t maximum_heap_size_in_bytes) {
969-
CHECK_LE(initial_heap_size_in_bytes, maximum_heap_size_in_bytes);
970-
if (maximum_heap_size_in_bytes == 0) {
971-
return;
972-
}
973-
size_t young_generation, old_generation;
974-
i::Heap::GenerationSizesFromHeapSize(maximum_heap_size_in_bytes,
975-
&young_generation, &old_generation);
976-
set_max_young_generation_size_in_bytes(
977-
i::Max(young_generation, i::Heap::MinYoungGenerationSize()));
978-
set_max_old_generation_size_in_bytes(
979-
i::Max(old_generation, i::Heap::MinOldGenerationSize()));
980-
if (initial_heap_size_in_bytes > 0) {
981-
i::Heap::GenerationSizesFromHeapSize(initial_heap_size_in_bytes,
982-
&young_generation, &old_generation);
983-
// We do not set lower bounds for the initial sizes.
984-
set_initial_young_generation_size_in_bytes(young_generation);
985-
set_initial_old_generation_size_in_bytes(old_generation);
986-
}
987-
if (i::kRequiresCodeRange) {
988-
set_code_range_size_in_bytes(
989-
i::Min(i::kMaximalCodeRangeSize, maximum_heap_size_in_bytes));
990-
}
991-
}
975+
ResourceConstraints::ResourceConstraints() {}
992976

993977
void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory,
994978
uint64_t virtual_memory_limit) {
@@ -1006,15 +990,14 @@ void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory,
1006990
}
1007991
}
1008992

1009-
size_t ResourceConstraints::max_semi_space_size_in_kb() const {
1010-
return i::Heap::SemiSpaceSizeFromYoungGenerationSize(
1011-
max_young_generation_size_) /
1012-
i::KB;
993+
size_t ResourceConstraints::max_young_generation_size_in_bytes() const {
994+
return i::Heap::YoungGenerationSizeFromSemiSpaceSize(
995+
max_semi_space_size_in_kb_ * i::KB);
1013996
}
1014997

1015-
void ResourceConstraints::set_max_semi_space_size_in_kb(size_t limit_in_kb) {
1016-
set_max_young_generation_size_in_bytes(
1017-
i::Heap::YoungGenerationSizeFromSemiSpaceSize(limit_in_kb * i::KB));
998+
void ResourceConstraints::set_max_young_generation_size_in_bytes(size_t limit) {
999+
max_semi_space_size_in_kb_ =
1000+
i::Heap::SemiSpaceSizeFromYoungGenerationSize(limit) / i::KB;
10181001
}
10191002

10201003
i::Address* V8::GlobalizeReference(i::Isolate* isolate, i::Address* obj) {
@@ -2518,6 +2501,16 @@ bool IsIdentifier(i::Isolate* isolate, i::Handle<i::String> string) {
25182501
}
25192502
} // anonymous namespace
25202503

2504+
MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext(
2505+
Local<Context> v8_context, Source* source, size_t arguments_count,
2506+
Local<String> arguments[], size_t context_extension_count,
2507+
Local<Object> context_extensions[], CompileOptions options,
2508+
NoCacheReason no_cache_reason) {
2509+
return ScriptCompiler::CompileFunctionInContext(
2510+
v8_context, source, arguments_count, arguments, context_extension_count,
2511+
context_extensions, options, no_cache_reason, nullptr);
2512+
}
2513+
25212514
MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext(
25222515
Local<Context> v8_context, Source* source, size_t arguments_count,
25232516
Local<String> arguments[], size_t context_extension_count,
@@ -3988,6 +3981,11 @@ Maybe<bool> v8::Object::Set(v8::Local<v8::Context> context,
39883981
return Just(true);
39893982
}
39903983

3984+
bool v8::Object::Set(v8::Local<Value> key, v8::Local<Value> value) {
3985+
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
3986+
return Set(context, key, value).FromMaybe(false);
3987+
}
3988+
39913989
Maybe<bool> v8::Object::Set(v8::Local<v8::Context> context, uint32_t index,
39923990
v8::Local<Value> value) {
39933991
auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
@@ -4001,6 +3999,11 @@ Maybe<bool> v8::Object::Set(v8::Local<v8::Context> context, uint32_t index,
40013999
return Just(true);
40024000
}
40034001

4002+
bool v8::Object::Set(uint32_t index, v8::Local<Value> value) {
4003+
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
4004+
return Set(context, index, value).FromMaybe(false);
4005+
}
4006+
40044007
Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context,
40054008
v8::Local<Name> key,
40064009
v8::Local<Value> value) {
@@ -4218,6 +4221,11 @@ MaybeLocal<Value> v8::Object::Get(Local<v8::Context> context,
42184221
RETURN_ESCAPED(Utils::ToLocal(result));
42194222
}
42204223

4224+
Local<Value> v8::Object::Get(v8::Local<Value> key) {
4225+
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
4226+
RETURN_TO_LOCAL_UNCHECKED(Get(context, key), Value);
4227+
}
4228+
42214229
MaybeLocal<Value> v8::Object::Get(Local<Context> context, uint32_t index) {
42224230
PREPARE_FOR_EXECUTION(context, Object, Get, Value);
42234231
auto self = Utils::OpenHandle(this);
@@ -4228,6 +4236,11 @@ MaybeLocal<Value> v8::Object::Get(Local<Context> context, uint32_t index) {
42284236
RETURN_ESCAPED(Utils::ToLocal(result));
42294237
}
42304238

4239+
Local<Value> v8::Object::Get(uint32_t index) {
4240+
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
4241+
RETURN_TO_LOCAL_UNCHECKED(Get(context, index), Value);
4242+
}
4243+
42314244
MaybeLocal<Value> v8::Object::GetPrivate(Local<Context> context,
42324245
Local<Private> key) {
42334246
return Get(context, Local<Value>(reinterpret_cast<Value*>(*key)));
@@ -10651,6 +10664,7 @@ void InvokeFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info,
1065110664
#undef EXCEPTION_BAILOUT_CHECK_SCOPED_DO_NOT_USE
1065210665
#undef RETURN_ON_FAILED_EXECUTION
1065310666
#undef RETURN_ON_FAILED_EXECUTION_PRIMITIVE
10667+
#undef RETURN_TO_LOCAL_UNCHECKED
1065410668
#undef RETURN_ESCAPED
1065510669
#undef SET_FIELD_WRAPPED
1065610670
#undef NEW_STRING

deps/v8/test/unittests/api/resource-constraints-unittest.cc

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace v8 {
1212

13+
/* These tests do not apply on Node 12.
1314
TEST(ResourceConstraints, ConfigureDefaultsFromHeapSizeSmall) {
1415
const size_t KB = static_cast<size_t>(i::KB);
1516
const size_t MB = static_cast<size_t>(i::MB);
@@ -39,6 +40,7 @@ TEST(ResourceConstraints, ConfigureDefaultsFromHeapSizeLarge) {
3940
ASSERT_EQ(3 * 512 * pm * KB,
4041
constraints.initial_young_generation_size_in_bytes());
4142
}
43+
*/
4244

4345
TEST(ResourceConstraints, ConfigureDefaults) {
4446
const size_t KB = static_cast<size_t>(i::KB);

0 commit comments

Comments
 (0)