Module: wine Branch: master Commit: fc5a8836e9e41c97536c372bf4c5c945701f21be URL: http://source.winehq.org/git/wine.git/?a=commit;h=fc5a8836e9e41c97536c372bf4...
Author: Jacek Caban jacek@codeweavers.com Date: Tue Sep 9 01:24:22 2008 +0200
jscript: Added scope chain implementation.
---
dlls/jscript/engine.c | 33 +++++++++++++++++++++++++++++++-- dlls/jscript/engine.h | 17 ++++++++++++++++- dlls/jscript/jscript.c | 2 +- 3 files changed, 48 insertions(+), 4 deletions(-)
diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c index 614c1a4..db13aef 100644 --- a/dlls/jscript/engine.c +++ b/dlls/jscript/engine.c @@ -96,7 +96,19 @@ static void exprval_set_idref(exprval_t *val, IDispatch *disp, DISPID id) IDispatch_AddRef(disp); }
-HRESULT create_exec_ctx(exec_ctx_t **ret) +void scope_release(scope_chain_t *scope) +{ + if(--scope->ref) + return; + + if(scope->next) + scope_release(scope->next); + + IDispatchEx_Release(_IDispatchEx_(scope->obj)); + heap_free(scope); +} + +HRESULT create_exec_ctx(scope_chain_t *scope, exec_ctx_t **ret) { exec_ctx_t *ctx;
@@ -104,6 +116,11 @@ HRESULT create_exec_ctx(exec_ctx_t **ret) if(!ctx) return E_OUTOFMEMORY;
+ if(scope) { + scope_addref(scope); + ctx->scope_chain = scope; + } + *ret = ctx; return S_OK; } @@ -113,6 +130,8 @@ void exec_release(exec_ctx_t *ctx) if(--ctx->ref) return;
+ if(ctx->scope_chain) + scope_release(ctx->scope_chain); heap_free(ctx); }
@@ -239,13 +258,23 @@ HRESULT exec_source(exec_ctx_t *ctx, parser_ctx_t *parser, source_elements_t *so /* ECMA-262 3rd Edition 10.1.4 */ static HRESULT identifier_eval(exec_ctx_t *ctx, BSTR identifier, DWORD flags, exprval_t *ret) { + scope_chain_t *scope; named_item_t *item; DISPID id = 0; HRESULT hres;
TRACE("%s\n", debugstr_w(identifier));
- /* FIXME: scope chain */ + for(scope = ctx->scope_chain; scope; scope = scope->next) { + hres = dispex_get_id(_IDispatchEx_(scope->obj), identifier, 0, &id); + if(SUCCEEDED(hres)) + break; + } + + if(scope) { + exprval_set_idref(ret, (IDispatch*)_IDispatchEx_(scope->obj), id); + return S_OK; + }
hres = dispex_get_id(_IDispatchEx_(ctx->parser->script->global), identifier, 0, &id); if(SUCCEEDED(hres)) { diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h index c8dcfba..964e2b7 100644 --- a/dlls/jscript/engine.h +++ b/dlls/jscript/engine.h @@ -56,10 +56,25 @@ static inline void *parser_alloc_tmp(parser_ctx_t *ctx, DWORD size) return jsheap_alloc(&ctx->tmp_heap, size); }
+typedef struct _scope_chain_t { + LONG ref; + DispatchEx *obj; + struct _scope_chain_t *next; +} scope_chain_t; + +HRESULT scope_push(scope_chain_t*,DispatchEx*,scope_chain_t**); +void scope_release(scope_chain_t*); + +static inline void scope_addref(scope_chain_t *scope) +{ + scope->ref++; +} + struct _exec_ctx_t { LONG ref;
parser_ctx_t *parser; + scope_chain_t *scope_chain; };
static inline void exec_addref(exec_ctx_t *ctx) @@ -68,7 +83,7 @@ static inline void exec_addref(exec_ctx_t *ctx) }
void exec_release(exec_ctx_t*); -HRESULT create_exec_ctx(exec_ctx_t**); +HRESULT create_exec_ctx(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 a9c0bb3..50ba18c 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(&exec_ctx); + hres = create_exec_ctx(NULL, &exec_ctx); if(FAILED(hres)) return hres;