From 0bd508db2f7e05d0317d3ab0e8eeb81219aa5572 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Wed, 10 Sep 2008 21:05:14 +0200 Subject: [PATCH] jscript: Added this expression implementation. --- dlls/jscript/engine.c | 16 +++++++++++++--- dlls/jscript/engine.h | 3 ++- dlls/jscript/jscript.c | 2 +- dlls/jscript/tests/lang.js | 1 + 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c index c15b05b1e3e..5119bb79782 100644 --- a/dlls/jscript/engine.c +++ b/dlls/jscript/engine.c @@ -132,7 +132,7 @@ void scope_release(scope_chain_t *scope) heap_free(scope); } -HRESULT create_exec_ctx(DispatchEx *var_disp, scope_chain_t *scope, exec_ctx_t **ret) +HRESULT create_exec_ctx(IDispatch *this_obj, DispatchEx *var_disp, scope_chain_t *scope, exec_ctx_t **ret) { exec_ctx_t *ctx; @@ -140,6 +140,9 @@ HRESULT create_exec_ctx(DispatchEx *var_disp, scope_chain_t *scope, exec_ctx_t * if(!ctx) return E_OUTOFMEMORY; + IDispatch_AddRef(this_obj); + ctx->this_obj = this_obj; + IDispatchEx_AddRef(_IDispatchEx_(var_disp)); ctx->var_disp = var_disp; @@ -161,6 +164,8 @@ void exec_release(exec_ctx_t *ctx) scope_release(ctx->scope_chain); if(ctx->var_disp) IDispatchEx_Release(_IDispatchEx_(ctx->var_disp)); + if(ctx->this_obj) + IDispatch_Release(ctx->this_obj); heap_free(ctx); } @@ -816,8 +821,13 @@ HRESULT call_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, HRESULT this_expression_eval(exec_ctx_t *ctx, expression_t *expr, DWORD flags, jsexcept_t *ei, exprval_t *ret) { - FIXME("\n"); - return E_NOTIMPL; + TRACE("\n"); + + ret->type = EXPRVAL_VARIANT; + V_VT(&ret->u.var) = VT_DISPATCH; + V_DISPATCH(&ret->u.var) = ctx->this_obj; + IDispatch_AddRef(ctx->this_obj); + return S_OK; } /* ECMA-262 3rd Edition 10.1.4 */ diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h index c8f41b0105c..57a68c2812b 100644 --- a/dlls/jscript/engine.h +++ b/dlls/jscript/engine.h @@ -76,6 +76,7 @@ struct _exec_ctx_t { parser_ctx_t *parser; scope_chain_t *scope_chain; DispatchEx *var_disp; + IDispatch *this_obj; }; static inline void exec_addref(exec_ctx_t *ctx) @@ -84,7 +85,7 @@ static inline void exec_addref(exec_ctx_t *ctx) } void exec_release(exec_ctx_t*); -HRESULT create_exec_ctx(DispatchEx*,scope_chain_t*,exec_ctx_t**); +HRESULT create_exec_ctx(IDispatch*,DispatchEx*,scope_chain_t*,exec_ctx_t**); HRESULT exec_source(exec_ctx_t*,parser_ctx_t*,source_elements_t*,jsexcept_t*,VARIANT*); typedef struct _statement_t statement_t; diff --git a/dlls/jscript/jscript.c b/dlls/jscript/jscript.c index a104aa9aadf..5646cb8cf7d 100644 --- a/dlls/jscript/jscript.c +++ b/dlls/jscript/jscript.c @@ -80,7 +80,7 @@ static HRESULT exec_global_code(JScript *This, parser_ctx_t *parser_ctx) VARIANT var; HRESULT hres; - hres = create_exec_ctx(This->ctx->script_disp, NULL, &exec_ctx); + hres = create_exec_ctx((IDispatch*)_IDispatchEx_(This->ctx->script_disp), This->ctx->script_disp, NULL, &exec_ctx); if(FAILED(hres)) return hres; diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js index 088468aa16f..4c26c2fd30e 100644 --- a/dlls/jscript/tests/lang.js +++ b/dlls/jscript/tests/lang.js @@ -68,5 +68,6 @@ ok(typeof(String.prototype) === "object", "typeof(String.prototype) is not objec ok(typeof(testFunc1) === "function", "typeof(testFunc1) is not function"); ok(typeof(String) === "function", "typeof(String) is not function"); ok(typeof(ScriptEngine) === "function", "typeof(ScriptEngine) is not function"); +ok(typeof(this) === "object", "typeof(this) is not object"); reportSuccess();