jscript: Added html comments handling.
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 @@
script_ctx_t *script;
source_elements_t *source;
BOOL nl;
+ BOOL is_html;
HRESULT hres;
jsheap_t heap;
@@ -65,7 +66,7 @@
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 @@
}
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 @@
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 @@
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 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 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 @@
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 @@
/* 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 @@
/* 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 @@
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);