File tree Expand file tree Collapse file tree 4 files changed +54
-0
lines changed
system/include/emscripten Expand file tree Collapse file tree 4 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -134,6 +134,18 @@ var LibraryEmVal = {
134
134
return Emval . toHandle ( getStringOrSymbol ( v ) ) ;
135
135
} ,
136
136
137
+ _emval_new_u8string__sig : 'ii' ,
138
+ _emval_new_u8string__deps : [ '$Emval' ] ,
139
+ _emval_new_u8string : function ( v ) {
140
+ return Emval . toHandle ( UTF8ToString ( v ) ) ;
141
+ } ,
142
+
143
+ _emval_new_u16string__sig : 'ii' ,
144
+ _emval_new_u16string__deps : [ '$Emval' ] ,
145
+ _emval_new_u16string : function ( v ) {
146
+ return Emval . toHandle ( UTF16ToString ( v ) ) ;
147
+ } ,
148
+
137
149
_emval_take_value__sig : 'iii' ,
138
150
_emval_take_value__deps : [ '$Emval' , '$requireRegisteredType' ] ,
139
151
_emval_take_value : function ( type , argv ) {
Original file line number Diff line number Diff line change @@ -54,6 +54,8 @@ void _emval_run_destructors(EM_DESTRUCTORS handle);
54
54
EM_VAL _emval_new_array ();
55
55
EM_VAL _emval_new_object ();
56
56
EM_VAL _emval_new_cstring (const char *);
57
+ EM_VAL _emval_new_u8string (const char *);
58
+ EM_VAL _emval_new_u16string (const char16_t *);
57
59
58
60
EM_VAL _emval_take_value (TYPEID type, EM_VAR_ARGS argv);
59
61
@@ -351,6 +353,14 @@ class val {
351
353
return val (internal::_emval_new_object ());
352
354
}
353
355
356
+ static val u8string (const char * s) {
357
+ return val (internal::_emval_new_u8string (s));
358
+ }
359
+
360
+ static val u16string (const char16_t * s) {
361
+ return val (internal::_emval_new_u16string (s));
362
+ }
363
+
354
364
static val undefined () {
355
365
return val (EM_VAL (internal::_EMVAL_UNDEFINED));
356
366
}
Original file line number Diff line number Diff line change @@ -639,6 +639,26 @@ int main()
639
639
ensure (aAsNumberVectorUint32_t.at (2 ) == 0 ); // 0 is returned if can not be converted for integers
640
640
ensure (aAsNumberVectorUint32_t.at (3 ) == 100000 ); // Date returns milliseconds since epoch
641
641
642
+ test (" val u8string(const char* s)" );
643
+ val::global ().set (" a" , val::u8string (u8" abc" ));
644
+ ensure_js (" a == 'abc'" );
645
+ val::global ().set (" a" , val::u8string (u8" 你好" ));
646
+ ensure_js_not (" a == 'abc'" );
647
+ ensure_js (" a == '你好'" );
648
+ auto u8_str = val::global ()[" a" ].as <std::string>();
649
+ ensure (u8_str == u8" 你好" );
650
+
651
+ test (" val u16string(const char16_t* s)" );
652
+ val::global ().set (" a" , val::u16string (u" hello" ));
653
+ ensure_js (" a == 'hello'" );
654
+ val::global ().set (" a" , val::u16string (u" 世界" ));
655
+ ensure_js_not (" a == 'hello'" );
656
+ ensure_js (" a == '世界'" );
657
+ // UTF-16 encoded SMILING FACE WITH OPEN MOUTH (U+1F603)
658
+ const char16_t * s = u" 😃 = \U0001F603 is :-D" ;
659
+ val::global ().set (" a" , val::u16string (s));
660
+ ensure_js (" a == '😃 = \U0001F603 is :-D'" );
661
+
642
662
printf (" end\n " );
643
663
return 0 ;
644
664
}
Original file line number Diff line number Diff line change @@ -268,4 +268,16 @@ pass
268
268
pass
269
269
pass
270
270
pass
271
+ test:
272
+ val u8string(const char* s)
273
+ pass
274
+ pass
275
+ pass
276
+ pass
277
+ test:
278
+ val u16string(const char16_t* s)
279
+ pass
280
+ pass
281
+ pass
282
+ pass
271
283
end
You can’t perform that action at this time.
0 commit comments