jscript: Store source code in bytecode_t.
This commit is contained in:
parent
6f35ec6092
commit
0762106648
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue