Skip to content

Commit 2a2ce09

Browse files
authored
fix: unicode parsing error by using utf8() instead of ascii() (#199)
1 parent 72c366d commit 2a2ce09

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

thirdparty/quickjs/quickjs_binder.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ JSValue QuickJSBinder::godot_builtin_function(JSContext *ctx, JSValue this_val,
343343
int arg_required = Expression::get_func_argument_count(func);
344344
if (argc < arg_required) {
345345
String func_name = Expression::get_func_name(func);
346-
return JS_ThrowTypeError(ctx, "%d arguments expected for builtin funtion %s", arg_required, func_name.ascii().get_data());
346+
return JS_ThrowTypeError(ctx, "%d arguments expected for builtin funtion %s", arg_required, func_name.utf8().get_data());
347347
}
348348

349349
QuickJSBinder *binder = get_context_binder(ctx);
@@ -378,7 +378,7 @@ JSValue QuickJSBinder::godot_builtin_function(JSContext *ctx, JSValue this_val,
378378

379379
if (err.error != Variant::CallError::CALL_OK) {
380380
String func_name = Expression::get_func_name(func);
381-
return JS_ThrowTypeError(ctx, "Call builtin function error %s: %s", func_name.ascii().get_data(), err_msg.utf8().get_data());
381+
return JS_ThrowTypeError(ctx, "Call builtin function error %s: %s", func_name.utf8().get_data(), err_msg.utf8().get_data());
382382
}
383383

384384
#endif
@@ -509,14 +509,14 @@ Dictionary QuickJSBinder::js_to_dictionary(JSContext *ctx, const JSValue &p_val,
509509

510510
JSAtom QuickJSBinder::get_atom(JSContext *ctx, const StringName &p_key) {
511511
String name = p_key;
512-
CharString name_str = name.ascii();
512+
CharString name_str = name.utf8();
513513
JSAtom atom = JS_NewAtom(ctx, name_str.get_data());
514514
return atom;
515515
}
516516

517517
JSValue QuickJSBinder::godot_to_string(JSContext *ctx, JSValue this_val, int argc, JSValue *argv) {
518518
String str = var_to_variant(ctx, this_val);
519-
CharString ascii = str.ascii();
519+
CharString ascii = str.utf8();
520520
return JS_NewStringLen(ctx, ascii.get_data(), ascii.length());
521521
}
522522

@@ -830,7 +830,7 @@ JSClassID QuickJSBinder::register_class(const ClassDB::ClassInfo *p_cls) {
830830
return 0;
831831
}
832832
} else {
833-
data.class_name = String(p_cls->name).ascii();
833+
data.class_name = String(p_cls->name).utf8();
834834
data.jsclass.class_name = data.class_name.get_data();
835835
}
836836

@@ -857,7 +857,7 @@ JSClassID QuickJSBinder::register_class(const ClassDB::ClassInfo *p_cls) {
857857

858858
MethodBind *mb = pair.value;
859859
godot_methods.set(internal_godot_method_id, mb);
860-
CharString name = String(pair.key).ascii();
860+
CharString name = String(pair.key).utf8();
861861
JSValue method = JS_NewCFunctionMagic(ctx, &QuickJSBinder::object_method, name.get_data(), mb->get_argument_count(), JS_CFUNC_generic_magic, internal_godot_method_id);
862862
JS_DefinePropertyValueStr(ctx, data.prototype, name.get_data(), method, PROP_DEF_DEFAULT);
863863
methods.insert(pair.key, method);
@@ -890,7 +890,7 @@ JSClassID QuickJSBinder::register_class(const ClassDB::ClassInfo *p_cls) {
890890
godot_object_indexed_properties.resize(size + 128);
891891
}
892892
godot_object_indexed_properties.write[internal_godot_indexed_property_id] = &prop;
893-
CharString name = String(prop_name).ascii();
893+
CharString name = String(prop_name).utf8();
894894
getter = JS_NewCFunctionMagic(ctx, &QuickJSBinder::object_indexed_property, name.get_data(), 0, JS_CFUNC_generic_magic, internal_godot_indexed_property_id);
895895
setter = JS_NewCFunctionMagic(ctx, &QuickJSBinder::object_indexed_property, name.get_data(), 1, JS_CFUNC_generic_magic, internal_godot_indexed_property_id);
896896
++internal_godot_indexed_property_id;
@@ -904,7 +904,7 @@ JSClassID QuickJSBinder::register_class(const ClassDB::ClassInfo *p_cls) {
904904
}
905905
godot_methods.write[internal_godot_method_id] = mb;
906906
String setter_name = prop.setter;
907-
setter = JS_NewCFunctionMagic(ctx, &QuickJSBinder::object_method, setter_name.ascii().get_data(), mb->get_argument_count(), JS_CFUNC_generic_magic, internal_godot_method_id);
907+
setter = JS_NewCFunctionMagic(ctx, &QuickJSBinder::object_method, setter_name.utf8().get_data(), mb->get_argument_count(), JS_CFUNC_generic_magic, internal_godot_method_id);
908908
++internal_godot_method_id;
909909
}
910910

@@ -917,7 +917,7 @@ JSClassID QuickJSBinder::register_class(const ClassDB::ClassInfo *p_cls) {
917917
}
918918
godot_methods.write[internal_godot_method_id] = mb;
919919
String getter_name = prop.getter;
920-
getter = JS_NewCFunctionMagic(ctx, &QuickJSBinder::object_method, getter_name.ascii().get_data(), mb->get_argument_count(), JS_CFUNC_generic_magic, internal_godot_method_id);
920+
getter = JS_NewCFunctionMagic(ctx, &QuickJSBinder::object_method, getter_name.utf8().get_data(), mb->get_argument_count(), JS_CFUNC_generic_magic, internal_godot_method_id);
921921
++internal_godot_method_id;
922922
}
923923
}
@@ -1153,7 +1153,7 @@ void QuickJSBinder::add_godot_globals() {
11531153
for (int i = 0; i < Expression::FUNC_MAX; ++i) {
11541154
Expression::BuiltinFunc func = (Expression::BuiltinFunc)i;
11551155
String name = Expression::get_func_name(func);
1156-
JSValue js_func = JS_NewCFunctionMagic(ctx, godot_builtin_function, name.ascii().get_data(), 0, JS_CFUNC_generic_magic, i);
1156+
JSValue js_func = JS_NewCFunctionMagic(ctx, godot_builtin_function, name.utf8().get_data(), 0, JS_CFUNC_generic_magic, i);
11571157
JSAtom atom = get_atom(ctx, name);
11581158
JS_DefinePropertyValue(ctx, godot_object, atom, js_func, QuickJSBinder::PROP_DEF_DEFAULT);
11591159
JS_FreeAtom(ctx, atom);

0 commit comments

Comments
 (0)