Skip to content

Commit a11132b

Browse files
authored
Fix napi-jsi coercion functions (#1153)
1 parent 5859ffa commit a11132b

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Dependencies/napi/napi-jsi/include/napi/napi-inl.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,11 @@ inline T Value::As() const {
242242
}
243243

244244
inline Boolean Value::ToBoolean() const {
245-
// TODO: need to coerce if not the right type
246-
return Boolean::New(_env, _value.getBool());
245+
return {_env, _env->boolean_func.call(_env->rt, _value)};
247246
}
248247

249248
inline Number Value::ToNumber() const {
250-
// TODO: need to coerce if not the right type
251-
return Number::New(_env, _value.getNumber());
249+
return {_env, _env->number_func.call(_env->rt, _value)};
252250
}
253251

254252
inline String Value::ToString() const {

Dependencies/napi/napi-jsi/include/napi/napi.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ struct napi_env__ {
5959
rt.global().getPropertyAsFunction(rt, "Int32Array"),
6060
rt.global().getPropertyAsFunction(rt, "Uint32Array"),
6161
rt.global().getPropertyAsFunction(rt, "Float32Array"),
62-
rt.global().getPropertyAsFunction(rt, "Float64Array")} {
62+
rt.global().getPropertyAsFunction(rt, "Float64Array")}
63+
, boolean_func{rt.global().getPropertyAsFunction(rt, "Boolean")}
64+
, number_func{rt.global().getPropertyAsFunction(rt, "Number")} {
6365
}
6466

6567
facebook::jsi::Runtime& rt;
@@ -68,6 +70,8 @@ struct napi_env__ {
6870
facebook::jsi::Function array_buffer_ctor;
6971
facebook::jsi::Function promise_ctor;
7072
facebook::jsi::Function typed_array_ctor[9];
73+
facebook::jsi::Function boolean_func;
74+
facebook::jsi::Function number_func;
7175

7276
facebook::jsi::Value last_exception;
7377
};

0 commit comments

Comments
 (0)