mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-20 10:35:50 +00:00
TextEncoder/Decoder working in jshooks
This commit is contained in:
@@ -625,10 +625,28 @@ static const JSCFunctionListEntry js_encoder_funcs[] = {
|
|||||||
JS_PROP_STRING_DEF("[Symbol.toStringTag]", "TextEncoder", JS_PROP_CONFIGURABLE),
|
JS_PROP_STRING_DEF("[Symbol.toStringTag]", "TextEncoder", JS_PROP_CONFIGURABLE),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern
|
||||||
|
void JS_NewGlobalCConstructor2(JSContext *ctx,
|
||||||
|
JSValue func_obj,
|
||||||
|
const char *name,
|
||||||
|
JSValueConst proto);
|
||||||
int
|
int
|
||||||
js_code_init(JSContext* ctx, JSModuleDef* m) {
|
js_code_init_textdecoder(JSContext* ctx, JSModuleDef* m)
|
||||||
|
{
|
||||||
|
// RH TODO: check if this (possibly being called twice or for some other reason) produces a mem leak
|
||||||
|
JS_NewClassID(&js_encoder_class_id);
|
||||||
|
JS_NewClass(JS_GetRuntime(ctx), js_encoder_class_id, &js_encoder_class);
|
||||||
|
|
||||||
|
textencoder_ctor = JS_NewCFunction2(ctx, js_encoder_constructor, "TextEncoder", 1, JS_CFUNC_constructor, 0);
|
||||||
|
textencoder_proto = JS_NewObject(ctx);
|
||||||
|
|
||||||
|
JS_SetPropertyFunctionList(ctx, textencoder_proto, js_encoder_funcs, countof(js_encoder_funcs));
|
||||||
|
JS_SetClassProto(ctx, js_encoder_class_id, textencoder_proto);
|
||||||
|
JS_SetConstructor(ctx, textencoder_ctor, textencoder_proto);
|
||||||
|
|
||||||
|
JS_NewGlobalCConstructor2(ctx, textencoder_ctor, "TextEncoder", textencoder_proto);
|
||||||
|
|
||||||
|
|
||||||
if(js_decoder_class_id == 0) {
|
|
||||||
JS_NewClassID(&js_decoder_class_id);
|
JS_NewClassID(&js_decoder_class_id);
|
||||||
JS_NewClass(JS_GetRuntime(ctx), js_decoder_class_id, &js_decoder_class);
|
JS_NewClass(JS_GetRuntime(ctx), js_decoder_class_id, &js_decoder_class);
|
||||||
|
|
||||||
@@ -639,33 +657,8 @@ js_code_init(JSContext* ctx, JSModuleDef* m) {
|
|||||||
JS_SetClassProto(ctx, js_decoder_class_id, textdecoder_proto);
|
JS_SetClassProto(ctx, js_decoder_class_id, textdecoder_proto);
|
||||||
|
|
||||||
JS_SetConstructor(ctx, textdecoder_ctor, textdecoder_proto);
|
JS_SetConstructor(ctx, textdecoder_ctor, textdecoder_proto);
|
||||||
|
|
||||||
JS_NewClassID(&js_encoder_class_id);
|
JS_NewGlobalCConstructor2(ctx, textdecoder_ctor, "TextDecoder", textdecoder_proto);
|
||||||
JS_NewClass(JS_GetRuntime(ctx), js_encoder_class_id, &js_encoder_class);
|
|
||||||
|
|
||||||
textencoder_ctor = JS_NewCFunction2(ctx, js_encoder_constructor, "TextEncoder", 1, JS_CFUNC_constructor, 0);
|
|
||||||
textencoder_proto = JS_NewObject(ctx);
|
|
||||||
|
|
||||||
JS_SetPropertyFunctionList(ctx, textencoder_proto, js_encoder_funcs, countof(js_encoder_funcs));
|
|
||||||
JS_SetClassProto(ctx, js_encoder_class_id, textencoder_proto);
|
|
||||||
|
|
||||||
JS_SetConstructor(ctx, textencoder_ctor, textencoder_proto);
|
|
||||||
|
|
||||||
// js_set_inspect_method(ctx, textdecoder_proto,
|
|
||||||
// js_decoder_inspect);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(m) {
|
|
||||||
JS_SetModuleExport(ctx, m, "TextDecoder", textdecoder_ctor);
|
|
||||||
JS_SetModuleExport(ctx, m, "TextEncoder", textencoder_ctor);
|
|
||||||
|
|
||||||
/* const char* module_name = JS_AtomToCString(ctx, m->module_name);
|
|
||||||
|
|
||||||
if(!strcmp(module_name, "textdecoder"))
|
|
||||||
JS_SetModuleExport(ctx, m, "default", textdecoder_ctor);
|
|
||||||
|
|
||||||
JS_FreeCString(ctx, module_name);*/
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -680,12 +673,13 @@ VISIBLE JSModuleDef*
|
|||||||
JS_INIT_MODULE(JSContext* ctx, const char* module_name) {
|
JS_INIT_MODULE(JSContext* ctx, const char* module_name) {
|
||||||
JSModuleDef* m;
|
JSModuleDef* m;
|
||||||
|
|
||||||
if((m = JS_NewCModule(ctx, module_name, js_code_init))) {
|
/*if((m = JS_NewCModule(ctx, module_name, js_code_init)))
|
||||||
|
{
|
||||||
JS_AddModuleExport(ctx, m, "TextDecoder");
|
JS_AddModuleExport(ctx, m, "TextDecoder");
|
||||||
JS_AddModuleExport(ctx, m, "TextEncoder");
|
JS_AddModuleExport(ctx, m, "TextEncoder");
|
||||||
/*if(!strcmp(module_name, "textdecoder"))
|
//if(!strcmp(module_name, "textdecoder"))
|
||||||
JS_AddModuleExport(ctx, m, "default");*/
|
// JS_AddModuleExport(ctx, m, "default");
|
||||||
}
|
}*/
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ extern const char* const textcode_encodings[];
|
|||||||
|
|
||||||
size_t textdecoder_length(TextDecoder*);
|
size_t textdecoder_length(TextDecoder*);
|
||||||
JSValue textdecoder_read(TextDecoder*, JSContext* ctx);
|
JSValue textdecoder_read(TextDecoder*, JSContext* ctx);
|
||||||
int js_code_init(JSContext*, JSModuleDef* m);
|
int js_code_init_textdecoder(JSContext*, JSModuleDef* m);
|
||||||
size_t textencoder_length(TextEncoder*);
|
size_t textencoder_length(TextEncoder*);
|
||||||
JSValue textencoder_read(TextEncoder*, JSContext* ctx);
|
JSValue textencoder_read(TextEncoder*, JSContext* ctx);
|
||||||
int js_encoder_init(JSContext*, JSModuleDef* m);
|
int js_encoder_init(JSContext*, JSModuleDef* m);
|
||||||
|
|||||||
@@ -37052,7 +37052,7 @@ void JS_SetConstructor(JSContext *ctx, JSValueConst func_obj,
|
|||||||
0, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
|
0, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void JS_NewGlobalCConstructor2(JSContext *ctx,
|
void JS_NewGlobalCConstructor2(JSContext *ctx,
|
||||||
JSValue func_obj,
|
JSValue func_obj,
|
||||||
const char *name,
|
const char *name,
|
||||||
JSValueConst proto)
|
JSValueConst proto)
|
||||||
@@ -37074,7 +37074,7 @@ static JSValueConst JS_NewGlobalCConstructor(JSContext *ctx, const char *name,
|
|||||||
return func_obj;
|
return func_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSValueConst JS_NewGlobalCConstructorOnly(JSContext *ctx, const char *name,
|
JSValueConst JS_NewGlobalCConstructorOnly(JSContext *ctx, const char *name,
|
||||||
JSCFunction *func, int length,
|
JSCFunction *func, int length,
|
||||||
JSValueConst proto)
|
JSValueConst proto)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
#include "quickjs-atom.h"
|
#include "quickjs-atom.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
JSModuleDef* js_init_module_textdecoder(JSContext* ctx, const char* name);
|
int js_code_init_textdecoder(JSContext*, JSModuleDef* m);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace hook {
|
namespace hook {
|
||||||
@@ -1317,7 +1317,8 @@ public:
|
|||||||
JS_AddIntrinsicMapSet(ctx);
|
JS_AddIntrinsicMapSet(ctx);
|
||||||
JS_AddIntrinsicTypedArrays(ctx);
|
JS_AddIntrinsicTypedArrays(ctx);
|
||||||
JS_AddIntrinsicBigInt(ctx);
|
JS_AddIntrinsicBigInt(ctx);
|
||||||
::js_init_module_textdecoder(ctx, "textdecoder");
|
//::js_init_module_textdecoder(ctx, "textdecoder");
|
||||||
|
::js_code_init_textdecoder(ctx, 0);
|
||||||
|
|
||||||
JS_SetMaxStackSize(rt, 65535);
|
JS_SetMaxStackSize(rt, 65535);
|
||||||
JS_SetMemoryLimit(rt, 16 * 1024 * 1024);
|
JS_SetMemoryLimit(rt, 16 * 1024 * 1024);
|
||||||
|
|||||||
Reference in New Issue
Block a user