summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYagiz Nizipli <yagiz@nizipli.com>2023-04-28 14:48:38 -0400
committerGitHub <noreply@github.com>2023-04-28 18:48:38 +0000
commit11233777917e7d5b73a8e9846b6a5308c69e8d30 (patch)
tree55b250736c2e0ce92059955e34ade2a23505d1eb /src
parent1baf96aeb88680bb89b1903b97a574b13e1674ab (diff)
downloadnode-new-11233777917e7d5b73a8e9846b6a5308c69e8d30.tar.gz
src: replace idna functions with ada::idna
Co-authored-by: Daniel Lemire <daniel@lemire.me> PR-URL: https://github.com/nodejs/node/pull/47735 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/encoding_binding.cc27
-rw-r--r--src/encoding_binding.h3
2 files changed, 30 insertions, 0 deletions
diff --git a/src/encoding_binding.cc b/src/encoding_binding.cc
index 25f4abf6ae..d665b38cfc 100644
--- a/src/encoding_binding.cc
+++ b/src/encoding_binding.cc
@@ -1,4 +1,5 @@
#include "encoding_binding.h"
+#include "ada.h"
#include "env-inl.h"
#include "node_errors.h"
#include "node_external_reference.h"
@@ -193,6 +194,28 @@ void BindingData::DecodeUTF8(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(ret);
}
+void BindingData::ToASCII(const v8::FunctionCallbackInfo<v8::Value>& args) {
+ Environment* env = Environment::GetCurrent(args);
+ CHECK_GE(args.Length(), 1);
+ CHECK(args[0]->IsString());
+
+ Utf8Value input(env->isolate(), args[0]);
+ auto out = ada::idna::to_ascii(input.ToStringView());
+ args.GetReturnValue().Set(
+ String::NewFromUtf8(env->isolate(), out.c_str()).ToLocalChecked());
+}
+
+void BindingData::ToUnicode(const v8::FunctionCallbackInfo<v8::Value>& args) {
+ Environment* env = Environment::GetCurrent(args);
+ CHECK_GE(args.Length(), 1);
+ CHECK(args[0]->IsString());
+
+ Utf8Value input(env->isolate(), args[0]);
+ auto out = ada::idna::to_unicode(input.ToStringView());
+ args.GetReturnValue().Set(
+ String::NewFromUtf8(env->isolate(), out.c_str()).ToLocalChecked());
+}
+
void BindingData::Initialize(Local<Object> target,
Local<Value> unused,
Local<Context> context,
@@ -205,6 +228,8 @@ void BindingData::Initialize(Local<Object> target,
SetMethod(context, target, "encodeInto", EncodeInto);
SetMethodNoSideEffect(context, target, "encodeUtf8String", EncodeUtf8String);
SetMethodNoSideEffect(context, target, "decodeUTF8", DecodeUTF8);
+ SetMethodNoSideEffect(context, target, "toASCII", ToASCII);
+ SetMethodNoSideEffect(context, target, "toUnicode", ToUnicode);
}
void BindingData::RegisterTimerExternalReferences(
@@ -212,6 +237,8 @@ void BindingData::RegisterTimerExternalReferences(
registry->Register(EncodeInto);
registry->Register(EncodeUtf8String);
registry->Register(DecodeUTF8);
+ registry->Register(ToASCII);
+ registry->Register(ToUnicode);
}
} // namespace encoding_binding
diff --git a/src/encoding_binding.h b/src/encoding_binding.h
index 0258b8188b..8a009dfce2 100644
--- a/src/encoding_binding.h
+++ b/src/encoding_binding.h
@@ -32,6 +32,9 @@ class BindingData : public SnapshotableObject {
static void EncodeUtf8String(const v8::FunctionCallbackInfo<v8::Value>& args);
static void DecodeUTF8(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void ToASCII(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void ToUnicode(const v8::FunctionCallbackInfo<v8::Value>& args);
+
static void Initialize(v8::Local<v8::Object> target,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,