Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: fix compatility with upcoming V8 12.1 APIs #50709

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -775,13 +775,18 @@ inline void Environment::ThrowRangeError(const char* errmsg) {
ThrowError(v8::Exception::RangeError, errmsg);
}

inline void Environment::ThrowError(
v8::Local<v8::Value> (*fun)(v8::Local<v8::String>),
const char* errmsg) {
inline void Environment::ThrowError(V8ExceptionConstructorOld fun,
const char* errmsg) {
v8::HandleScope handle_scope(isolate());
isolate()->ThrowException(fun(OneByteString(isolate(), errmsg)));
}

inline void Environment::ThrowError(V8ExceptionConstructorNew fun,
const char* errmsg) {
v8::HandleScope handle_scope(isolate());
isolate()->ThrowException(fun(OneByteString(isolate(), errmsg), {}));
}

inline void Environment::ThrowErrnoException(int errorno,
const char* syscall,
const char* message,
Expand Down
10 changes: 8 additions & 2 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -1016,8 +1016,14 @@ class Environment : public MemoryRetainer {
};

private:
inline void ThrowError(v8::Local<v8::Value> (*fun)(v8::Local<v8::String>),
const char* errmsg);
// V8 has changed the constructor of exceptions, support both APIs before Node
// updates to V8 12.1.
using V8ExceptionConstructorOld =
v8::Local<v8::Value> (*)(v8::Local<v8::String>);
using V8ExceptionConstructorNew =
v8::Local<v8::Value> (*)(v8::Local<v8::String>, v8::Local<v8::Value>);
inline void ThrowError(V8ExceptionConstructorOld fun, const char* errmsg);
inline void ThrowError(V8ExceptionConstructorNew fun, const char* errmsg);
void TrackContext(v8::Local<v8::Context> context);
void UntrackContext(v8::Local<v8::Context> context);

Expand Down
7 changes: 2 additions & 5 deletions src/js_native_api_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -968,11 +968,8 @@ napi_define_class(napi_env env,
env, p->setter, p->data, &setter_tpl));
}

tpl->PrototypeTemplate()->SetAccessorProperty(property_name,
getter_tpl,
setter_tpl,
attributes,
v8::AccessControl::DEFAULT);
tpl->PrototypeTemplate()->SetAccessorProperty(
property_name, getter_tpl, setter_tpl, attributes);
} else if (p->method != nullptr) {
v8::Local<v8::FunctionTemplate> t;
STATUS_CALL(v8impl::FunctionCallbackWrapper::NewTemplate(
Expand Down
63 changes: 32 additions & 31 deletions src/node_builtins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -680,37 +680,38 @@ void BuiltinLoader::CreatePerIsolateProperties(IsolateData* isolate_data,
Local<ObjectTemplate> target) {
Isolate* isolate = isolate_data->isolate();

target->SetAccessor(isolate_data->config_string(),
ConfigStringGetter,
nullptr,
Local<Value>(),
DEFAULT,
None,
SideEffectType::kHasNoSideEffect);

target->SetAccessor(FIXED_ONE_BYTE_STRING(isolate, "builtinIds"),
BuiltinIdsGetter,
nullptr,
Local<Value>(),
DEFAULT,
None,
SideEffectType::kHasNoSideEffect);

target->SetAccessor(FIXED_ONE_BYTE_STRING(isolate, "builtinCategories"),
GetBuiltinCategories,
nullptr,
Local<Value>(),
DEFAULT,
None,
SideEffectType::kHasNoSideEffect);

target->SetAccessor(FIXED_ONE_BYTE_STRING(isolate, "natives"),
GetNatives,
nullptr,
Local<Value>(),
DEFAULT,
None,
SideEffectType::kHasNoSideEffect);
target->SetNativeDataProperty(isolate_data->config_string(),
ConfigStringGetter,
nullptr,
Local<Value>(),
None,
DEFAULT,
SideEffectType::kHasNoSideEffect);

target->SetNativeDataProperty(FIXED_ONE_BYTE_STRING(isolate, "builtinIds"),
BuiltinIdsGetter,
nullptr,
Local<Value>(),
None,
DEFAULT,
SideEffectType::kHasNoSideEffect);

target->SetNativeDataProperty(
FIXED_ONE_BYTE_STRING(isolate, "builtinCategories"),
GetBuiltinCategories,
nullptr,
Local<Value>(),
None,
DEFAULT,
SideEffectType::kHasNoSideEffect);

target->SetNativeDataProperty(FIXED_ONE_BYTE_STRING(isolate, "natives"),
GetNatives,
nullptr,
Local<Value>(),
None,
DEFAULT,
SideEffectType::kHasNoSideEffect);

SetMethod(isolate, target, "getCacheUsage", BuiltinLoader::GetCacheUsage);
SetMethod(isolate, target, "compileFunction", BuiltinLoader::CompileFunction);
Expand Down