Skip to content

Commit

Permalink
src: fix compatility with upcoming V8 12.1 APIs
Browse files Browse the repository at this point in the history
PR-URL: nodejs#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>
  • Loading branch information
zcbenz authored and martenrichter committed Nov 26, 2023
1 parent f12fad8 commit 0ac07c0
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 41 deletions.
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

0 comments on commit 0ac07c0

Please sign in to comment.