Piotr Caban : jscript: Added html comments handling.

Alexandre Julliard julliard at winehq.org
Fri Apr 10 08:10:15 CDT 2009


Module: wine
Branch: master
Commit: 84ef7eced2ab45000efc05c70a2b29fc782d639f
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=84ef7eced2ab45000efc05c70a2b29fc782d639f

Author: Piotr Caban <piotr.caban at gmail.com>
Date:   Thu Apr  9 23:34:26 2009 +0200

jscript: Added html comments handling.

---

 dlls/jscript/engine.h  |    3 ++-
 dlls/jscript/global.c  |    2 +-
 dlls/jscript/jscript.c |    4 ++--
 dlls/jscript/lex.c     |   24 +++++++++++++++++++++---
 dlls/jscript/parser.y  |   15 ++++++++++++---
 5 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h
index e02b717..f1a78ec 100644
--- a/dlls/jscript/engine.h
+++ b/dlls/jscript/engine.h
@@ -55,6 +55,7 @@ typedef struct _parser_ctx_t {
     script_ctx_t *script;
     source_elements_t *source;
     BOOL nl;
+    BOOL is_html;
     HRESULT hres;
 
     jsheap_t heap;
@@ -65,7 +66,7 @@ typedef struct _parser_ctx_t {
     struct _parser_ctx_t *next;
 } parser_ctx_t;
 
-HRESULT script_parse(script_ctx_t*,const WCHAR*,parser_ctx_t**);
+HRESULT script_parse(script_ctx_t*,const WCHAR*,const WCHAR*,parser_ctx_t**);
 void parser_release(parser_ctx_t*);
 
 int parser_lex(void*,parser_ctx_t*);
diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c
index d98b7b4..01d9eb2 100644
--- a/dlls/jscript/global.c
+++ b/dlls/jscript/global.c
@@ -264,7 +264,7 @@ static HRESULT JSGlobal_eval(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARA
     }
 
     TRACE("parsing %s\n", debugstr_w(V_BSTR(arg)));
-    hres = script_parse(dispex->ctx, V_BSTR(arg), &parser_ctx);
+    hres = script_parse(dispex->ctx, V_BSTR(arg), NULL, &parser_ctx);
     if(FAILED(hres)) {
         WARN("parse (%s) failed: %08x\n", debugstr_w(V_BSTR(arg)), hres);
         return hres;
diff --git a/dlls/jscript/jscript.c b/dlls/jscript/jscript.c
index fb99d24..b536014 100644
--- a/dlls/jscript/jscript.c
+++ b/dlls/jscript/jscript.c
@@ -596,7 +596,7 @@ static HRESULT WINAPI JScriptParse_ParseScriptText(IActiveScriptParse *iface,
     if(This->thread_id != GetCurrentThreadId() || This->ctx->state == SCRIPTSTATE_CLOSED)
         return E_UNEXPECTED;
 
-    hres = script_parse(This->ctx, pstrCode, &parser_ctx);
+    hres = script_parse(This->ctx, pstrCode, pstrDelimiter, &parser_ctx);
     if(FAILED(hres))
         return hres;
 
@@ -662,7 +662,7 @@ static HRESULT WINAPI JScriptParseProcedure_ParseProcedureText(IActiveScriptPars
     if(This->thread_id != GetCurrentThreadId() || This->ctx->state == SCRIPTSTATE_CLOSED)
         return E_UNEXPECTED;
 
-    hres = script_parse(This->ctx, pstrCode, &parser_ctx);
+    hres = script_parse(This->ctx, pstrCode, pstrDelimiter, &parser_ctx);
     if(FAILED(hres)) {
         WARN("Parse failed %08x\n", hres);
         return hres;
diff --git a/dlls/jscript/lex.c b/dlls/jscript/lex.c
index bf298bf..68bfef8 100644
--- a/dlls/jscript/lex.c
+++ b/dlls/jscript/lex.c
@@ -174,6 +174,20 @@ static void skip_spaces(parser_ctx_t *ctx)
     }
 }
 
+static BOOL skip_html_comment(parser_ctx_t *ctx)
+{
+    const WCHAR html_commentW[] = {'<','!','-','-',0};
+
+    if(!ctx->is_html || ctx->ptr+3 >= ctx->end ||
+        memcmp(ctx->ptr, html_commentW, sizeof(WCHAR)*4))
+        return FALSE;
+
+    ctx->nl = TRUE;
+    while(ctx->ptr < ctx->end && !is_endline(*ctx->ptr++));
+
+    return TRUE;
+}
+
 static BOOL skip_comment(parser_ctx_t *ctx)
 {
     if(ctx->ptr+1 >= ctx->end || *ctx->ptr != '/')
@@ -466,13 +480,13 @@ int parser_lex(void *lval, parser_ctx_t *ctx)
 {
     int ret;
 
-    ctx->nl = FALSE;
+    ctx->nl = ctx->ptr == ctx->begin;
 
     do {
         skip_spaces(ctx);
         if(ctx->ptr == ctx->end)
             return 0;
-    }while(skip_comment(ctx));
+    }while(skip_comment(ctx) || skip_html_comment(ctx));
 
     if(isalphaW(*ctx->ptr)) {
         ret = check_keywords(ctx, lval);
@@ -585,8 +599,12 @@ int parser_lex(void *lval, parser_ctx_t *ctx)
         ctx->ptr++;
         if(ctx->ptr < ctx->end) {
             switch(*ctx->ptr) {
-            case '-':  /* -- */
+            case '-':  /* -- or --> */
                 ctx->ptr++;
+                if(ctx->is_html && ctx->nl && ctx->ptr < ctx->end && *ctx->ptr == '>') {
+                    ctx->ptr++;
+                    return tHTMLCOMMENT;
+                }
                 return tDEC;
             case '=':  /* -= */
                 ctx->ptr++;
diff --git a/dlls/jscript/parser.y b/dlls/jscript/parser.y
index 96ba29c..52a31c8 100644
--- a/dlls/jscript/parser.y
+++ b/dlls/jscript/parser.y
@@ -170,7 +170,7 @@ static source_elements_t *source_elements_add_statement(source_elements_t*,state
 /* keywords */
 %token kBREAK kCASE kCATCH kCONTINUE kDEFAULT kDELETE kDO kELSE kIF kFINALLY kFOR kIN
 %token kINSTANCEOF kNEW kNULL kUNDEFINED kRETURN kSWITCH kTHIS kTHROW kTRUE kFALSE kTRY kTYPEOF kVAR kVOID kWHILE kWITH
-%token tANDAND tOROR tINC tDEC
+%token tANDAND tOROR tINC tDEC tHTMLCOMMENT
 
 %token <srcptr> kFUNCTION '}'
 
@@ -251,7 +251,12 @@ static source_elements_t *source_elements_add_statement(source_elements_t*,state
 
 /* ECMA-262 3rd Edition    14 */
 Program
-       : SourceElements         { program_parsed(ctx, $1); }
+       : SourceElements HtmlComment
+                                { program_parsed(ctx, $1); }
+
+HtmlComment
+        : tHTMLCOMMENT          {}
+        | /* empty */           {}
 
 /* ECMA-262 3rd Edition    14 */
 SourceElements
@@ -1549,18 +1554,22 @@ void parser_release(parser_ctx_t *ctx)
     heap_free(ctx);
 }
 
-HRESULT script_parse(script_ctx_t *ctx, const WCHAR *code, parser_ctx_t **ret)
+HRESULT script_parse(script_ctx_t *ctx, const WCHAR *code, const WCHAR *delimiter,
+        parser_ctx_t **ret)
 {
     parser_ctx_t *parser_ctx;
     jsheap_t *mark;
     HRESULT hres;
 
+    const WCHAR html_tagW[] = {'<','/','s','c','r','i','p','t','>',0};
+
     parser_ctx = heap_alloc_zero(sizeof(parser_ctx_t));
     if(!parser_ctx)
         return E_OUTOFMEMORY;
 
     parser_ctx->ref = 1;
     parser_ctx->hres = E_FAIL;
+    parser_ctx->is_html = delimiter && !strcmpiW(delimiter, html_tagW);
 
     parser_ctx->begin = parser_ctx->ptr = code;
     parser_ctx->end = code + strlenW(code);




More information about the wine-cvs mailing list