mirror of
https://github.com/DoneJS-Runtime/quickjs-done-nextgen.git
synced 2025-01-09 17:43:15 +00:00
37fe427d59
This commit implements resizable ArrayBuffers - RABs for short - and extends typed arrays (TAs) to support fixed-length and length-tracking modes. SharedArrayBuffers (SABs) also support the maxByteLength option now but I cheated and allocate all memory upfront because atomically resizing memory allocations is hard and this commit is already big and complex. The lion's share is updating all the TA prototype methods to deal with RABs resizing underneath them. Method arguments can be arbitrary objects with arbitrary .valueOf methods and arbitrary side effects, like... resizing the RAB we're currently operating on. Fixes: https://github.com/quickjs-ng/quickjs/issues/477
104 lines
3.9 KiB
C
104 lines
3.9 KiB
C
/* File generated automatically by the QuickJS-ng compiler. */
|
|
|
|
#include "quickjs-libc.h"
|
|
|
|
const uint32_t qjsc_fib_module_size = 314;
|
|
|
|
const uint8_t qjsc_fib_module[314] = {
|
|
0x11, 0x03, 0x01, 0x2c, 0x65, 0x78, 0x61, 0x6d,
|
|
0x70, 0x6c, 0x65, 0x73, 0x2f, 0x66, 0x69, 0x62,
|
|
0x5f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e,
|
|
0x6a, 0x73, 0x01, 0x06, 0x66, 0x69, 0x62, 0x01,
|
|
0x02, 0x6e, 0x0d, 0xbc, 0x03, 0x00, 0x01, 0x00,
|
|
0x00, 0xbe, 0x03, 0x00, 0x00, 0x00, 0x0c, 0x20,
|
|
0xfa, 0x01, 0xa2, 0x01, 0x00, 0x00, 0x00, 0x01,
|
|
0x01, 0x01, 0x09, 0x00, 0xbe, 0x03, 0x00, 0x01,
|
|
0x0c, 0x43, 0xfa, 0x01, 0xbe, 0x03, 0x01, 0x00,
|
|
0x01, 0x04, 0x01, 0x00, 0x1a, 0x01, 0xc0, 0x03,
|
|
0x00, 0x01, 0x00, 0xbe, 0x03, 0x00, 0x00, 0xd1,
|
|
0xb4, 0xa7, 0xea, 0x03, 0xb4, 0x28, 0xd1, 0xb5,
|
|
0xac, 0xea, 0x03, 0xb5, 0x28, 0xdd, 0xd1, 0xb5,
|
|
0x9e, 0xef, 0xdd, 0xd1, 0xb6, 0x9e, 0xef, 0x9d,
|
|
0x28, 0xbc, 0x03, 0x02, 0x08, 0x20, 0x04, 0x00,
|
|
0x07, 0x06, 0x07, 0x06, 0x12, 0x09, 0x08, 0x07,
|
|
0x07, 0x10, 0x07, 0x06, 0x07, 0x06, 0x12, 0x13,
|
|
0x08, 0x07, 0x08, 0x16, 0x0c, 0x0c, 0x07, 0x04,
|
|
0x0c, 0x0a, 0x0c, 0x0c, 0x07, 0x04, 0x8d, 0x01,
|
|
0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e,
|
|
0x20, 0x66, 0x69, 0x62, 0x28, 0x6e, 0x29, 0x0a,
|
|
0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66,
|
|
0x20, 0x28, 0x6e, 0x20, 0x3c, 0x3d, 0x20, 0x30,
|
|
0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
|
0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e,
|
|
0x20, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20,
|
|
0x65, 0x6c, 0x73, 0x65, 0x20, 0x69, 0x66, 0x20,
|
|
0x28, 0x6e, 0x20, 0x3d, 0x3d, 0x20, 0x31, 0x29,
|
|
0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
|
0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20,
|
|
0x31, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x65,
|
|
0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x20,
|
|
0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75,
|
|
0x72, 0x6e, 0x20, 0x66, 0x69, 0x62, 0x28, 0x6e,
|
|
0x20, 0x2d, 0x20, 0x31, 0x29, 0x20, 0x2b, 0x20,
|
|
0x66, 0x69, 0x62, 0x28, 0x6e, 0x20, 0x2d, 0x20,
|
|
0x32, 0x29, 0x3b, 0x0a, 0x7d, 0x08, 0xea, 0x05,
|
|
0xbf, 0x00, 0xe1, 0x29, 0x06, 0x2e, 0xbc, 0x03,
|
|
0x01, 0x01, 0x06, 0x01, 0x01, 0x00, 0x07, 0x14,
|
|
0x02, 0x00,
|
|
};
|
|
|
|
const uint32_t qjsc_hello_module_size = 185;
|
|
|
|
const uint8_t qjsc_hello_module[185] = {
|
|
0x11, 0x07, 0x01, 0x30, 0x65, 0x78, 0x61, 0x6d,
|
|
0x70, 0x6c, 0x65, 0x73, 0x2f, 0x68, 0x65, 0x6c,
|
|
0x6c, 0x6f, 0x5f, 0x6d, 0x6f, 0x64, 0x75, 0x6c,
|
|
0x65, 0x2e, 0x6a, 0x73, 0x01, 0x1e, 0x2e, 0x2f,
|
|
0x66, 0x69, 0x62, 0x5f, 0x6d, 0x6f, 0x64, 0x75,
|
|
0x6c, 0x65, 0x2e, 0x6a, 0x73, 0x01, 0x06, 0x66,
|
|
0x69, 0x62, 0x01, 0x0e, 0x63, 0x6f, 0x6e, 0x73,
|
|
0x6f, 0x6c, 0x65, 0x01, 0x06, 0x6c, 0x6f, 0x67,
|
|
0x01, 0x16, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20,
|
|
0x57, 0x6f, 0x72, 0x6c, 0x64, 0x01, 0x10, 0x66,
|
|
0x69, 0x62, 0x28, 0x31, 0x30, 0x29, 0x3d, 0x0d,
|
|
0xbc, 0x03, 0x01, 0xbe, 0x03, 0x00, 0x00, 0x01,
|
|
0x00, 0xc0, 0x03, 0x00, 0x00, 0x0c, 0x20, 0xfa,
|
|
0x01, 0xa2, 0x01, 0x00, 0x00, 0x00, 0x05, 0x01,
|
|
0x00, 0x32, 0x00, 0xc0, 0x03, 0x00, 0x0c, 0x08,
|
|
0xea, 0x02, 0x29, 0x38, 0xe1, 0x00, 0x00, 0x00,
|
|
0x42, 0xe2, 0x00, 0x00, 0x00, 0x04, 0xe3, 0x00,
|
|
0x00, 0x00, 0x24, 0x01, 0x00, 0x0e, 0x38, 0xe1,
|
|
0x00, 0x00, 0x00, 0x42, 0xe2, 0x00, 0x00, 0x00,
|
|
0x04, 0xe4, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00,
|
|
0xbc, 0x0a, 0xef, 0x24, 0x02, 0x00, 0x0e, 0x06,
|
|
0x2e, 0xbc, 0x03, 0x01, 0x01, 0x0a, 0x01, 0x01,
|
|
0x00, 0x04, 0x0a, 0x02, 0x62, 0x00, 0x4d, 0x30,
|
|
0x00,
|
|
};
|
|
|
|
static JSContext *JS_NewCustomContext(JSRuntime *rt)
|
|
{
|
|
JSContext *ctx = JS_NewContext(rt);
|
|
if (!ctx)
|
|
return NULL;
|
|
js_std_eval_binary(ctx, qjsc_fib_module, qjsc_fib_module_size, 1);
|
|
return ctx;
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
JSRuntime *rt;
|
|
JSContext *ctx;
|
|
rt = JS_NewRuntime();
|
|
js_std_set_worker_new_context_func(JS_NewCustomContext);
|
|
js_std_init_handlers(rt);
|
|
JS_SetModuleLoaderFunc(rt, NULL, js_module_loader, NULL);
|
|
ctx = JS_NewCustomContext(rt);
|
|
js_std_add_helpers(ctx, argc, argv);
|
|
js_std_eval_binary(ctx, qjsc_hello_module, qjsc_hello_module_size, 0);
|
|
js_std_loop(ctx);
|
|
JS_FreeContext(ctx);
|
|
js_std_free_handlers(rt);
|
|
JS_FreeRuntime(rt);
|
|
return 0;
|
|
}
|