Commit f6201b4b authored by Gabriel Ivăncescu's avatar Gabriel Ivăncescu Committed by Alexandre Julliard

jscript: Lookup the named item and keep a ref to it from the associated bytecode.

parent 05dd8212
...@@ -2250,6 +2250,8 @@ void release_bytecode(bytecode_t *code) ...@@ -2250,6 +2250,8 @@ void release_bytecode(bytecode_t *code)
for(i=0; i < code->str_cnt; i++) for(i=0; i < code->str_cnt; i++)
jsstr_release(code->str_pool[i]); jsstr_release(code->str_pool[i]);
if(code->named_item)
release_named_item(code->named_item);
heap_free(code->source); heap_free(code->source);
heap_pool_free(&code->heap); heap_pool_free(&code->heap);
heap_free(code->bstr_pool); heap_free(code->bstr_pool);
...@@ -2485,7 +2487,8 @@ static HRESULT compile_arguments(compiler_ctx_t *ctx, const WCHAR *args) ...@@ -2485,7 +2487,8 @@ static HRESULT compile_arguments(compiler_ctx_t *ctx, const WCHAR *args)
} }
HRESULT compile_script(script_ctx_t *ctx, const WCHAR *code, UINT64 source_context, unsigned start_line, HRESULT compile_script(script_ctx_t *ctx, const WCHAR *code, UINT64 source_context, unsigned start_line,
const WCHAR *args, const WCHAR *delimiter, BOOL from_eval, BOOL use_decode, bytecode_t **ret) const WCHAR *args, const WCHAR *delimiter, BOOL from_eval, BOOL use_decode,
named_item_t *named_item, bytecode_t **ret)
{ {
compiler_ctx_t compiler = {0}; compiler_ctx_t compiler = {0};
HRESULT hres; HRESULT hres;
...@@ -2526,6 +2529,11 @@ HRESULT compile_script(script_ctx_t *ctx, const WCHAR *code, UINT64 source_conte ...@@ -2526,6 +2529,11 @@ HRESULT compile_script(script_ctx_t *ctx, const WCHAR *code, UINT64 source_conte
return DISP_E_EXCEPTION; return DISP_E_EXCEPTION;
} }
if(named_item) {
compiler.code->named_item = named_item;
named_item->ref++;
}
*ret = compiler.code; *ret = compiler.code;
return S_OK; return S_OK;
} }
...@@ -181,6 +181,7 @@ struct _bytecode_t { ...@@ -181,6 +181,7 @@ struct _bytecode_t {
heap_pool_t heap; heap_pool_t heap;
function_code_t global_code; function_code_t global_code;
named_item_t *named_item;
WCHAR *source; WCHAR *source;
UINT64 source_context; UINT64 source_context;
...@@ -197,7 +198,7 @@ struct _bytecode_t { ...@@ -197,7 +198,7 @@ struct _bytecode_t {
struct list entry; struct list entry;
}; };
HRESULT compile_script(script_ctx_t*,const WCHAR*,UINT64,unsigned,const WCHAR*,const WCHAR*,BOOL,BOOL,bytecode_t**) DECLSPEC_HIDDEN; HRESULT compile_script(script_ctx_t*,const WCHAR*,UINT64,unsigned,const WCHAR*,const WCHAR*,BOOL,BOOL,named_item_t*,bytecode_t**) DECLSPEC_HIDDEN;
void release_bytecode(bytecode_t*) DECLSPEC_HIDDEN; void release_bytecode(bytecode_t*) DECLSPEC_HIDDEN;
static inline bytecode_t *bytecode_addref(bytecode_t *code) static inline bytecode_t *bytecode_addref(bytecode_t *code)
......
...@@ -982,7 +982,8 @@ static HRESULT construct_function(script_ctx_t *ctx, unsigned argc, jsval_t *arg ...@@ -982,7 +982,8 @@ static HRESULT construct_function(script_ctx_t *ctx, unsigned argc, jsval_t *arg
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
hres = compile_script(ctx, str, 0, 0, NULL, NULL, FALSE, FALSE, &code); hres = compile_script(ctx, str, 0, 0, NULL, NULL, FALSE, FALSE,
ctx->call_ctx ? ctx->call_ctx->bytecode->named_item : NULL, &code);
heap_free(str); heap_free(str);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
......
...@@ -204,7 +204,7 @@ HRESULT JSGlobal_eval(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned a ...@@ -204,7 +204,7 @@ HRESULT JSGlobal_eval(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned a
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
TRACE("parsing %s\n", debugstr_jsval(argv[0])); TRACE("parsing %s\n", debugstr_jsval(argv[0]));
hres = compile_script(ctx, src, 0, 0, NULL, NULL, TRUE, FALSE, &code); hres = compile_script(ctx, src, 0, 0, NULL, NULL, TRUE, FALSE, frame ? frame->bytecode->named_item : NULL, &code);
if(FAILED(hres)) { if(FAILED(hres)) {
WARN("parse (%s) failed: %08x\n", debugstr_jsval(argv[0]), hres); WARN("parse (%s) failed: %08x\n", debugstr_jsval(argv[0]), hres);
return hres; return hres;
......
...@@ -983,6 +983,7 @@ static HRESULT WINAPI JScriptParse_ParseScriptText(IActiveScriptParse *iface, ...@@ -983,6 +983,7 @@ static HRESULT WINAPI JScriptParse_ParseScriptText(IActiveScriptParse *iface,
DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo) DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo)
{ {
JScript *This = impl_from_IActiveScriptParse(iface); JScript *This = impl_from_IActiveScriptParse(iface);
named_item_t *item = NULL;
bytecode_t *code; bytecode_t *code;
jsexcept_t ei; jsexcept_t ei;
HRESULT hres; HRESULT hres;
...@@ -994,9 +995,17 @@ static HRESULT WINAPI JScriptParse_ParseScriptText(IActiveScriptParse *iface, ...@@ -994,9 +995,17 @@ static HRESULT WINAPI JScriptParse_ParseScriptText(IActiveScriptParse *iface,
if(This->thread_id != GetCurrentThreadId() || This->ctx->state == SCRIPTSTATE_CLOSED) if(This->thread_id != GetCurrentThreadId() || This->ctx->state == SCRIPTSTATE_CLOSED)
return E_UNEXPECTED; return E_UNEXPECTED;
if(pstrItemName) {
item = lookup_named_item(This->ctx, pstrItemName, 0);
if(!item) {
WARN("Unknown context %s\n", debugstr_w(pstrItemName));
return E_INVALIDARG;
}
}
enter_script(This->ctx, &ei); enter_script(This->ctx, &ei);
hres = compile_script(This->ctx, pstrCode, dwSourceContextCookie, ulStartingLine, NULL, pstrDelimiter, hres = compile_script(This->ctx, pstrCode, dwSourceContextCookie, ulStartingLine, NULL, pstrDelimiter,
(dwFlags & SCRIPTTEXT_ISEXPRESSION) != 0, This->is_encode, &code); (dwFlags & SCRIPTTEXT_ISEXPRESSION) != 0, This->is_encode, item, &code);
if(FAILED(hres)) if(FAILED(hres))
return leave_script(This->ctx, hres); return leave_script(This->ctx, hres);
...@@ -1075,6 +1084,7 @@ static HRESULT WINAPI JScriptParseProcedure_ParseProcedureText(IActiveScriptPars ...@@ -1075,6 +1084,7 @@ static HRESULT WINAPI JScriptParseProcedure_ParseProcedureText(IActiveScriptPars
CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags, IDispatch **ppdisp) CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags, IDispatch **ppdisp)
{ {
JScript *This = impl_from_IActiveScriptParseProcedure2(iface); JScript *This = impl_from_IActiveScriptParseProcedure2(iface);
named_item_t *item = NULL;
bytecode_t *code; bytecode_t *code;
jsdisp_t *dispex; jsdisp_t *dispex;
jsexcept_t ei; jsexcept_t ei;
...@@ -1087,9 +1097,17 @@ static HRESULT WINAPI JScriptParseProcedure_ParseProcedureText(IActiveScriptPars ...@@ -1087,9 +1097,17 @@ static HRESULT WINAPI JScriptParseProcedure_ParseProcedureText(IActiveScriptPars
if(This->thread_id != GetCurrentThreadId() || This->ctx->state == SCRIPTSTATE_CLOSED) if(This->thread_id != GetCurrentThreadId() || This->ctx->state == SCRIPTSTATE_CLOSED)
return E_UNEXPECTED; return E_UNEXPECTED;
if(pstrItemName) {
item = lookup_named_item(This->ctx, pstrItemName, 0);
if(!item) {
WARN("Unknown context %s\n", debugstr_w(pstrItemName));
return E_INVALIDARG;
}
}
enter_script(This->ctx, &ei); enter_script(This->ctx, &ei);
hres = compile_script(This->ctx, pstrCode, dwSourceContextCookie, ulStartingLineNumber, pstrFormalParams, hres = compile_script(This->ctx, pstrCode, dwSourceContextCookie, ulStartingLineNumber, pstrFormalParams,
pstrDelimiter, FALSE, This->is_encode, &code); pstrDelimiter, FALSE, This->is_encode, item, &code);
if(SUCCEEDED(hres)) if(SUCCEEDED(hres))
hres = create_source_function(This->ctx, code, &code->global_code, NULL, &dispex); hres = create_source_function(This->ctx, code, &code->global_code, NULL, &dispex);
release_bytecode(code); release_bytecode(code);
......
...@@ -1267,6 +1267,9 @@ static void test_named_items(void) ...@@ -1267,6 +1267,9 @@ static void test_named_items(void)
parse_script(parse, L"visibleItem.testCall();"); parse_script(parse, L"visibleItem.testCall();");
CHECK_CALLED(testCall); CHECK_CALLED(testCall);
hr = IActiveScriptParse_ParseScriptText(parse, L"function testFunc() { }", L"CodeOnlyItem", NULL, NULL, 0, 0, 0, NULL, NULL);
ok(hr == E_INVALIDARG, "ParseScriptText returned: %08x\n", hr);
SET_EXPECT(OnEnterScript); SET_EXPECT(OnEnterScript);
SET_EXPECT(GetIDsOfNames); SET_EXPECT(GetIDsOfNames);
SET_EXPECT(OnLeaveScript); SET_EXPECT(OnLeaveScript);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment