60
60
#include < unicode/uchar.h>
61
61
#include < unicode/uclean.h>
62
62
#include < unicode/ucnv.h>
63
- #include < unicode/udata.h>
64
- #include < unicode/uidna.h>
65
63
#include < unicode/ulocdata.h>
66
64
#include < unicode/urename.h>
67
- #include < unicode/ustring.h>
68
65
#include < unicode/utf16.h>
69
- #include < unicode/utf8.h>
70
66
#include < unicode/utypes.h>
71
67
#include < unicode/uvernum.h>
72
68
#include < unicode/uversion.h>
73
69
#include " nbytes.h"
74
70
75
71
#ifdef NODE_HAVE_SMALL_ICU
72
+ #include < unicode/udata.h>
73
+
76
74
/* if this is defined, we have a 'secondary' entry point.
77
75
compare following to utypes.h defs for U_ICUDATA_ENTRY_POINT */
78
76
#define SMALL_ICUDATA_ENTRY_POINT \
@@ -96,7 +94,6 @@ using v8::Int32;
96
94
using v8::Isolate;
97
95
using v8::Local;
98
96
using v8::MaybeLocal;
99
- using v8::NewStringType;
100
97
using v8::Object;
101
98
using v8::ObjectTemplate;
102
99
using v8::String;
@@ -583,167 +580,6 @@ void SetDefaultTimeZone(const char* tzid) {
583
580
CHECK (U_SUCCESS (status));
584
581
}
585
582
586
- int32_t ToUnicode (MaybeStackBuffer<char >* buf,
587
- const char * input,
588
- size_t length) {
589
- UErrorCode status = U_ZERO_ERROR;
590
- uint32_t options = UIDNA_NONTRANSITIONAL_TO_UNICODE;
591
- UIDNA* uidna = uidna_openUTS46 (options, &status);
592
- if (U_FAILURE (status))
593
- return -1 ;
594
- UIDNAInfo info = UIDNA_INFO_INITIALIZER;
595
-
596
- int32_t len = uidna_nameToUnicodeUTF8 (uidna,
597
- input, length,
598
- **buf, buf->capacity (),
599
- &info,
600
- &status);
601
-
602
- // Do not check info.errors like we do with ToASCII since ToUnicode always
603
- // returns a string, despite any possible errors that may have occurred.
604
-
605
- if (status == U_BUFFER_OVERFLOW_ERROR) {
606
- status = U_ZERO_ERROR;
607
- buf->AllocateSufficientStorage (len);
608
- len = uidna_nameToUnicodeUTF8 (uidna,
609
- input, length,
610
- **buf, buf->capacity (),
611
- &info,
612
- &status);
613
- }
614
-
615
- // info.errors is ignored as UTS #46 ToUnicode always produces a Unicode
616
- // string, regardless of whether an error occurred.
617
-
618
- if (U_FAILURE (status)) {
619
- len = -1 ;
620
- buf->SetLength (0 );
621
- } else {
622
- buf->SetLength (len);
623
- }
624
-
625
- uidna_close (uidna);
626
- return len;
627
- }
628
-
629
- int32_t ToASCII (MaybeStackBuffer<char >* buf,
630
- const char * input,
631
- size_t length,
632
- idna_mode mode) {
633
- UErrorCode status = U_ZERO_ERROR;
634
- uint32_t options = // CheckHyphens = false; handled later
635
- UIDNA_CHECK_BIDI | // CheckBidi = true
636
- UIDNA_CHECK_CONTEXTJ | // CheckJoiners = true
637
- UIDNA_NONTRANSITIONAL_TO_ASCII; // Nontransitional_Processing
638
- if (mode == idna_mode::kStrict ) {
639
- options |= UIDNA_USE_STD3_RULES; // UseSTD3ASCIIRules = beStrict
640
- // VerifyDnsLength = beStrict;
641
- // handled later
642
- }
643
-
644
- UIDNA* uidna = uidna_openUTS46 (options, &status);
645
- if (U_FAILURE (status))
646
- return -1 ;
647
- UIDNAInfo info = UIDNA_INFO_INITIALIZER;
648
-
649
- int32_t len = uidna_nameToASCII_UTF8 (uidna,
650
- input, length,
651
- **buf, buf->capacity (),
652
- &info,
653
- &status);
654
-
655
- if (status == U_BUFFER_OVERFLOW_ERROR) {
656
- status = U_ZERO_ERROR;
657
- buf->AllocateSufficientStorage (len);
658
- len = uidna_nameToASCII_UTF8 (uidna,
659
- input, length,
660
- **buf, buf->capacity (),
661
- &info,
662
- &status);
663
- }
664
-
665
- // In UTS #46 which specifies ToASCII, certain error conditions are
666
- // configurable through options, and the WHATWG URL Standard promptly elects
667
- // to disable some of them to accommodate for real-world use cases.
668
- // Unfortunately, ICU4C's IDNA module does not support disabling some of
669
- // these options through `options` above, and thus continues throwing
670
- // unnecessary errors. To counter this situation, we just filter out the
671
- // errors that may have happened afterwards, before deciding whether to
672
- // return an error from this function.
673
-
674
- // CheckHyphens = false
675
- // (Specified in the current UTS #46 draft rev. 18.)
676
- // Refs:
677
- // - https://github.com/whatwg/url/issues/53
678
- // - https://github.com/whatwg/url/pull/309
679
- // - http://www.unicode.org/review/pri317/
680
- // - http://www.unicode.org/reports/tr46/tr46-18.html
681
- // - https://www.icann.org/news/announcement-2000-01-07-en
682
- info.errors &= ~UIDNA_ERROR_HYPHEN_3_4;
683
- info.errors &= ~UIDNA_ERROR_LEADING_HYPHEN;
684
- info.errors &= ~UIDNA_ERROR_TRAILING_HYPHEN;
685
-
686
- if (mode != idna_mode::kStrict ) {
687
- // VerifyDnsLength = beStrict
688
- info.errors &= ~UIDNA_ERROR_EMPTY_LABEL;
689
- info.errors &= ~UIDNA_ERROR_LABEL_TOO_LONG;
690
- info.errors &= ~UIDNA_ERROR_DOMAIN_NAME_TOO_LONG;
691
- }
692
-
693
- if (U_FAILURE (status) || (mode != idna_mode::kLenient && info.errors != 0 )) {
694
- len = -1 ;
695
- buf->SetLength (0 );
696
- } else {
697
- buf->SetLength (len);
698
- }
699
-
700
- uidna_close (uidna);
701
- return len;
702
- }
703
-
704
- static void ToUnicode (const FunctionCallbackInfo<Value>& args) {
705
- Environment* env = Environment::GetCurrent (args);
706
- CHECK_GE (args.Length (), 1 );
707
- CHECK (args[0 ]->IsString ());
708
- Utf8Value val (env->isolate (), args[0 ]);
709
-
710
- MaybeStackBuffer<char > buf;
711
- int32_t len = ToUnicode (&buf, *val, val.length ());
712
-
713
- if (len < 0 ) {
714
- return THROW_ERR_INVALID_ARG_VALUE (env, " Cannot convert name to Unicode" );
715
- }
716
-
717
- args.GetReturnValue ().Set (
718
- String::NewFromUtf8 (env->isolate (),
719
- *buf,
720
- NewStringType::kNormal ,
721
- len).ToLocalChecked ());
722
- }
723
-
724
- static void ToASCII (const FunctionCallbackInfo<Value>& args) {
725
- Environment* env = Environment::GetCurrent (args);
726
- CHECK_GE (args.Length (), 1 );
727
- CHECK (args[0 ]->IsString ());
728
- Utf8Value val (env->isolate (), args[0 ]);
729
- // optional arg
730
- bool lenient = args[1 ]->BooleanValue (env->isolate ());
731
- idna_mode mode = lenient ? idna_mode::kLenient : idna_mode::kDefault ;
732
-
733
- MaybeStackBuffer<char > buf;
734
- int32_t len = ToASCII (&buf, *val, val.length (), mode);
735
-
736
- if (len < 0 ) {
737
- return THROW_ERR_INVALID_ARG_VALUE (env, " Cannot convert name to ASCII" );
738
- }
739
-
740
- args.GetReturnValue ().Set (
741
- String::NewFromUtf8 (env->isolate (),
742
- *buf,
743
- NewStringType::kNormal ,
744
- len).ToLocalChecked ());
745
- }
746
-
747
583
// This is similar to wcwidth except that it takes the current unicode
748
584
// character properties database into consideration, allowing it to
749
585
// correctly calculate the column widths of things like emoji's and
@@ -850,8 +686,6 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data,
850
686
Local<ObjectTemplate> target) {
851
687
Isolate* isolate = isolate_data->isolate ();
852
688
853
- SetMethod (isolate, target, " toUnicode" , ToUnicode);
854
- SetMethod (isolate, target, " toASCII" , ToASCII);
855
689
SetMethod (isolate, target, " getStringWidth" , GetStringWidth);
856
690
857
691
// One-shot converters
@@ -880,8 +714,6 @@ void CreatePerContextProperties(Local<Object> target,
880
714
void * priv) {}
881
715
882
716
void RegisterExternalReferences (ExternalReferenceRegistry* registry) {
883
- registry->Register (ToUnicode);
884
- registry->Register (ToASCII);
885
717
registry->Register (GetStringWidth);
886
718
registry->Register (ICUErrorName);
887
719
registry->Register (Transcode);
0 commit comments