diff --git a/src/maluuba/speech/nodejs/enhybriddistance/enhybriddistance.cpp b/src/maluuba/speech/nodejs/enhybriddistance/enhybriddistance.cpp index c930505..b847b3c 100644 --- a/src/maluuba/speech/nodejs/enhybriddistance/enhybriddistance.cpp +++ b/src/maluuba/speech/nodejs/enhybriddistance/enhybriddistance.cpp @@ -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.", v8::NewStringType::kNormal).ToLocalChecked())); return; } } @@ -53,15 +53,15 @@ namespace nodejs v8::Local context = isolate->GetCurrentContext(); auto tpl = v8::FunctionTemplate::New(isolate, New); - tpl->SetClassName(v8::String::NewFromUtf8(isolate, "EnHybridDistance")); + tpl->SetClassName(v8::String::NewFromUtf8(isolate, "EnHybridDistance", v8::NewStringType::kNormal).ToLocalChecked()); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "phoneticWeightPercentage"), getphoneticWeightPercentage, setThrow); + tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "phoneticWeightPercentage", v8::NewStringType::kNormal).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", v8::NewStringType::kNormal).ToLocalChecked(), tpl->GetFunction(context).ToLocalChecked()); } void @@ -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.", v8::NewStringType::kNormal).ToLocalChecked())); return; } @@ -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", v8::NewStringType::kNormal).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()`", v8::NewStringType::kNormal).ToLocalChecked())); return; } } @@ -99,40 +99,42 @@ namespace nodejs EnHybridDistance::Distance(const v8::FunctionCallbackInfo& args) { auto isolate = args.GetIsolate(); + v8::Local 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.", v8::NewStringType::kNormal).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.", v8::NewStringType::kNormal).ToLocalChecked())); return; } auto obj = ObjectWrap::Unwrap(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", v8::NewStringType::kNormal).ToLocalChecked(); + auto pronunciation_key = v8::String::NewFromUtf8(isolate, "pronunciation", v8::NewStringType::kNormal).ToLocalChecked(); auto en_pronunciation_type = EnPronunciation::type(isolate); try { auto a = args[0].As(); auto b = args[1].As(); - 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.", v8::NewStringType::kNormal).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.", v8::NewStringType::kNormal).ToLocalChecked())); return; } auto a_pronunciation = node::ObjectWrap::Unwrap(a_wrap_pronunciation.As())->pronunciation(); @@ -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.", v8::NewStringType::kNormal).ToLocalChecked())); return; } } diff --git a/src/maluuba/speech/nodejs/enphoneticdistance/enphoneticdistance.cpp b/src/maluuba/speech/nodejs/enphoneticdistance/enphoneticdistance.cpp index 090fb04..efacfdd 100644 --- a/src/maluuba/speech/nodejs/enphoneticdistance/enphoneticdistance.cpp +++ b/src/maluuba/speech/nodejs/enphoneticdistance/enphoneticdistance.cpp @@ -33,14 +33,14 @@ namespace nodejs v8::Local context = isolate->GetCurrentContext(); auto tpl = v8::FunctionTemplate::New(isolate, New); - tpl->SetClassName(v8::String::NewFromUtf8(isolate, "EnPhoneticDistance")); + tpl->SetClassName(v8::String::NewFromUtf8(isolate, "EnPhoneticDistance", v8::NewStringType::kNormal).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", v8::NewStringType::kNormal).ToLocalChecked(), tpl->GetFunction(context).ToLocalChecked()); } void @@ -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()`", v8::NewStringType::kNormal).ToLocalChecked())); return; } } @@ -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.", v8::NewStringType::kNormal).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.", v8::NewStringType::kNormal).ToLocalChecked())); return; } diff --git a/src/maluuba/speech/nodejs/enpronouncer/enpronouncer.cpp b/src/maluuba/speech/nodejs/enpronouncer/enpronouncer.cpp index 4135622..0fb94b6 100644 --- a/src/maluuba/speech/nodejs/enpronouncer/enpronouncer.cpp +++ b/src/maluuba/speech/nodejs/enpronouncer/enpronouncer.cpp @@ -26,13 +26,13 @@ namespace nodejs v8::Local context = isolate->GetCurrentContext(); auto tpl = v8::FunctionTemplate::New(isolate, New); - tpl->SetClassName(v8::String::NewFromUtf8(isolate, "EnPronouncer")); + tpl->SetClassName(v8::String::NewFromUtf8(isolate, "EnPronouncer", v8::NewStringType::kNormal).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", v8::NewStringType::kNormal).ToLocalChecked(), tpl->GetFunction(context).ToLocalChecked()); } void @@ -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()`", v8::NewStringType::kNormal).ToLocalChecked())); return; } } @@ -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.", v8::NewStringType::kNormal).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.", v8::NewStringType::kNormal).ToLocalChecked())); return; } @@ -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(), v8::NewStringType::kNormal).ToLocalChecked())); return; } } diff --git a/src/maluuba/speech/nodejs/enpronunciation/enpronunciation.cpp b/src/maluuba/speech/nodejs/enpronunciation/enpronunciation.cpp index c4e3dac..ec2c548 100644 --- a/src/maluuba/speech/nodejs/enpronunciation/enpronunciation.cpp +++ b/src/maluuba/speech/nodejs/enpronunciation/enpronunciation.cpp @@ -19,13 +19,14 @@ namespace nodejs auto isolate = info.GetIsolate(); auto obj = node::ObjectWrap::Unwrap(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 property, const v8::PropertyCallbackInfo& info) { auto isolate = info.GetIsolate(); + auto obj = node::ObjectWrap::Unwrap(info.Holder()); const auto& phones = obj->pronunciation(); auto array = v8::Array::New(isolate); @@ -38,7 +39,7 @@ namespace nodejs const auto argc = 1; v8::Local 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); } @@ -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.", v8::NewStringType::kNormal).ToLocalChecked())); return; } } @@ -79,19 +80,19 @@ namespace nodejs v8::Local context = isolate->GetCurrentContext(); auto tpl = v8::FunctionTemplate::New(isolate, New); - tpl->SetClassName(v8::String::NewFromUtf8(isolate, "EnPronunciation")); + tpl->SetClassName(v8::String::NewFromUtf8(isolate, "EnPronunciation", v8::NewStringType::kNormal).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", v8::NewStringType::kNormal).ToLocalChecked(), getIpa, setThrow); + tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "phones", v8::NewStringType::kNormal).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", v8::NewStringType::kNormal).ToLocalChecked(), v8::FunctionTemplate::New(isolate, FromIpa)); + otpl->Set(v8::String::NewFromUtf8(isolate, "fromArpabet", v8::NewStringType::kNormal).ToLocalChecked(), v8::FunctionTemplate::New(isolate, FromArpabet)); - exports->Set(context, v8::String::NewFromUtf8(isolate, "EnPronunciation"), + exports->Set(context, v8::String::NewFromUtf8(isolate, "EnPronunciation", v8::NewStringType::kNormal).ToLocalChecked(), otpl->NewInstance(context).ToLocalChecked()); } @@ -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.", v8::NewStringType::kNormal).ToLocalChecked())); return; } @@ -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.", v8::NewStringType::kNormal).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.", v8::NewStringType::kNormal).ToLocalChecked())); return; } @@ -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(), v8::NewStringType::kNormal).ToLocalChecked())); return; } } @@ -151,26 +152,27 @@ namespace nodejs EnPronunciation::FromArpabet(const v8::FunctionCallbackInfo& 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.", v8::NewStringType::kNormal).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[].", v8::NewStringType::kNormal).ToLocalChecked())); return; } auto array_arg = args[0].As(); std::vector 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[].", v8::NewStringType::kNormal).ToLocalChecked())); return; } v8::String::Utf8Value phoneme{isolate, wrap_phoneme}; @@ -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(), v8::NewStringType::kNormal).ToLocalChecked())); return; } } diff --git a/src/maluuba/speech/nodejs/fuzzymatcher.hpp b/src/maluuba/speech/nodejs/fuzzymatcher.hpp index edb6ff3..ca159be 100644 --- a/src/maluuba/speech/nodejs/fuzzymatcher.hpp +++ b/src/maluuba/speech/nodejs/fuzzymatcher.hpp @@ -70,7 +70,7 @@ namespace nodejs auto isolate = exports->GetIsolate(); v8::Local context = isolate->GetCurrentContext(); - auto localClassName = v8::String::NewFromUtf8(isolate, className.data(), v8::String::kNormalString, className.length()); + auto localClassName = v8::String::NewFromUtf8(isolate, className.data(), v8::NewStringType::kNormal, className.length()).ToLocalChecked(); auto tpl = v8::FunctionTemplate::New(isolate, New); tpl->SetClassName(localClassName); tpl->InstanceTemplate()->SetInternalFieldCount(1); @@ -113,7 +113,7 @@ namespace nodejs std::vector targets; const auto argc = 1; for (uint32_t i = 0; i < arg_targets->Length(); ++i) { - auto obj = arg_targets->Get(i); + auto obj = arg_targets->Get(context, i).ToLocalChecked(); auto value = obj; if (!arg_extract.IsEmpty()) { v8::Local argv[argc] = { obj }; @@ -150,7 +150,7 @@ namespace nodejs std::vector targets; const auto argc = 1; for (uint32_t i = 0; i < arg_targets->Length(); ++i) { - auto obj = arg_targets->Get(i); + auto obj = arg_targets->Get(context, i).ToLocalChecked(); auto value = obj; if (!arg_extract.IsEmpty()) { v8::Local argv[argc] = { obj }; @@ -184,7 +184,7 @@ namespace nodejs std::vector targets; const auto argc = 1; for (uint32_t i = 0; i < arg_targets->Length(); ++i) { - auto obj = arg_targets->Get(i); + auto obj = arg_targets->Get(context, i).ToLocalChecked(); auto value = obj; if (!arg_extract.IsEmpty()) { v8::Local argv[argc] = { obj }; @@ -219,7 +219,7 @@ namespace nodejs std::vector targets; const auto argc = 1; for (uint32_t i = 0; i < arg_targets->Length(); ++i) { - auto obj = arg_targets->Get(i); + auto obj = arg_targets->Get(context, i).ToLocalChecked(); auto value = obj; if (!arg_extract.IsEmpty()) { v8::Local argv[argc] = { obj }; @@ -259,20 +259,20 @@ namespace nodejs if (args.IsConstructCall()) { if (args.Length() < 2) { isolate->ThrowException(v8::Exception::TypeError( - v8::String::NewFromUtf8(isolate, "Expected at least 2 arguments."))); + v8::String::NewFromUtf8(isolate, "Expected at least 2 arguments.", v8::NewStringType::kNormal).ToLocalChecked())); return; } if (!args[0]->IsArray()) { isolate->ThrowException(v8::Exception::TypeError( - v8::String::NewFromUtf8(isolate, "Expected 'targets' argument to be an Object[]."))); + v8::String::NewFromUtf8(isolate, "Expected 'targets' argument to be an Object[].", v8::NewStringType::kNormal).ToLocalChecked())); return; } v8::Local arg_extract{}; if (args.Length() > 2) { if (!args[2]->IsFunction()) { isolate->ThrowException(v8::Exception::TypeError( - v8::String::NewFromUtf8(isolate, "Expected 'extract' argument to be a Function."))); + v8::String::NewFromUtf8(isolate, "Expected 'extract' argument to be a Function.", v8::NewStringType::kNormal).ToLocalChecked())); return; } arg_extract = args[2].As(); @@ -296,7 +296,7 @@ namespace nodejs // User provided JS distance function. if (!arg_distance->IsFunction()) { isolate->ThrowException(v8::Exception::TypeError( - v8::String::NewFromUtf8(isolate, "Expected 'distance' argument to be a Function."))); + v8::String::NewFromUtf8(isolate, "Expected 'distance' argument to be a Function.", v8::NewStringType::kNormal).ToLocalChecked())); return; } auto obj = make_fuzzy_matcher_js(isolate, arg_targets, arg_distance, arg_extract); @@ -306,12 +306,12 @@ namespace nodejs args.GetReturnValue().Set(args.This()); } catch (const std::exception& e) { isolate->ThrowException(v8::Exception::TypeError( - v8::String::NewFromUtf8(isolate, e.what()))); + v8::String::NewFromUtf8(isolate, e.what(), v8::NewStringType::kNormal).ToLocalChecked())); return; } } else { isolate->ThrowException(v8::Exception::SyntaxError( - v8::String::NewFromUtf8(isolate, "Not invoked as constructor, use `new`."))); + v8::String::NewFromUtf8(isolate, "Not invoked as constructor, use `new`.", v8::NewStringType::kNormal).ToLocalChecked())); return; } } @@ -340,7 +340,7 @@ 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.", v8::NewStringType::kNormal).ToLocalChecked())); return; } @@ -364,7 +364,7 @@ namespace nodejs } } catch(const std::exception& e) { isolate->ThrowException(v8::Exception::Error( - v8::String::NewFromUtf8(isolate, e.what()))); + v8::String::NewFromUtf8(isolate, e.what(), v8::NewStringType::kNormal).ToLocalChecked())); return; } } @@ -376,13 +376,13 @@ 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.", v8::NewStringType::kNormal).ToLocalChecked())); return; } if (!args[1]->IsNumber()) { isolate->ThrowException(v8::Exception::TypeError( - v8::String::NewFromUtf8(isolate, "Expected argument to be a number."))); + v8::String::NewFromUtf8(isolate, "Expected argument to be a number.", v8::NewStringType::kNormal).ToLocalChecked())); return; } @@ -407,7 +407,7 @@ namespace nodejs } } catch(const std::exception& e) { isolate->ThrowException(v8::Exception::Error( - v8::String::NewFromUtf8(isolate, e.what()))); + v8::String::NewFromUtf8(isolate, e.what(), v8::NewStringType::kNormal).ToLocalChecked())); return; } } @@ -419,13 +419,15 @@ 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.", v8::NewStringType::kNormal).ToLocalChecked())); return; } if (!args[1]->IsUint32()) { - isolate->ThrowException(v8::Exception::TypeError( - v8::String::NewFromUtf8(isolate, "Expected argument to be an integer."))); + v8::Local err = v8::Exception::TypeError( + v8::String::NewFromUtf8(isolate, "Expected argument to be an integer.", v8::NewStringType::kNormal).ToLocalChecked()); + isolate->ThrowException(err); + return; } @@ -446,12 +448,13 @@ namespace nodejs const auto argc = 1; v8::Local argv[argc] = { v8::External::New(isolate, wrap_match) }; auto instance = Match::constructor(isolate)->NewInstance(context, argc, argv).ToLocalChecked(); - wrap_matches->Set(i, instance); + wrap_matches->Set(context, i, instance); } args.GetReturnValue().Set(wrap_matches); } catch(const std::exception& e) { - isolate->ThrowException(v8::Exception::Error( - v8::String::NewFromUtf8(isolate, e.what()))); + v8::Local err = v8::Exception::Error( + v8::String::NewFromUtf8(isolate, e.what(), v8::NewStringType::kNormal).ToLocalChecked()); + isolate->ThrowException(err); return; } } @@ -462,19 +465,22 @@ namespace nodejs v8::Local context = isolate->GetCurrentContext(); if (args.Length() < 3) { - isolate->ThrowException(v8::Exception::TypeError( - v8::String::NewFromUtf8(isolate, "Expected 3 arguments."))); + v8::Local err = v8::Exception::TypeError( + v8::String::NewFromUtf8(isolate, "Expected 3 arguments.", v8::NewStringType::kNormal).ToLocalChecked()); + isolate->ThrowException(err); return; } if (!args[1]->IsUint32()) { - isolate->ThrowException(v8::Exception::TypeError( - v8::String::NewFromUtf8(isolate, "Expected argument to be an integer."))); + v8::Local err = v8::Exception::TypeError( + v8::String::NewFromUtf8(isolate, "Expected argument to be a number.", v8::NewStringType::kNormal).ToLocalChecked()); + isolate->ThrowException(err); return; } - if (!args[2]->IsNumber()) { - isolate->ThrowException(v8::Exception::TypeError( - v8::String::NewFromUtf8(isolate, "Expected argument to be a number."))); + if (!args[2]->IsNumber()) { + v8::Local err = v8::Exception::TypeError( + v8::String::NewFromUtf8(isolate, "Expected argument to be a number.", v8::NewStringType::kNormal).ToLocalChecked()); + isolate->ThrowException(err); return; } @@ -495,13 +501,15 @@ namespace nodejs const auto argc = 1; v8::Local argv[argc] = { v8::External::New(isolate, wrap_match) }; - auto instance = Match::constructor(isolate)->NewInstance(context, argc, argv).ToLocalChecked(); - wrap_matches->Set(i, instance); + v8::Local instance; + Match::constructor(isolate)->NewInstance(context, argc, argv).ToLocal(&instance); + wrap_matches->Set(context, i, instance); } args.GetReturnValue().Set(wrap_matches); } catch(const std::exception& e) { - isolate->ThrowException(v8::Exception::Error( - v8::String::NewFromUtf8(isolate, e.what()))); + v8::Local err = v8::Exception::Error( + v8::String::NewFromUtf8(isolate, e.what(), v8::NewStringType::kNormal).ToLocalChecked()); + isolate->ThrowException(err); return; } } diff --git a/src/maluuba/speech/nodejs/match/match.cpp b/src/maluuba/speech/nodejs/match/match.cpp index bca38d0..8d3783e 100644 --- a/src/maluuba/speech/nodejs/match/match.cpp +++ b/src/maluuba/speech/nodejs/match/match.cpp @@ -35,7 +35,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.", v8::NewStringType::kNormal).ToLocalChecked())); return; } } @@ -59,10 +59,10 @@ namespace nodejs v8::Local context = isolate->GetCurrentContext(); auto tpl = v8::FunctionTemplate::New(isolate, New); - tpl->SetClassName(v8::String::NewFromUtf8(isolate, "Match")); + tpl->SetClassName(v8::String::NewFromUtf8(isolate, "Match", v8::NewStringType::kNormal).ToLocalChecked()); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "distance"), getDistance, setThrow); - tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "element"), getElement, setThrow); + tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "distance", v8::NewStringType::kNormal).ToLocalChecked(), getDistance, setThrow); + tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "element", v8::NewStringType::kNormal).ToLocalChecked(), getElement, setThrow); s_constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked()); } @@ -74,7 +74,7 @@ namespace nodejs if (!args[0]->IsExternal()) { isolate->ThrowException(v8::Exception::TypeError( - v8::String::NewFromUtf8(isolate, "Not Expected to initialize directly, use a Fuzzy Matcher."))); + v8::String::NewFromUtf8(isolate, "Not Expected to initialize directly, use a Fuzzy Matcher.", v8::NewStringType::kNormal).ToLocalChecked())); return; } diff --git a/src/maluuba/speech/nodejs/performance/performance.cpp b/src/maluuba/speech/nodejs/performance/performance.cpp index b45e3aa..bd7ff68 100644 --- a/src/maluuba/speech/nodejs/performance/performance.cpp +++ b/src/maluuba/speech/nodejs/performance/performance.cpp @@ -17,11 +17,11 @@ namespace nodejs auto isolate = module->GetIsolate(); v8::Local context = isolate->GetCurrentContext(); - auto require = module->Get(v8::String::NewFromUtf8(isolate, "require")).As(); + auto require = module->Get(context, v8::String::NewFromUtf8(isolate, "require", v8::NewStringType::kNormal).ToLocalChecked()).ToLocalChecked().As(); const auto argc = 1; - v8::Local argv[argc] = { v8::String::NewFromUtf8(isolate, "perf_hooks") }; + v8::Local argv[argc] = { v8::String::NewFromUtf8(isolate, "perf_hooks", v8::NewStringType::kNormal).ToLocalChecked() }; auto perf_hooks = require->Call(context, module, argc, argv).ToLocalChecked().As(); - auto performance = perf_hooks->Get(v8::String::NewFromUtf8(isolate, "performance")).As(); + auto performance = perf_hooks->Get(context, v8::String::NewFromUtf8(isolate, "performance", v8::NewStringType::kNormal).ToLocalChecked()).ToLocalChecked().As(); s_performance.Reset(isolate, performance); } @@ -32,9 +32,9 @@ namespace nodejs v8::Local context = isolate->GetCurrentContext(); auto performance = s_performance.Get(isolate); - auto mark = performance->Get(v8::String::NewFromUtf8(isolate, "mark")).As(); + auto mark = performance->Get(context, v8::String::NewFromUtf8(isolate, "mark", v8::NewStringType::kNormal).ToLocalChecked()).ToLocalChecked().As(); const auto argc = 1; - v8::Local argv[argc] = { v8::String::NewFromUtf8(isolate, name.data()) }; + v8::Local argv[argc] = { v8::String::NewFromUtf8(isolate, name.data(), v8::NewStringType::kNormal).ToLocalChecked() }; mark->Call(context, performance, argc, argv); } @@ -45,10 +45,10 @@ namespace nodejs v8::Local context = isolate->GetCurrentContext(); auto performance = s_performance.Get(isolate); - auto measure = performance->Get(v8::String::NewFromUtf8(isolate, "measure")).As(); + auto measure = performance->Get(context, v8::String::NewFromUtf8(isolate, "measure", v8::NewStringType::kNormal).ToLocalChecked()).ToLocalChecked().As(); const auto argc = 3; - v8::Local argv[argc] = { v8::String::NewFromUtf8(isolate, name.data()), - v8::String::NewFromUtf8(isolate, start_mark.data()), v8::String::NewFromUtf8(isolate, end_mark.data()) }; + v8::Local argv[argc] = { v8::String::NewFromUtf8(isolate, name.data(), v8::NewStringType::kNormal).ToLocalChecked(), + v8::String::NewFromUtf8(isolate, start_mark.data(), v8::NewStringType::kNormal).ToLocalChecked(), v8::String::NewFromUtf8(isolate, end_mark.data(), v8::NewStringType::kNormal).ToLocalChecked() }; measure->Call(context, performance, argc, argv); } } diff --git a/src/maluuba/speech/nodejs/phone/phone.cpp b/src/maluuba/speech/nodejs/phone/phone.cpp index d147b05..a1494b6 100644 --- a/src/maluuba/speech/nodejs/phone/phone.cpp +++ b/src/maluuba/speech/nodejs/phone/phone.cpp @@ -128,7 +128,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.", v8::NewStringType::kNormal).ToLocalChecked())); return; } } @@ -152,17 +152,17 @@ namespace nodejs v8::Local context = isolate->GetCurrentContext(); auto tpl = v8::FunctionTemplate::New(isolate, New); - tpl->SetClassName(v8::String::NewFromUtf8(isolate, "Phone")); + tpl->SetClassName(v8::String::NewFromUtf8(isolate, "Phone", v8::NewStringType::kNormal).ToLocalChecked()); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "type"), getType, setThrow); - tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "phonation"), getPhonation, setThrow); - tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "place"), getPlace, setThrow); - tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "manner"), getManner, setThrow); - tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "height"), getHeight, setThrow); - tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "backness"), getBackness, setThrow); - tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "roundedness"), getRoundedness, setThrow); - tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "isRhotic"), getRhotic, setThrow); - tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "isSyllabic"), getSyllabic, setThrow); + tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "type", v8::NewStringType::kNormal).ToLocalChecked(), getType, setThrow); + tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "phonation", v8::NewStringType::kNormal).ToLocalChecked(), getPhonation, setThrow); + tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "place", v8::NewStringType::kNormal).ToLocalChecked(), getPlace, setThrow); + tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "manner", v8::NewStringType::kNormal).ToLocalChecked(), getManner, setThrow); + tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "height", v8::NewStringType::kNormal).ToLocalChecked(), getHeight, setThrow); + tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "backness", v8::NewStringType::kNormal).ToLocalChecked(), getBackness, setThrow); + tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "roundedness", v8::NewStringType::kNormal).ToLocalChecked(), getRoundedness, setThrow); + tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "isRhotic", v8::NewStringType::kNormal).ToLocalChecked(), getRhotic, setThrow); + tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "isSyllabic", v8::NewStringType::kNormal).ToLocalChecked(), getSyllabic, setThrow); s_constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked()); } @@ -174,7 +174,7 @@ namespace nodejs if (!args[0]->IsExternal()) { isolate->ThrowException(v8::Exception::TypeError( - v8::String::NewFromUtf8(isolate, "Not Expected to initialize directly, use EnPronunciation."))); + v8::String::NewFromUtf8(isolate, "Not Expected to initialize directly, use EnPronunciation.", v8::NewStringType::kNormal).ToLocalChecked())); return; } diff --git a/src/maluuba/speech/nodejs/stringdistance/stringdistance.cpp b/src/maluuba/speech/nodejs/stringdistance/stringdistance.cpp index 03a1046..f7341de 100644 --- a/src/maluuba/speech/nodejs/stringdistance/stringdistance.cpp +++ b/src/maluuba/speech/nodejs/stringdistance/stringdistance.cpp @@ -33,14 +33,14 @@ namespace nodejs v8::Local context = isolate->GetCurrentContext(); auto tpl = v8::FunctionTemplate::New(isolate, New); - tpl->SetClassName(v8::String::NewFromUtf8(isolate, "StringDistance")); + tpl->SetClassName(v8::String::NewFromUtf8(isolate, "StringDistance", v8::NewStringType::kNormal).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, "StringDistance"), tpl->GetFunction(context).ToLocalChecked()); + exports->Set(context, v8::String::NewFromUtf8(isolate, "StringDistance", v8::NewStringType::kNormal).ToLocalChecked(), tpl->GetFunction(context).ToLocalChecked()); } void @@ -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 StringDistance()`"))); + v8::String::NewFromUtf8(isolate, "Not invoked as constructor, change to: `new StringDistance()`", v8::NewStringType::kNormal).ToLocalChecked())); return; } } @@ -67,13 +67,13 @@ 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.", v8::NewStringType::kNormal).ToLocalChecked())); return; } if (!args[0]->IsString() || !args[1]->IsString()) { isolate->ThrowException(v8::Exception::TypeError( - v8::String::NewFromUtf8(isolate, "Expected arguments to be string."))); + v8::String::NewFromUtf8(isolate, "Expected arguments to be string.", v8::NewStringType::kNormal).ToLocalChecked())); return; }