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,31 @@ 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
+ printf (" to_ascii_returns '%s' for '%s'\n " ,
205
+ out.c_str (),
206
+ input.ToString ().c_str ());
207
+ args.GetReturnValue ().Set (
208
+ String::NewFromUtf8 (env->isolate (), out.c_str ()).ToLocalChecked ());
209
+ }
210
+
211
+ void BindingData::ToUnicode (const v8::FunctionCallbackInfo<v8::Value>& args) {
212
+ Environment* env = Environment::GetCurrent (args);
213
+ CHECK_GE (args.Length (), 1 );
214
+ CHECK (args[0 ]->IsString ());
215
+
216
+ Utf8Value input (env->isolate (), args[0 ]);
217
+ auto out = ada::idna::to_unicode (input.ToStringView ());
218
+ args.GetReturnValue ().Set (
219
+ String::NewFromUtf8 (env->isolate (), out.c_str ()).ToLocalChecked ());
220
+ }
221
+
196
222
void BindingData::Initialize (Local<Object> target,
197
223
Local<Value> unused,
198
224
Local<Context> context,
@@ -205,13 +231,17 @@ void BindingData::Initialize(Local<Object> target,
205
231
SetMethod (context, target, " encodeInto" , EncodeInto);
206
232
SetMethodNoSideEffect (context, target, " encodeUtf8String" , EncodeUtf8String);
207
233
SetMethodNoSideEffect (context, target, " decodeUTF8" , DecodeUTF8);
234
+ SetMethodNoSideEffect (context, target, " toASCII" , ToASCII);
235
+ SetMethodNoSideEffect (context, target, " toUnicode" , ToUnicode);
208
236
}
209
237
210
238
void BindingData::RegisterTimerExternalReferences (
211
239
ExternalReferenceRegistry* registry) {
212
240
registry->Register (EncodeInto);
213
241
registry->Register (EncodeUtf8String);
214
242
registry->Register (DecodeUTF8);
243
+ registry->Register (ToASCII);
244
+ registry->Register (ToUnicode);
215
245
}
216
246
217
247
} // namespace encoding_binding
0 commit comments