Skip to content

Commit 90713c6

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

File tree

3 files changed

+94
-72
lines changed

3 files changed

+94
-72
lines changed

deps/v8/include/v8.h

+46-40
Original file line numberDiff line numberDiff line change
@@ -1732,8 +1732,14 @@ class V8_EXPORT ScriptCompiler {
17321732
Local<String> arguments[], size_t context_extension_count,
17331733
Local<Object> context_extensions[],
17341734
CompileOptions options = kNoCompileOptions,
1735-
NoCacheReason no_cache_reason = kNoCacheNoReason,
1736-
Local<ScriptOrModule>* script_or_module_out = nullptr);
1735+
NoCacheReason no_cache_reason = kNoCacheNoReason);
1736+
1737+
static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInContext(
1738+
Local<Context> context, Source* source, size_t arguments_count,
1739+
Local<String> arguments[], size_t context_extension_count,
1740+
Local<Object> context_extensions[], CompileOptions options,
1741+
NoCacheReason no_cache_reason,
1742+
Local<ScriptOrModule>* script_or_module_out);
17371743

17381744
/**
17391745
* Creates and returns code cache for the specified unbound_script.
@@ -3393,13 +3399,17 @@ enum class IntegrityLevel { kFrozen, kSealed };
33933399
*/
33943400
class V8_EXPORT Object : public Value {
33953401
public:
3402+
V8_DEPRECATED("Use maybe version",
3403+
bool Set(Local<Value> key, Local<Value> value));
33963404
/**
33973405
* Set only return Just(true) or Empty(), so if it should never fail, use
33983406
* result.Check().
33993407
*/
34003408
V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
34013409
Local<Value> key, Local<Value> value);
34023410

3411+
V8_DEPRECATED("Use maybe version",
3412+
bool Set(uint32_t index, Local<Value> value));
34033413
V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
34043414
Local<Value> value);
34053415

@@ -3444,9 +3454,11 @@ class V8_EXPORT Object : public Value {
34443454
Local<Context> context, Local<Name> key,
34453455
PropertyDescriptor& descriptor); // NOLINT(runtime/references)
34463456

3457+
V8_DEPRECATED("Use maybe version", Local<Value> Get(Local<Value> key));
34473458
V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
34483459
Local<Value> key);
34493460

3461+
V8_DEPRECATED("Use maybe version", Local<Value> Get(uint32_t index));
34503462
V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
34513463
uint32_t index);
34523464

@@ -6560,19 +6572,7 @@ V8_INLINE Local<Boolean> False(Isolate* isolate);
65606572
*/
65616573
class V8_EXPORT ResourceConstraints {
65626574
public:
6563-
/**
6564-
* Configures the constraints with reasonable default values based on the
6565-
* provided heap size limit. The heap size includes both the young and
6566-
* the old generation.
6567-
*
6568-
* \param maximum_heap_size_in_bytes The hard limit for the heap size.
6569-
* When the heap size approaches this limit, V8 will perform series of
6570-
* garbage collections and invoke the NearHeapLimitCallback.
6571-
* If the garbage collections do not help and the callback does not
6572-
* increase the limit, then V8 will crash with V8::FatalProcessOutOfMemory.
6573-
*/
6574-
void ConfigureDefaultsFromHeapSize(size_t initial_heap_size_in_bytes,
6575-
size_t maximum_heap_size_in_bytes);
6575+
ResourceConstraints();
65766576

65776577
/**
65786578
* Configures the constraints with reasonable default values based on the
@@ -6596,8 +6596,12 @@ class V8_EXPORT ResourceConstraints {
65966596
* The amount of virtual memory reserved for generated code. This is relevant
65976597
* for 64-bit architectures that rely on code range for calls in code.
65986598
*/
6599-
size_t code_range_size_in_bytes() const { return code_range_size_; }
6600-
void set_code_range_size_in_bytes(size_t limit) { code_range_size_ = limit; }
6599+
size_t code_range_size_in_bytes() const {
6600+
return code_range_size_ * kMB;
6601+
}
6602+
void set_code_range_size_in_bytes(size_t limit) {
6603+
code_range_size_ = limit / kMB;
6604+
}
66016605

66026606
/**
66036607
* The maximum size of the old generation.
@@ -6607,60 +6611,60 @@ class V8_EXPORT ResourceConstraints {
66076611
* increase the limit, then V8 will crash with V8::FatalProcessOutOfMemory.
66086612
*/
66096613
size_t max_old_generation_size_in_bytes() const {
6610-
return max_old_generation_size_;
6614+
return max_old_space_size_ * kMB;
66116615
}
66126616
void set_max_old_generation_size_in_bytes(size_t limit) {
6613-
max_old_generation_size_ = limit;
6617+
max_old_space_size_ = limit / kMB;
66146618
}
66156619

66166620
/**
66176621
* The maximum size of the young generation, which consists of two semi-spaces
66186622
* and a large object space. This affects frequency of Scavenge garbage
66196623
* collections and should be typically much smaller that the old generation.
66206624
*/
6621-
size_t max_young_generation_size_in_bytes() const {
6622-
return max_young_generation_size_;
6623-
}
6624-
void set_max_young_generation_size_in_bytes(size_t limit) {
6625-
max_young_generation_size_ = limit;
6626-
}
6625+
size_t max_young_generation_size_in_bytes() const;
6626+
void set_max_young_generation_size_in_bytes(size_t limit);
66276627

66286628
size_t initial_old_generation_size_in_bytes() const {
6629-
return initial_old_generation_size_;
6629+
return 0;
66306630
}
66316631
void set_initial_old_generation_size_in_bytes(size_t initial_size) {
6632-
initial_old_generation_size_ = initial_size;
6632+
// Not available on Node 12.
66336633
}
66346634

66356635
size_t initial_young_generation_size_in_bytes() const {
6636-
return initial_young_generation_size_;
6636+
return 0;
66376637
}
66386638
void set_initial_young_generation_size_in_bytes(size_t initial_size) {
6639-
initial_young_generation_size_ = initial_size;
6639+
// Not available on Node 12.
66406640
}
66416641

66426642
/**
66436643
* Deprecated functions. Do not use in new code.
66446644
*/
66456645
V8_DEPRECATE_SOON("Use code_range_size_in_bytes.",
66466646
size_t code_range_size() const) {
6647-
return code_range_size_ / kMB;
6647+
return code_range_size_;
66486648
}
66496649
V8_DEPRECATE_SOON("Use set_code_range_size_in_bytes.",
66506650
void set_code_range_size(size_t limit_in_mb)) {
6651-
code_range_size_ = limit_in_mb * kMB;
6651+
code_range_size_ = limit_in_mb;
66526652
}
66536653
V8_DEPRECATE_SOON("Use max_young_generation_size_in_bytes.",
6654-
size_t max_semi_space_size_in_kb() const);
6654+
size_t max_semi_space_size_in_kb() const) {
6655+
return max_semi_space_size_in_kb_;
6656+
}
66556657
V8_DEPRECATE_SOON("Use set_max_young_generation_size_in_bytes.",
6656-
void set_max_semi_space_size_in_kb(size_t limit_in_kb));
6658+
void set_max_semi_space_size_in_kb(size_t limit_in_kb)) {
6659+
max_semi_space_size_in_kb_ = limit_in_kb;
6660+
}
66576661
V8_DEPRECATE_SOON("Use max_old_generation_size_in_bytes.",
66586662
size_t max_old_space_size() const) {
6659-
return max_old_generation_size_ / kMB;
6663+
return max_old_space_size_;
66606664
}
66616665
V8_DEPRECATE_SOON("Use set_max_old_generation_size_in_bytes.",
66626666
void set_max_old_space_size(size_t limit_in_mb)) {
6663-
max_old_generation_size_ = limit_in_mb * kMB;
6667+
max_old_space_size_ = limit_in_mb;
66646668
}
66656669
V8_DEPRECATE_SOON("Zone does not pool memory any more.",
66666670
size_t max_zone_pool_size() const) {
@@ -6673,13 +6677,15 @@ class V8_EXPORT ResourceConstraints {
66736677

66746678
private:
66756679
static constexpr size_t kMB = 1048576u;
6680+
6681+
// max_semi_space_size_ is in KB
6682+
size_t max_semi_space_size_in_kb_ = 0;
6683+
6684+
// The remaining limits are in MB
6685+
size_t max_old_space_size_ = 0;
6686+
uint32_t* stack_limit_ = nullptr;
66766687
size_t code_range_size_ = 0;
6677-
size_t max_old_generation_size_ = 0;
6678-
size_t max_young_generation_size_ = 0;
66796688
size_t max_zone_pool_size_ = 0;
6680-
size_t initial_old_generation_size_ = 0;
6681-
size_t initial_young_generation_size_ = 0;
6682-
uint32_t* stack_limit_ = nullptr;
66836689
};
66846690

66856691

deps/v8/src/api/api.cc

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

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

242245
namespace {
243246

247+
Local<Context> ContextFromNeverReadOnlySpaceObject(
248+
i::Handle<i::JSReceiver> obj) {
249+
return reinterpret_cast<v8::Isolate*>(obj->GetIsolate())->GetCurrentContext();
250+
}
251+
244252
class InternalEscapableScope : public v8::EscapableHandleScope {
245253
public:
246254
explicit inline InternalEscapableScope(i::Isolate* isolate)
@@ -953,31 +961,7 @@ Extension::Extension(const char* name, const char* source, int dep_count,
953961
CHECK(source != nullptr || source_length_ == 0);
954962
}
955963

956-
void ResourceConstraints::ConfigureDefaultsFromHeapSize(
957-
size_t initial_heap_size_in_bytes, size_t maximum_heap_size_in_bytes) {
958-
CHECK_LE(initial_heap_size_in_bytes, maximum_heap_size_in_bytes);
959-
if (maximum_heap_size_in_bytes == 0) {
960-
return;
961-
}
962-
size_t young_generation, old_generation;
963-
i::Heap::GenerationSizesFromHeapSize(maximum_heap_size_in_bytes,
964-
&young_generation, &old_generation);
965-
set_max_young_generation_size_in_bytes(
966-
i::Max(young_generation, i::Heap::MinYoungGenerationSize()));
967-
set_max_old_generation_size_in_bytes(
968-
i::Max(old_generation, i::Heap::MinOldGenerationSize()));
969-
if (initial_heap_size_in_bytes > 0) {
970-
i::Heap::GenerationSizesFromHeapSize(initial_heap_size_in_bytes,
971-
&young_generation, &old_generation);
972-
// We do not set lower bounds for the initial sizes.
973-
set_initial_young_generation_size_in_bytes(young_generation);
974-
set_initial_old_generation_size_in_bytes(old_generation);
975-
}
976-
if (i::kRequiresCodeRange) {
977-
set_code_range_size_in_bytes(
978-
i::Min(i::kMaximalCodeRangeSize, maximum_heap_size_in_bytes));
979-
}
980-
}
964+
ResourceConstraints::ResourceConstraints() {}
981965

982966
void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory,
983967
uint64_t virtual_memory_limit) {
@@ -995,15 +979,14 @@ void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory,
995979
}
996980
}
997981

998-
size_t ResourceConstraints::max_semi_space_size_in_kb() const {
999-
return i::Heap::SemiSpaceSizeFromYoungGenerationSize(
1000-
max_young_generation_size_) /
1001-
i::KB;
982+
size_t ResourceConstraints::max_young_generation_size_in_bytes() const {
983+
return i::Heap::YoungGenerationSizeFromSemiSpaceSize(
984+
max_semi_space_size_in_kb_ * i::KB);
1002985
}
1003986

1004-
void ResourceConstraints::set_max_semi_space_size_in_kb(size_t limit_in_kb) {
1005-
set_max_young_generation_size_in_bytes(
1006-
i::Heap::YoungGenerationSizeFromSemiSpaceSize(limit_in_kb * i::KB));
987+
void ResourceConstraints::set_max_young_generation_size_in_bytes(size_t limit) {
988+
max_semi_space_size_in_kb_ =
989+
i::Heap::SemiSpaceSizeFromYoungGenerationSize(limit) / i::KB;
1007990
}
1008991

1009992
i::Address* V8::GlobalizeReference(i::Isolate* isolate, i::Address* obj) {
@@ -2499,6 +2482,16 @@ bool IsIdentifier(i::Isolate* isolate, i::Handle<i::String> string) {
24992482
}
25002483
} // anonymous namespace
25012484

2485+
MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext(
2486+
Local<Context> v8_context, Source* source, size_t arguments_count,
2487+
Local<String> arguments[], size_t context_extension_count,
2488+
Local<Object> context_extensions[], CompileOptions options,
2489+
NoCacheReason no_cache_reason) {
2490+
return ScriptCompiler::CompileFunctionInContext(
2491+
v8_context, source, arguments_count, arguments, context_extension_count,
2492+
context_extensions, options, no_cache_reason, nullptr);
2493+
}
2494+
25022495
MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext(
25032496
Local<Context> v8_context, Source* source, size_t arguments_count,
25042497
Local<String> arguments[], size_t context_extension_count,
@@ -3969,6 +3962,11 @@ Maybe<bool> v8::Object::Set(v8::Local<v8::Context> context,
39693962
return Just(true);
39703963
}
39713964

3965+
bool v8::Object::Set(v8::Local<Value> key, v8::Local<Value> value) {
3966+
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
3967+
return Set(context, key, value).FromMaybe(false);
3968+
}
3969+
39723970
Maybe<bool> v8::Object::Set(v8::Local<v8::Context> context, uint32_t index,
39733971
v8::Local<Value> value) {
39743972
auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
@@ -3982,6 +3980,11 @@ Maybe<bool> v8::Object::Set(v8::Local<v8::Context> context, uint32_t index,
39823980
return Just(true);
39833981
}
39843982

3983+
bool v8::Object::Set(uint32_t index, v8::Local<Value> value) {
3984+
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
3985+
return Set(context, index, value).FromMaybe(false);
3986+
}
3987+
39853988
Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context,
39863989
v8::Local<Name> key,
39873990
v8::Local<Value> value) {
@@ -4199,6 +4202,11 @@ MaybeLocal<Value> v8::Object::Get(Local<v8::Context> context,
41994202
RETURN_ESCAPED(Utils::ToLocal(result));
42004203
}
42014204

4205+
Local<Value> v8::Object::Get(v8::Local<Value> key) {
4206+
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
4207+
RETURN_TO_LOCAL_UNCHECKED(Get(context, key), Value);
4208+
}
4209+
42024210
MaybeLocal<Value> v8::Object::Get(Local<Context> context, uint32_t index) {
42034211
PREPARE_FOR_EXECUTION(context, Object, Get, Value);
42044212
auto self = Utils::OpenHandle(this);
@@ -4209,6 +4217,11 @@ MaybeLocal<Value> v8::Object::Get(Local<Context> context, uint32_t index) {
42094217
RETURN_ESCAPED(Utils::ToLocal(result));
42104218
}
42114219

4220+
Local<Value> v8::Object::Get(uint32_t index) {
4221+
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
4222+
RETURN_TO_LOCAL_UNCHECKED(Get(context, index), Value);
4223+
}
4224+
42124225
MaybeLocal<Value> v8::Object::GetPrivate(Local<Context> context,
42134226
Local<Private> key) {
42144227
return Get(context, Local<Value>(reinterpret_cast<Value*>(*key)));
@@ -10545,6 +10558,7 @@ void InvokeFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info,
1054510558
#undef EXCEPTION_BAILOUT_CHECK_SCOPED_DO_NOT_USE
1054610559
#undef RETURN_ON_FAILED_EXECUTION
1054710560
#undef RETURN_ON_FAILED_EXECUTION_PRIMITIVE
10561+
#undef RETURN_TO_LOCAL_UNCHECKED
1054810562
#undef RETURN_ESCAPED
1054910563
#undef SET_FIELD_WRAPPED
1055010564
#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)