From 0702e3495dc31a783a72c0f63a9a1e4f8632f7d0 Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Sun, 15 Jun 2025 05:15:51 -0500 Subject: [PATCH] finish remove? --- benchmarks/montecarlo.ce | 2 +- meson.build | 16 - scripts/base.cm | 150 ------- scripts/engine.cm | 3 +- source/cell.c | 75 +++- source/jsffi.c | 2 - source/quickjs-opcode.h | 10 - source/quickjs.c | 858 +++------------------------------------ source/quickjs.h | 6 - 9 files changed, 136 insertions(+), 986 deletions(-) diff --git a/benchmarks/montecarlo.ce b/benchmarks/montecarlo.ce index e4e7891d..f847c5da 100644 --- a/benchmarks/montecarlo.ce +++ b/benchmarks/montecarlo.ce @@ -1,4 +1,4 @@ -var N = 10000000; +var N = 1000000; var num = 0; for (var i = 0; i < N; i ++) { var x = 2 * $_.random(); diff --git a/meson.build b/meson.build index fdb43506..c88eab2f 100644 --- a/meson.build +++ b/meson.build @@ -162,14 +162,6 @@ else endif # Try to find system-installed qjs-layout first -qjs_layout_dep = dependency('qjs-layout', static: true, required: false) -if not qjs_layout_dep.found() - message('βš™ System qjs-layout not found, building subproject...') - deps += dependency('qjs-layout', static:true) -else - deps += qjs_layout_dep -endif - miniz_dep = dependency('miniz', static: true, required: false) if not miniz_dep.found() message('βš™ System miniz not found, building subproject...') @@ -178,14 +170,6 @@ else deps += miniz_dep endif -libuv_dep = dependency('libuv', static: true, required: false) -if not libuv_dep.found() - message('βš™ System libuv not found, building subproject...') - deps += dependency('libuv', static:true, fallback: ['libuv', 'libuv_dep']) -else - deps += libuv_dep -endif - # Try to find system-installed physfs first physfs_dep = dependency('physfs', static: true, required: false) if not physfs_dep.found() diff --git a/scripts/base.cm b/scripts/base.cm index d33424c6..b60e1d5a 100644 --- a/scripts/base.cm +++ b/scripts/base.cm @@ -4,13 +4,6 @@ Object.mixin = function (target, source) { return target; }; -Object.mixin[cell.DOC] = `Copy all property descriptors from 'source' into 'target'. - -:param target: The object that will receive properties. -:param source: The object whose properties are to be copied. -:return: The updated 'target' object. -`; - Object.defineProperty(Object.prototype, "mixin", { value: function mixin(obj) { if (typeof obj === "string") obj = use(obj); @@ -18,13 +11,6 @@ Object.defineProperty(Object.prototype, "mixin", { }, }); -(Object.prototype.mixin)[cell.DOC] = `Mix properties from 'obj' into the current object. If 'obj' is a string, -it first calls 'use(obj)' to retrieve the object. - -:param obj: The object (or string reference to an object) to mix in. -:return: None -`; - /* STRING DEFS */ Object.defineProperty(String.prototype, "rm", { value: function (index, endidx = index + 1) { @@ -32,14 +18,6 @@ Object.defineProperty(String.prototype, "rm", { }, }); -(String.prototype.rm)[cell.DOC] = `Remove characters from this string between 'index' (inclusive) -and 'endidx' (exclusive). If 'endidx' is omitted, it defaults to 'index + 1'. - -:param index: The starting index to remove. -:param endidx: The ending index (exclusive). -:return: A new string with the specified characters removed. -`; - Object.defineProperty(String.prototype, "tolast", { value: function (val) { var idx = this.lastIndexOf(val); @@ -48,12 +26,6 @@ Object.defineProperty(String.prototype, "tolast", { }, }); -(String.prototype.tolast)[cell.DOC] = `Return the substring of this string up to the last occurrence of 'val'. -If 'val' is not found, the entire string is returned. - -:param val: The substring to locate from the end. -:return: A substring up to the last occurrence of 'val'. -`; Object.defineProperty(String.prototype, "dir", { value: function () { @@ -62,11 +34,6 @@ Object.defineProperty(String.prototype, "dir", { }, }); -(String.prototype.dir)[cell.DOC] = `Return everything before the last slash ('/') in the string. -If no slash is found, return an empty string. - -:return: The directory portion of the path. -`; Object.defineProperty(String.prototype, "next", { value: function (char, from) { @@ -89,14 +56,6 @@ Object.defineProperty(String.prototype, "next", { }, }); -(String.prototype.next)[cell.DOC] = `Search for the next occurrence of 'char' in this string, starting at 'from'. -If 'char' is an array, any of those characters qualifies. Return the matching index, -or -1 if none is found. - -:param char: A character (or array of characters) to locate. -:param from: The index to start from. -:return: The index of the next occurrence, or -1 if not found. -`; Object.defineProperty(String.prototype, "prev", { value: function (char, from, count = 0) { @@ -115,15 +74,6 @@ Object.defineProperty(String.prototype, "prev", { }, }); -(String.prototype.prev)[cell.DOC] = `Search for the previous occurrence of 'char' before index 'from'. -If 'count' is greater than 1, skip multiple occurrences going backward. -Return the found index or 0 if not found. - -:param char: The character to locate. -:param from: The index to start from (defaults to the end of the string). -:param count: How many occurrences to skip backward (default 0). -:return: The index of the previous occurrence, or 0 if not found. -`; Object.defineProperty(String.prototype, "strip_ext", { value: function () { @@ -131,11 +81,6 @@ Object.defineProperty(String.prototype, "strip_ext", { }, }); -(String.prototype.strip_ext)[cell.DOC] = `Return the string up to (but not including) the last '.' character. -If '.' is not found, the entire string is returned. - -:return: The string without its last extension. -`; Object.defineProperty(String.prototype, "ext", { value: function () { @@ -143,11 +88,6 @@ Object.defineProperty(String.prototype, "ext", { }, }); -(String.prototype.ext)[cell.DOC] = `Return the substring after the last '.' in this string. -If '.' is not found, return an empty string. - -:return: The file extension or an empty string. -`; Object.defineProperty(String.prototype, "up_path", { value: function () { @@ -158,10 +98,6 @@ Object.defineProperty(String.prototype, "up_path", { }, }); -(String.prototype.up_path)[cell.DOC] = `Go up one directory level from the current path, preserving the file name at the end. - -:return: A new path string one directory up, with the base filename preserved. -`; Object.defineProperty(String.prototype, "fromlast", { value: function (val) { @@ -171,12 +107,6 @@ Object.defineProperty(String.prototype, "fromlast", { }, }); -(String.prototype.fromlast)[cell.DOC] = `Return the substring that appears after the last occurrence of 'val'. -If 'val' is not found, an empty string is returned. - -:param val: The substring to locate. -:return: The substring after the last occurrence of 'val'. -`; Object.defineProperty(String.prototype, "tofirst", { value: function (val) { @@ -186,12 +116,6 @@ Object.defineProperty(String.prototype, "tofirst", { }, }); -(String.prototype.tofirst)[cell.DOC] = `Return the substring from the start of this string up to the first occurrence -of 'val' (excluded). If 'val' is not found, the entire string is returned. - -:param val: The substring to locate. -:return: A substring up to the first occurrence of 'val'. -`; Object.defineProperty(String.prototype, "fromfirst", { value: function (val) { @@ -201,12 +125,6 @@ Object.defineProperty(String.prototype, "fromfirst", { }, }); -(String.prototype.fromfirst)[cell.DOC] = `Return the substring after the first occurrence of 'val'. -If 'val' is not found, the entire string is returned. - -:param val: The substring to locate. -:return: The substring after 'val', or the entire string if 'val' not found. -`; Object.defineProperty(String.prototype, "name", { value: function () { @@ -216,12 +134,6 @@ Object.defineProperty(String.prototype, "name", { }, }); -(String.prototype.name)[cell.DOC] = `Return the "name" portion of the path without extension. -If no slash is found, it's up to the last '.' in the entire string. -If there is a slash, it's from the last slash up to (but not including) the last '.'. - -:return: The name portion of the path without extension. -`; Object.defineProperty(String.prototype, "set_name", { value: function (name) { @@ -230,12 +142,6 @@ Object.defineProperty(String.prototype, "set_name", { }, }); -(String.prototype.set_name)[cell.DOC] = `Set the base name (excluding extension) of the path to 'name', preserving -the original directory and extension. - -:param name: The new name to use. -:return: A new path string with the updated name. -`; Object.defineProperty(String.prototype, "base", { value: function () { @@ -243,11 +149,6 @@ Object.defineProperty(String.prototype, "base", { }, }); -(String.prototype.base)[cell.DOC] = `Return the portion of this string after the last '/' character. -If no '/' is present, the entire string is returned. - -:return: The base name of the path. -`; Object.defineProperty(String.prototype, "updir", { value: function () { @@ -257,11 +158,6 @@ Object.defineProperty(String.prototype, "updir", { }, }); -(String.prototype.updir)[cell.DOC] = `Go up one directory from the current path, removing the last directory name. -If the path ends with a slash, remove it first. Then remove the final directory. - -:return: A new string representing one directory level up. -`; /* ARRAY DEFS */ Object.defineProperty(Array.prototype, "filter!", { @@ -276,13 +172,6 @@ Object.defineProperty(Array.prototype, "filter!", { }, }); -(Array.prototype["filter!"])[cell.DOC] = `Perform an in-place filter of this array using the provided callback 'fn'. -Any element for which 'fn' returns a falsy value is removed. The array is modified -and then returned. - -:param fn: A callback function(element, index, array) => boolean. -:return: The filtered (modified) array. -`; Object.defineProperty(Array.prototype, "delete", { value: function(item) { @@ -292,12 +181,6 @@ Object.defineProperty(Array.prototype, "delete", { } }); -(Array.prototype.delete)[cell.DOC] = `Remove the first occurrence of 'item' from the array, if it exists. -Returns undefined. - -:param item: The item to remove. -:return: undefined -`; Object.defineProperty(Array.prototype, "copy", { value: function () { @@ -309,11 +192,6 @@ Object.defineProperty(Array.prototype, "copy", { }, }); -(Array.prototype.copy)[cell.DOC] = `Return a deep copy of this array by applying 'deep_copy' to each element. -The resulting array is entirely new. - -:return: A new array that is a deep copy of the original. -`; Object.defineProperty(Array.prototype, "equal", { value: function equal(b) { @@ -329,12 +207,6 @@ Object.defineProperty(Array.prototype, "equal", { }, }); -(Array.prototype.equal)[cell.DOC] = `Check if this array and array 'b' have the same elements in the same order. -If they are of different lengths, return false. Otherwise compare them via JSON. - -:param b: Another array to compare against. -:return: True if they match, false otherwise. -`; Object.defineProperty(Array.prototype, "last", { value: function () { @@ -342,10 +214,6 @@ Object.defineProperty(Array.prototype, "last", { }, }); -(Array.prototype.last)[cell.DOC] = `Return the last element of this array. If the array is empty, returns undefined. - -:return: The last element of the array, or undefined if empty. -`; Object.defineProperty(Array.prototype, "wrapped", { value: function (x) { @@ -355,12 +223,6 @@ Object.defineProperty(Array.prototype, "wrapped", { }, }); -(Array.prototype.wrapped)[cell.DOC] = `Return a copy of the array with the first 'x' elements appended to the end. -Does not modify the original array. - -:param x: The number of leading elements to re-append. -:return: A new array with the leading elements wrapped to the end. -`; Object.defineProperty(Array.prototype, "wrap_idx", { value: function (x) { @@ -371,12 +233,6 @@ Object.defineProperty(Array.prototype, "wrap_idx", { }, }); -(Array.prototype.wrap_idx)[cell.DOC] = `Wrap the integer 'x' around this array's length, ensuring the resulting index -lies within [0, this.length - 1]. - -:param x: The index to wrap. -:return: A wrapped index within this array's bounds. -`; Object.defineProperty(Array.prototype, "mirrored", { value: function (x) { @@ -387,9 +243,3 @@ Object.defineProperty(Array.prototype, "mirrored", { }, }); -(Array.prototype.mirrored)[cell.DOC] = `Return a new array that appends a reversed copy (excluding the last element) -of itself to the end. For example, [1,2,3] -> [1,2,3,2,1]. If the array has length -<= 1, a copy of it is returned directly. - -:return: A new "mirrored" array. -`; diff --git a/scripts/engine.cm b/scripts/engine.cm index 27345849..287d8665 100644 --- a/scripts/engine.cm +++ b/scripts/engine.cm @@ -248,6 +248,7 @@ globalThis.use = function use(file, ...args) { return ret } + globalThis.json = use('json') var time = use('time') var st_now = time.number() @@ -424,7 +425,7 @@ $_.connection[cell.DOC] = "The connection function takes a callback function, an var peers = {} var id_address = {} -var peer_queue = new WeakMap() +var peer_queue = new Map() var portal = undefined var portal_fn = undefined diff --git a/source/cell.c b/source/cell.c index 20570d40..5ede7449 100644 --- a/source/cell.c +++ b/source/cell.c @@ -870,7 +870,80 @@ int main(int argc, char **argv) int profile_enabled = 0; int script_start = 1; - /* Check for --profile flag first */ + /* Check for --script flag - execute script directly without engine */ + if (argc > 2 && strcmp(argv[1], "--script") == 0) { + /* Read and execute the script file */ + FILE *f = fopen(argv[2], "rb"); + if (!f) { + perror("fopen"); + return 1; + } + + fseek(f, 0, SEEK_END); + long size = ftell(f); + if (size < 0) { + perror("ftell"); + fclose(f); + return 1; + } + + char *script = malloc(size + 1); + if (!script) { + perror("malloc"); + fclose(f); + return 1; + } + + rewind(f); + if (fread(script, 1, size, f) != size) { + perror("fread"); + free(script); + fclose(f); + return 1; + } + fclose(f); + script[size] = '\0'; + + /* Create minimal JS runtime */ + JSRuntime *rt = JS_NewRuntime(); + JSContext *js = JS_NewContextRaw(rt); + + /* Add basic intrinsics */ + JS_AddIntrinsicBaseObjects(js); + JS_AddIntrinsicEval(js); + JS_AddIntrinsicRegExp(js); + JS_AddIntrinsicJSON(js); + JS_AddIntrinsicMapSet(js); + JS_AddIntrinsicProxy(js); + + cell_rt *prt = malloc(sizeof(*prt)); + JS_SetContextOpaque(js, prt); + + /* Load FFI functions */ + ffi_load(js); + + /* Execute the script */ + JSValue result = JS_Eval(js, script, size, argv[2], JS_EVAL_FLAG_STRICT); + free(script); + + /* Check for exceptions */ + if (JS_IsException(result)) { + JSValue exp = JS_GetException(js); + const char *str = JS_ToCString(js, exp); + if (str) { + fprintf(stderr, "Exception: %s\n", str); + JS_FreeCString(js, str); + } + JS_FreeValue(js, exp); + } + + JS_FreeValue(js, result); + JS_FreeContext(js); + JS_FreeRuntime(rt); + return 0; + } + + /* Check for --profile flag */ if (argc > 1 && strcmp(argv[1], "--profile") == 0) { profile_enabled = 1; script_start = 2; } diff --git a/source/jsffi.c b/source/jsffi.c index 034ab555..03a3a0d8 100644 --- a/source/jsffi.c +++ b/source/jsffi.c @@ -1530,7 +1530,6 @@ js_##NAME = JS_NewObject(js); \ JS_SetPropertyFunctionList(js, js_##NAME, js_##NAME##_funcs, countof(js_##NAME##_funcs)); \ JS_SetPrototype(js, js_##NAME, PARENT); \ -JSValue js_layout_use(JSContext *js); JSValue js_miniz_use(JSContext *js); JSValue js_num_use(JSContext *js); @@ -1621,7 +1620,6 @@ void ffi_load(JSContext *js) arrput(rt->module_registry, MISTLINE(graphics)); arrput(rt->module_registry, MISTLINE(video)); arrput(rt->module_registry, MISTLINE(soloud)); - arrput(rt->module_registry, MISTLINE(layout)); // arrput(rt->module_registry, MISTLINE(imgui)); arrput(rt->module_registry, ((ModuleEntry){"camera", js_camera_use})); diff --git a/source/quickjs-opcode.h b/source/quickjs-opcode.h index 814a7cba..3f070f05 100644 --- a/source/quickjs-opcode.h +++ b/source/quickjs-opcode.h @@ -69,7 +69,6 @@ DEF( push_i32, 5, 0, 1, i32) DEF( push_const, 5, 0, 1, const) DEF( fclosure, 5, 0, 1, const) /* must follow push_const */ DEF(push_atom_value, 5, 0, 1, atom) -DEF( private_symbol, 5, 0, 1, atom) DEF( undefined, 1, 0, 1, none) DEF( null, 1, 0, 1, none) DEF( push_this, 1, 0, 1, none) /* only used at the start of a function */ @@ -113,7 +112,6 @@ DEF( check_ctor, 1, 0, 0, none) DEF( init_ctor, 1, 0, 1, none) DEF( check_brand, 1, 2, 2, none) /* this_obj func -> this_obj func */ DEF( add_brand, 1, 2, 0, none) /* this_obj home_obj -> */ -DEF( return_async, 1, 1, 0, none) DEF( throw, 1, 1, 0, none) DEF( throw_error, 6, 0, 0, atom_u8) DEF( eval, 5, 1, 1, npop_u16) /* func args... -> ret_val */ @@ -121,7 +119,6 @@ DEF( apply_eval, 3, 2, 1, u16) /* func array -> ret_eval */ DEF( regexp, 1, 2, 1, none) /* create a RegExp object from the pattern and a bytecode string */ DEF( get_super, 1, 1, 1, none) -DEF( import, 1, 2, 1, none) /* dynamic module import */ DEF( check_var, 5, 0, 1, atom) /* check if a variable exists */ DEF( get_var_undef, 5, 0, 1, atom) /* push undefined if the variable does not exist */ @@ -204,20 +201,13 @@ DEF( make_var_ref, 5, 0, 2, atom) DEF( for_in_start, 1, 1, 1, none) DEF( for_of_start, 1, 1, 3, none) -DEF(for_await_of_start, 1, 1, 3, none) DEF( for_in_next, 1, 1, 3, none) DEF( for_of_next, 2, 3, 5, u8) -DEF(for_await_of_next, 1, 3, 4, none) /* iter next catch_offset -> iter next catch_offset obj */ DEF(iterator_check_object, 1, 1, 1, none) DEF(iterator_get_value_done, 1, 2, 3, none) /* catch_offset obj -> catch_offset value done */ DEF( iterator_close, 1, 3, 0, none) DEF( iterator_next, 1, 4, 4, none) DEF( iterator_call, 2, 4, 5, u8) -DEF( initial_yield, 1, 0, 0, none) -DEF( yield, 1, 1, 2, none) -DEF( yield_star, 1, 1, 2, none) -DEF(async_yield_star, 1, 1, 2, none) -DEF( await, 1, 1, 1, none) /* arithmetic/logic operations */ DEF( neg, 1, 1, 1, none) diff --git a/source/quickjs.c b/source/quickjs.c index 2a9e1c7d..98172446 100644 --- a/source/quickjs.c +++ b/source/quickjs.c @@ -285,7 +285,6 @@ struct JSClass { }; #define JS_MODE_STRICT (1 << 0) -#define JS_MODE_ASYNC (1 << 2) /* async function */ #define JS_MODE_BACKTRACE_BARRIER (1 << 3) /* stop backtrace before this frame */ typedef struct JSStackFrame { @@ -298,9 +297,6 @@ typedef struct JSStackFrame { instruction after the call */ int arg_count; int js_mode; /* not supported for C functions */ - /* only used in generators. Current stack pointer value. NULL if - the function is running. */ - JSValue *cur_sp; } JSStackFrame; typedef enum { @@ -394,7 +390,6 @@ typedef struct { typedef enum { JS_AUTOINIT_ID_PROTOTYPE, - JS_AUTOINIT_ID_MODULE_NS, JS_AUTOINIT_ID_PROP, } JSAutoInitIDEnum; @@ -796,7 +791,6 @@ struct JSObject { struct JSRegExpStringIteratorData *regexp_string_iterator_data; /* JS_CLASS_REGEXP_STRING_ITERATOR */ struct JSProxyData *proxy_data; /* JS_CLASS_PROXY */ struct { /* JS_CLASS_BYTECODE_FUNCTION: 12/24 bytes */ - /* also used by JS_CLASS_GENERATOR_FUNCTION, JS_CLASS_ASYNC_FUNCTION and JS_CLASS_ASYNC_GENERATOR_FUNCTION */ struct JSFunctionBytecode *function_bytecode; JSVarRef **var_refs; JSObject *home_object; /* for 'super' access */ @@ -1045,7 +1039,6 @@ static JSVarRef *get_var_ref(JSContext *ctx, JSStackFrame *sf, int var_idx, static JSValue JS_EvalInternal(JSContext *ctx, JSValueConst this_obj, const char *input, size_t input_len, const char *filename, int flags, int scope_idx); -static JSValue js_import_meta(JSContext *ctx); static JSValue js_dynamic_import(JSContext *ctx, JSValueConst specifier, JSValueConst options); static void free_var_ref(JSRuntime *rt, JSVarRef *var_ref); @@ -1075,8 +1068,6 @@ static JSValue *build_arg_list(JSContext *ctx, uint32_t *plen, JSValueConst array_arg); static BOOL js_get_fast_array(JSContext *ctx, JSValueConst obj, JSValue **arrpp, uint32_t *countp); -static JSValue JS_CreateAsyncFromSyncIterator(JSContext *ctx, - JSValueConst sync_iter); static void js_c_function_data_finalizer(JSRuntime *rt, JSValue val); static void js_c_function_data_mark(JSRuntime *rt, JSValueConst val, JS_MarkFunc *mark_func); @@ -1088,8 +1079,6 @@ static void add_gc_object(JSRuntime *rt, JSGCObjectHeader *h, JSGCObjectTypeEnum type); static void remove_gc_object(JSGCObjectHeader *h); static JSValue js_instantiate_prototype(JSContext *ctx, JSObject *p, JSAtom atom, void *opaque); -static JSValue js_module_ns_autoinit(JSContext *ctx, JSObject *p, JSAtom atom, - void *opaque); static JSValue JS_InstantiateFunctionListItem2(JSContext *ctx, JSObject *p, JSAtom atom, void *opaque); static JSValue js_object_groupBy(JSContext *ctx, JSValueConst this_val, @@ -1864,7 +1853,6 @@ JSContext *JS_NewContext(JSRuntime *rt) JS_AddIntrinsicProxy(ctx); JS_AddIntrinsicMapSet(ctx); JS_AddIntrinsicTypedArrays(ctx); - JS_AddIntrinsicWeakRef(ctx); return ctx; } @@ -1934,7 +1922,6 @@ static void JS_MarkContext(JSRuntime *rt, JSContext *ctx, JS_MarkValue(rt, ctx->class_proto[i], mark_func); } JS_MarkValue(rt, ctx->iterator_proto, mark_func); - JS_MarkValue(rt, ctx->async_iterator_proto, mark_func); JS_MarkValue(rt, ctx->array_ctor, mark_func); JS_MarkValue(rt, ctx->regexp_ctor, mark_func); JS_MarkValue(rt, ctx->function_ctor, mark_func); @@ -1995,7 +1982,6 @@ void JS_FreeContext(JSContext *ctx) } js_free_rt(rt, ctx->class_proto); JS_FreeValue(ctx, ctx->iterator_proto); - JS_FreeValue(ctx, ctx->async_iterator_proto); JS_FreeValue(ctx, ctx->array_ctor); JS_FreeValue(ctx, ctx->regexp_ctor); JS_FreeValue(ctx, ctx->function_ctor); @@ -5559,9 +5545,6 @@ void __JS_FreeValueRT(JSRuntime *rt, JSValue v) } } break; - case JS_TAG_MODULE: - abort(); /* never freed here */ - break; case JS_TAG_BIG_INT: { JSBigInt *p = JS_VALUE_GET_PTR(v); @@ -7117,7 +7100,6 @@ typedef JSValue JSAutoInitFunc(JSContext *ctx, JSObject *p, JSAtom atom, void *o static JSAutoInitFunc *js_autoinit_func_table[] = { js_instantiate_prototype, /* JS_AUTOINIT_ID_PROTOTYPE */ - js_module_ns_autoinit, /* JS_AUTOINIT_ID_MODULE_NS */ JS_InstantiateFunctionListItem2, /* JS_AUTOINIT_ID_PROP */ }; @@ -7143,15 +7125,7 @@ static int JS_AutoInitProperty(JSContext *ctx, JSObject *p, JSAtom prop, pr->u.value = JS_UNDEFINED; if (JS_IsException(val)) return -1; - if (id == JS_AUTOINIT_ID_MODULE_NS && - JS_VALUE_GET_TAG(val) == JS_TAG_STRING) { - /* WARNING: a varref is returned as a string ! */ - prs->flags |= JS_PROP_VARREF; - pr->u.var_ref = JS_VALUE_GET_PTR(val); - pr->u.var_ref->header.ref_count++; - } else { - pr->u.value = val; - } + pr->u.value = val; return 0; } @@ -13229,9 +13203,6 @@ static void js_print_value(JSPrintValueState *s, JSValueConst val) js_putc(s, ')'); } break; - case JS_TAG_MODULE: - js_puts(s, "[module]"); - break; default: js_printf(s, "[unknown tag %d]", tag); break; @@ -15546,21 +15517,6 @@ static __exception int js_for_of_next(JSContext *ctx, JSValue *sp, int offset) return 0; } -static __exception int js_for_await_of_next(JSContext *ctx, JSValue *sp) -{ - JSValue obj, iter, next; - - sp[-1] = JS_UNDEFINED; /* disable the catch offset so that - exceptions do not close the iterator */ - iter = sp[-3]; - next = sp[-2]; - obj = JS_Call(ctx, next, iter, 0, NULL); - if (JS_IsException(obj)) - return -1; - sp[0] = obj; - return 0; -} - static JSValue JS_IteratorGetCompleteValue(JSContext *ctx, JSValueConst obj, BOOL *pdone) { @@ -15994,7 +15950,6 @@ static int js_op_define_class(JSContext *ctx, JSValue *sp, goto fail; b = JS_VALUE_GET_PTR(bfunc); - assert(b->func_kind == JS_FUNC_NORMAL); ctor = JS_NewObjectProtoClass(ctx, parent_class, JS_CLASS_BYTECODE_FUNCTION); if (JS_IsException(ctor)) @@ -16085,7 +16040,6 @@ static void close_lexical_var(JSContext *ctx, JSStackFrame *sf, int var_idx) } #define JS_CALL_FLAG_COPY_ARGV (1 << 1) -#define JS_CALL_FLAG_GENERATOR (1 << 2) static JSValue js_call_c_function(JSContext *ctx, JSValueConst func_obj, JSValueConst this_obj, @@ -16271,14 +16225,8 @@ typedef enum { OP_SPECIAL_OBJECT_NEW_TARGET, OP_SPECIAL_OBJECT_HOME_OBJECT, OP_SPECIAL_OBJECT_VAR_OBJECT, - OP_SPECIAL_OBJECT_IMPORT_META, } OPSpecialObjectEnum; -#define FUNC_RET_AWAIT 0 -#define FUNC_RET_YIELD 1 -#define FUNC_RET_YIELD_STAR 2 -#define FUNC_RET_INITIAL_YIELD 3 - /* argv[] is modified if (flags & JS_CALL_FLAG_COPY_ARGV) = 0. */ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, JSValueConst this_obj, JSValueConst new_target, @@ -16524,11 +16472,6 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, if (unlikely(JS_IsException(sp[-1]))) goto exception; break; - case OP_SPECIAL_OBJECT_IMPORT_META: - *sp++ = js_import_meta(ctx); - if (unlikely(JS_IsException(sp[-1]))) - goto exception; - break; default: abort(); } @@ -16981,20 +16924,6 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, } BREAK; - CASE(OP_import): - { - JSValue val; - sf->cur_pc = pc; - val = js_dynamic_import(ctx, sp[-2], sp[-1]); - if (JS_IsException(val)) - goto exception; - JS_FreeValue(ctx, sp[-2]); - JS_FreeValue(ctx, sp[-1]); - sp--; - sp[-1] = val; - } - BREAK; - CASE(OP_check_var): { int ret; @@ -17545,19 +17474,6 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, sp += 2; } BREAK; - CASE(OP_for_await_of_next): - sf->cur_pc = pc; - if (js_for_await_of_next(ctx, sp)) - goto exception; - sp++; - BREAK; - CASE(OP_for_await_of_start): - sf->cur_pc = pc; - if (js_for_of_start(ctx, sp)) - goto exception; - sp += 1; - *sp++ = JS_NewCatchOffset(ctx, 0); - BREAK; CASE(OP_iterator_get_value_done): sf->cur_pc = pc; if (js_iterator_get_value_done(ctx, sp)) @@ -17713,20 +17629,6 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, } BREAK; - CASE(OP_private_symbol): - { - JSAtom atom; - JSValue val; - - atom = get_u32(pc); - pc += 4; - val = JS_NewSymbolFromAtom(ctx, atom, JS_ATOM_TYPE_PRIVATE); - if (JS_IsException(val)) - goto exception; - *sp++ = val; - } - BREAK; - CASE(OP_get_private_field): { JSValue val; @@ -18789,23 +18691,6 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, } BREAK; - CASE(OP_await): - ret_val = JS_NewInt32(ctx, FUNC_RET_AWAIT); - goto done_generator; - CASE(OP_yield): - ret_val = JS_NewInt32(ctx, FUNC_RET_YIELD); - goto done_generator; - CASE(OP_yield_star): - CASE(OP_async_yield_star): - ret_val = JS_NewInt32(ctx, FUNC_RET_YIELD_STAR); - goto done_generator; - CASE(OP_return_async): - ret_val = JS_UNDEFINED; - goto done_generator; - CASE(OP_initial_yield): - ret_val = JS_NewInt32(ctx, FUNC_RET_INITIAL_YIELD); - goto done_generator; - CASE(OP_nop): BREAK; CASE(OP_is_undefined_or_null): @@ -19258,12 +19143,6 @@ typedef enum JSParseFunctionEnum { JS_PARSE_FUNC_DERIVED_CLASS_CONSTRUCTOR, } JSParseFunctionEnum; -typedef enum JSParseExportEnum { - JS_PARSE_EXPORT_NONE, - JS_PARSE_EXPORT_NAMED, - JS_PARSE_EXPORT_DEFAULT, -} JSParseExportEnum; - typedef struct JSFunctionDef { JSContext *ctx; struct JSFunctionDef *parent; @@ -19372,9 +19251,6 @@ typedef struct JSFunctionDef { char *source; /* raw source, utf-8 encoded */ int source_len; - - JSModuleDef *module; /* != NULL when parsing a module */ - BOOL has_await; /* TRUE if await is used (used in module eval) */ } JSFunctionDef; typedef struct JSToken { @@ -20007,30 +19883,21 @@ static __exception int ident_realloc(JSContext *ctx, char **pbuf, size_t *psize, /* convert a TOK_IDENT to a keyword when needed */ static void update_token_ident(JSParseState *s) { - if (s->token.u.ident.atom <= JS_ATOM_LAST_KEYWORD || - (s->token.u.ident.atom <= JS_ATOM_LAST_STRICT_KEYWORD && - (s->cur_func->js_mode & JS_MODE_STRICT)) || - (s->token.u.ident.atom == JS_ATOM_yield && - ((s->cur_func->func_kind & JS_FUNC_GENERATOR) || - (s->cur_func->func_type == JS_PARSE_FUNC_ARROW && - !s->cur_func->in_function_body && s->cur_func->parent && - (s->cur_func->parent->func_kind & JS_FUNC_GENERATOR)))) || - (s->token.u.ident.atom == JS_ATOM_await && - (s->is_module || - (s->cur_func->func_kind & JS_FUNC_ASYNC) || - s->cur_func->func_type == JS_PARSE_FUNC_CLASS_STATIC_INIT || - (s->cur_func->func_type == JS_PARSE_FUNC_ARROW && - !s->cur_func->in_function_body && s->cur_func->parent && - ((s->cur_func->parent->func_kind & JS_FUNC_ASYNC) || - s->cur_func->parent->func_type == JS_PARSE_FUNC_CLASS_STATIC_INIT))))) { - if (s->token.u.ident.has_escape) { - s->token.u.ident.is_reserved = TRUE; - s->token.val = TOK_IDENT; - } else { - /* The keywords atoms are pre allocated */ - s->token.val = s->token.u.ident.atom - 1 + TOK_FIRST_KEYWORD; - } + JSAtom atom = s->token.u.ident.atom; + /* if it’s a (strict-mode) keyword, convert it */ + if(atom <= JS_ATOM_LAST_KEYWORD || + (atom <= JS_ATOM_LAST_STRICT_KEYWORD && + (s->cur_func->js_mode & JS_MODE_STRICT))) { + if(s->token.u.ident.has_escape) { + /* identifiers with escape sequences stay identifiers */ + s->token.u.ident.is_reserved = TRUE; + s->token.val = TOK_IDENT; + } else { + /* keyword atoms are laid out so: + TOK_FIRST_KEYWORD + (atom - 1) == the right token code */ + s->token.val = TOK_FIRST_KEYWORD + (atom - 1); } + } } /* if the current token is an identifier or keyword, reparse it @@ -21027,54 +20894,6 @@ static int peek_token(JSParseState *s, BOOL no_line_terminator) return simple_next_token(&p, no_line_terminator); } -static void skip_shebang(const uint8_t **pp, const uint8_t *buf_end) -{ - const uint8_t *p = *pp; - int c; - - if (p[0] == '#' && p[1] == '!') { - p += 2; - while (p < buf_end) { - if (*p == '\n' || *p == '\r') { - break; - } else if (*p >= 0x80) { - c = unicode_from_utf8(p, UTF8_CHAR_LEN_MAX, &p); - if (c == CP_LS || c == CP_PS) { - break; - } else if (c == -1) { - p++; /* skip invalid UTF-8 */ - } - } else { - p++; - } - } - *pp = p; - } -} - -/* return true if 'input' contains the source of a module - (heuristic). 'input' must be a zero terminated. - - Heuristic: skip comments and expect 'import' keyword not followed - by '(' or '.' or export keyword. -*/ -BOOL JS_DetectModule(const char *input, size_t input_len) -{ - const uint8_t *p = (const uint8_t *)input; - int tok; - - skip_shebang(&p, p + input_len); - switch(simple_next_token(&p, FALSE)) { - case TOK_IMPORT: - tok = simple_next_token(&p, FALSE); - return (tok != '.' && tok != '('); - case TOK_EXPORT: - return TRUE; - default: - return FALSE; - } -} - static inline int get_prev_opcode(JSFunctionDef *fd) { if (fd->last_opcode_pos < 0 || dbuf_error(&fd->byte_code)) return OP_invalid; @@ -21088,7 +20907,6 @@ static BOOL js_is_live_code(JSParseState *s) { case OP_tail_call_method: case OP_return: case OP_return_undef: - case OP_return_async: case OP_throw: case OP_throw_error: case OP_goto: @@ -21716,14 +21534,11 @@ static int add_private_class_field(JSParseState *s, JSFunctionDef *fd, static __exception int js_parse_expr(JSParseState *s); static __exception int js_parse_function_decl(JSParseState *s, JSParseFunctionEnum func_type, - JSFunctionKindEnum func_kind, JSAtom func_name, const uint8_t *ptr); static __exception int js_parse_function_decl2(JSParseState *s, JSParseFunctionEnum func_type, - JSFunctionKindEnum func_kind, JSAtom func_name, const uint8_t *ptr, - JSParseExportEnum export_flag, JSFunctionDef **pfd); static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags); static __exception int js_parse_assign_expr(JSParseState *s); @@ -21866,9 +21681,6 @@ static __exception int js_parse_template(JSParseState *s, int call, int *argc) #define PROP_TYPE_VAR 1 #define PROP_TYPE_GET 2 #define PROP_TYPE_SET 3 -#define PROP_TYPE_STAR 4 -#define PROP_TYPE_ASYNC 5 -#define PROP_TYPE_ASYNC_STAR 6 #define PROP_TYPE_PRIVATE (1 << 4) @@ -21912,30 +21724,7 @@ static int __exception js_parse_property_name(JSParseState *s, } prop_type = PROP_TYPE_GET + (name == JS_ATOM_set); JS_FreeAtom(s->ctx, name); - } else if (s->token.val == '*') { - if (next_token(s)) - goto fail; - prop_type = PROP_TYPE_STAR; - } else if (token_is_pseudo_keyword(s, JS_ATOM_async) && - peek_token(s, TRUE) != '\n') { - name = JS_DupAtom(s->ctx, s->token.u.ident.atom); - if (next_token(s)) - goto fail1; - if (s->token.val == ':' || s->token.val == ',' || - s->token.val == '}' || s->token.val == '(' || - s->token.val == '=') { - is_non_reserved_ident = TRUE; - goto ident_found; - } - JS_FreeAtom(s->ctx, name); - if (s->token.val == '*') { - if (next_token(s)) - goto fail; - prop_type = PROP_TYPE_ASYNC_STAR; - } else { - prop_type = PROP_TYPE_ASYNC; - } - } + } } if (token_is_ident(s->token.val)) { @@ -22271,7 +22060,6 @@ static __exception int js_parse_object_literal(JSParseState *s) BOOL is_getset = (prop_type == PROP_TYPE_GET || prop_type == PROP_TYPE_SET); JSParseFunctionEnum func_type; - JSFunctionKindEnum func_kind; int op_flags; if (is_getset) { @@ -22279,7 +22067,7 @@ static __exception int js_parse_object_literal(JSParseState *s) } else { func_type = JS_PARSE_FUNC_METHOD; } - if (js_parse_function_decl(s, func_type, func_kind, JS_ATOM_NULL, + if (js_parse_function_decl(s, func_type, JS_ATOM_NULL, start_ptr)) goto fail; if (name == JS_ATOM_NULL) { @@ -23461,7 +23249,7 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) break; case TOK_FUNCTION: if (js_parse_function_decl(s, JS_PARSE_FUNC_EXPR, - JS_FUNC_NORMAL, JS_ATOM_NULL, + JS_ATOM_NULL, s->token.ptr)) return -1; break; @@ -23489,42 +23277,26 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) break; case TOK_IDENT: { - JSAtom name; - const uint8_t *source_ptr; - if (s->token.u.ident.is_reserved) { - return js_parse_error_reserved_identifier(s); - } - source_ptr = s->token.ptr; - if (token_is_pseudo_keyword(s, JS_ATOM_async) && - peek_token(s, TRUE) != '\n') { - if (next_token(s)) - return -1; - if (s->token.val == TOK_FUNCTION) { - if (js_parse_function_decl(s, JS_PARSE_FUNC_EXPR, - JS_FUNC_ASYNC, JS_ATOM_NULL, - source_ptr)) - return -1; - } else { - name = JS_DupAtom(s->ctx, JS_ATOM_async); - goto do_get_var; - } - } else { - if (s->token.u.ident.atom == JS_ATOM_arguments && - !s->cur_func->arguments_allowed) { - js_parse_error(s, "'arguments' identifier is not allowed in class field initializer"); - return -1; - } - name = JS_DupAtom(s->ctx, s->token.u.ident.atom); - if (next_token(s)) { - JS_FreeAtom(s->ctx, name); - return -1; - } - do_get_var: - emit_source_pos(s, source_ptr); - emit_op(s, OP_scope_get_var); - emit_u32(s, name); - emit_u16(s, s->cur_func->scope_level); - } + JSAtom name; + const uint8_t *source_ptr; + if (s->token.u.ident.is_reserved) { + return js_parse_error_reserved_identifier(s); + } + source_ptr = s->token.ptr; + if (s->token.u.ident.atom == JS_ATOM_arguments && + !s->cur_func->arguments_allowed) { + js_parse_error(s, "'arguments' identifier is not allowed in class field initializer"); + return -1; + } + name = JS_DupAtom(s->ctx, s->token.u.ident.atom); + if (next_token(s)) { + JS_FreeAtom(s->ctx, name); + return -1; + } + emit_source_pos(s, source_ptr); + emit_op(s, OP_scope_get_var); + emit_u32(s, name); + emit_u16(s, s->cur_func->scope_level); } break; case '{': @@ -23567,49 +23339,6 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) } } break; - case TOK_IMPORT: - if (next_token(s)) - return -1; - if (s->token.val == '.') { - if (next_token(s)) - return -1; - if (!token_is_pseudo_keyword(s, JS_ATOM_meta)) - return js_parse_error(s, "meta expected"); - if (!s->is_module) - return js_parse_error(s, "import.meta only valid in module code"); - if (next_token(s)) - return -1; - emit_op(s, OP_special_object); - emit_u8(s, OP_SPECIAL_OBJECT_IMPORT_META); - } else { - if (js_parse_expect(s, '(')) - return -1; - if (!accept_lparen) - return js_parse_error(s, "invalid use of 'import()'"); - if (js_parse_assign_expr(s)) - return -1; - if (s->token.val == ',') { - if (next_token(s)) - return -1; - if (s->token.val != ')') { - if (js_parse_assign_expr(s)) - return -1; - /* accept a trailing comma */ - if (s->token.val == ',') { - if (next_token(s)) - return -1; - } - } else { - emit_op(s, OP_undefined); - } - } else { - emit_op(s, OP_undefined); - } - if (js_parse_expect(s, ')')) - return -1; - emit_op(s, OP_import); - } - break; default: return js_parse_error(s, "unexpected token in expression: '%.*s'", (int)(s->buf_ptr - s->token.ptr), s->token.ptr); @@ -24170,19 +23899,6 @@ static __exception int js_parse_unary(JSParseState *s, int parse_flags) return -1; parse_flags = 0; break; - case TOK_AWAIT: - if (!(s->cur_func->func_kind & JS_FUNC_ASYNC)) - return js_parse_error(s, "unexpected 'await' keyword"); - if (!s->cur_func->in_function_body) - return js_parse_error(s, "await in default expression"); - if (next_token(s)) - return -1; - if (js_parse_unary(s, PF_POW_FORBIDDEN)) - return -1; - s->cur_func->has_await = TRUE; - emit_op(s, OP_await); - parse_flags = 0; - break; default: if (js_parse_postfix_expr(s, PF_POSTFIX_CALL)) return -1; @@ -24499,178 +24215,15 @@ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags) JSAtom name0 = JS_ATOM_NULL; JSAtom name; - if (s->token.val == TOK_YIELD) { - BOOL is_star = FALSE, is_async; - - if (!(s->cur_func->func_kind & JS_FUNC_GENERATOR)) - return js_parse_error(s, "unexpected 'yield' keyword"); - if (!s->cur_func->in_function_body) - return js_parse_error(s, "yield in default expression"); - if (next_token(s)) - return -1; - /* XXX: is there a better method to detect 'yield' without - parameters ? */ - if (s->token.val != ';' && s->token.val != ')' && - s->token.val != ']' && s->token.val != '}' && - s->token.val != ',' && s->token.val != ':' && !s->got_lf) { - if (s->token.val == '*') { - is_star = TRUE; - if (next_token(s)) - return -1; - } - if (js_parse_assign_expr2(s, parse_flags)) - return -1; - } else { - emit_op(s, OP_undefined); - } - is_async = (s->cur_func->func_kind == JS_FUNC_ASYNC_GENERATOR); - - if (is_star) { - int label_loop, label_return, label_next; - int label_return1, label_yield, label_throw, label_throw1; - int label_throw2; - - label_loop = new_label(s); - label_yield = new_label(s); - - emit_op(s, is_async ? OP_for_await_of_start : OP_for_of_start); - - /* remove the catch offset (XXX: could avoid pushing back - undefined) */ - emit_op(s, OP_drop); - emit_op(s, OP_undefined); - - emit_op(s, OP_undefined); /* initial value */ - - emit_label(s, label_loop); - emit_op(s, OP_iterator_next); - if (is_async) - emit_op(s, OP_await); - emit_op(s, OP_iterator_check_object); - emit_op(s, OP_get_field2); - emit_atom(s, JS_ATOM_done); - label_next = emit_goto(s, OP_if_true, -1); /* end of loop */ - emit_label(s, label_yield); - if (is_async) { - /* OP_async_yield_star takes the value as parameter */ - emit_op(s, OP_get_field); - emit_atom(s, JS_ATOM_value); - emit_op(s, OP_async_yield_star); - } else { - /* OP_yield_star takes (value, done) as parameter */ - emit_op(s, OP_yield_star); - } - emit_op(s, OP_dup); - label_return = emit_goto(s, OP_if_true, -1); - emit_op(s, OP_drop); - emit_goto(s, OP_goto, label_loop); - - emit_label(s, label_return); - emit_op(s, OP_push_i32); - emit_u32(s, 2); - emit_op(s, OP_strict_eq); - label_throw = emit_goto(s, OP_if_true, -1); - - /* return handling */ - if (is_async) - emit_op(s, OP_await); - emit_op(s, OP_iterator_call); - emit_u8(s, 0); - label_return1 = emit_goto(s, OP_if_true, -1); - if (is_async) - emit_op(s, OP_await); - emit_op(s, OP_iterator_check_object); - emit_op(s, OP_get_field2); - emit_atom(s, JS_ATOM_done); - emit_goto(s, OP_if_false, label_yield); - - emit_op(s, OP_get_field); - emit_atom(s, JS_ATOM_value); - - emit_label(s, label_return1); - emit_op(s, OP_nip); - emit_op(s, OP_nip); - emit_op(s, OP_nip); - emit_return(s, TRUE); - - /* throw handling */ - emit_label(s, label_throw); - emit_op(s, OP_iterator_call); - emit_u8(s, 1); - label_throw1 = emit_goto(s, OP_if_true, -1); - if (is_async) - emit_op(s, OP_await); - emit_op(s, OP_iterator_check_object); - emit_op(s, OP_get_field2); - emit_atom(s, JS_ATOM_done); - emit_goto(s, OP_if_false, label_yield); - emit_goto(s, OP_goto, label_next); - /* close the iterator and throw a type error exception */ - emit_label(s, label_throw1); - emit_op(s, OP_iterator_call); - emit_u8(s, 2); - label_throw2 = emit_goto(s, OP_if_true, -1); - if (is_async) - emit_op(s, OP_await); - emit_label(s, label_throw2); - - emit_op(s, OP_throw_error); - emit_atom(s, JS_ATOM_NULL); - emit_u8(s, JS_THROW_ERROR_ITERATOR_THROW); - - emit_label(s, label_next); - emit_op(s, OP_get_field); - emit_atom(s, JS_ATOM_value); - emit_op(s, OP_nip); /* keep the value associated with - done = true */ - emit_op(s, OP_nip); - emit_op(s, OP_nip); - } else { - int label_next; - - if (is_async) - emit_op(s, OP_await); - emit_op(s, OP_yield); - label_next = emit_goto(s, OP_if_false, -1); - emit_return(s, TRUE); - emit_label(s, label_next); - } - return 0; - } else if (s->token.val == '(' && + if (s->token.val == '(' && js_parse_skip_parens_token(s, NULL, TRUE) == TOK_ARROW) { return js_parse_function_decl(s, JS_PARSE_FUNC_ARROW, - JS_FUNC_NORMAL, JS_ATOM_NULL, + JS_ATOM_NULL, s->token.ptr); - } else if (token_is_pseudo_keyword(s, JS_ATOM_async)) { - const uint8_t *source_ptr; - int tok; - JSParsePos pos; - - /* fast test */ - tok = peek_token(s, TRUE); - if (tok == TOK_FUNCTION || tok == '\n') - goto next; - - source_ptr = s->token.ptr; - js_parse_get_pos(s, &pos); - if (next_token(s)) - return -1; - if ((s->token.val == '(' && - js_parse_skip_parens_token(s, NULL, TRUE) == TOK_ARROW) || - (s->token.val == TOK_IDENT && !s->token.u.ident.is_reserved && - peek_token(s, TRUE) == TOK_ARROW)) { - return js_parse_function_decl(s, JS_PARSE_FUNC_ARROW, - JS_FUNC_ASYNC, JS_ATOM_NULL, - source_ptr); - } else { - /* undo the token parsing */ - if (js_parse_seek_token(s, &pos)) - return -1; - } } else if (s->token.val == TOK_IDENT && peek_token(s, TRUE) == TOK_ARROW) { return js_parse_function_decl(s, JS_PARSE_FUNC_ARROW, - JS_FUNC_NORMAL, JS_ATOM_NULL, + JS_ATOM_NULL, s->token.ptr); } else if ((s->token.val == '{' || s->token.val == '[') && js_parse_skip_parens_token(s, &skip_bits, FALSE) == '=') { @@ -24992,11 +24545,6 @@ static __exception int js_parse_var(JSParseState *s, int parse_flags, int tok, goto var_error; if (js_define_var(s, name, tok)) goto var_error; - if (export_flag) { - if (!add_export_entry(s, s->cur_func->module, name, name, - JS_EXPORT_TYPE_LOCAL)) - goto var_error; - } if (s->token.val == '=') { if (next_token(s)) @@ -25118,8 +24666,7 @@ static int is_let(JSParseState *s, int decl_mask) /* XXX: handle IteratorClose when exiting the loop before the enumeration is done */ -static __exception int js_parse_for_in_of(JSParseState *s, int label_name, - BOOL is_async) +static __exception int js_parse_for_in_of(JSParseState *s, int label_name) { JSContext *ctx = s->ctx; JSFunctionDef *fd = s->cur_func; @@ -25193,9 +24740,6 @@ static __exception int js_parse_for_in_of(JSParseState *s, int label_name, emit_atom(s, var_name); emit_u16(s, fd->scope_level); } - } else if (!is_async && token_is_pseudo_keyword(s, JS_ATOM_async) && - peek_token(s, FALSE) == TOK_OF) { - return js_parse_error(s, "'for of' expression cannot start with 'async'"); } else { int skip_bits; if ((s->token.val == '[' || s->token.val == '{') @@ -25242,8 +24786,6 @@ static __exception int js_parse_for_in_of(JSParseState *s, int label_name, if (has_initializer) goto initializer_error; } else if (s->token.val == TOK_IN) { - if (is_async) - return js_parse_error(s, "'for await' loop should be used with 'of'"); if (has_initializer && (tok != TOK_VAR || (fd->js_mode & JS_MODE_STRICT) || has_destructuring)) { @@ -25267,10 +24809,7 @@ static __exception int js_parse_for_in_of(JSParseState *s, int label_name, the TDZ values are in the closures */ close_scopes(s, s->cur_func->scope_level, block_scope_level); if (is_for_of) { - if (is_async) - emit_op(s, OP_for_await_of_start); - else - emit_op(s, OP_for_of_start); + emit_op(s, OP_for_of_start); /* on stack: enum_rec */ } else { emit_op(s, OP_for_in_start); @@ -25565,32 +25104,21 @@ static __exception int js_parse_statement_or_decl(JSParseState *s, int pos_cont, pos_body, block_scope_level; BlockEnv break_entry; int tok, bits; - BOOL is_async; if (next_token(s)) goto fail; set_eval_ret_undefined(s); bits = 0; - is_async = FALSE; if (s->token.val == '(') { js_parse_skip_parens_token(s, &bits, FALSE); - } else if (s->token.val == TOK_AWAIT) { - if (!(s->cur_func->func_kind & JS_FUNC_ASYNC)) { - js_parse_error(s, "for await is only valid in asynchronous functions"); - goto fail; - } - is_async = TRUE; - if (next_token(s)) - goto fail; - s->cur_func->has_await = TRUE; } if (js_parse_expect(s, '(')) goto fail; if (!(bits & SKIP_HAS_SEMI)) { /* parse for/in or for/of */ - if (js_parse_for_in_of(s, label_name, is_async)) + if (js_parse_for_in_of(s, label_name)) goto fail; break; } @@ -26045,7 +25573,7 @@ static __exception int js_parse_statement_or_decl(JSParseState *s, } parse_func_var: if (js_parse_function_decl(s, JS_PARSE_FUNC_VAR, - JS_FUNC_NORMAL, JS_ATOM_NULL, + JS_ATOM_NULL, s->token.ptr)) goto fail; break; @@ -26106,18 +25634,9 @@ static __exception int js_parse_source_element(JSParseState *s) (token_is_pseudo_keyword(s, JS_ATOM_async) && peek_token(s, TRUE) == TOK_FUNCTION)) { if (js_parse_function_decl(s, JS_PARSE_FUNC_STATEMENT, - JS_FUNC_NORMAL, JS_ATOM_NULL, + JS_ATOM_NULL, s->token.ptr)) return -1; - } else if (s->token.val == TOK_EXPORT && fd->module) { - if (js_parse_export(s)) - return -1; - } else if (s->token.val == TOK_IMPORT && fd->module && - ((tok = peek_token(s, FALSE)) != '(' && tok != '.')) { - /* the peek_token is needed to avoid confusion with ImportCall - (dynamic import) or import.meta */ - if (js_parse_import(s)) - return -1; } else { if (js_parse_statement_or_decl(s, DECL_MASK_ALL)) return -1; @@ -26662,7 +26181,7 @@ static __maybe_unused void js_dump_function_bytecode(JSContext *ctx, JSFunctionB } str = JS_AtomGetStr(ctx, atom_buf, sizeof(atom_buf), b->func_name); - printf("function: %s%s\n", &"*"[b->func_kind != JS_FUNC_GENERATOR], str); + printf("function: %s%s\n", "", str); if (b->js_mode) { printf(" mode:"); if (b->js_mode & JS_MODE_STRICT) @@ -28051,23 +27570,6 @@ static void instantiate_hoisted_definitions(JSContext *ctx, JSFunctionDef *s, Dy } } - /* the module global variables must be initialized before - evaluating the module so that the exported functions are - visible if there are cyclic module references */ - if (s->module) { - label_next = new_label_fd(s); - if (label_next < 0) { - dbuf_set_error(bc); - return; - } - /* if 'this' is true, initialize the global variables and return */ - dbuf_putc(bc, OP_push_this); - dbuf_putc(bc, OP_if_false); - dbuf_put_u32(bc, label_next); - update_label(s, label_next, 1); - s->jump_size++; - } - /* add the global variables (only happens if s->is_global_var is true) */ for(i = 0; i < s->global_var_count; i++) { @@ -28150,14 +27652,6 @@ static void instantiate_hoisted_definitions(JSContext *ctx, JSFunctionDef *s, Dy JS_FreeAtom(ctx, hf->var_name); } - if (s->module) { - dbuf_putc(bc, OP_return_undef); - - dbuf_putc(bc, OP_label); - dbuf_put_u32(bc, label_next); - s->label_slots[label_next].pos2 = bc->size; - } - js_free(ctx, s->global_vars); s->global_vars = NULL; s->global_var_count = 0; @@ -29012,7 +28506,6 @@ static __exception int resolve_labels(JSContext *ctx, JSFunctionDef *s) case OP_return: case OP_return_undef: - case OP_return_async: case OP_throw: case OP_throw_error: pos_next = skip_dead_code(s, bc_buf, bc_len, pos_next, &line_num); @@ -29883,7 +29376,6 @@ static __exception int compute_stack_size(JSContext *ctx, case OP_tail_call_method: case OP_return: case OP_return_undef: - case OP_return_async: case OP_throw: case OP_throw_error: case OP_ret: @@ -29943,7 +29435,6 @@ static __exception int compute_stack_size(JSContext *ctx, catch_pos = pos; break; case OP_for_of_start: - case OP_for_await_of_start: catch_pos = pos; break; /* we assume the catch offset entry is only removed with @@ -30050,12 +29541,6 @@ static JSValue js_create_function(JSContext *ctx, JSFunctionDef *fd) if (fd->has_eval_call) add_eval_variables(ctx, fd); - /* add the module global variables in the closure */ - if (fd->module) { - if (add_module_variables(ctx, fd)) - goto fail; - } - /* first create all the child functions */ list_for_each_safe(el, el1, &fd->child_list) { JSFunctionDef *fd1; @@ -30202,7 +29687,6 @@ static JSValue js_create_function(JSContext *ctx, JSFunctionDef *fd) b->has_simple_parameter_list = fd->has_simple_parameter_list; b->js_mode = fd->js_mode; b->is_derived_class_constructor = fd->is_derived_class_constructor; - b->func_kind = fd->func_kind; b->need_home_object = (fd->home_object_var_idx >= 0 || fd->need_home_object); b->new_target_allowed = fd->new_target_allowed; @@ -30394,7 +29878,6 @@ static int js_parse_function_check_names(JSParseState *s, JSFunctionDef *fd, /* check async_generator case */ if ((fd->js_mode & JS_MODE_STRICT) || !fd->has_simple_parameter_list - || (fd->func_type == JS_PARSE_FUNC_METHOD && fd->func_kind == JS_FUNC_ASYNC) || fd->func_type == JS_PARSE_FUNC_ARROW || fd->func_type == JS_PARSE_FUNC_METHOD) { for (idx = 0; idx < fd->arg_count; idx++) { @@ -30452,7 +29935,6 @@ static __exception int js_parse_function_decl2(JSParseState *s, JSParseFunctionEnum func_type, JSAtom func_name, const uint8_t *ptr, - JSParseExportEnum export_flag, JSFunctionDef **pfd) { JSContext *ctx = s->ctx; @@ -30470,23 +29952,9 @@ static __exception int js_parse_function_decl2(JSParseState *s, func_type == JS_PARSE_FUNC_EXPR) { if (next_token(s)) return -1; - if (s->token.val == '*') { - if (next_token(s)) - return -1; - func_kind |= JS_FUNC_GENERATOR; - } - if (s->token.val == TOK_IDENT) { - if (s->token.u.ident.is_reserved || - (s->token.u.ident.atom == JS_ATOM_yield && - func_type == JS_PARSE_FUNC_EXPR && - (func_kind & JS_FUNC_GENERATOR)) || - (s->token.u.ident.atom == JS_ATOM_await && - ((func_type == JS_PARSE_FUNC_EXPR && - (func_kind & JS_FUNC_ASYNC)) || - func_type == JS_PARSE_FUNC_CLASS_STATIC_INIT))) { - return js_parse_error_reserved_identifier(s); - } + if (s->token.val == TOK_IDENT && s->token.u.ident.is_reserved) { + return js_parse_error_reserved_identifier(s); } if (s->token.val == TOK_IDENT || (((s->token.val == TOK_YIELD && !(fd->js_mode & JS_MODE_STRICT)) || @@ -30498,8 +29966,7 @@ static __exception int js_parse_function_decl2(JSParseState *s, return -1; } } else { - if (func_type != JS_PARSE_FUNC_EXPR && - export_flag != JS_PARSE_EXPORT_DEFAULT) { + if (func_type != JS_PARSE_FUNC_EXPR) { return js_parse_error(s, "function name expected"); } } @@ -30521,7 +29988,6 @@ static __exception int js_parse_function_decl2(JSParseState *s, if (func_type == JS_PARSE_FUNC_VAR) { if (!(fd->js_mode & JS_MODE_STRICT) - && func_kind == JS_FUNC_NORMAL && find_lexical_decl(ctx, fd, func_name, fd->scope_first, FALSE) < 0 && !((func_idx = find_var(ctx, fd, func_name)) >= 0 && (func_idx & ARGUMENT_VAR_OFFSET)) && !(func_name == JS_ATOM_arguments && fd->has_arguments_binding)) { @@ -30547,10 +30013,7 @@ static __exception int js_parse_function_decl2(JSParseState *s, /* Always create a lexical name, fail if at the same scope as existing name */ /* Lexical variable will be initialized upon entering scope */ - lexical_func_idx = define_var(s, fd, func_name, - func_kind != JS_FUNC_NORMAL ? - JS_VAR_DEF_NEW_FUNCTION_DECL : - JS_VAR_DEF_FUNCTION_DECL); + lexical_func_idx = define_var(s, fd, func_name, JS_VAR_DEF_FUNCTION_DECL); if (lexical_func_idx < 0) { JS_FreeAtom(ctx, func_name); return -1; @@ -30572,8 +30035,7 @@ static __exception int js_parse_function_decl2(JSParseState *s, /* XXX: test !fd->is_generator is always false */ fd->has_prototype = (func_type == JS_PARSE_FUNC_STATEMENT || func_type == JS_PARSE_FUNC_VAR || - func_type == JS_PARSE_FUNC_EXPR) && - func_kind == JS_FUNC_NORMAL; + func_type == JS_PARSE_FUNC_EXPR); fd->has_home_object = (func_type == JS_PARSE_FUNC_METHOD || func_type == JS_PARSE_FUNC_GETTER || func_type == JS_PARSE_FUNC_SETTER || @@ -30603,7 +30065,6 @@ static __exception int js_parse_function_decl2(JSParseState *s, /* fd->in_function_body == FALSE prevents yield/await during the parsing of the arguments in generator/async functions. They are parsed as regular identifiers for other function kinds. */ - fd->func_kind = func_kind; fd->func_type = func_type; if (func_type == JS_PARSE_FUNC_CLASS_CONSTRUCTOR || @@ -30612,10 +30073,6 @@ static __exception int js_parse_function_decl2(JSParseState *s, emit_op(s, OP_check_ctor); } - if (func_type == JS_PARSE_FUNC_CLASS_CONSTRUCTOR) { - emit_class_field_init(s); - } - /* parse arguments */ fd->has_simple_parameter_list = TRUE; fd->has_parameter_expressions = FALSE; @@ -30688,10 +30145,6 @@ static __exception int js_parse_function_decl2(JSParseState *s, goto fail; } name = s->token.u.ident.atom; - if (name == JS_ATOM_yield && fd->func_kind == JS_FUNC_GENERATOR) { - js_parse_error_reserved_identifier(s); - goto fail; - } if (fd->has_parameter_expressions) { if (js_parse_check_duplicate_parameter(s, name)) goto fail; @@ -30816,11 +30269,6 @@ static __exception int js_parse_function_decl2(JSParseState *s, if (next_token(s)) goto fail; - /* generator function: yield after the parameters are evaluated */ - if (func_kind == JS_FUNC_GENERATOR || - func_kind == JS_FUNC_ASYNC_GENERATOR) - emit_op(s, OP_initial_yield); - /* in generators, yield expression is forbidden during the parsing of the arguments */ fd->in_function_body = TRUE; @@ -30838,10 +30286,7 @@ static __exception int js_parse_function_decl2(JSParseState *s, if (js_parse_assign_expr(s)) goto fail; - if (func_kind != JS_FUNC_NORMAL) - emit_op(s, OP_return_async); - else - emit_op(s, OP_return); + emit_op(s, OP_return); if (!fd->strip_source) { /* save the function source code */ @@ -30991,11 +30436,6 @@ static __exception int js_parse_function_decl2(JSParseState *s, if (!hf) goto fail; hf->cpool_idx = idx; - if (export_flag != JS_PARSE_EXPORT_NONE) { - if (!add_export_entry(s, s->cur_func->module, func_var_name, - export_flag == JS_PARSE_EXPORT_NAMED ? func_var_name : JS_ATOM_default, JS_EXPORT_TYPE_LOCAL)) - goto fail; - } } } } @@ -31010,12 +30450,10 @@ static __exception int js_parse_function_decl2(JSParseState *s, static __exception int js_parse_function_decl(JSParseState *s, JSParseFunctionEnum func_type, - JSFunctionKindEnum func_kind, JSAtom func_name, const uint8_t *ptr) { - return js_parse_function_decl2(s, func_type, func_kind, func_name, ptr, - JS_PARSE_EXPORT_NONE, NULL); + return js_parse_function_decl2(s, func_type, func_name, ptr, NULL); } static __exception int js_parse_program(JSParseState *s) @@ -31047,21 +30485,8 @@ static __exception int js_parse_program(JSParseState *s) if (!s->is_module) { /* return the value of the hidden variable eval_ret_idx */ - if (fd->func_kind == JS_FUNC_ASYNC) { - /* wrap the return value in an object so that promises can - be safely returned */ - emit_op(s, OP_object); - emit_op(s, OP_dup); - - emit_op(s, OP_get_loc); - emit_u16(s, fd->eval_ret_idx); - - emit_op(s, OP_put_field); - emit_atom(s, JS_ATOM_value); - } else { - emit_op(s, OP_get_loc); - emit_u16(s, fd->eval_ret_idx); - } + emit_op(s, OP_get_loc); + emit_u16(s, fd->eval_ret_idx); emit_return(s, TRUE); } else { emit_return(s, FALSE); @@ -31099,20 +30524,6 @@ static JSValue JS_EvalFunctionInternal(JSContext *ctx, JSValue fun_obj, if (tag == JS_TAG_FUNCTION_BYTECODE) { fun_obj = js_closure(ctx, fun_obj, var_refs, sf); ret_val = JS_CallFree(ctx, fun_obj, this_obj, 0, NULL); - } else if (tag == JS_TAG_MODULE) { - JSModuleDef *m; - m = JS_VALUE_GET_PTR(fun_obj); - /* the module refcount should be >= 2 */ - JS_FreeValue(ctx, fun_obj); - if (js_create_module_function(ctx, m) < 0) - goto fail; - if (js_link_module(ctx, m) < 0) - goto fail; - ret_val = js_evaluate_module(ctx, m); - if (JS_IsException(ret_val)) { - fail: - return JS_EXCEPTION; - } } else { JS_FreeValue(ctx, fun_obj); ret_val = JS_ThrowTypeError(ctx, "bytecode function expected"); @@ -31137,13 +30548,10 @@ static JSValue __JS_EvalInternal(JSContext *ctx, JSValueConst this_obj, JSVarRef **var_refs; JSFunctionBytecode *b; JSFunctionDef *fd; - JSModuleDef *m; js_parse_init(ctx, s, input, input_len, filename); - skip_shebang(&s->buf_ptr, s->buf_end); eval_type = flags & JS_EVAL_TYPE_MASK; - m = NULL; if (eval_type == JS_EVAL_TYPE_DIRECT) { JSObject *p; sf = ctx->rt->current_stack_frame; @@ -31161,15 +30569,6 @@ static JSValue __JS_EvalInternal(JSContext *ctx, JSValueConst this_obj, js_mode = 0; if (flags & JS_EVAL_FLAG_STRICT) js_mode |= JS_MODE_STRICT; - if (eval_type == JS_EVAL_TYPE_MODULE) { - JSAtom module_name = JS_NewAtom(ctx, filename); - if (module_name == JS_ATOM_NULL) - return JS_EXCEPTION; - m = js_new_module_def(ctx, module_name); - if (!m) - return JS_EXCEPTION; - js_mode |= JS_MODE_STRICT; - } } fd = js_new_function_def(ctx, NULL, TRUE, FALSE, filename, s->buf_start, &s->get_line_col_cache); @@ -31195,12 +30594,7 @@ static JSValue __JS_EvalInternal(JSContext *ctx, JSValueConst this_obj, if (add_closure_variables(ctx, fd, b, scope_idx)) goto fail; } - fd->module = m; - if (m != NULL || (flags & JS_EVAL_FLAG_ASYNC)) { - fd->in_function_body = TRUE; - fd->func_kind = JS_FUNC_ASYNC; - } - s->is_module = (m != NULL); + s->allow_html_comments = !s->is_module; push_scope(s); /* body scope */ @@ -31214,20 +30608,11 @@ static JSValue __JS_EvalInternal(JSContext *ctx, JSValueConst this_obj, goto fail1; } - if (m != NULL) - m->has_tla = fd->has_await; - /* create the function object and all the enclosed functions */ fun_obj = js_create_function(ctx, fd); if (JS_IsException(fun_obj)) goto fail1; /* Could add a flag to avoid resolution if necessary */ - if (m) { - m->func_obj = fun_obj; - if (js_resolve_module(ctx, m) < 0) - goto fail1; - fun_obj = JS_NewModuleValue(ctx, m); - } if (flags & JS_EVAL_FLAG_COMPILE_ONLY) { ret_val = fun_obj; } else { @@ -31837,59 +31222,6 @@ static int JS_WriteFunctionTag(BCWriterState *s, JSValueConst obj) return -1; } -static int JS_WriteModule(BCWriterState *s, JSValueConst obj) -{ - JSModuleDef *m = JS_VALUE_GET_PTR(obj); - int i; - - bc_put_u8(s, BC_TAG_MODULE); - bc_put_atom(s, m->module_name); - - bc_put_leb128(s, m->req_module_entries_count); - for(i = 0; i < m->req_module_entries_count; i++) { - JSReqModuleEntry *rme = &m->req_module_entries[i]; - bc_put_atom(s, rme->module_name); - if (JS_WriteObjectRec(s, rme->attributes)) - goto fail; - } - - bc_put_leb128(s, m->export_entries_count); - for(i = 0; i < m->export_entries_count; i++) { - JSExportEntry *me = &m->export_entries[i]; - bc_put_u8(s, me->export_type); - if (me->export_type == JS_EXPORT_TYPE_LOCAL) { - bc_put_leb128(s, me->u.local.var_idx); - } else { - bc_put_leb128(s, me->u.req_module_idx); - bc_put_atom(s, me->local_name); - } - bc_put_atom(s, me->export_name); - } - - bc_put_leb128(s, m->star_export_entries_count); - for(i = 0; i < m->star_export_entries_count; i++) { - JSStarExportEntry *se = &m->star_export_entries[i]; - bc_put_leb128(s, se->req_module_idx); - } - - bc_put_leb128(s, m->import_entries_count); - for(i = 0; i < m->import_entries_count; i++) { - JSImportEntry *mi = &m->import_entries[i]; - bc_put_leb128(s, mi->var_idx); - bc_put_u8(s, mi->is_star); - bc_put_atom(s, mi->import_name); - bc_put_leb128(s, mi->req_module_idx); - } - - bc_put_u8(s, m->has_tla); - - if (JS_WriteObjectRec(s, m->func_obj)) - goto fail; - return 0; - fail: - return -1; -} - static int JS_WriteArray(BCWriterState *s, JSValueConst obj) { JSObject *p = JS_VALUE_GET_OBJ(obj); @@ -32071,12 +31403,6 @@ static int JS_WriteObjectRec(BCWriterState *s, JSValueConst obj) if (JS_WriteFunctionTag(s, obj)) goto fail; break; - case JS_TAG_MODULE: - if (!s->allow_bytecode) - goto invalid_tag; - if (JS_WriteModule(s, obj)) - goto fail; - break; case JS_TAG_OBJECT: { JSObject *p = JS_VALUE_GET_OBJ(obj); @@ -33077,11 +32403,6 @@ static JSValue JS_ReadObjectRec(BCReaderState *s) goto invalid_tag; obj = JS_ReadFunctionTag(s); break; - case BC_TAG_MODULE: - if (!s->allow_bytecode) - goto invalid_tag; - obj = JS_ReadModule(s); - break; case BC_TAG_OBJECT: obj = JS_ReadObjectTag(s); break; @@ -33395,55 +32716,6 @@ int JS_SetPropertyFunctionList(JSContext *ctx, JSValueConst obj, return 0; } -int JS_AddModuleExportList(JSContext *ctx, JSModuleDef *m, - const JSCFunctionListEntry *tab, int len) -{ - int i; - for(i = 0; i < len; i++) { - if (JS_AddModuleExport(ctx, m, tab[i].name)) - return -1; - } - return 0; -} - -int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m, - const JSCFunctionListEntry *tab, int len) -{ - int i; - JSValue val; - - for(i = 0; i < len; i++) { - const JSCFunctionListEntry *e = &tab[i]; - switch(e->def_type) { - case JS_DEF_CFUNC: - val = JS_NewCFunction2(ctx, e->u.func.cfunc.generic, - e->name, e->u.func.length, e->u.func.cproto, e->magic); - break; - case JS_DEF_PROP_STRING: - val = JS_NewString(ctx, e->u.str); - break; - case JS_DEF_PROP_INT32: - val = JS_NewInt32(ctx, e->u.i32); - break; - case JS_DEF_PROP_INT64: - val = JS_NewInt64(ctx, e->u.i64); - break; - case JS_DEF_PROP_DOUBLE: - val = __JS_NewFloat64(ctx, e->u.f64); - break; - case JS_DEF_OBJECT: - val = JS_NewObject(ctx); - JS_SetPropertyFunctionList(ctx, val, e->u.prop_list.tab, e->u.prop_list.len); - break; - default: - abort(); - } - if (JS_SetModuleExport(ctx, m, e->name, val)) - return -1; - } - return 0; -} - /* Note: 'func_obj' is not necessarily a constructor */ static void JS_SetConstructor2(JSContext *ctx, JSValueConst func_obj, @@ -34788,7 +34060,6 @@ static JSValue js_function_proto(JSContext *ctx, JSValueConst this_val, static JSValue js_function_constructor(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv, int magic) { - JSFunctionKindEnum func_kind = magic; int i, n, ret; JSValue s, proto, obj = JS_UNDEFINED; StringBuffer b_s, *b = &b_s; @@ -43956,7 +43227,7 @@ static JSValue js_object_groupBy(JSContext *ctx, JSValueConst this_val, if (check_function(ctx, cb)) return JS_EXCEPTION; - iter = JS_GetIterator(ctx, argv[0], /*is_async*/FALSE); + iter = JS_GetIterator(ctx, argv[0]); if (JS_IsException(iter)) return JS_EXCEPTION; @@ -44942,7 +44213,7 @@ void JS_AddIntrinsicBaseObjects(JSContext *ctx) JS_SetPropertyFunctionList(ctx, ctx->function_proto, js_function_proto_funcs, countof(js_function_proto_funcs)); ctx->function_ctor = JS_NewCFunctionMagic(ctx, js_function_constructor, "Function", 1, JS_CFUNC_constructor_or_func_magic, - JS_FUNC_NORMAL); + 0); JS_NewGlobalCConstructor2(ctx, JS_DupValue(ctx, ctx->function_ctor), "Function", ctx->function_proto); @@ -48333,7 +47604,6 @@ static void finrec_delete_weakref(JSRuntime *rt, JSWeakRefHeader *wh) JSValueConst args[2]; args[0] = frd->cb; args[1] = fre->held_val; - JS_EnqueueJob(frd->ctx, js_finrec_job, 2, args); js_weakref_free(rt, fre->target); js_weakref_free(rt, fre->token); @@ -48707,13 +47977,3 @@ JSValue js_debugger_closure_variables(JSContext *ctx, JSValue fn) { done: return ret; } - -JSValue js_newsymbol(JSContext *ctx, const char *description, int is_global) -{ - JSAtom atom = JS_NewAtom(ctx, description); - if (atom == JS_ATOM_NULL) - return JS_EXCEPTION; - JSValue sym = JS_NewSymbolFromAtom(ctx, atom, is_global ? JS_ATOM_TYPE_GLOBAL_SYMBOL : JS_ATOM_TYPE_SYMBOL); - JS_FreeAtom(ctx, atom); - return sym; -} diff --git a/source/quickjs.h b/source/quickjs.h index 23c6f646..46ee8895 100644 --- a/source/quickjs.h +++ b/source/quickjs.h @@ -340,9 +340,6 @@ static inline JSValue __JS_NewShortBigInt(JSContext *ctx, int64_t d) #define JS_EVAL_FLAG_COMPILE_ONLY (1 << 5) /* don't include the stack frames before this eval in the Error() backtraces */ #define JS_EVAL_FLAG_BACKTRACE_BARRIER (1 << 6) -/* allow top-level await in normal script. JS_Eval() returns a - promise. Only allowed with JS_EVAL_TYPE_GLOBAL */ -#define JS_EVAL_FLAG_ASYNC (1 << 7) typedef JSValue JSCFunction(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv); typedef JSValue JSCFunctionMagic(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic); @@ -404,7 +401,6 @@ void JS_AddIntrinsicJSON(JSContext *ctx); void JS_AddIntrinsicProxy(JSContext *ctx); void JS_AddIntrinsicMapSet(JSContext *ctx); void JS_AddIntrinsicTypedArrays(JSContext *ctx); -void JS_AddIntrinsicWeakRef(JSContext *ctx); JSValue js_string_codePointRange(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv); @@ -1103,8 +1099,6 @@ typedef struct js_debug { void js_debug_info(JSContext *js, JSValue fn, js_debug *dbg); void free_js_debug_info(JSContext *js, js_debug *dbg); -JSValue js_newsymbol(JSContext *js, const char *desc, int global); - typedef void (*js_hook)(JSContext*, JSValue); #define JS_HOOK_CALL 0 #define JS_HOOK_RET 1