Skip to content

Commit adcab85

Browse files
zcbenzRafaelGSS
authored andcommitted
src: fix compatility with upcoming V8 12.1 APIs
PR-URL: #50709 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent e116fcd commit adcab85

File tree

4 files changed

+50
-41
lines changed

4 files changed

+50
-41
lines changed

src/env-inl.h

+8-3
Original file line numberDiff line numberDiff line change
@@ -775,13 +775,18 @@ inline void Environment::ThrowRangeError(const char* errmsg) {
775775
ThrowError(v8::Exception::RangeError, errmsg);
776776
}
777777

778-
inline void Environment::ThrowError(
779-
v8::Local<v8::Value> (*fun)(v8::Local<v8::String>),
780-
const char* errmsg) {
778+
inline void Environment::ThrowError(V8ExceptionConstructorOld fun,
779+
const char* errmsg) {
781780
v8::HandleScope handle_scope(isolate());
782781
isolate()->ThrowException(fun(OneByteString(isolate(), errmsg)));
783782
}
784783

784+
inline void Environment::ThrowError(V8ExceptionConstructorNew fun,
785+
const char* errmsg) {
786+
v8::HandleScope handle_scope(isolate());
787+
isolate()->ThrowException(fun(OneByteString(isolate(), errmsg), {}));
788+
}
789+
785790
inline void Environment::ThrowErrnoException(int errorno,
786791
const char* syscall,
787792
const char* message,

src/env.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -1016,8 +1016,14 @@ class Environment : public MemoryRetainer {
10161016
};
10171017

10181018
private:
1019-
inline void ThrowError(v8::Local<v8::Value> (*fun)(v8::Local<v8::String>),
1020-
const char* errmsg);
1019+
// V8 has changed the constructor of exceptions, support both APIs before Node
1020+
// updates to V8 12.1.
1021+
using V8ExceptionConstructorOld =
1022+
v8::Local<v8::Value> (*)(v8::Local<v8::String>);
1023+
using V8ExceptionConstructorNew =
1024+
v8::Local<v8::Value> (*)(v8::Local<v8::String>, v8::Local<v8::Value>);
1025+
inline void ThrowError(V8ExceptionConstructorOld fun, const char* errmsg);
1026+
inline void ThrowError(V8ExceptionConstructorNew fun, const char* errmsg);
10211027
void TrackContext(v8::Local<v8::Context> context);
10221028
void UntrackContext(v8::Local<v8::Context> context);
10231029

src/js_native_api_v8.cc

+2-5
Original file line numberDiff line numberDiff line change
@@ -968,11 +968,8 @@ napi_define_class(napi_env env,
968968
env, p->setter, p->data, &setter_tpl));
969969
}
970970

971-
tpl->PrototypeTemplate()->SetAccessorProperty(property_name,
972-
getter_tpl,
973-
setter_tpl,
974-
attributes,
975-
v8::AccessControl::DEFAULT);
971+
tpl->PrototypeTemplate()->SetAccessorProperty(
972+
property_name, getter_tpl, setter_tpl, attributes);
976973
} else if (p->method != nullptr) {
977974
v8::Local<v8::FunctionTemplate> t;
978975
STATUS_CALL(v8impl::FunctionCallbackWrapper::NewTemplate(

src/node_builtins.cc

+32-31
Original file line numberDiff line numberDiff line change
@@ -680,37 +680,38 @@ void BuiltinLoader::CreatePerIsolateProperties(IsolateData* isolate_data,
680680
Local<ObjectTemplate> target) {
681681
Isolate* isolate = isolate_data->isolate();
682682

683-
target->SetAccessor(isolate_data->config_string(),
684-
ConfigStringGetter,
685-
nullptr,
686-
Local<Value>(),
687-
DEFAULT,
688-
None,
689-
SideEffectType::kHasNoSideEffect);
690-
691-
target->SetAccessor(FIXED_ONE_BYTE_STRING(isolate, "builtinIds"),
692-
BuiltinIdsGetter,
693-
nullptr,
694-
Local<Value>(),
695-
DEFAULT,
696-
None,
697-
SideEffectType::kHasNoSideEffect);
698-
699-
target->SetAccessor(FIXED_ONE_BYTE_STRING(isolate, "builtinCategories"),
700-
GetBuiltinCategories,
701-
nullptr,
702-
Local<Value>(),
703-
DEFAULT,
704-
None,
705-
SideEffectType::kHasNoSideEffect);
706-
707-
target->SetAccessor(FIXED_ONE_BYTE_STRING(isolate, "natives"),
708-
GetNatives,
709-
nullptr,
710-
Local<Value>(),
711-
DEFAULT,
712-
None,
713-
SideEffectType::kHasNoSideEffect);
683+
target->SetNativeDataProperty(isolate_data->config_string(),
684+
ConfigStringGetter,
685+
nullptr,
686+
Local<Value>(),
687+
None,
688+
DEFAULT,
689+
SideEffectType::kHasNoSideEffect);
690+
691+
target->SetNativeDataProperty(FIXED_ONE_BYTE_STRING(isolate, "builtinIds"),
692+
BuiltinIdsGetter,
693+
nullptr,
694+
Local<Value>(),
695+
None,
696+
DEFAULT,
697+
SideEffectType::kHasNoSideEffect);
698+
699+
target->SetNativeDataProperty(
700+
FIXED_ONE_BYTE_STRING(isolate, "builtinCategories"),
701+
GetBuiltinCategories,
702+
nullptr,
703+
Local<Value>(),
704+
None,
705+
DEFAULT,
706+
SideEffectType::kHasNoSideEffect);
707+
708+
target->SetNativeDataProperty(FIXED_ONE_BYTE_STRING(isolate, "natives"),
709+
GetNatives,
710+
nullptr,
711+
Local<Value>(),
712+
None,
713+
DEFAULT,
714+
SideEffectType::kHasNoSideEffect);
714715

715716
SetMethod(isolate, target, "getCacheUsage", BuiltinLoader::GetCacheUsage);
716717
SetMethod(isolate, target, "compileFunction", BuiltinLoader::CompileFunction);

0 commit comments

Comments
 (0)