Fix JS_DetectModule if the first statement is an await

This commit is contained in:
Saúl Ibarra Corretgé 2024-09-10 13:07:00 +02:00
parent 902cc2cf0e
commit 6dd2ce308a
4 changed files with 18 additions and 2 deletions

View file

@ -218,6 +218,7 @@ jobs:
build\${{matrix.buildType}}\qjs.exe tests\test_std.js build\${{matrix.buildType}}\qjs.exe tests\test_std.js
build\${{matrix.buildType}}\qjs.exe tests\test_worker.js build\${{matrix.buildType}}\qjs.exe tests\test_worker.js
build\${{matrix.buildType}}\qjs.exe tests\test_queue_microtask.js build\${{matrix.buildType}}\qjs.exe tests\test_queue_microtask.js
build\${{matrix.buildType}}\qjs.exe tests\test_module_detect.js
build\${{matrix.buildType}}\function_source.exe build\${{matrix.buildType}}\function_source.exe
windows-clang: windows-clang:
@ -253,6 +254,7 @@ jobs:
build\${{matrix.buildType}}\qjs.exe tests\test_std.js build\${{matrix.buildType}}\qjs.exe tests\test_std.js
build\${{matrix.buildType}}\qjs.exe tests\test_worker.js build\${{matrix.buildType}}\qjs.exe tests\test_worker.js
build\${{matrix.buildType}}\qjs.exe tests\test_queue_microtask.js build\${{matrix.buildType}}\qjs.exe tests\test_queue_microtask.js
build\${{matrix.buildType}}\qjs.exe tests\test_module_detect.js
build\${{matrix.buildType}}\function_source.exe build\${{matrix.buildType}}\function_source.exe
windows-ninja: windows-ninja:
@ -292,6 +294,7 @@ jobs:
build\qjs.exe tests\test_std.js build\qjs.exe tests\test_std.js
build\qjs.exe tests\test_worker.js build\qjs.exe tests\test_worker.js
build\qjs.exe tests\test_queue_microtask.js build\qjs.exe tests\test_queue_microtask.js
build\qjs.exe tests\test_module_detect.js
build\function_source.exe build\function_source.exe
windows-mingw: windows-mingw:

View file

@ -88,6 +88,7 @@ test: $(QJS)
$(QJS) tests/test_std.js $(QJS) tests/test_std.js
$(QJS) tests/test_worker.js $(QJS) tests/test_worker.js
$(QJS) tests/test_queue_microtask.js $(QJS) tests/test_queue_microtask.js
$(QJS) tests/test_module_detect.js
testconv: $(BUILD_DIR)/test_conv testconv: $(BUILD_DIR)/test_conv
$(BUILD_DIR)/test_conv $(BUILD_DIR)/test_conv

View file

@ -20007,6 +20007,9 @@ static int simple_next_token(const uint8_t **pp, BOOL no_line_terminator)
p[2] == 'c' && p[3] == 't' && p[4] == 'i' && p[2] == 'c' && p[3] == 't' && p[4] == 'i' &&
p[5] == 'o' && p[6] == 'n' && !lre_js_is_ident_next(p[7])) { p[5] == 'o' && p[6] == 'n' && !lre_js_is_ident_next(p[7])) {
return TOK_FUNCTION; return TOK_FUNCTION;
} else if (c == 'a' && p[0] == 'w' && p[1] == 'a' &&
p[2] == 'i' && p[3] == 't' && !lre_js_is_ident_next(p[4])) {
return TOK_AWAIT;
} }
return TOK_IDENT; return TOK_IDENT;
} }
@ -20048,8 +20051,11 @@ static void skip_shebang(const uint8_t **pp, const uint8_t *buf_end)
/* return true if 'input' contains the source of a module /* return true if 'input' contains the source of a module
(heuristic). 'input' must be a zero terminated. (heuristic). 'input' must be a zero terminated.
Heuristic: skip comments and expect 'import' keyword not followed Heuristic:
by '(' or '.' or export keyword. - Skip comments
- Expect 'import' keyword not followed by '(' or '.'
- Expect 'export' keyword
- Expect 'await' keyword
*/ */
/* input is pure ASCII or UTF-8 encoded source code */ /* input is pure ASCII or UTF-8 encoded source code */
BOOL JS_DetectModule(const char *input, size_t input_len) BOOL JS_DetectModule(const char *input, size_t input_len)
@ -20062,6 +20068,7 @@ BOOL JS_DetectModule(const char *input, size_t input_len)
case TOK_IMPORT: case TOK_IMPORT:
tok = simple_next_token(&p, FALSE); tok = simple_next_token(&p, FALSE);
return (tok != '.' && tok != '('); return (tok != '.' && tok != '(');
case TOK_AWAIT:
case TOK_EXPORT: case TOK_EXPORT:
return TRUE; return TRUE;
default: default:

View file

@ -0,0 +1,5 @@
// This needs to be parsed as a module or will throw SyntaxError.
//
await 0;