1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[quickjs] Set 64M memory limit for JSRuntime

This commit is contained in:
Witold Filipczyk 2021-11-29 19:28:38 +01:00
parent 0fd7386bf5
commit 3aa9483cd2
4 changed files with 19 additions and 136 deletions

View File

@ -27,6 +27,7 @@
#include "ecmascript/quickjs.h" #include "ecmascript/quickjs.h"
#include "ecmascript/quickjs/console.h" #include "ecmascript/quickjs/console.h"
#include "ecmascript/quickjs/document.h" #include "ecmascript/quickjs/document.h"
#include "ecmascript/quickjs/element.h"
#include "ecmascript/quickjs/heartbeat.h" #include "ecmascript/quickjs/heartbeat.h"
#include "ecmascript/quickjs/history.h" #include "ecmascript/quickjs/history.h"
#include "ecmascript/quickjs/localstorage.h" #include "ecmascript/quickjs/localstorage.h"
@ -146,6 +147,9 @@ quickjs_get_interpreter(struct ecmascript_interpreter *interpreter)
return nullptr; return nullptr;
} }
JS_SetMemoryLimit(rt, 64 * 1024 * 1024);
JS_SetGCThreshold(rt, 16 * 1024 * 1024);
ctx = JS_NewContext(rt); ctx = JS_NewContext(rt);
if (!ctx) { if (!ctx) {
@ -170,141 +174,12 @@ quickjs_get_interpreter(struct ecmascript_interpreter *interpreter)
js_history_init(ctx); js_history_init(ctx);
js_console_init(ctx); js_console_init(ctx);
js_localstorage_init(ctx); js_localstorage_init(ctx);
js_element_init(ctx);
interpreter->document_obj = js_document_init(ctx); interpreter->document_obj = js_document_init(ctx);
interpreter->location_obj = js_location_init(ctx); interpreter->location_obj = js_location_init(ctx);
return ctx; return ctx;
#if 0
if (window_obj) {
interpreter->ac = window_obj;
interpreter->ac2 = new JSAutoRealm(ctx, window_obj);
} else {
goto release_and_fail;
}
if (!JS::InitRealmStandardClasses(ctx)) {
goto release_and_fail;
}
if (!JS_DefineProperties(ctx, window_obj, window_props)) {
goto release_and_fail;
}
if (!spidermonkey_DefineFunctions(ctx, window_obj, window_funcs)) {
goto release_and_fail;
}
//JS_SetPrivate(window_obj, interpreter); /* to @window_class */
document_obj = spidermonkey_InitClass(ctx, window_obj, NULL,
&document_class, NULL, 0,
document_props,
document_funcs,
NULL, NULL);
if (!document_obj) {
goto release_and_fail;
}
interpreter->document_obj = document_obj;
/*
forms_obj = spidermonkey_InitClass(ctx, document_obj, NULL,
&forms_class, NULL, 0,
forms_props,
forms_funcs,
NULL, NULL);
if (!forms_obj) {
goto release_and_fail;
}
*/
history_obj = spidermonkey_InitClass(ctx, window_obj, NULL,
&history_class, NULL, 0,
(JSPropertySpec *) NULL,
history_funcs,
NULL, NULL);
if (!history_obj) {
goto release_and_fail;
}
location_obj = spidermonkey_InitClass(ctx, window_obj, NULL,
&location_class, NULL, 0,
location_props,
location_funcs,
NULL, NULL);
if (!location_obj) {
goto release_and_fail;
}
interpreter->location_obj = location_obj;
screen_obj = spidermonkey_InitClass(ctx, window_obj, NULL,
&screen_class, NULL, 0,
screen_props,
NULL,
NULL, NULL);
if (!screen_obj) {
goto release_and_fail;
}
menubar_obj = JS_InitClass(ctx, window_obj, nullptr,
&menubar_class, NULL, 0,
unibar_props, NULL,
NULL, NULL);
if (!menubar_obj) {
goto release_and_fail;
}
JS_SetPrivate(menubar_obj, "t"); /* to @menubar_class */
statusbar_obj = JS_InitClass(ctx, window_obj, nullptr,
&statusbar_class, NULL, 0,
unibar_props, NULL,
NULL, NULL);
if (!statusbar_obj) {
goto release_and_fail;
}
JS_SetPrivate(statusbar_obj, "s"); /* to @statusbar_class */
navigator_obj = JS_InitClass(ctx, window_obj, nullptr,
&navigator_class, NULL, 0,
navigator_props, NULL,
NULL, NULL);
if (!navigator_obj) {
goto release_and_fail;
}
console_obj = spidermonkey_InitClass(ctx, window_obj, NULL,
&console_class, NULL, 0,
nullptr,
console_funcs,
NULL, NULL);
if (!console_obj) {
goto release_and_fail;
}
localstorage_obj = spidermonkey_InitClass(ctx, window_obj, NULL,
&localstorage_class, NULL, 0,
nullptr,
localstorage_funcs,
NULL, NULL);
if (!localstorage_obj) {
goto release_and_fail;
}
JS::SetRealmPrivate(js::GetContextRealm(ctx), interpreter);
return ctx;
release_and_fail:
spidermonkey_put_interpreter(interpreter);
return NULL;
#endif
} }
void void
@ -440,11 +315,9 @@ quickjs_call_function(struct ecmascript_interpreter *interpreter,
// return; // return;
// } // }
ctx = interpreter->backend_data; ctx = interpreter->backend_data;
// JS::Realm *comp = JS::EnterRealm(ctx, interpreter->ac);
interpreter->heartbeat = add_heartbeat(interpreter); interpreter->heartbeat = add_heartbeat(interpreter);
interpreter->ret = ret; interpreter->ret = ret;
JSValue r = JS_Call(ctx, fun, JS_GetGlobalObject(ctx), 0, nullptr); JSValue r = JS_Call(ctx, fun, JS_GetGlobalObject(ctx), 0, nullptr);
done_heartbeat(interpreter->heartbeat); done_heartbeat(interpreter->heartbeat);

View File

@ -7,6 +7,10 @@
#define RETURN_JS(obj) \ #define RETURN_JS(obj) \
fprintf(stderr, "%s:%d obj=%p\n", __FILE__, __LINE__, JS_VALUE_GET_PTR(obj)); \ fprintf(stderr, "%s:%d obj=%p\n", __FILE__, __LINE__, JS_VALUE_GET_PTR(obj)); \
if (JS_VALUE_HAS_REF_COUNT(obj)) { \
JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(obj); \
fprintf(stderr, "ref_count=%d\n", p->ref_count); \
} \
return obj return obj
#else #else

View File

@ -1688,7 +1688,7 @@ void js_element_finalizer(JSRuntime *rt, JSValue val)
} }
static JSClassDef js_element_class = { static JSClassDef js_element_class = {
"element", "Element",
js_element_finalizer js_element_finalizer
}; };
@ -1718,7 +1718,7 @@ fail:
} }
int int
js_element_init(JSContext *ctx, JSValue global_obj) js_element_init(JSContext *ctx)
{ {
JSValue element_proto, element_class; JSValue element_proto, element_class;
@ -1726,18 +1726,23 @@ js_element_init(JSContext *ctx, JSValue global_obj)
JS_NewClassID(&js_element_class_id); JS_NewClassID(&js_element_class_id);
JS_NewClass(JS_GetRuntime(ctx), js_element_class_id, &js_element_class); JS_NewClass(JS_GetRuntime(ctx), js_element_class_id, &js_element_class);
JSValue global_obj = JS_GetGlobalObject(ctx);
element_proto = JS_NewObject(ctx); element_proto = JS_NewObject(ctx);
JS_SetPropertyFunctionList(ctx, element_proto, js_element_proto_funcs, countof(js_element_proto_funcs)); JS_SetPropertyFunctionList(ctx, element_proto, js_element_proto_funcs, countof(js_element_proto_funcs));
element_class = JS_NewCFunction2(ctx, js_element_ctor, "element", 0, JS_CFUNC_constructor, 0); element_class = JS_NewCFunction2(ctx, js_element_ctor, "Element", 0, JS_CFUNC_constructor, 0);
/* set proto.constructor and ctor.prototype */ /* set proto.constructor and ctor.prototype */
JS_SetConstructor(ctx, element_class, element_proto); JS_SetConstructor(ctx, element_class, element_proto);
JS_SetClassProto(ctx, js_element_class_id, element_proto); JS_SetClassProto(ctx, js_element_class_id, element_proto);
JS_SetPropertyStr(ctx, global_obj, "element", element_proto); JS_SetPropertyStr(ctx, global_obj, "Element", element_class);
JS_FreeValue(ctx, global_obj);
return 0; return 0;
} }
JSValue JSValue
getElement(JSContext *ctx, void *node) getElement(JSContext *ctx, void *node)
{ {

View File

@ -5,6 +5,7 @@
JSValue getElement(JSContext *ctx, void *node); JSValue getElement(JSContext *ctx, void *node);
int js_element_init(JSContext *ctx);
void walk_tree(struct string *buf, void *nod, bool start = true, bool toSortAttrs = false); void walk_tree(struct string *buf, void *nod, bool start = true, bool toSortAttrs = false);
#endif #endif