Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/jscript/compile.c | 10 +++++++++- dlls/jscript/engine.h | 3 ++- dlls/jscript/function.c | 3 ++- dlls/jscript/global.c | 2 +- dlls/jscript/jscript.c | 22 ++++++++++++++++++++-- dlls/jscript/tests/jscript.c | 3 +++ 6 files changed, 37 insertions(+), 6 deletions(-)
diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c index 61db10c..5ac93c9 100644 --- a/dlls/jscript/compile.c +++ b/dlls/jscript/compile.c @@ -2250,6 +2250,8 @@ void release_bytecode(bytecode_t *code) for(i=0; i < code->str_cnt; i++) jsstr_release(code->str_pool[i]);
+ if(code->named_item) + release_named_item(code->named_item); heap_free(code->source); heap_pool_free(&code->heap); heap_free(code->bstr_pool); @@ -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, - 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}; HRESULT hres; @@ -2526,6 +2529,11 @@ HRESULT compile_script(script_ctx_t *ctx, const WCHAR *code, UINT64 source_conte return DISP_E_EXCEPTION; }
+ if(named_item) { + compiler.code->named_item = named_item; + named_item->ref++; + } + *ret = compiler.code; return S_OK; } diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h index 7be98c5..fe6b2a0 100644 --- a/dlls/jscript/engine.h +++ b/dlls/jscript/engine.h @@ -181,6 +181,7 @@ struct _bytecode_t { heap_pool_t heap;
function_code_t global_code; + named_item_t *named_item;
WCHAR *source; UINT64 source_context; @@ -197,7 +198,7 @@ struct _bytecode_t { 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;
static inline bytecode_t *bytecode_addref(bytecode_t *code) diff --git a/dlls/jscript/function.c b/dlls/jscript/function.c index ef0de96..007aec0 100644 --- a/dlls/jscript/function.c +++ b/dlls/jscript/function.c @@ -982,7 +982,8 @@ static HRESULT construct_function(script_ctx_t *ctx, unsigned argc, jsval_t *arg if(FAILED(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); if(FAILED(hres)) return hres; diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c index e2758bf..2a1dcb2 100644 --- a/dlls/jscript/global.c +++ b/dlls/jscript/global.c @@ -204,7 +204,7 @@ HRESULT JSGlobal_eval(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned a return E_OUTOFMEMORY;
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)) { WARN("parse (%s) failed: %08x\n", debugstr_jsval(argv[0]), hres); return hres; diff --git a/dlls/jscript/jscript.c b/dlls/jscript/jscript.c index 36d9f84..694ea8b 100644 --- a/dlls/jscript/jscript.c +++ b/dlls/jscript/jscript.c @@ -983,6 +983,7 @@ static HRESULT WINAPI JScriptParse_ParseScriptText(IActiveScriptParse *iface, DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo) { JScript *This = impl_from_IActiveScriptParse(iface); + named_item_t *item = NULL; bytecode_t *code; jsexcept_t ei; HRESULT hres; @@ -994,9 +995,17 @@ static HRESULT WINAPI JScriptParse_ParseScriptText(IActiveScriptParse *iface, if(This->thread_id != GetCurrentThreadId() || This->ctx->state == SCRIPTSTATE_CLOSED) 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); 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)) return leave_script(This->ctx, hres);
@@ -1075,6 +1084,7 @@ static HRESULT WINAPI JScriptParseProcedure_ParseProcedureText(IActiveScriptPars CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags, IDispatch **ppdisp) { JScript *This = impl_from_IActiveScriptParseProcedure2(iface); + named_item_t *item = NULL; bytecode_t *code; jsdisp_t *dispex; jsexcept_t ei; @@ -1087,9 +1097,17 @@ static HRESULT WINAPI JScriptParseProcedure_ParseProcedureText(IActiveScriptPars if(This->thread_id != GetCurrentThreadId() || This->ctx->state == SCRIPTSTATE_CLOSED) 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); 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)) hres = create_source_function(This->ctx, code, &code->global_code, NULL, &dispex); release_bytecode(code); diff --git a/dlls/jscript/tests/jscript.c b/dlls/jscript/tests/jscript.c index 8d4f6e1..56b8cff 100644 --- a/dlls/jscript/tests/jscript.c +++ b/dlls/jscript/tests/jscript.c @@ -1267,6 +1267,9 @@ static void test_named_items(void) parse_script(parse, L"visibleItem.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(GetIDsOfNames); SET_EXPECT(OnLeaveScript);