diff --git a/sys/patches/basic_msvc_compat.patch b/sys/patches/basic_msvc_compat.patch index 11d90a4b..f4c68674 100644 --- a/sys/patches/basic_msvc_compat.patch +++ b/sys/patches/basic_msvc_compat.patch @@ -186,18 +186,9 @@ index a1436ab..65e111c 100644 #else #define LIMB_LOG2_BITS 5 diff --git a/quickjs.c b/quickjs.c -index e8fdd8a..9c121a9 100644 +index e8fdd8a..2b5894f 100644 --- a/quickjs.c +++ b/quickjs.c -@@ -14,7 +14,7 @@ - * 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 -+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR && !defined(_MSC_VER) - * 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 @@ -48,7 +48,7 @@ #define OPTIMIZE 1 diff --git a/sys/patches/error_column_number.patch b/sys/patches/error_column_number.patch index ec0fd77c..2d89b306 100644 --- a/sys/patches/error_column_number.patch +++ b/sys/patches/error_column_number.patch @@ -1,3 +1,15 @@ +diff --git a/Makefile b/Makefile +index 0270a6a..1c78547 100644 +--- a/Makefile ++++ b/Makefile +@@ -445,6 +445,7 @@ test: qjs + ./qjs tests/test_bignum.js + ./qjs tests/test_std.js + ./qjs tests/test_worker.js ++ ./qjs tests/test_line_column.js + ifdef CONFIG_SHARED_LIBS + ifdef CONFIG_BIGNUM + ./qjs --bignum tests/test_bjson.js diff --git a/cutils.c b/cutils.c index c0aacef..37ed9c2 100644 --- a/cutils.c @@ -56,7 +68,7 @@ index 1e18212..40cb15e 100644 #if SHORT_OPCODES DEF( push_minus1, 1, 0, 1, none_int) diff --git a/quickjs.c b/quickjs.c -index e8fdd8a..bb9eadc 100644 +index e8fdd8a..92745d8 100644 --- a/quickjs.c +++ b/quickjs.c @@ -573,6 +573,10 @@ typedef struct JSVarDef { @@ -141,8 +153,8 @@ index e8fdd8a..bb9eadc 100644 return line_num; } -+int find_column_num(JSContext* ctx, JSFunctionBytecode* b, -+ uint32_t pc_value) ++int find_column_num(JSContext* ctx, JSFunctionBytecode* b, ++ uint32_t pc_value) +{ + const uint8_t* p_end, *p; + int new_column_num, column_num, pc, v, ret; @@ -206,10 +218,9 @@ index e8fdd8a..bb9eadc 100644 const char *str1; JSObject *p; BOOL backtrace_barrier; -- + int latest_line_num = -1; + int latest_column_num = -1; -+ + js_dbuf_init(ctx, &dbuf); if (filename) { dbuf_printf(&dbuf, " at %s", filename); @@ -275,11 +286,11 @@ index e8fdd8a..bb9eadc 100644 JS_DefinePropertyValue(ctx, error_obj, JS_ATOM_stack, str, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE); + if (line_num != -1) { -+ JS_DefinePropertyValue(ctx, error_obj, JS_ATOM_lineNumber, JS_NewInt32(ctx, latest_line_num), ++ JS_DefinePropertyValue(ctx, error_obj, JS_ATOM_lineNumber, JS_NewInt32(ctx, latest_line_num), + JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE); + + if (column_num != -1) { -+ JS_DefinePropertyValue(ctx, error_obj, JS_ATOM_columnNumber, JS_NewInt32(ctx, latest_column_num), ++ JS_DefinePropertyValue(ctx, error_obj, JS_ATOM_columnNumber, JS_NewInt32(ctx, latest_column_num), + JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE); + } + } @@ -370,7 +381,7 @@ index e8fdd8a..bb9eadc 100644 const char *filename; JSToken token; BOOL got_lf; /* true if got line feed before the current token */ -@@ -20213,19 +20340,28 @@ static void __attribute((unused)) dump_token(JSParseState *s, +@@ -20213,11 +20340,19 @@ static void __attribute((unused)) dump_token(JSParseState *s, } } @@ -387,11 +398,11 @@ index e8fdd8a..bb9eadc 100644 JSContext *ctx = s->ctx; va_list ap; - int backtrace_flags; -- + int backtrace_flags, column_num; + va_start(ap, fmt); JS_ThrowError2(ctx, JS_SYNTAX_ERROR, fmt, ap, FALSE); - va_end(ap); +@@ -20225,7 +20360,9 @@ int __attribute__((format(printf, 2, 3))) js_parse_error(JSParseState *s, const backtrace_flags = 0; if (s->cur_func && s->cur_func->backtrace_barrier) backtrace_flags = JS_BACKTRACE_FLAG_SINGLE_LEVEL; @@ -401,7 +412,7 @@ index e8fdd8a..bb9eadc 100644 backtrace_flags); return -1; } -@@ -20263,6 +20399,7 @@ static __exception int js_parse_template_part(JSParseState *s, const uint8_t *p) +@@ -20263,6 +20400,7 @@ static __exception int js_parse_template_part(JSParseState *s, const uint8_t *p) { uint32_t c; StringBuffer b_s, *b = &b_s; @@ -409,7 +420,7 @@ index e8fdd8a..bb9eadc 100644 /* p points to the first byte of the template part */ if (string_buffer_init(s->ctx, b, 32)) -@@ -20295,6 +20432,8 @@ static __exception int js_parse_template_part(JSParseState *s, const uint8_t *p) +@@ -20295,6 +20433,8 @@ static __exception int js_parse_template_part(JSParseState *s, const uint8_t *p) } if (c == '\n') { s->line_num++; @@ -418,7 +429,7 @@ index e8fdd8a..bb9eadc 100644 } else if (c >= 0x80) { const uint8_t *p_next; c = unicode_from_utf8(p - 1, UTF8_CHAR_LEN_MAX, &p_next); -@@ -20327,6 +20466,7 @@ static __exception int js_parse_string(JSParseState *s, int sep, +@@ -20327,6 +20467,7 @@ static __exception int js_parse_string(JSParseState *s, int sep, int ret; uint32_t c; StringBuffer b_s, *b = &b_s; @@ -426,21 +437,20 @@ index e8fdd8a..bb9eadc 100644 /* string */ if (string_buffer_init(s->ctx, b, 32)) -@@ -20382,8 +20522,11 @@ static __exception int js_parse_string(JSParseState *s, int sep, +@@ -20382,8 +20523,11 @@ static __exception int js_parse_string(JSParseState *s, int sep, case '\n': /* ignore escaped newline sequence */ p++; - if (sep != '`') -- s->line_num++; + if (sep != '`') { -+ s->line_num++; + s->line_num++; + s->column_ptr = s->column_last_ptr = p; + s->column_num_count = 0; + } continue; default: if (c >= '0' && c <= '9') { -@@ -20698,7 +20841,9 @@ static __exception int next_token(JSParseState *s) +@@ -20698,7 +20842,9 @@ static __exception int next_token(JSParseState *s) s->got_lf = FALSE; s->last_line_num = s->token.line_num; redo: @@ -450,7 +460,7 @@ index e8fdd8a..bb9eadc 100644 s->token.ptr = p; c = *p; switch(c) { -@@ -20729,6 +20874,8 @@ static __exception int next_token(JSParseState *s) +@@ -20729,6 +20875,8 @@ static __exception int next_token(JSParseState *s) line_terminator: s->got_lf = TRUE; s->line_num++; @@ -459,7 +469,7 @@ index e8fdd8a..bb9eadc 100644 goto redo; case '\f': case '\v': -@@ -20752,7 +20899,8 @@ static __exception int next_token(JSParseState *s) +@@ -20752,7 +20900,8 @@ static __exception int next_token(JSParseState *s) if (*p == '\n') { s->line_num++; s->got_lf = TRUE; /* considered as LF for ASI */ @@ -469,7 +479,7 @@ index e8fdd8a..bb9eadc 100644 } else if (*p == '\r') { s->got_lf = TRUE; /* considered as LF for ASI */ p++; -@@ -21164,6 +21312,9 @@ static __exception int next_token(JSParseState *s) +@@ -21164,6 +21313,9 @@ static __exception int next_token(JSParseState *s) break; } s->buf_ptr = p; @@ -479,7 +489,7 @@ index e8fdd8a..bb9eadc 100644 // dump_token(s, &s->token); return 0; -@@ -21222,7 +21373,9 @@ static __exception int json_next_token(JSParseState *s) +@@ -21222,7 +21374,9 @@ static __exception int json_next_token(JSParseState *s) p = s->last_ptr = s->buf_ptr; s->last_line_num = s->token.line_num; redo: @@ -489,7 +499,7 @@ index e8fdd8a..bb9eadc 100644 s->token.ptr = p; c = *p; switch(c) { -@@ -21251,6 +21404,8 @@ static __exception int json_next_token(JSParseState *s) +@@ -21251,6 +21405,8 @@ static __exception int json_next_token(JSParseState *s) case '\n': p++; s->line_num++; @@ -498,19 +508,17 @@ index e8fdd8a..bb9eadc 100644 goto redo; case '\f': case '\v': -@@ -21281,8 +21436,9 @@ static __exception int json_next_token(JSParseState *s) - break; +@@ -21282,7 +21438,8 @@ static __exception int json_next_token(JSParseState *s) } if (*p == '\n') { -- s->line_num++; + s->line_num++; - p++; -+ s->line_num++; + s->column_ptr = ++p; + s->column_num_count = 0; } else if (*p == '\r') { p++; } else if (*p >= 0x80) { -@@ -21392,6 +21548,9 @@ static __exception int json_next_token(JSParseState *s) +@@ -21392,6 +21549,9 @@ static __exception int json_next_token(JSParseState *s) break; } s->buf_ptr = p; @@ -520,7 +528,7 @@ index e8fdd8a..bb9eadc 100644 // dump_token(s, &s->token); return 0; -@@ -21599,6 +21758,11 @@ static void emit_atom(JSParseState *s, JSAtom name) +@@ -21599,6 +21759,11 @@ static void emit_atom(JSParseState *s, JSAtom name) emit_u32(s, JS_DupAtom(s->ctx, name)); } @@ -532,7 +540,7 @@ index e8fdd8a..bb9eadc 100644 static int update_label(JSFunctionDef *s, int label, int delta) { LabelSlot *ls; -@@ -22162,7 +22326,7 @@ static __exception int js_parse_function_decl(JSParseState *s, +@@ -22162,7 +22327,7 @@ static __exception int js_parse_function_decl(JSParseState *s, JSParseFunctionEnum func_type, JSFunctionKindEnum func_kind, JSAtom func_name, const uint8_t *ptr, @@ -541,7 +549,7 @@ index e8fdd8a..bb9eadc 100644 static JSFunctionDef *js_parse_function_class_fields_init(JSParseState *s); static __exception int js_parse_function_decl2(JSParseState *s, JSParseFunctionEnum func_type, -@@ -22170,6 +22334,7 @@ static __exception int js_parse_function_decl2(JSParseState *s, +@@ -22170,6 +22335,7 @@ static __exception int js_parse_function_decl2(JSParseState *s, JSAtom func_name, const uint8_t *ptr, int function_line_num, @@ -549,7 +557,7 @@ index e8fdd8a..bb9eadc 100644 JSParseExportEnum export_flag, JSFunctionDef **pfd); static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags); -@@ -22463,12 +22628,18 @@ typedef struct JSParsePos { +@@ -22463,12 +22629,18 @@ typedef struct JSParsePos { int line_num; BOOL got_lf; const uint8_t *ptr; @@ -568,7 +576,7 @@ index e8fdd8a..bb9eadc 100644 sp->ptr = s->token.ptr; sp->got_lf = s->got_lf; return 0; -@@ -22478,6 +22649,9 @@ static __exception int js_parse_seek_token(JSParseState *s, const JSParsePos *sp +@@ -22478,6 +22650,9 @@ static __exception int js_parse_seek_token(JSParseState *s, const JSParsePos *sp { s->token.line_num = sp->last_line_num; s->line_num = sp->line_num; @@ -578,7 +586,7 @@ index e8fdd8a..bb9eadc 100644 s->buf_ptr = sp->ptr; s->got_lf = sp->got_lf; return next_token(s); -@@ -22683,7 +22857,7 @@ static __exception int js_parse_object_literal(JSParseState *s) +@@ -22683,7 +22858,7 @@ static __exception int js_parse_object_literal(JSParseState *s) { JSAtom name = JS_ATOM_NULL; const uint8_t *start_ptr; @@ -587,17 +595,15 @@ index e8fdd8a..bb9eadc 100644 BOOL has_proto; if (next_token(s)) -@@ -22694,7 +22868,8 @@ static __exception int js_parse_object_literal(JSParseState *s) - while (s->token.val != '}') { +@@ -22695,6 +22870,7 @@ static __exception int js_parse_object_literal(JSParseState *s) /* specific case for getter/setter */ start_ptr = s->token.ptr; -- start_line = s->token.line_num; -+ start_line = s->token.line_num; + start_line = s->token.line_num; + start_column = s->token.column_num; if (s->token.val == TOK_ELLIPSIS) { if (next_token(s)) -@@ -22740,7 +22915,7 @@ static __exception int js_parse_object_literal(JSParseState *s) +@@ -22740,7 +22916,7 @@ static __exception int js_parse_object_literal(JSParseState *s) func_kind = JS_FUNC_ASYNC_GENERATOR; } if (js_parse_function_decl(s, func_type, func_kind, JS_ATOM_NULL, @@ -606,7 +612,7 @@ index e8fdd8a..bb9eadc 100644 goto fail; if (name == JS_ATOM_NULL) { emit_op(s, OP_define_method_computed); -@@ -22816,7 +22991,7 @@ static __exception int js_parse_class_default_ctor(JSParseState *s, +@@ -22816,7 +22992,7 @@ static __exception int js_parse_class_default_ctor(JSParseState *s, { JSParsePos pos; const char *str; @@ -615,37 +621,45 @@ index e8fdd8a..bb9eadc 100644 JSParseFunctionEnum func_type; const uint8_t *saved_buf_end; -@@ -22830,14 +23005,17 @@ static __exception int js_parse_class_default_ctor(JSParseState *s, +@@ -22830,14 +23006,17 @@ static __exception int js_parse_class_default_ctor(JSParseState *s, func_type = JS_PARSE_FUNC_CLASS_CONSTRUCTOR; } line_num = s->token.line_num; + column_num = s->token.column_num; saved_buf_end = s->buf_end; s->buf_ptr = (uint8_t *)str; -- s->buf_end = (uint8_t *)(str + strlen(str)); -+ s->buf_end = (uint8_t *)(str + strlen(str)); + s->buf_end = (uint8_t *)(str + strlen(str)); + s->column_last_ptr = s->buf_ptr; ret = next_token(s); if (!ret) { ret = js_parse_function_decl2(s, func_type, JS_FUNC_NORMAL, JS_ATOM_NULL, (uint8_t *)str, - line_num, JS_PARSE_EXPORT_NONE, pfd); -+ line_num, column_num, ++ line_num, column_num, + JS_PARSE_EXPORT_NONE, pfd); } s->buf_end = saved_buf_end; ret |= js_parse_seek_token(s, &pos); -@@ -23146,7 +23324,8 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr, +@@ -23070,7 +23249,7 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr, + // stack is now: + if (js_parse_function_decl2(s, JS_PARSE_FUNC_CLASS_STATIC_INIT, + JS_FUNC_NORMAL, JS_ATOM_NULL, +- s->token.ptr, s->token.line_num, ++ s->token.ptr, s->token.line_num,s->token.column_num, + JS_PARSE_EXPORT_NONE, &init) < 0) { + goto fail; + } +@@ -23146,7 +23325,8 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr, if (js_parse_function_decl2(s, JS_PARSE_FUNC_GETTER + is_set, JS_FUNC_NORMAL, JS_ATOM_NULL, start_ptr, s->token.line_num, - JS_PARSE_EXPORT_NONE, &method_fd)) -+ s->token.column_num, JS_PARSE_EXPORT_NONE, ++ s->token.column_num, JS_PARSE_EXPORT_NONE, + &method_fd)) goto fail; if (is_private) { method_fd->need_home_object = TRUE; /* needed for brand check */ -@@ -23289,7 +23468,7 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr, +@@ -23289,7 +23469,7 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr, if (is_private) { class_fields[is_static].need_brand = TRUE; } @@ -654,16 +668,15 @@ index e8fdd8a..bb9eadc 100644 goto fail; if (func_type == JS_PARSE_FUNC_DERIVED_CLASS_CONSTRUCTOR || func_type == JS_PARSE_FUNC_CLASS_CONSTRUCTOR) { -@@ -23979,7 +24158,7 @@ static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg, +@@ -23979,6 +24159,7 @@ static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg, JSAtom prop_name, var_name; int opcode, scope, tok1, skip_bits; BOOL has_initializer; -- + emit_column(s, s->token.column_num); + if (has_ellipsis < 0) { /* pre-parse destructuration target for spread detection */ - js_parse_skip_parens_token(s, &skip_bits, FALSE); -@@ -24416,10 +24595,12 @@ static void optional_chain_test(JSParseState *s, int *poptional_chaining_label, +@@ -24416,10 +24597,12 @@ static void optional_chain_test(JSParseState *s, int *poptional_chaining_label, static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) { FuncCallType call_type; @@ -677,7 +690,7 @@ index e8fdd8a..bb9eadc 100644 switch(s->token.val) { case TOK_NUMBER: { -@@ -24499,7 +24680,7 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) +@@ -24499,7 +24682,7 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) backtrace_flags = JS_BACKTRACE_FLAG_SINGLE_LEVEL; build_backtrace(s->ctx, s->ctx->rt->current_exception, s->filename, s->token.line_num, @@ -686,7 +699,7 @@ index e8fdd8a..bb9eadc 100644 return -1; } ret = emit_push_const(s, str, 0); -@@ -24521,7 +24702,8 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) +@@ -24521,7 +24704,8 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) case TOK_FUNCTION: if (js_parse_function_decl(s, JS_PARSE_FUNC_EXPR, JS_FUNC_NORMAL, JS_ATOM_NULL, @@ -696,7 +709,7 @@ index e8fdd8a..bb9eadc 100644 return -1; break; case TOK_CLASS: -@@ -24560,15 +24742,18 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) +@@ -24560,15 +24744,18 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) peek_token(s, TRUE) != '\n') { const uint8_t *source_ptr; int source_line_num; @@ -716,7 +729,7 @@ index e8fdd8a..bb9eadc 100644 return -1; } else { name = JS_DupAtom(s->ctx, JS_ATOM_async); -@@ -24960,6 +25145,7 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) +@@ -24960,6 +25147,7 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) break; } } else { @@ -724,7 +737,7 @@ index e8fdd8a..bb9eadc 100644 if (next_token(s)) return -1; emit_func_call: -@@ -25003,6 +25189,8 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) +@@ -25003,6 +25191,8 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) } else if (s->token.val == '.') { if (next_token(s)) return -1; @@ -733,7 +746,7 @@ index e8fdd8a..bb9eadc 100644 parse_property: if (s->token.val == TOK_PRIVATE_NAME) { /* private class field */ -@@ -25086,6 +25274,7 @@ static __exception int js_parse_delete(JSParseState *s) +@@ -25086,6 +25276,7 @@ static __exception int js_parse_delete(JSParseState *s) JSFunctionDef *fd = s->cur_func; JSAtom name; int opcode; @@ -741,15 +754,7 @@ index e8fdd8a..bb9eadc 100644 if (next_token(s)) return -1; -@@ -25514,6 +25703,7 @@ static __exception int js_parse_logical_and_or(JSParseState *s, int op, - emit_op(s, OP_drop); - - if (op == TOK_LAND) { -+ emit_column(s, s->token.column_num); - if (js_parse_expr_binary(s, 8, parse_flags)) - return -1; - } else { -@@ -25549,6 +25739,7 @@ static __exception int js_parse_coalesce_expr(JSParseState *s, int parse_flags) +@@ -25549,6 +25740,7 @@ static __exception int js_parse_coalesce_expr(JSParseState *s, int parse_flags) emit_op(s, OP_is_undefined_or_null); emit_goto(s, OP_if_false, label1); emit_op(s, OP_drop); @@ -757,7 +762,7 @@ index e8fdd8a..bb9eadc 100644 if (js_parse_expr_binary(s, 8, parse_flags)) return -1; -@@ -25597,6 +25788,7 @@ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags) +@@ -25597,6 +25789,7 @@ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags) int opcode, op, scope; JSAtom name0 = JS_ATOM_NULL; JSAtom name; @@ -765,7 +770,46 @@ index e8fdd8a..bb9eadc 100644 if (s->token.val == TOK_YIELD) { BOOL is_star = FALSE, is_async; -@@ -26496,6 +26688,7 @@ static __exception int js_parse_statement_or_decl(JSParseState *s, +@@ -25739,10 +25932,10 @@ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags) + 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, +- s->token.ptr, s->token.line_num); ++ s->token.ptr, s->token.line_num, s->token.column_num); + } else if (token_is_pseudo_keyword(s, JS_ATOM_async)) { + const uint8_t *source_ptr; +- int source_line_num, tok; ++ int source_line_num, source_column_num, tok; + JSParsePos pos; + + /* fast test */ +@@ -25752,6 +25945,7 @@ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags) + + source_ptr = s->token.ptr; + source_line_num = s->token.line_num; ++ source_column_num = s->token.column_num; + js_parse_get_pos(s, &pos); + if (next_token(s)) + return -1; +@@ -25761,7 +25955,7 @@ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags) + peek_token(s, TRUE) == TOK_ARROW)) { + return js_parse_function_decl(s, JS_PARSE_FUNC_ARROW, + JS_FUNC_ASYNC, JS_ATOM_NULL, +- source_ptr, source_line_num); ++ source_ptr, source_line_num, source_column_num); + } else { + /* undo the token parsing */ + if (js_parse_seek_token(s, &pos)) +@@ -25771,7 +25965,7 @@ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags) + peek_token(s, TRUE) == TOK_ARROW) { + return js_parse_function_decl(s, JS_PARSE_FUNC_ARROW, + JS_FUNC_NORMAL, JS_ATOM_NULL, +- s->token.ptr, s->token.line_num); ++ s->token.ptr, s->token.line_num, s->token.column_num); + } + next: + if (s->token.val == TOK_IDENT) { +@@ -26496,6 +26690,7 @@ static __exception int js_parse_statement_or_decl(JSParseState *s, JSContext *ctx = s->ctx; JSAtom label_name; int tok; @@ -773,7 +817,7 @@ index e8fdd8a..bb9eadc 100644 /* specific label handling */ /* XXX: support multiple labels on loop statements */ -@@ -27185,7 +27378,8 @@ static __exception int js_parse_statement_or_decl(JSParseState *s, +@@ -27185,7 +27380,8 @@ 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, @@ -783,7 +827,7 @@ index e8fdd8a..bb9eadc 100644 goto fail; break; } -@@ -29096,7 +29290,8 @@ static __exception int js_parse_export(JSParseState *s) +@@ -29096,7 +29292,8 @@ static __exception int js_parse_export(JSParseState *s) return js_parse_function_decl2(s, JS_PARSE_FUNC_STATEMENT, JS_FUNC_NORMAL, JS_ATOM_NULL, s->token.ptr, s->token.line_num, @@ -793,7 +837,7 @@ index e8fdd8a..bb9eadc 100644 } if (next_token(s)) -@@ -29206,7 +29401,8 @@ static __exception int js_parse_export(JSParseState *s) +@@ -29206,7 +29403,8 @@ static __exception int js_parse_export(JSParseState *s) return js_parse_function_decl2(s, JS_PARSE_FUNC_STATEMENT, JS_FUNC_NORMAL, JS_ATOM_NULL, s->token.ptr, s->token.line_num, @@ -803,7 +847,7 @@ index e8fdd8a..bb9eadc 100644 } else { if (js_parse_assign_expr(s)) return -1; -@@ -29403,7 +29599,8 @@ static __exception int js_parse_source_element(JSParseState *s) +@@ -29403,7 +29601,8 @@ static __exception int js_parse_source_element(JSParseState *s) peek_token(s, TRUE) == TOK_FUNCTION)) { if (js_parse_function_decl(s, JS_PARSE_FUNC_STATEMENT, JS_FUNC_NORMAL, JS_ATOM_NULL, @@ -813,18 +857,18 @@ index e8fdd8a..bb9eadc 100644 return -1; } else if (s->token.val == TOK_EXPORT && fd->module) { if (js_parse_export(s)) -@@ -29425,7 +29622,9 @@ static JSFunctionDef *js_new_function_def(JSContext *ctx, +@@ -29425,7 +29624,9 @@ static JSFunctionDef *js_new_function_def(JSContext *ctx, JSFunctionDef *parent, BOOL is_eval, BOOL is_func_expr, - const char *filename, int line_num) -+ const char *filename, ++ const char *filename, + int line_num, + int column_num) { JSFunctionDef *fd; -@@ -29473,8 +29672,10 @@ static JSFunctionDef *js_new_function_def(JSContext *ctx, +@@ -29473,8 +29674,10 @@ static JSFunctionDef *js_new_function_def(JSContext *ctx, fd->filename = JS_NewAtom(ctx, filename); fd->line_num = line_num; @@ -835,7 +879,7 @@ index e8fdd8a..bb9eadc 100644 //fd->pc2line_last_line_num = line_num; //fd->pc2line_last_pc = 0; fd->last_opcode_line_num = line_num; -@@ -29533,6 +29734,7 @@ static void js_free_function_def(JSContext *ctx, JSFunctionDef *fd) +@@ -29533,6 +29736,7 @@ static void js_free_function_def(JSContext *ctx, JSFunctionDef *fd) js_free(ctx, fd->jump_slots); js_free(ctx, fd->label_slots); js_free(ctx, fd->line_number_slots); @@ -843,7 +887,7 @@ index e8fdd8a..bb9eadc 100644 for(i = 0; i < fd->cpool_count; i++) { JS_FreeValue(ctx, fd->cpool[i]); -@@ -29566,6 +29768,7 @@ static void js_free_function_def(JSContext *ctx, JSFunctionDef *fd) +@@ -29566,6 +29770,7 @@ static void js_free_function_def(JSContext *ctx, JSFunctionDef *fd) JS_FreeAtom(ctx, fd->filename); dbuf_free(&fd->pc2line); @@ -851,7 +895,7 @@ index e8fdd8a..bb9eadc 100644 js_free(ctx, fd->source); -@@ -31563,6 +31766,10 @@ static __exception int resolve_variables(JSContext *ctx, JSFunctionDef *s) +@@ -31563,6 +31768,10 @@ static __exception int resolve_variables(JSContext *ctx, JSFunctionDef *s) s->line_number_size++; goto no_change; @@ -862,12 +906,12 @@ index e8fdd8a..bb9eadc 100644 case OP_eval: /* convert scope index to adjusted variable index */ { int call_argc = get_u16(bc_buf + pos + 1); -@@ -31877,6 +32084,21 @@ static void add_pc2line_info(JSFunctionDef *s, uint32_t pc, int line_num) +@@ -31877,6 +32086,21 @@ static void add_pc2line_info(JSFunctionDef *s, uint32_t pc, int line_num) } } +/* the pc2col table gives a column number for each PC value */ -+static void add_pc2col_info(JSFunctionDef *s, uint32_t pc, int column_num) ++static void add_pc2col_info(JSFunctionDef *s, uint32_t pc, int column_num) +{ + if(s->column_number_slots != NULL + && s->column_number_count < s->column_number_size @@ -884,11 +928,11 @@ index e8fdd8a..bb9eadc 100644 static void compute_pc2line_info(JSFunctionDef *s) { if (!(s->js_mode & JS_MODE_STRIP) && s->line_number_slots) { -@@ -31915,6 +32137,45 @@ static void compute_pc2line_info(JSFunctionDef *s) +@@ -31915,6 +32139,45 @@ static void compute_pc2line_info(JSFunctionDef *s) } } -+static void compute_pc2column_info(JSFunctionDef *s) ++static void compute_pc2column_info(JSFunctionDef *s) +{ + if(!(s->js_mode & JS_MODE_STRIP) && s->column_number_slots) { + int last_column_num = s->column_num; @@ -930,7 +974,7 @@ index e8fdd8a..bb9eadc 100644 static RelocEntry *add_reloc(JSContext *ctx, LabelSlot *ls, uint32_t addr, int size) { RelocEntry *re; -@@ -32079,7 +32340,7 @@ static void put_short_code(DynBuf *bc_out, int op, int idx) +@@ -32079,7 +32342,7 @@ static void put_short_code(DynBuf *bc_out, int op, int idx) /* peephole optimizations and resolve goto/labels */ static __exception int resolve_labels(JSContext *ctx, JSFunctionDef *s) { @@ -939,7 +983,7 @@ index e8fdd8a..bb9eadc 100644 const uint8_t *bc_buf; DynBuf bc_out; LabelSlot *label_slots, *ls; -@@ -32093,7 +32354,7 @@ static __exception int resolve_labels(JSContext *ctx, JSFunctionDef *s) +@@ -32093,7 +32356,7 @@ static __exception int resolve_labels(JSContext *ctx, JSFunctionDef *s) label_slots = s->label_slots; line_num = s->line_num; @@ -948,7 +992,7 @@ index e8fdd8a..bb9eadc 100644 cc.bc_buf = bc_buf = s->byte_code.buf; cc.bc_len = bc_len = s->byte_code.size; js_dbuf_init(ctx, &bc_out); -@@ -32114,6 +32375,14 @@ static __exception int resolve_labels(JSContext *ctx, JSFunctionDef *s) +@@ -32114,6 +32377,14 @@ static __exception int resolve_labels(JSContext *ctx, JSFunctionDef *s) s->line_number_last_pc = 0; } @@ -963,7 +1007,7 @@ index e8fdd8a..bb9eadc 100644 /* initialize the 'home_object' variable if needed */ if (s->home_object_var_idx >= 0) { dbuf_putc(&bc_out, OP_special_object); -@@ -32187,6 +32456,12 @@ static __exception int resolve_labels(JSContext *ctx, JSFunctionDef *s) +@@ -32187,6 +32458,12 @@ static __exception int resolve_labels(JSContext *ctx, JSFunctionDef *s) line_num = get_u32(bc_buf + pos + 1); break; @@ -976,7 +1020,7 @@ index e8fdd8a..bb9eadc 100644 case OP_label: { label = get_u32(bc_buf + pos + 1); -@@ -32910,6 +33185,11 @@ static __exception int resolve_labels(JSContext *ctx, JSFunctionDef *s) +@@ -32910,6 +33187,11 @@ static __exception int resolve_labels(JSContext *ctx, JSFunctionDef *s) if (s->line_number_slots[j].pc > pos) s->line_number_slots[j].pc -= delta; } @@ -988,7 +1032,7 @@ index e8fdd8a..bb9eadc 100644 continue; } break; -@@ -32941,8 +33221,11 @@ static __exception int resolve_labels(JSContext *ctx, JSFunctionDef *s) +@@ -32941,8 +33223,11 @@ static __exception int resolve_labels(JSContext *ctx, JSFunctionDef *s) s->label_slots = NULL; /* XXX: should delay until copying to runtime bytecode function */ compute_pc2line_info(s); @@ -1000,7 +1044,7 @@ index e8fdd8a..bb9eadc 100644 /* set the new byte code */ dbuf_free(&s->byte_code); s->byte_code = bc_out; -@@ -33413,6 +33696,7 @@ static JSValue js_create_function(JSContext *ctx, JSFunctionDef *fd) +@@ -33413,6 +33698,7 @@ static JSValue js_create_function(JSContext *ctx, JSFunctionDef *fd) if (fd->js_mode & JS_MODE_STRIP) { JS_FreeAtom(ctx, fd->filename); dbuf_free(&fd->pc2line); // probably useless @@ -1008,7 +1052,7 @@ index e8fdd8a..bb9eadc 100644 } else { /* XXX: source and pc2line info should be packed at the end of the JSFunctionBytecode structure, avoiding allocation overhead -@@ -33420,14 +33704,19 @@ static JSValue js_create_function(JSContext *ctx, JSFunctionDef *fd) +@@ -33420,14 +33706,19 @@ static JSValue js_create_function(JSContext *ctx, JSFunctionDef *fd) b->has_debug = 1; b->debug.filename = fd->filename; b->debug.line_num = fd->line_num; @@ -1028,7 +1072,7 @@ index e8fdd8a..bb9eadc 100644 b->debug.source = fd->source; b->debug.source_len = fd->source_len; } -@@ -33510,6 +33799,7 @@ static void free_function_bytecode(JSRuntime *rt, JSFunctionBytecode *b) +@@ -33510,6 +33801,7 @@ static void free_function_bytecode(JSRuntime *rt, JSFunctionBytecode *b) if (b->has_debug) { JS_FreeAtomRT(rt, b->debug.filename); js_free_rt(rt, b->debug.pc2line_buf); @@ -1036,7 +1080,7 @@ index e8fdd8a..bb9eadc 100644 js_free_rt(rt, b->debug.source); } -@@ -33673,7 +33963,7 @@ static JSFunctionDef *js_parse_function_class_fields_init(JSParseState *s) +@@ -33673,7 +33965,7 @@ static JSFunctionDef *js_parse_function_class_fields_init(JSParseState *s) JSFunctionDef *fd; fd = js_new_function_def(s->ctx, s->cur_func, FALSE, FALSE, @@ -1045,7 +1089,7 @@ index e8fdd8a..bb9eadc 100644 if (!fd) return NULL; fd->func_name = JS_ATOM_NULL; -@@ -33701,6 +33991,7 @@ static __exception int js_parse_function_decl2(JSParseState *s, +@@ -33701,6 +33993,7 @@ static __exception int js_parse_function_decl2(JSParseState *s, JSAtom func_name, const uint8_t *ptr, int function_line_num, @@ -1053,7 +1097,7 @@ index e8fdd8a..bb9eadc 100644 JSParseExportEnum export_flag, JSFunctionDef **pfd) { -@@ -33815,7 +34106,8 @@ static __exception int js_parse_function_decl2(JSParseState *s, +@@ -33815,7 +34108,8 @@ static __exception int js_parse_function_decl2(JSParseState *s, } fd = js_new_function_def(ctx, fd, FALSE, is_expr, @@ -1063,7 +1107,7 @@ index e8fdd8a..bb9eadc 100644 if (!fd) { JS_FreeAtom(ctx, func_name); return -1; -@@ -34265,11 +34557,12 @@ static __exception int js_parse_function_decl(JSParseState *s, +@@ -34265,11 +34559,12 @@ static __exception int js_parse_function_decl(JSParseState *s, JSFunctionKindEnum func_kind, JSAtom func_name, const uint8_t *ptr, @@ -1074,12 +1118,12 @@ index e8fdd8a..bb9eadc 100644 return js_parse_function_decl2(s, func_type, func_kind, func_name, ptr, - function_line_num, JS_PARSE_EXPORT_NONE, - NULL); -+ function_line_num, function_column_num, ++ function_line_num, function_column_num, + JS_PARSE_EXPORT_NONE, NULL); } static __exception int js_parse_program(JSParseState *s) -@@ -34332,10 +34625,14 @@ static void js_parse_init(JSContext *ctx, JSParseState *s, +@@ -34332,10 +34627,14 @@ static void js_parse_init(JSContext *ctx, JSParseState *s, s->ctx = ctx; s->filename = filename; s->line_num = 1; @@ -1094,7 +1138,7 @@ index e8fdd8a..bb9eadc 100644 } static JSValue JS_EvalFunctionInternal(JSContext *ctx, JSValue fun_obj, -@@ -34423,7 +34720,7 @@ static JSValue __JS_EvalInternal(JSContext *ctx, JSValueConst this_obj, +@@ -34423,7 +34722,7 @@ static JSValue __JS_EvalInternal(JSContext *ctx, JSValueConst this_obj, js_mode |= JS_MODE_STRICT; } } @@ -1103,7 +1147,7 @@ index e8fdd8a..bb9eadc 100644 if (!fd) goto fail1; s->cur_func = fd; -@@ -35174,6 +35471,9 @@ static int JS_WriteFunctionTag(BCWriterState *s, JSValueConst obj) +@@ -35174,6 +35473,9 @@ static int JS_WriteFunctionTag(BCWriterState *s, JSValueConst obj) bc_put_leb128(s, b->debug.line_num); bc_put_leb128(s, b->debug.pc2line_len); dbuf_put(&s->dbuf, b->debug.pc2line_buf, b->debug.pc2line_len); @@ -1113,7 +1157,7 @@ index e8fdd8a..bb9eadc 100644 } for(i = 0; i < b->cpool_count; i++) { -@@ -36216,6 +36516,17 @@ static JSValue JS_ReadFunctionTag(BCReaderState *s) +@@ -36216,6 +36518,17 @@ static JSValue JS_ReadFunctionTag(BCReaderState *s) if (bc_get_buf(s, b->debug.pc2line_buf, b->debug.pc2line_len)) goto fail; } @@ -1131,7 +1175,7 @@ index e8fdd8a..bb9eadc 100644 #ifdef DUMP_READ_OBJECT bc_read_trace(s, "filename: "); print_atom(s->ctx, b->debug.filename); printf("\n"); #endif -@@ -38674,6 +38985,7 @@ static const JSCFunctionListEntry js_function_proto_funcs[] = { +@@ -38674,6 +38987,7 @@ static const JSCFunctionListEntry js_function_proto_funcs[] = { JS_CFUNC_DEF("[Symbol.hasInstance]", 1, js_function_hasInstance ), JS_CGETSET_DEF("fileName", js_function_proto_fileName, NULL ), JS_CGETSET_DEF("lineNumber", js_function_proto_lineNumber, NULL ), @@ -1139,7 +1183,7 @@ index e8fdd8a..bb9eadc 100644 }; /* Error class */ -@@ -38783,7 +39095,7 @@ static JSValue js_error_constructor(JSContext *ctx, JSValueConst new_target, +@@ -38783,7 +39097,7 @@ static JSValue js_error_constructor(JSContext *ctx, JSValueConst new_target, } /* skip the Error() function in the backtrace */ @@ -1162,7 +1206,7 @@ index 7199936..1986647 100644 int64_t binary_object_count, binary_object_size; diff --git a/tests/test_line_column.js b/tests/test_line_column.js new file mode 100644 -index 0000000..d1c5989 +index 0000000..4301ee0 --- /dev/null +++ b/tests/test_line_column.js @@ -0,0 +1,240 @@ @@ -1267,9 +1311,9 @@ index 0000000..d1c5989 + } +} + -+/** -+ * if comment is first line, -+ * the line number of one line should be locate at next line ++/** ++ * if comment is first line, ++ * the line number of one line should be locate at next line + */ +function test_line_column8() { + try {