1
1
#include " encoding_binding.h"
2
+ #include " ada.h"
2
3
#include " env-inl.h"
3
4
#include " node_errors.h"
4
5
#include " node_external_reference.h"
@@ -193,6 +194,28 @@ void BindingData::DecodeUTF8(const FunctionCallbackInfo<Value>& args) {
193
194
args.GetReturnValue ().Set (ret);
194
195
}
195
196
197
+ void BindingData::ToASCII (const v8::FunctionCallbackInfo<v8::Value>& args) {
198
+ Environment* env = Environment::GetCurrent (args);
199
+ CHECK_GE (args.Length (), 1 );
200
+ CHECK (args[0 ]->IsString ());
201
+
202
+ Utf8Value input (env->isolate (), args[0 ]);
203
+ auto out = ada::idna::to_ascii (input.ToStringView ());
204
+ args.GetReturnValue ().Set (
205
+ String::NewFromUtf8 (env->isolate (), out.c_str ()).ToLocalChecked ());
206
+ }
207
+
208
+ void BindingData::ToUnicode (const v8::FunctionCallbackInfo<v8::Value>& args) {
209
+ Environment* env = Environment::GetCurrent (args);
210
+ CHECK_GE (args.Length (), 1 );
211
+ CHECK (args[0 ]->IsString ());
212
+
213
+ Utf8Value input (env->isolate (), args[0 ]);
214
+ auto out = ada::idna::to_unicode (input.ToStringView ());
215
+ args.GetReturnValue ().Set (
216
+ String::NewFromUtf8 (env->isolate (), out.c_str ()).ToLocalChecked ());
217
+ }
218
+
196
219
void BindingData::Initialize (Local<Object> target,
197
220
Local<Value> unused,
198
221
Local<Context> context,
@@ -205,13 +228,17 @@ void BindingData::Initialize(Local<Object> target,
205
228
SetMethod (context, target, " encodeInto" , EncodeInto);
206
229
SetMethodNoSideEffect (context, target, " encodeUtf8String" , EncodeUtf8String);
207
230
SetMethodNoSideEffect (context, target, " decodeUTF8" , DecodeUTF8);
231
+ SetMethodNoSideEffect (context, target, " toASCII" , ToASCII);
232
+ SetMethodNoSideEffect (context, target, " toUnicode" , ToUnicode);
208
233
}
209
234
210
235
void BindingData::RegisterTimerExternalReferences (
211
236
ExternalReferenceRegistry* registry) {
212
237
registry->Register (EncodeInto);
213
238
registry->Register (EncodeUtf8String);
214
239
registry->Register (DecodeUTF8);
240
+ registry->Register (ToASCII);
241
+ registry->Register (ToUnicode);
215
242
}
216
243
217
244
} // namespace encoding_binding
0 commit comments