Skip to content

Commit 894bab4

Browse files
committed
Fix a couple of small bugs with Node-API to JSI adapter
1 parent b3dbf37 commit 894bab4

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

Core/Node-API-JSI/Include/napi/napi-inl.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ inline Function Function::New(napi_env env,
13441344
Callable cb,
13451345
const char* utf8name,
13461346
void* data) {
1347-
auto function{jsi::Function::createFromHostFunction(env->rt, jsi::PropNameID::forUtf8(env->rt, utf8name), 0,
1347+
auto function{jsi::Function::createFromHostFunction(env->rt, jsi::PropNameID::forUtf8(env->rt, utf8name == nullptr ? "" : utf8name), 0,
13481348
[env, cb{std::move(cb)}, data](jsi::Runtime&, const jsi::Value& thisVal, const jsi::Value* args, size_t count) -> jsi::Value {
13491349
typedef decltype(cb(CallbackInfo({}, {}, {}, {}, {}, {}))) ReturnType;
13501350
return details::Function<Callable, ReturnType>::Callback(env, thisVal, args, count, data, cb);
@@ -1569,7 +1569,12 @@ inline Error::Error(napi_env env, jsi::Object object)
15691569
: ObjectReference{env, std::move(object)} {
15701570
}
15711571

1572-
inline Error::Error(Error&& other) : ObjectReference(other) {
1572+
inline Error::Error(napi_env env, jsi::Value value)
1573+
: ObjectReference{env, value.getObject(env->rt)} {
1574+
}
1575+
1576+
inline Error::Error(Error&& other)
1577+
: ObjectReference(other) {
15731578
}
15741579

15751580
inline Error& Error::operator =(Error&& other) {
@@ -1623,6 +1628,10 @@ inline TypeError::TypeError(napi_env env, jsi::Object object)
16231628
: Error{env, std::move(object)} {
16241629
}
16251630

1631+
inline TypeError::TypeError(napi_env env, jsi::Value value)
1632+
: Error{env, std::move(value)} {
1633+
}
1634+
16261635
inline RangeError RangeError::New(napi_env env, const char* message) {
16271636
return Error::New<RangeError, const char*>(env, message, "RangeError");
16281637
}
@@ -1635,6 +1644,10 @@ inline RangeError::RangeError(napi_env env, jsi::Object object)
16351644
: Error{env, std::move(object)} {
16361645
}
16371646

1647+
inline RangeError::RangeError(napi_env env, jsi::Value value)
1648+
: Error{env, std::move(value)} {
1649+
}
1650+
16381651
////////////////////////////////////////////////////////////////////////////////
16391652
// Reference<T> class
16401653
////////////////////////////////////////////////////////////////////////////////

Core/Node-API-JSI/Include/napi/napi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,7 @@ namespace Napi {
10501050
public:
10511051
FunctionReference();
10521052
FunctionReference(napi_env env, jsi::Function function);
1053+
FunctionReference(napi_env env, jsi::Value value);
10531054

10541055
// A reference can be moved but cannot be copied.
10551056
FunctionReference(Reference<Function>&& other);
@@ -1139,6 +1140,7 @@ namespace Napi {
11391140

11401141
Error();
11411142
Error(napi_env env, jsi::Object object);
1143+
Error(napi_env env, jsi::Value value);
11421144

11431145
// An error can be moved or copied.
11441146
Error(Error&& other);
@@ -1168,6 +1170,7 @@ namespace Napi {
11681170

11691171
TypeError();
11701172
TypeError(napi_env env, jsi::Object object);
1173+
TypeError(napi_env env, jsi::Value value);
11711174
};
11721175

11731176
class RangeError : public Error {
@@ -1177,6 +1180,7 @@ namespace Napi {
11771180

11781181
RangeError();
11791182
RangeError(napi_env env, jsi::Object object);
1183+
RangeError(napi_env env, jsi::Value value);
11801184
};
11811185

11821186
class CallbackInfo {

0 commit comments

Comments
 (0)