Commit fc5a8836 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Added scope chain implementation.

parent 86a787bb
......@@ -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)) {
......
......@@ -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;
......
......@@ -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;
......
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