Skip to content

Commit

Permalink
Adding a setter for score
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricioszabo committed Jun 3, 2024
1 parent d2a885b commit a46a625
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/bindings/text-buffer-wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class RegexWrapper : public ObjectWrap<RegexWrapper> {

static const Regex *regex_from_js(const Napi::Value &value) {
auto env = value.Env();

String js_pattern;
bool ignore_case = false;
bool unicode = false;
Expand Down Expand Up @@ -158,7 +158,9 @@ class SubsequenceMatchWrapper : public ObjectWrap<SubsequenceMatchWrapper> {
Function func = DefineClass(env, "SubsequenceMatch", {
InstanceAccessor<&SubsequenceMatchWrapper::get_word>("word", static_cast<napi_property_attributes>(napi_enumerable | napi_configurable)),
InstanceAccessor<&SubsequenceMatchWrapper::get_match_indices>("matchIndices", static_cast<napi_property_attributes>(napi_enumerable | napi_configurable)),
InstanceAccessor<&SubsequenceMatchWrapper::get_score>("score", static_cast<napi_property_attributes>(napi_enumerable | napi_configurable)),
InstanceAccessor<&SubsequenceMatchWrapper::get_score, &SubsequenceMatchWrapper::set_score>(
"score", static_cast<napi_property_attributes>(napi_enumerable | napi_configurable)
),
});

constructor.Reset(func, 1);
Expand Down Expand Up @@ -195,6 +197,15 @@ class SubsequenceMatchWrapper : public ObjectWrap<SubsequenceMatchWrapper> {
return Number::New(info.Env(), this->match.score);
}

void set_score(const CallbackInfo &info, const Napi::Value &value) {
if (value.IsNumber()) {
this->match.score = value.As<Number>().DoubleValue();
} else {
auto env = info.Env();
Error::New(env, "Expected a number.").ThrowAsJavaScriptException();
}
}

TextBuffer::SubsequenceMatch match;
static FunctionReference constructor;
};
Expand Down

0 comments on commit a46a625

Please sign in to comment.