Skip to content
Draft
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
7,055 changes: 7,037 additions & 18 deletions package-lock.json

Large diffs are not rendered by default.

38 changes: 20 additions & 18 deletions src/maluuba/speech/nodejs/enhybriddistance/enhybriddistance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace nodejs
{
auto isolate = info.GetIsolate();
isolate->ThrowException(v8::Exception::Error(
v8::String::NewFromUtf8(isolate, "Object is immutable, setters not allowed.")));
v8::String::NewFromUtf8(isolate, "Object is immutable, setters not allowed.").ToLocalChecked()));
return;
}
}
Expand All @@ -53,15 +53,15 @@ namespace nodejs
v8::Local<v8::Context> context = isolate->GetCurrentContext();

auto tpl = v8::FunctionTemplate::New(isolate, New);
tpl->SetClassName(v8::String::NewFromUtf8(isolate, "EnHybridDistance"));
tpl->SetClassName(v8::String::NewFromUtf8(isolate, "EnHybridDistance").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "phoneticWeightPercentage"), getphoneticWeightPercentage, setThrow);
tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "phoneticWeightPercentage").ToLocalChecked(), getphoneticWeightPercentage, setThrow);

NODE_SET_PROTOTYPE_METHOD(tpl, "distance", Distance);

s_constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked());
s_type.Reset(isolate, tpl);
exports->Set(context, v8::String::NewFromUtf8(isolate, "EnHybridDistance"), tpl->GetFunction(context).ToLocalChecked());
exports->Set(context, v8::String::NewFromUtf8(isolate, "EnHybridDistance").ToLocalChecked(), tpl->GetFunction(context).ToLocalChecked());
}

void
Expand All @@ -73,7 +73,7 @@ namespace nodejs
if (args.IsConstructCall()) {
if (args.Length() < 1) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Expected 1 argument.")));
v8::String::NewFromUtf8(isolate, "Expected 1 argument.").ToLocalChecked()));
return;
}

Expand All @@ -85,12 +85,12 @@ namespace nodejs
args.GetReturnValue().Set(args.This());
} catch (const std::exception& e) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Invalid phoneticWeightPercentage argument")));
v8::String::NewFromUtf8(isolate, "Invalid phoneticWeightPercentage argument").ToLocalChecked()));
return;
}
} else {
isolate->ThrowException(v8::Exception::SyntaxError(
v8::String::NewFromUtf8(isolate, "Not invoked as constructor, change to: `new EnHybridDistance()`")));
v8::String::NewFromUtf8(isolate, "Not invoked as constructor, change to: `new EnHybridDistance()`").ToLocalChecked()));
return;
}
}
Expand All @@ -99,40 +99,42 @@ namespace nodejs
EnHybridDistance::Distance(const v8::FunctionCallbackInfo<v8::Value>& args)
{
auto isolate = args.GetIsolate();
v8::Local<v8::Context> context = isolate->GetCurrentContext();


if (args.Length() < 2) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Expected 2 arguments.")));
v8::String::NewFromUtf8(isolate, "Expected 2 arguments.").ToLocalChecked()));
return;
}

if (!args[0]->IsObject() || !args[1]->IsObject()) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Expected arguments to be objects.")));
v8::String::NewFromUtf8(isolate, "Expected arguments to be objects.").ToLocalChecked()));
return;
}

auto obj = ObjectWrap::Unwrap<EnHybridDistance>(args.Holder());
auto phrase_key = v8::String::NewFromUtf8(isolate, "phrase");
auto pronunciation_key = v8::String::NewFromUtf8(isolate, "pronunciation");
auto phrase_key = v8::String::NewFromUtf8(isolate, "phrase").ToLocalChecked();
auto pronunciation_key = v8::String::NewFromUtf8(isolate, "pronunciation").ToLocalChecked();
auto en_pronunciation_type = EnPronunciation::type(isolate);
try {
auto a = args[0].As<v8::Object>();
auto b = args[1].As<v8::Object>();
auto a_wrap_string = a->Get(phrase_key);
auto b_wrap_string = b->Get(phrase_key);
auto a_wrap_string = a->Get(context, phrase_key).ToLocalChecked();
auto b_wrap_string = b->Get(context, phrase_key).ToLocalChecked();
if (!a_wrap_string->IsString() || !b_wrap_string->IsString()) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Expected 'phrase' to be strings.")));
v8::String::NewFromUtf8(isolate, "Expected 'phrase' to be strings.").ToLocalChecked()));
return;
}
std::string a_phrase{*v8::String::Utf8Value{isolate, a_wrap_string}};
std::string b_phrase{*v8::String::Utf8Value{isolate, b_wrap_string}};
auto a_wrap_pronunciation = a->Get(pronunciation_key);
auto b_wrap_pronunciation = b->Get(pronunciation_key);
auto a_wrap_pronunciation = a->Get(context, pronunciation_key).ToLocalChecked();
auto b_wrap_pronunciation = b->Get(context, pronunciation_key).ToLocalChecked();
if (!en_pronunciation_type->HasInstance(a_wrap_pronunciation) || !en_pronunciation_type->HasInstance(b_wrap_pronunciation)) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Expected 'pronunciation' to be EnPronunciation.")));
v8::String::NewFromUtf8(isolate, "Expected 'pronunciation' to be EnPronunciation.").ToLocalChecked()));
return;
}
auto a_pronunciation = node::ObjectWrap::Unwrap<EnPronunciation>(a_wrap_pronunciation.As<v8::Object>())->pronunciation();
Expand All @@ -142,7 +144,7 @@ namespace nodejs
args.GetReturnValue().Set(v8::Number::New(isolate, distance));
} catch (const std::exception& e) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Expected arguments to contain valid 'phrase' and 'pronunciation' entries.")));
v8::String::NewFromUtf8(isolate, "Expected arguments to contain valid 'phrase' and 'pronunciation' entries.").ToLocalChecked()));
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ namespace nodejs
v8::Local<v8::Context> context = isolate->GetCurrentContext();

auto tpl = v8::FunctionTemplate::New(isolate, New);
tpl->SetClassName(v8::String::NewFromUtf8(isolate, "EnPhoneticDistance"));
tpl->SetClassName(v8::String::NewFromUtf8(isolate, "EnPhoneticDistance").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);

NODE_SET_PROTOTYPE_METHOD(tpl, "distance", Distance);

s_constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked());
s_type.Reset(isolate, tpl);
exports->Set(context, v8::String::NewFromUtf8(isolate, "EnPhoneticDistance"), tpl->GetFunction(context).ToLocalChecked());
exports->Set(context, v8::String::NewFromUtf8(isolate, "EnPhoneticDistance").ToLocalChecked(), tpl->GetFunction(context).ToLocalChecked());
}

void
Expand All @@ -55,7 +55,7 @@ namespace nodejs
args.GetReturnValue().Set(args.This());
} else {
isolate->ThrowException(v8::Exception::SyntaxError(
v8::String::NewFromUtf8(isolate, "Not invoked as constructor, change to: `new EnPhoneticDistance()`")));
v8::String::NewFromUtf8(isolate, "Not invoked as constructor, change to: `new EnPhoneticDistance()`").ToLocalChecked()));
return;
}
}
Expand All @@ -67,14 +67,14 @@ namespace nodejs

if (args.Length() < 2) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Expected 2 arguments.")));
v8::String::NewFromUtf8(isolate, "Expected 2 arguments.").ToLocalChecked()));
return;
}

auto enPronunciationType = EnPronunciation::type(isolate);
if (!enPronunciationType->HasInstance(args[0]) || !enPronunciationType->HasInstance(args[1])) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Expected arguments to be EnPronunciation.")));
v8::String::NewFromUtf8(isolate, "Expected arguments to be EnPronunciation.").ToLocalChecked()));
return;
}

Expand Down
12 changes: 6 additions & 6 deletions src/maluuba/speech/nodejs/enpronouncer/enpronouncer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ namespace nodejs
v8::Local<v8::Context> context = isolate->GetCurrentContext();

auto tpl = v8::FunctionTemplate::New(isolate, New);
tpl->SetClassName(v8::String::NewFromUtf8(isolate, "EnPronouncer"));
tpl->SetClassName(v8::String::NewFromUtf8(isolate, "EnPronouncer").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);

NODE_SET_PROTOTYPE_METHOD(tpl, "pronounce", Pronounce);

s_constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked());
exports->Set(context, v8::String::NewFromUtf8(isolate, "EnPronouncer"), tpl->GetFunction(context).ToLocalChecked());
exports->Set(context, v8::String::NewFromUtf8(isolate, "EnPronouncer").ToLocalChecked(), tpl->GetFunction(context).ToLocalChecked());
}

void
Expand All @@ -47,7 +47,7 @@ namespace nodejs
args.GetReturnValue().Set(args.This());
} else {
isolate->ThrowException(v8::Exception::SyntaxError(
v8::String::NewFromUtf8(isolate, "Not invoked as constructor, change to: `new EnPronouncer()`")));
v8::String::NewFromUtf8(isolate, "Not invoked as constructor, change to: `new EnPronouncer()`").ToLocalChecked()));
return;
}
}
Expand All @@ -59,13 +59,13 @@ namespace nodejs

if (args.Length() < 1) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Expected 1 argument.")));
v8::String::NewFromUtf8(isolate, "Expected 1 argument.").ToLocalChecked()));
return;
}

if (!args[0]->IsString()) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Expected argument to be a string.")));
v8::String::NewFromUtf8(isolate, "Expected argument to be a string.").ToLocalChecked()));
return;
}

Expand All @@ -82,7 +82,7 @@ namespace nodejs
args.GetReturnValue().Set(instance);
} catch (const std::exception& e) {
isolate->ThrowException(v8::Exception::Error(
v8::String::NewFromUtf8(isolate, e.what())));
v8::String::NewFromUtf8(isolate, e.what()).ToLocalChecked()));
return;
}
}
Expand Down
38 changes: 20 additions & 18 deletions src/maluuba/speech/nodejs/enpronunciation/enpronunciation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ namespace nodejs
auto isolate = info.GetIsolate();
auto obj = node::ObjectWrap::Unwrap<nodejs::EnPronunciation>(info.Holder());
auto ipa = obj->pronunciation().to_ipa();
info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, ipa.data(), v8::String::kNormalString, ipa.length()));
info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, ipa.data(), v8::NewStringType::kNormal, ipa.length()).ToLocalChecked());
}

void
getPhones(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info)
{
auto isolate = info.GetIsolate();

auto obj = node::ObjectWrap::Unwrap<nodejs::EnPronunciation>(info.Holder());
const auto& phones = obj->pronunciation();
auto array = v8::Array::New(isolate);
Expand All @@ -38,7 +39,7 @@ namespace nodejs
const auto argc = 1;
v8::Local<v8::Value> argv[argc] = { v8::External::New(isolate, obj) };
auto instance = Phone::constructor(isolate)->NewInstance(context, argc, argv).ToLocalChecked();
array->Set(i++, instance);
array->Set(context, i++, instance);
}
info.GetReturnValue().Set(array);
}
Expand All @@ -48,7 +49,7 @@ namespace nodejs
{
auto isolate = info.GetIsolate();
isolate->ThrowException(v8::Exception::Error(
v8::String::NewFromUtf8(isolate, "Object is immutable, setters not allowed.")));
v8::String::NewFromUtf8(isolate, "Object is immutable, setters not allowed.").ToLocalChecked()));
return;
}
}
Expand Down Expand Up @@ -79,19 +80,19 @@ namespace nodejs
v8::Local<v8::Context> context = isolate->GetCurrentContext();

auto tpl = v8::FunctionTemplate::New(isolate, New);
tpl->SetClassName(v8::String::NewFromUtf8(isolate, "EnPronunciation"));
tpl->SetClassName(v8::String::NewFromUtf8(isolate, "EnPronunciation").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "ipa"), getIpa, setThrow);
tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "phones"), getPhones, setThrow);
tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "ipa").ToLocalChecked(), getIpa, setThrow);
tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "phones").ToLocalChecked(), getPhones, setThrow);

s_constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked());
s_type.Reset(isolate, tpl);

auto otpl = v8::ObjectTemplate::New(isolate);
otpl->Set(v8::String::NewFromUtf8(isolate, "fromIpa"), v8::FunctionTemplate::New(isolate, FromIpa));
otpl->Set(v8::String::NewFromUtf8(isolate, "fromArpabet"), v8::FunctionTemplate::New(isolate, FromArpabet));
otpl->Set(v8::String::NewFromUtf8(isolate, "fromIpa").ToLocalChecked(), v8::FunctionTemplate::New(isolate, FromIpa));
otpl->Set(v8::String::NewFromUtf8(isolate, "fromArpabet").ToLocalChecked(), v8::FunctionTemplate::New(isolate, FromArpabet));

exports->Set(context, v8::String::NewFromUtf8(isolate, "EnPronunciation"),
exports->Set(context, v8::String::NewFromUtf8(isolate, "EnPronunciation").ToLocalChecked(),
otpl->NewInstance(context).ToLocalChecked());
}

Expand All @@ -102,7 +103,7 @@ namespace nodejs

if (!args[0]->IsExternal()) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Expected use as EnPronunciation.fromIpa() or similar.")));
v8::String::NewFromUtf8(isolate, "Expected use as EnPronunciation.fromIpa() or similar.").ToLocalChecked()));
return;
}

Expand All @@ -120,13 +121,13 @@ namespace nodejs

if (args.Length() < 1) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Expected 1 argument.")));
v8::String::NewFromUtf8(isolate, "Expected 1 argument.").ToLocalChecked()));
return;
}

if (!args[0]->IsString()) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Expected argument to be a string.")));
v8::String::NewFromUtf8(isolate, "Expected argument to be a string.").ToLocalChecked()));
return;
}

Expand All @@ -142,7 +143,7 @@ namespace nodejs
args.GetReturnValue().Set(instance);
} catch (const std::exception& e) {
isolate->ThrowException(v8::Exception::Error(
v8::String::NewFromUtf8(isolate, e.what())));
v8::String::NewFromUtf8(isolate, e.what()).ToLocalChecked()));
return;
}
}
Expand All @@ -151,26 +152,27 @@ namespace nodejs
EnPronunciation::FromArpabet(const v8::FunctionCallbackInfo<v8::Value>& args)
{
auto isolate = args.GetIsolate();
auto context = isolate->GetCurrentContext();

if (args.Length() < 1) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Expected 1 argument.")));
v8::String::NewFromUtf8(isolate, "Expected 1 argument.").ToLocalChecked()));
return;
}

if (!args[0]->IsArray()) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Expected argument to be a string[].")));
v8::String::NewFromUtf8(isolate, "Expected argument to be a string[].").ToLocalChecked()));
return;
}

auto array_arg = args[0].As<v8::Array>();
std::vector<std::string> arpabet;
for (uint32_t i = 0; i < array_arg->Length(); ++i) {
auto wrap_phoneme = array_arg->Get(i);
auto wrap_phoneme = array_arg->Get(context, i).ToLocalChecked();
if (!wrap_phoneme->IsString()) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Expected argument to be a string[].")));
v8::String::NewFromUtf8(isolate, "Expected argument to be a string[].").ToLocalChecked()));
return;
}
v8::String::Utf8Value phoneme{isolate, wrap_phoneme};
Expand All @@ -188,7 +190,7 @@ namespace nodejs
args.GetReturnValue().Set(instance);
} catch (const std::exception& e) {
isolate->ThrowException(v8::Exception::Error(
v8::String::NewFromUtf8(isolate, e.what())));
v8::String::NewFromUtf8(isolate, e.what()).ToLocalChecked()));
return;
}
}
Expand Down
Loading