Jacek Caban : jscript: Store source code in bytecode_t.
Alexandre Julliard
julliard at winehq.org
Mon Mar 26 12:29:30 CDT 2012
Module: wine
Branch: master
Commit: 0762106648a52883b21f07cb344b879d6a2b6e44
URL: http://source.winehq.org/git/wine.git/?a=commit;h=0762106648a52883b21f07cb344b879d6a2b6e44
Author: Jacek Caban <jacek at codeweavers.com>
Date: Mon Mar 26 11:41:38 2012 +0200
jscript: Store source code in bytecode_t.
---
dlls/jscript/compile.c | 15 +++++++++++----
dlls/jscript/engine.h | 4 +++-
dlls/jscript/parser.y | 9 +--------
3 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c
index bb00aec..c9d814f 100644
--- a/dlls/jscript/compile.c
+++ b/dlls/jscript/compile.c
@@ -1703,13 +1703,14 @@ void release_bytecode(bytecode_t *code)
for(i=0; i < code->bstr_cnt; i++)
SysFreeString(code->bstr_pool[i]);
+ heap_free(code->source);
jsheap_free(&code->heap);
heap_free(code->bstr_pool);
heap_free(code->instrs);
heap_free(code);
}
-static HRESULT init_code(compiler_ctx_t *compiler)
+static HRESULT init_code(compiler_ctx_t *compiler, const WCHAR *source)
{
compiler->code = heap_alloc_zero(sizeof(bytecode_t));
if(!compiler->code)
@@ -1718,6 +1719,12 @@ static HRESULT init_code(compiler_ctx_t *compiler)
compiler->code->ref = 1;
jsheap_init(&compiler->code->heap);
+ compiler->code->source = heap_strdupW(source);
+ if(!compiler->code->source) {
+ release_bytecode(compiler->code);
+ return E_OUTOFMEMORY;
+ }
+
compiler->code->instrs = heap_alloc(64 * sizeof(instr_t));
if(!compiler->code->instrs) {
release_bytecode(compiler->code);
@@ -1769,13 +1776,13 @@ HRESULT compile_script(script_ctx_t *ctx, const WCHAR *code, const WCHAR *delimi
compiler_ctx_t compiler = {0};
HRESULT hres;
- hres = script_parse(ctx, code, delimiter, from_eval, &compiler.parser);
+ hres = init_code(&compiler, code);
if(FAILED(hres))
return hres;
- hres = init_code(&compiler);
+ hres = script_parse(ctx, compiler.code->source, delimiter, from_eval, &compiler.parser);
if(FAILED(hres)) {
- parser_release(compiler.parser);
+ release_bytecode(compiler.code);
return hres;
}
diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h
index 040b3c4..64c0fea 100644
--- a/dlls/jscript/engine.h
+++ b/dlls/jscript/engine.h
@@ -43,7 +43,7 @@ typedef struct _func_stack {
} func_stack_t;
typedef struct {
- WCHAR *begin;
+ const WCHAR *begin;
const WCHAR *end;
const WCHAR *ptr;
@@ -172,6 +172,8 @@ typedef struct _bytecode_t {
instr_t *instrs;
jsheap_t heap;
+ WCHAR *source;
+
BSTR *bstr_pool;
unsigned bstr_pool_size;
unsigned bstr_cnt;
diff --git a/dlls/jscript/parser.y b/dlls/jscript/parser.y
index 717a95c..4eb3f1d 100644
--- a/dlls/jscript/parser.y
+++ b/dlls/jscript/parser.y
@@ -1533,7 +1533,6 @@ static void program_parsed(parser_ctx_t *ctx, source_elements_t *source)
void parser_release(parser_ctx_t *ctx)
{
script_release(ctx->script);
- heap_free(ctx->begin);
jsheap_free(&ctx->heap);
heap_free(ctx);
}
@@ -1554,13 +1553,7 @@ HRESULT script_parse(script_ctx_t *ctx, const WCHAR *code, const WCHAR *delimite
parser_ctx->hres = JS_E_SYNTAX;
parser_ctx->is_html = delimiter && !strcmpiW(delimiter, html_tagW);
- parser_ctx->begin = heap_strdupW(code);
- if(!parser_ctx->begin) {
- heap_free(parser_ctx);
- return E_OUTOFMEMORY;
- }
-
- parser_ctx->ptr = parser_ctx->begin;
+ parser_ctx->begin = parser_ctx->ptr = code;
parser_ctx->end = parser_ctx->begin + strlenW(parser_ctx->begin);
script_addref(ctx);
More information about the wine-cvs
mailing list