regexp literal after for/if/while header causes SyntaxError in js_parse_skip_parens_token

Aperta
#620 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 5 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
c, javascript
Ambito
compilers

Direzione di ricerca

Start by reading js_parse_skip_parens_token(), is_regexp_allowed(), and js_parse_regexp() in the parser; the issue identifies these as the paths involved in the incorrect lookahead and pending exception. Reproduce with the supplied snippets and trace how parsing handles / after each listed header. Done means all snippets parse and the IIFE leaves no pending syntax error.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

var f1 = (fn = function(e){ for (var r in e) /data-/gi.test(r); var s = "#"; }) => fn;
var f2 = (fn = function(){ for (var x in {a:1}) /[)]/.test(x); }) => fn;
var f3 = (fn = function(){ if (1) /[)]/.test(")"); }) => fn;
var f4 = (fn = function(){ while (0) /[)]/.test(")"); }) => fn;
var f5 = (fn = function(){ with ({}) /[)]/.test(")"); }) => fn;
var f6 = (fn = async function(){ for await (var x of [1]) /[)]/.test(")"); }) => fn;

All the valid snippets above fail to parse with SyntaxError: expecting ';'. In addition, for an IIFE like:

(function(e){ for (var r in e) /data-/gi.test(r); var s = "#"; })({a:1});

JS_Eval() succeeds, but JS_GetException(ctx) still returns a pending SyntaxError: unexpected end of regexp.

The root cause is that is_regexp_allowed(')') always returns FALSE inside js_parse_skip_parens_token(). However, after the closing ) of a for (...), for await (...), if (...), while (...), or with (...) header, a statement follows and / starts a regexp literal rather than division. Treating / as division breaks paren matching during lookahead and also leaves an uncleared exception in rt->current_exception when js_parse_regexp() fails. Could you help look into fixing this?

Lingua principale
C
Stelle
11.1k
Fork
1.2k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di bellard/quickjs

Tutte le issue di bellard/quickjs

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.