refactor
This commit is contained in:
@@ -1,30 +1,5 @@
|
||||
/*
|
||||
* QuickJS Javascript Engine
|
||||
*
|
||||
* Copyright (c) 2017-2025 Fabrice Bellard
|
||||
* Copyright (c) 2017-2025 Charlie Gordon
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#define BLOB_IMPLEMENTATION
|
||||
#include "quickjs-internal.h"
|
||||
#include "pit_internal.h"
|
||||
#include <unistd.h>
|
||||
|
||||
// #define DUMP_BUDDY
|
||||
@@ -87,7 +62,7 @@ static inline JS_BOOL JS_IsInteger (JSValue v) {
|
||||
JSClassID js_class_id_alloc = JS_CLASS_INIT_COUNT;
|
||||
|
||||
/* === Public API wrappers (non-inline, for quickjs.h declarations) ===
|
||||
These delegate to the static inline versions in quickjs-internal.h. */
|
||||
These delegate to the static inline versions in pit_internal.h. */
|
||||
|
||||
JS_BOOL JS_IsStone(JSValue v) { return mist_is_stone(v); }
|
||||
JS_BOOL JS_IsArray(JSValue v) { return mist_is_array(v); }
|
||||
@@ -1943,10 +1918,8 @@ int ctx_gc (JSContext *ctx, int allow_grow, size_t alloc_size) {
|
||||
/* Check memory limit — kill actor if heap exceeds cap */
|
||||
if (ctx->heap_memory_limit > 0 && ctx->current_block_size > ctx->heap_memory_limit) {
|
||||
#ifdef ACTOR_TRACE
|
||||
void *crt = ctx->user_opaque;
|
||||
if (crt)
|
||||
fprintf(stderr, "[ACTOR_TRACE] heap %zu > limit %zu, OOM\n",
|
||||
ctx->current_block_size, ctx->heap_memory_limit);
|
||||
fprintf(stderr, "[ACTOR_TRACE] heap %zu > limit %zu, OOM\n",
|
||||
ctx->current_block_size, ctx->heap_memory_limit);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
@@ -2080,6 +2053,18 @@ JSContext *JS_NewContextRawWithHeapSize (JSRuntime *rt, size_t heap_size) {
|
||||
ctx->log_callback_js = JS_NULL;
|
||||
ctx->log_callback = NULL;
|
||||
|
||||
/* Register actor GCRef fields so the Cheney GC can relocate them. */
|
||||
JS_AddGCRef(ctx, &ctx->idx_buffer_ref);
|
||||
JS_AddGCRef(ctx, &ctx->on_exception_ref);
|
||||
JS_AddGCRef(ctx, &ctx->message_handle_ref);
|
||||
JS_AddGCRef(ctx, &ctx->unneeded_ref);
|
||||
JS_AddGCRef(ctx, &ctx->actor_sym_ref);
|
||||
ctx->idx_buffer_ref.val = JS_NULL;
|
||||
ctx->on_exception_ref.val = JS_NULL;
|
||||
ctx->message_handle_ref.val = JS_NULL;
|
||||
ctx->unneeded_ref.val = JS_NULL;
|
||||
ctx->actor_sym_ref.val = JS_NULL;
|
||||
|
||||
/* Initialize constant text pool (avoids overflow pages for common case) */
|
||||
{
|
||||
size_t ct_pool_size = 64 * 1024; /* 64KB initial CT pool */
|
||||
@@ -2156,11 +2141,7 @@ JSContext *JS_NewContextWithHeapSize (JSRuntime *rt, size_t heap_size) {
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void *JS_GetContextOpaque (JSContext *ctx) { return ctx->user_opaque; }
|
||||
|
||||
void JS_SetContextOpaque (JSContext *ctx, void *opaque) {
|
||||
ctx->user_opaque = opaque;
|
||||
}
|
||||
|
||||
void JS_SetGCScanExternal(JSContext *ctx, JS_GCScanFn fn) {
|
||||
ctx->gc_scan_external = fn;
|
||||
@@ -2190,6 +2171,11 @@ void JS_FreeContext (JSContext *ctx) {
|
||||
|
||||
cell_rt_free_native_state(ctx);
|
||||
JS_DeleteGCRef(ctx, &ctx->suspended_frame_ref);
|
||||
JS_DeleteGCRef(ctx, &ctx->idx_buffer_ref);
|
||||
JS_DeleteGCRef(ctx, &ctx->on_exception_ref);
|
||||
JS_DeleteGCRef(ctx, &ctx->message_handle_ref);
|
||||
JS_DeleteGCRef(ctx, &ctx->unneeded_ref);
|
||||
JS_DeleteGCRef(ctx, &ctx->actor_sym_ref);
|
||||
|
||||
for (i = 0; i < ctx->class_count; i++) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user