@@ -19924,6 +19924,31 @@ static int peek_token(JSParseState *s, BOOL no_line_terminator)
19924
19924
return simple_next_token(&p, no_line_terminator);
19925
19925
}
19926
19926
19927
+ static void skip_shebang(const uint8_t **pp, const uint8_t *buf_end)
19928
+ {
19929
+ const uint8_t *p = *pp;
19930
+ int c;
19931
+
19932
+ if (p[0] == '#' && p[1] == '!') {
19933
+ p += 2;
19934
+ while (p < buf_end) {
19935
+ if (*p == '\n' || *p == '\r') {
19936
+ break;
19937
+ } else if (*p >= 0x80) {
19938
+ c = unicode_from_utf8(p, UTF8_CHAR_LEN_MAX, &p);
19939
+ if (c == CP_LS || c == CP_PS) {
19940
+ break;
19941
+ } else if (c == -1) {
19942
+ p++; /* skip invalid UTF-8 */
19943
+ }
19944
+ } else {
19945
+ p++;
19946
+ }
19947
+ }
19948
+ *pp = p;
19949
+ }
19950
+ }
19951
+
19927
19952
/* return true if 'input' contains the source of a module
19928
19953
(heuristic). 'input' must be a zero terminated.
19929
19954
@@ -19934,6 +19959,8 @@ BOOL JS_DetectModule(const char *input, size_t input_len)
19934
19959
{
19935
19960
const uint8_t *p = (const uint8_t *)input;
19936
19961
int tok;
19962
+
19963
+ skip_shebang(&p, p + input_len);
19937
19964
switch(simple_next_token(&p, FALSE)) {
19938
19965
case TOK_IMPORT:
19939
19966
tok = simple_next_token(&p, FALSE);
@@ -32247,31 +32274,6 @@ JSValue JS_EvalFunction(JSContext *ctx, JSValue fun_obj)
32247
32274
return JS_EvalFunctionInternal(ctx, fun_obj, ctx->global_obj, NULL, NULL);
32248
32275
}
32249
32276
32250
- static void skip_shebang(JSParseState *s)
32251
- {
32252
- const uint8_t *p = s->buf_ptr;
32253
- int c;
32254
-
32255
- if (p[0] == '#' && p[1] == '!') {
32256
- p += 2;
32257
- while (p < s->buf_end) {
32258
- if (*p == '\n' || *p == '\r') {
32259
- break;
32260
- } else if (*p >= 0x80) {
32261
- c = unicode_from_utf8(p, UTF8_CHAR_LEN_MAX, &p);
32262
- if (c == CP_LS || c == CP_PS) {
32263
- break;
32264
- } else if (c == -1) {
32265
- p++; /* skip invalid UTF-8 */
32266
- }
32267
- } else {
32268
- p++;
32269
- }
32270
- }
32271
- s->buf_ptr = p;
32272
- }
32273
- }
32274
-
32275
32277
/* 'input' must be zero terminated i.e. input[input_len] = '\0'. */
32276
32278
static JSValue __JS_EvalInternal(JSContext *ctx, JSValue this_obj,
32277
32279
const char *input, size_t input_len,
@@ -32287,7 +32289,7 @@ static JSValue __JS_EvalInternal(JSContext *ctx, JSValue this_obj,
32287
32289
JSModuleDef *m;
32288
32290
32289
32291
js_parse_init(ctx, s, input, input_len, filename);
32290
- skip_shebang(s );
32292
+ skip_shebang(&s->buf_ptr, s->buf_end );
32291
32293
32292
32294
eval_type = flags & JS_EVAL_TYPE_MASK;
32293
32295
m = NULL;
0 commit comments