2008-09-03 00:25:21 +02:00
|
|
|
/*
|
2011-12-30 11:20:43 +01:00
|
|
|
* Copyright 2008,2011 Jacek Caban for CodeWeavers
|
2008-09-03 00:25:21 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2008-10-16 21:31:30 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2008-10-09 01:09:17 +02:00
|
|
|
#include <math.h>
|
2011-11-18 14:09:44 +01:00
|
|
|
#include <assert.h>
|
2008-10-09 01:09:17 +02:00
|
|
|
|
2008-09-03 00:25:21 +02:00
|
|
|
#include "jscript.h"
|
|
|
|
#include "engine.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(jscript);
|
|
|
|
|
2011-12-13 11:57:11 +01:00
|
|
|
static const WCHAR booleanW[] = {'b','o','o','l','e','a','n',0};
|
|
|
|
static const WCHAR functionW[] = {'f','u','n','c','t','i','o','n',0};
|
|
|
|
static const WCHAR numberW[] = {'n','u','m','b','e','r',0};
|
|
|
|
static const WCHAR objectW[] = {'o','b','j','e','c','t',0};
|
|
|
|
static const WCHAR stringW[] = {'s','t','r','i','n','g',0};
|
|
|
|
static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
|
|
|
|
static const WCHAR unknownW[] = {'u','n','k','n','o','w','n',0};
|
|
|
|
|
2011-12-28 12:06:28 +01:00
|
|
|
struct _except_frame_t {
|
|
|
|
unsigned stack_top;
|
|
|
|
scope_chain_t *scope;
|
|
|
|
unsigned catch_off;
|
|
|
|
BSTR ident;
|
|
|
|
|
|
|
|
except_frame_t *next;
|
|
|
|
};
|
|
|
|
|
2011-11-18 14:09:44 +01:00
|
|
|
static HRESULT stack_push(exec_ctx_t *ctx, VARIANT *v)
|
|
|
|
{
|
|
|
|
if(!ctx->stack_size) {
|
|
|
|
ctx->stack = heap_alloc(16*sizeof(VARIANT));
|
|
|
|
if(!ctx->stack)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
ctx->stack_size = 16;
|
|
|
|
}else if(ctx->stack_size == ctx->top) {
|
|
|
|
VARIANT *new_stack;
|
|
|
|
|
|
|
|
new_stack = heap_realloc(ctx->stack, ctx->stack_size*2*sizeof(VARIANT));
|
|
|
|
if(!new_stack) {
|
|
|
|
VariantClear(v);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->stack = new_stack;
|
|
|
|
ctx->stack_size *= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->stack[ctx->top++] = *v;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT stack_push_bool(exec_ctx_t *ctx, BOOL b)
|
|
|
|
{
|
|
|
|
VARIANT v;
|
|
|
|
|
|
|
|
V_VT(&v) = VT_BOOL;
|
|
|
|
V_BOOL(&v) = b ? VARIANT_TRUE : VARIANT_FALSE;
|
|
|
|
return stack_push(ctx, &v);
|
|
|
|
}
|
|
|
|
|
2011-11-25 12:06:05 +01:00
|
|
|
static inline HRESULT stack_push_number(exec_ctx_t *ctx, double number)
|
|
|
|
{
|
|
|
|
VARIANT v;
|
|
|
|
|
|
|
|
num_set_val(&v, number);
|
|
|
|
return stack_push(ctx, &v);
|
|
|
|
}
|
|
|
|
|
2011-11-29 11:09:35 +01:00
|
|
|
static inline HRESULT stack_push_int(exec_ctx_t *ctx, INT n)
|
|
|
|
{
|
|
|
|
VARIANT v;
|
|
|
|
|
|
|
|
V_VT(&v) = VT_I4;
|
|
|
|
V_I4(&v) = n;
|
|
|
|
return stack_push(ctx, &v);
|
|
|
|
}
|
|
|
|
|
2011-12-13 11:57:11 +01:00
|
|
|
static inline HRESULT stack_push_string(exec_ctx_t *ctx, const WCHAR *str)
|
|
|
|
{
|
|
|
|
VARIANT v;
|
|
|
|
|
|
|
|
V_VT(&v) = VT_BSTR;
|
|
|
|
V_BSTR(&v) = SysAllocString(str);
|
|
|
|
return V_BSTR(&v) ? stack_push(ctx, &v) : E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2011-12-05 11:11:29 +01:00
|
|
|
static HRESULT stack_push_objid(exec_ctx_t *ctx, IDispatch *disp, DISPID id)
|
|
|
|
{
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
V_VT(&v) = VT_DISPATCH;
|
|
|
|
V_DISPATCH(&v) = disp;
|
|
|
|
hres = stack_push(ctx, &v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
V_VT(&v) = VT_INT;
|
|
|
|
V_INT(&v) = id;
|
|
|
|
return stack_push(ctx, &v);
|
|
|
|
}
|
|
|
|
|
2011-11-28 12:03:57 +01:00
|
|
|
static inline VARIANT *stack_top(exec_ctx_t *ctx)
|
|
|
|
{
|
2011-11-28 12:05:07 +01:00
|
|
|
assert(ctx->top);
|
2011-11-28 12:03:57 +01:00
|
|
|
return ctx->stack + ctx->top-1;
|
|
|
|
}
|
|
|
|
|
2011-11-28 12:05:07 +01:00
|
|
|
static inline VARIANT *stack_topn(exec_ctx_t *ctx, unsigned n)
|
|
|
|
{
|
|
|
|
assert(ctx->top > n);
|
|
|
|
return ctx->stack + ctx->top-1-n;
|
|
|
|
}
|
|
|
|
|
2011-11-18 14:09:44 +01:00
|
|
|
static inline VARIANT *stack_pop(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
assert(ctx->top);
|
|
|
|
return ctx->stack + --ctx->top;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stack_popn(exec_ctx_t *ctx, unsigned n)
|
|
|
|
{
|
|
|
|
while(n--)
|
|
|
|
VariantClear(stack_pop(ctx));
|
|
|
|
}
|
|
|
|
|
2012-03-27 11:30:03 +02:00
|
|
|
static HRESULT stack_pop_number(exec_ctx_t *ctx, double *r)
|
2011-11-25 12:06:05 +01:00
|
|
|
{
|
|
|
|
VARIANT *v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
v = stack_pop(ctx);
|
2012-03-27 11:30:03 +02:00
|
|
|
hres = to_number(ctx->script, v, ctx->ei, r);
|
2011-11-25 12:06:05 +01:00
|
|
|
VariantClear(v);
|
2012-03-27 11:30:03 +02:00
|
|
|
return hres;
|
2011-11-25 12:06:05 +01:00
|
|
|
}
|
|
|
|
|
2011-12-06 10:42:09 +01:00
|
|
|
static HRESULT stack_pop_object(exec_ctx_t *ctx, IDispatch **r)
|
|
|
|
{
|
|
|
|
VARIANT *v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
v = stack_pop(ctx);
|
|
|
|
if(V_VT(v) == VT_DISPATCH) {
|
2011-12-12 14:44:09 +01:00
|
|
|
if(!V_DISPATCH(v))
|
2012-03-12 19:23:56 +01:00
|
|
|
return throw_type_error(ctx->script, ctx->ei, JS_E_OBJECT_REQUIRED, NULL);
|
2011-12-06 10:42:09 +01:00
|
|
|
*r = V_DISPATCH(v);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = to_object(ctx->script, v, r);
|
2011-12-06 10:42:09 +01:00
|
|
|
VariantClear(v);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2011-11-29 11:09:35 +01:00
|
|
|
static inline HRESULT stack_pop_int(exec_ctx_t *ctx, INT *r)
|
|
|
|
{
|
2012-03-12 19:23:56 +01:00
|
|
|
return to_int32(ctx->script, stack_pop(ctx), ctx->ei, r);
|
2011-11-29 11:09:35 +01:00
|
|
|
}
|
|
|
|
|
2011-12-08 12:03:22 +01:00
|
|
|
static inline HRESULT stack_pop_uint(exec_ctx_t *ctx, DWORD *r)
|
|
|
|
{
|
2012-03-12 19:23:56 +01:00
|
|
|
return to_uint32(ctx->script, stack_pop(ctx), ctx->ei, r);
|
2011-12-08 12:03:22 +01:00
|
|
|
}
|
|
|
|
|
2011-12-05 11:11:29 +01:00
|
|
|
static inline IDispatch *stack_pop_objid(exec_ctx_t *ctx, DISPID *id)
|
|
|
|
{
|
|
|
|
assert(V_VT(stack_top(ctx)) == VT_INT && V_VT(stack_topn(ctx, 1)) == VT_DISPATCH);
|
|
|
|
|
|
|
|
*id = V_INT(stack_pop(ctx));
|
|
|
|
return V_DISPATCH(stack_pop(ctx));
|
|
|
|
}
|
|
|
|
|
2011-12-07 11:00:20 +01:00
|
|
|
static inline IDispatch *stack_topn_objid(exec_ctx_t *ctx, unsigned n, DISPID *id)
|
2011-12-05 11:13:02 +01:00
|
|
|
{
|
2011-12-07 11:00:20 +01:00
|
|
|
assert(V_VT(stack_topn(ctx, n)) == VT_INT && V_VT(stack_topn(ctx, n+1)) == VT_DISPATCH);
|
2011-12-05 11:13:02 +01:00
|
|
|
|
2011-12-07 11:00:20 +01:00
|
|
|
*id = V_INT(stack_topn(ctx, n));
|
|
|
|
return V_DISPATCH(stack_topn(ctx, n+1));
|
2011-12-05 11:13:02 +01:00
|
|
|
}
|
|
|
|
|
2008-09-09 01:21:55 +02:00
|
|
|
static void exprval_release(exprval_t *val)
|
|
|
|
{
|
|
|
|
switch(val->type) {
|
|
|
|
case EXPRVAL_VARIANT:
|
2008-09-17 23:29:58 +02:00
|
|
|
if(V_VT(&val->u.var) != VT_EMPTY)
|
|
|
|
VariantClear(&val->u.var);
|
2008-09-09 01:21:55 +02:00
|
|
|
return;
|
|
|
|
case EXPRVAL_IDREF:
|
|
|
|
if(val->u.idref.disp)
|
|
|
|
IDispatch_Release(val->u.idref.disp);
|
|
|
|
return;
|
2009-08-27 01:21:38 +02:00
|
|
|
case EXPRVAL_INVALID:
|
2011-12-20 11:47:02 +01:00
|
|
|
return;
|
2008-09-09 01:21:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 8.7.1 */
|
|
|
|
static HRESULT exprval_value(script_ctx_t *ctx, exprval_t *val, jsexcept_t *ei, VARIANT *ret)
|
|
|
|
{
|
|
|
|
V_VT(ret) = VT_EMPTY;
|
|
|
|
|
|
|
|
switch(val->type) {
|
|
|
|
case EXPRVAL_VARIANT:
|
|
|
|
return VariantCopy(ret, &val->u.var);
|
|
|
|
case EXPRVAL_IDREF:
|
|
|
|
if(!val->u.idref.disp) {
|
|
|
|
FIXME("throw ReferenceError\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2012-03-08 14:28:48 +01:00
|
|
|
return disp_propget(ctx, val->u.idref.disp, val->u.idref.id, ret, ei);
|
2009-08-27 01:21:38 +02:00
|
|
|
case EXPRVAL_INVALID:
|
2011-12-20 11:47:02 +01:00
|
|
|
assert(0);
|
2008-09-09 01:21:55 +02:00
|
|
|
}
|
2009-08-27 01:21:38 +02:00
|
|
|
|
|
|
|
ERR("type %d\n", val->type);
|
|
|
|
return E_FAIL;
|
2008-09-09 01:21:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT exprval_to_value(script_ctx_t *ctx, exprval_t *val, jsexcept_t *ei, VARIANT *ret)
|
|
|
|
{
|
|
|
|
if(val->type == EXPRVAL_VARIANT) {
|
|
|
|
*ret = val->u.var;
|
|
|
|
V_VT(&val->u.var) = VT_EMPTY;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return exprval_value(ctx, val, ei, ret);
|
|
|
|
}
|
|
|
|
|
2008-09-09 01:22:13 +02:00
|
|
|
static void exprval_set_idref(exprval_t *val, IDispatch *disp, DISPID id)
|
|
|
|
{
|
|
|
|
val->type = EXPRVAL_IDREF;
|
|
|
|
val->u.idref.disp = disp;
|
|
|
|
val->u.idref.id = id;
|
|
|
|
|
|
|
|
if(disp)
|
|
|
|
IDispatch_AddRef(disp);
|
|
|
|
}
|
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
HRESULT scope_push(scope_chain_t *scope, jsdisp_t *obj, scope_chain_t **ret)
|
2008-09-10 21:06:09 +02:00
|
|
|
{
|
|
|
|
scope_chain_t *new_scope;
|
|
|
|
|
|
|
|
new_scope = heap_alloc(sizeof(scope_chain_t));
|
|
|
|
if(!new_scope)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
new_scope->ref = 1;
|
|
|
|
|
2010-09-07 15:42:34 +02:00
|
|
|
jsdisp_addref(obj);
|
2008-09-10 21:06:09 +02:00
|
|
|
new_scope->obj = obj;
|
|
|
|
|
|
|
|
if(scope) {
|
|
|
|
scope_addref(scope);
|
|
|
|
new_scope->next = scope;
|
|
|
|
}else {
|
|
|
|
new_scope->next = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret = new_scope;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-09-16 20:44:54 +02:00
|
|
|
static void scope_pop(scope_chain_t **scope)
|
|
|
|
{
|
|
|
|
scope_chain_t *tmp;
|
|
|
|
|
|
|
|
tmp = *scope;
|
|
|
|
*scope = tmp->next;
|
|
|
|
scope_release(tmp);
|
|
|
|
}
|
|
|
|
|
2008-09-09 01:24:22 +02:00
|
|
|
void scope_release(scope_chain_t *scope)
|
|
|
|
{
|
|
|
|
if(--scope->ref)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(scope->next)
|
|
|
|
scope_release(scope->next);
|
|
|
|
|
2009-09-01 13:26:08 +02:00
|
|
|
jsdisp_release(scope->obj);
|
2008-09-09 01:24:22 +02:00
|
|
|
heap_free(scope);
|
|
|
|
}
|
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
HRESULT create_exec_ctx(script_ctx_t *script_ctx, IDispatch *this_obj, jsdisp_t *var_disp,
|
2010-10-14 15:21:13 +02:00
|
|
|
scope_chain_t *scope, BOOL is_global, exec_ctx_t **ret)
|
2008-09-05 02:37:59 +02:00
|
|
|
{
|
|
|
|
exec_ctx_t *ctx;
|
|
|
|
|
|
|
|
ctx = heap_alloc_zero(sizeof(exec_ctx_t));
|
|
|
|
if(!ctx)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2009-07-16 01:17:00 +02:00
|
|
|
ctx->ref = 1;
|
2010-10-14 15:21:13 +02:00
|
|
|
ctx->is_global = is_global;
|
2009-07-16 01:17:00 +02:00
|
|
|
|
2009-09-27 20:59:28 +02:00
|
|
|
if(this_obj)
|
|
|
|
ctx->this_obj = this_obj;
|
|
|
|
else if(script_ctx->host_global)
|
|
|
|
ctx->this_obj = script_ctx->host_global;
|
|
|
|
else
|
2010-09-07 15:42:01 +02:00
|
|
|
ctx->this_obj = to_disp(script_ctx->global);
|
2009-09-27 20:59:28 +02:00
|
|
|
IDispatch_AddRef(ctx->this_obj);
|
2008-09-10 21:05:14 +02:00
|
|
|
|
2010-09-07 15:42:34 +02:00
|
|
|
jsdisp_addref(var_disp);
|
2008-09-09 01:24:49 +02:00
|
|
|
ctx->var_disp = var_disp;
|
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
script_addref(script_ctx);
|
|
|
|
ctx->script = script_ctx;
|
|
|
|
|
2008-09-09 01:24:22 +02:00
|
|
|
if(scope) {
|
|
|
|
scope_addref(scope);
|
|
|
|
ctx->scope_chain = scope;
|
|
|
|
}
|
|
|
|
|
2008-09-05 02:37:59 +02:00
|
|
|
*ret = ctx;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void exec_release(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
if(--ctx->ref)
|
|
|
|
return;
|
|
|
|
|
2008-09-09 01:24:22 +02:00
|
|
|
if(ctx->scope_chain)
|
|
|
|
scope_release(ctx->scope_chain);
|
2008-09-09 01:24:49 +02:00
|
|
|
if(ctx->var_disp)
|
2009-09-01 13:26:08 +02:00
|
|
|
jsdisp_release(ctx->var_disp);
|
2008-09-10 21:05:14 +02:00
|
|
|
if(ctx->this_obj)
|
|
|
|
IDispatch_Release(ctx->this_obj);
|
2012-03-12 19:23:56 +01:00
|
|
|
if(ctx->script)
|
|
|
|
script_release(ctx->script);
|
2011-11-18 14:09:44 +01:00
|
|
|
heap_free(ctx->stack);
|
2008-09-05 02:37:59 +02:00
|
|
|
heap_free(ctx);
|
|
|
|
}
|
|
|
|
|
2009-10-19 20:40:17 +02:00
|
|
|
static HRESULT disp_get_id(script_ctx_t *ctx, IDispatch *disp, BSTR name, DWORD flags, DISPID *id)
|
2008-09-09 01:22:31 +02:00
|
|
|
{
|
|
|
|
IDispatchEx *dispex;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
|
|
|
|
if(FAILED(hres)) {
|
2012-04-17 22:09:00 +02:00
|
|
|
TRACE("using IDispatch\n");
|
2008-09-09 01:22:31 +02:00
|
|
|
|
|
|
|
*id = 0;
|
|
|
|
return IDispatch_GetIDsOfNames(disp, &IID_NULL, &name, 1, 0, id);
|
|
|
|
}
|
|
|
|
|
2008-09-30 17:47:24 +02:00
|
|
|
*id = 0;
|
2009-10-19 20:40:17 +02:00
|
|
|
hres = IDispatchEx_GetDispID(dispex, name, make_grfdex(ctx, flags|fdexNameCaseSensitive), id);
|
2008-09-09 01:22:31 +02:00
|
|
|
IDispatchEx_Release(dispex);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2009-09-11 18:47:14 +02:00
|
|
|
static inline BOOL is_null(const VARIANT *v)
|
|
|
|
{
|
|
|
|
return V_VT(v) == VT_NULL || (V_VT(v) == VT_DISPATCH && !V_DISPATCH(v));
|
|
|
|
}
|
|
|
|
|
2008-09-09 01:26:20 +02:00
|
|
|
static HRESULT disp_cmp(IDispatch *disp1, IDispatch *disp2, BOOL *ret)
|
|
|
|
{
|
|
|
|
IObjectIdentity *identity;
|
|
|
|
IUnknown *unk1, *unk2;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if(disp1 == disp2) {
|
|
|
|
*ret = TRUE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-09-17 01:06:13 +02:00
|
|
|
if(!disp1 || !disp2) {
|
|
|
|
*ret = FALSE;
|
2009-09-11 18:47:14 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-09-09 01:26:20 +02:00
|
|
|
hres = IDispatch_QueryInterface(disp1, &IID_IUnknown, (void**)&unk1);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = IDispatch_QueryInterface(disp2, &IID_IUnknown, (void**)&unk2);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
IUnknown_Release(unk1);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(unk1 == unk2) {
|
|
|
|
*ret = TRUE;
|
|
|
|
}else {
|
|
|
|
hres = IUnknown_QueryInterface(unk1, &IID_IObjectIdentity, (void**)&identity);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = IObjectIdentity_IsEqualObject(identity, unk2);
|
|
|
|
IObjectIdentity_Release(identity);
|
|
|
|
*ret = hres == S_OK;
|
|
|
|
}else {
|
|
|
|
*ret = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_Release(unk1);
|
|
|
|
IUnknown_Release(unk2);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.9.6 */
|
2008-12-02 15:26:49 +01:00
|
|
|
static HRESULT equal2_values(VARIANT *lval, VARIANT *rval, BOOL *ret)
|
2008-09-09 01:26:20 +02:00
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
if(V_VT(lval) != V_VT(rval)) {
|
2009-09-11 18:47:14 +02:00
|
|
|
if(is_num_vt(V_VT(lval)) && is_num_vt(V_VT(rval)))
|
2008-09-09 01:26:20 +02:00
|
|
|
*ret = num_val(lval) == num_val(rval);
|
2009-09-11 18:47:14 +02:00
|
|
|
else if(is_null(lval))
|
|
|
|
*ret = is_null(rval);
|
|
|
|
else
|
|
|
|
*ret = FALSE;
|
2008-09-09 01:26:20 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(V_VT(lval)) {
|
|
|
|
case VT_EMPTY:
|
|
|
|
case VT_NULL:
|
|
|
|
*ret = VARIANT_TRUE;
|
|
|
|
break;
|
|
|
|
case VT_I4:
|
|
|
|
*ret = V_I4(lval) == V_I4(rval);
|
|
|
|
break;
|
|
|
|
case VT_R8:
|
|
|
|
*ret = V_R8(lval) == V_R8(rval);
|
|
|
|
break;
|
|
|
|
case VT_BSTR:
|
2009-08-05 23:27:31 +02:00
|
|
|
if(!V_BSTR(lval))
|
|
|
|
*ret = SysStringLen(V_BSTR(rval))?FALSE:TRUE;
|
|
|
|
else if(!V_BSTR(rval))
|
|
|
|
*ret = SysStringLen(V_BSTR(lval))?FALSE:TRUE;
|
|
|
|
else
|
|
|
|
*ret = !strcmpW(V_BSTR(lval), V_BSTR(rval));
|
2008-09-09 01:26:20 +02:00
|
|
|
break;
|
|
|
|
case VT_DISPATCH:
|
|
|
|
return disp_cmp(V_DISPATCH(lval), V_DISPATCH(rval), ret);
|
|
|
|
case VT_BOOL:
|
|
|
|
*ret = !V_BOOL(lval) == !V_BOOL(rval);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("unimplemented vt %d\n", V_VT(lval));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-10 12:57:23 +02:00
|
|
|
static BOOL lookup_global_members(script_ctx_t *ctx, BSTR identifier, exprval_t *ret)
|
|
|
|
{
|
|
|
|
named_item_t *item;
|
|
|
|
DISPID id;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
for(item = ctx->named_items; item; item = item->next) {
|
|
|
|
if(item->flags & SCRIPTITEM_GLOBALMEMBERS) {
|
2009-10-19 20:40:17 +02:00
|
|
|
hres = disp_get_id(ctx, item->disp, identifier, 0, &id);
|
2009-08-10 12:57:23 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
if(ret)
|
|
|
|
exprval_set_idref(ret, item->disp, id);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 01:22:13 +02:00
|
|
|
/* ECMA-262 3rd Edition 10.1.4 */
|
2012-01-18 13:28:29 +01:00
|
|
|
static HRESULT identifier_eval(script_ctx_t *ctx, BSTR identifier, exprval_t *ret)
|
2008-09-09 01:22:13 +02:00
|
|
|
{
|
2008-09-09 01:24:22 +02:00
|
|
|
scope_chain_t *scope;
|
2008-09-09 01:22:31 +02:00
|
|
|
named_item_t *item;
|
2008-09-09 01:22:13 +02:00
|
|
|
DISPID id = 0;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(identifier));
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
for(scope = ctx->exec_ctx->scope_chain; scope; scope = scope->next) {
|
2008-09-30 17:47:24 +02:00
|
|
|
hres = jsdisp_get_id(scope->obj, identifier, 0, &id);
|
2010-10-23 16:41:55 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
exprval_set_idref(ret, to_disp(scope->obj), id);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2008-09-09 01:24:22 +02:00
|
|
|
}
|
2008-09-09 01:22:54 +02:00
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = jsdisp_get_id(ctx->global, identifier, 0, &id);
|
2008-09-09 01:22:54 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
2010-10-23 16:41:55 +02:00
|
|
|
exprval_set_idref(ret, to_disp(ctx->global), id);
|
2008-09-09 01:22:54 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
2008-09-09 01:22:31 +02:00
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
for(item = ctx->named_items; item; item = item->next) {
|
2008-11-05 01:03:38 +01:00
|
|
|
if((item->flags & SCRIPTITEM_ISVISIBLE) && !strcmpW(item->name, identifier)) {
|
2008-12-15 22:24:33 +01:00
|
|
|
if(!item->disp) {
|
|
|
|
IUnknown *unk;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
if(!ctx->site)
|
2008-12-15 22:24:33 +01:00
|
|
|
break;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = IActiveScriptSite_GetItemInfo(ctx->site, identifier,
|
2008-12-15 22:24:33 +01:00
|
|
|
SCRIPTINFO_IUNKNOWN, &unk, NULL);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
WARN("GetItemInfo failed: %08x\n", hres);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&item->disp);
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
WARN("object does not implement IDispatch\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-05 01:03:38 +01:00
|
|
|
ret->type = EXPRVAL_VARIANT;
|
|
|
|
V_VT(&ret->u.var) = VT_DISPATCH;
|
|
|
|
V_DISPATCH(&ret->u.var) = item->disp;
|
|
|
|
IDispatch_AddRef(item->disp);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
if(lookup_global_members(ctx, identifier, ret))
|
2009-08-10 12:57:23 +02:00
|
|
|
return S_OK;
|
|
|
|
|
2009-08-27 01:21:38 +02:00
|
|
|
ret->type = EXPRVAL_INVALID;
|
|
|
|
return S_OK;
|
2008-09-09 01:22:13 +02:00
|
|
|
}
|
|
|
|
|
2008-09-09 01:25:59 +02:00
|
|
|
/* ECMA-262 3rd Edition 12.2 */
|
2011-12-20 11:45:37 +01:00
|
|
|
static HRESULT interp_var_set(exec_ctx_t *ctx)
|
2008-09-09 01:25:59 +02:00
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const BSTR name = ctx->code->instrs[ctx->ip].arg1.bstr;
|
2011-12-20 11:45:37 +01:00
|
|
|
VARIANT *v;
|
2008-09-09 01:25:59 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2011-12-20 11:45:37 +01:00
|
|
|
TRACE("%s\n", debugstr_w(name));
|
2008-09-09 01:25:59 +02:00
|
|
|
|
2011-12-20 11:45:37 +01:00
|
|
|
v = stack_pop(ctx);
|
2012-03-12 12:14:10 +01:00
|
|
|
hres = jsdisp_propput_name(ctx->var_disp, name, v, ctx->ei);
|
2011-12-20 11:45:37 +01:00
|
|
|
VariantClear(v);
|
|
|
|
return hres;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2011-12-28 12:05:53 +01:00
|
|
|
/* ECMA-262 3rd Edition 12.6.4 */
|
|
|
|
static HRESULT interp_forin(exec_ctx_t *ctx)
|
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const HRESULT arg = ctx->code->instrs[ctx->ip].arg1.uint;
|
2011-12-28 12:05:53 +01:00
|
|
|
IDispatch *var_obj, *obj = NULL;
|
|
|
|
IDispatchEx *dispex;
|
|
|
|
DISPID id, var_id;
|
|
|
|
BSTR name = NULL;
|
|
|
|
VARIANT *val;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
val = stack_pop(ctx);
|
|
|
|
|
|
|
|
assert(V_VT(stack_top(ctx)) == VT_I4);
|
|
|
|
id = V_I4(stack_top(ctx));
|
|
|
|
|
|
|
|
var_obj = stack_topn_objid(ctx, 1, &var_id);
|
|
|
|
if(!var_obj) {
|
|
|
|
FIXME("invalid ref\n");
|
|
|
|
VariantClear(val);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(V_VT(stack_topn(ctx, 3)) == VT_DISPATCH)
|
|
|
|
obj = V_DISPATCH(stack_topn(ctx, 3));
|
|
|
|
|
|
|
|
if(obj) {
|
|
|
|
hres = IDispatch_QueryInterface(obj, &IID_IDispatchEx, (void**)&dispex);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, id, &id);
|
|
|
|
if(hres == S_OK)
|
|
|
|
hres = IDispatchEx_GetMemberName(dispex, id, &name);
|
|
|
|
IDispatchEx_Release(dispex);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
VariantClear(val);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
TRACE("No IDispatchEx\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(name) {
|
|
|
|
VARIANT v;
|
|
|
|
|
|
|
|
VariantClear(val);
|
|
|
|
|
|
|
|
V_I4(stack_top(ctx)) = id;
|
|
|
|
|
|
|
|
V_VT(&v) = VT_BSTR;
|
|
|
|
V_BSTR(&v) = name;
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = disp_propput(ctx->script, var_obj, var_id, &v, ctx->ei);
|
2011-12-28 12:05:53 +01:00
|
|
|
SysFreeString(name);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
ctx->ip++;
|
|
|
|
}else {
|
|
|
|
stack_popn(ctx, 4);
|
|
|
|
ctx->ip = arg;
|
|
|
|
return stack_push(ctx, val);
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-12-27 11:16:26 +01:00
|
|
|
/* ECMA-262 3rd Edition 12.10 */
|
2012-01-09 09:33:13 +01:00
|
|
|
static HRESULT interp_push_scope(exec_ctx_t *ctx)
|
2011-12-27 11:16:26 +01:00
|
|
|
{
|
|
|
|
IDispatch *disp;
|
|
|
|
jsdisp_t *obj;
|
|
|
|
VARIANT *v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
v = stack_pop(ctx);
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = to_object(ctx->script, v, &disp);
|
2011-12-27 11:16:26 +01:00
|
|
|
VariantClear(v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
obj = to_jsdisp(disp);
|
|
|
|
if(!obj) {
|
|
|
|
IDispatch_Release(disp);
|
|
|
|
FIXME("disp is not jsdisp\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = scope_push(ctx->scope_chain, obj, &ctx->scope_chain);
|
|
|
|
jsdisp_release(obj);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.10 */
|
2012-01-09 09:33:13 +01:00
|
|
|
static HRESULT interp_pop_scope(exec_ctx_t *ctx)
|
2011-12-27 11:16:26 +01:00
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
scope_pop(&ctx->scope_chain);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-12-27 11:16:40 +01:00
|
|
|
/* ECMA-262 3rd Edition 12.13 */
|
|
|
|
static HRESULT interp_case(exec_ctx_t *ctx)
|
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const unsigned arg = ctx->code->instrs[ctx->ip].arg1.uint;
|
2011-12-27 11:16:40 +01:00
|
|
|
VARIANT *v;
|
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
v = stack_pop(ctx);
|
|
|
|
hres = equal2_values(stack_top(ctx), v, &b);
|
|
|
|
VariantClear(v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(b) {
|
|
|
|
stack_popn(ctx, 1);
|
|
|
|
ctx->ip = arg;
|
|
|
|
}else {
|
|
|
|
ctx->ip++;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-09-17 23:30:20 +02:00
|
|
|
/* ECMA-262 3rd Edition 12.13 */
|
2011-12-28 12:06:17 +01:00
|
|
|
static HRESULT interp_throw(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-16 20:45:13 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2011-12-30 11:21:05 +01:00
|
|
|
ctx->ei->var = *stack_pop(ctx);
|
2008-09-16 20:45:13 +02:00
|
|
|
return DISP_E_EXCEPTION;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2011-12-28 12:06:03 +01:00
|
|
|
static HRESULT interp_throw_ref(exec_ctx_t *ctx)
|
2011-12-05 11:12:32 +01:00
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const HRESULT arg = ctx->code->instrs[ctx->ip].arg1.uint;
|
2011-12-05 11:12:32 +01:00
|
|
|
|
|
|
|
TRACE("%08x\n", arg);
|
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
return throw_reference_error(ctx->script, ctx->ei, arg, NULL);
|
2011-12-05 11:12:32 +01:00
|
|
|
}
|
|
|
|
|
2011-12-15 15:43:01 +01:00
|
|
|
static HRESULT interp_throw_type(exec_ctx_t *ctx)
|
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const HRESULT hres = ctx->code->instrs[ctx->ip].arg1.uint;
|
|
|
|
const WCHAR *str = ctx->code->instrs[ctx->ip].arg2.str;
|
2011-12-15 15:43:01 +01:00
|
|
|
|
|
|
|
TRACE("%08x %s\n", hres, debugstr_w(str));
|
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
return throw_type_error(ctx->script, ctx->ei, hres, str);
|
2011-12-15 15:43:01 +01:00
|
|
|
}
|
|
|
|
|
2011-12-28 12:06:28 +01:00
|
|
|
/* ECMA-262 3rd Edition 12.14 */
|
|
|
|
static HRESULT interp_push_except(exec_ctx_t *ctx)
|
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const unsigned arg1 = ctx->code->instrs[ctx->ip].arg1.uint;
|
|
|
|
const BSTR arg2 = ctx->code->instrs[ctx->ip].arg2.bstr;
|
2011-12-28 12:06:28 +01:00
|
|
|
except_frame_t *except;
|
|
|
|
unsigned stack_top;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
stack_top = ctx->top;
|
|
|
|
|
|
|
|
if(!arg2) {
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = stack_push_bool(ctx, TRUE);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2011-12-28 12:06:41 +01:00
|
|
|
hres = stack_push_bool(ctx, TRUE);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2011-12-28 12:06:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
except = heap_alloc(sizeof(*except));
|
|
|
|
if(!except)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
except->stack_top = stack_top;
|
|
|
|
except->scope = ctx->scope_chain;
|
|
|
|
except->catch_off = arg1;
|
|
|
|
except->ident = arg2;
|
|
|
|
except->next = ctx->except_frame;
|
|
|
|
ctx->except_frame = except;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.14 */
|
|
|
|
static HRESULT interp_pop_except(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
except_frame_t *except;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
except = ctx->except_frame;
|
|
|
|
assert(except != NULL);
|
|
|
|
|
|
|
|
ctx->except_frame = except->next;
|
|
|
|
heap_free(except);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.14 */
|
|
|
|
static HRESULT interp_end_finally(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
VARIANT *v;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
v = stack_pop(ctx);
|
|
|
|
|
|
|
|
assert(V_VT(stack_top(ctx)) == VT_BOOL);
|
|
|
|
if(!V_BOOL(stack_top(ctx))) {
|
|
|
|
TRACE("passing exception\n");
|
|
|
|
|
|
|
|
VariantClear(v);
|
|
|
|
stack_popn(ctx, 1);
|
2011-12-30 11:21:05 +01:00
|
|
|
ctx->ei->var = *stack_pop(ctx);
|
2011-12-28 12:06:28 +01:00
|
|
|
return DISP_E_EXCEPTION;
|
|
|
|
}
|
|
|
|
|
2011-12-28 12:06:41 +01:00
|
|
|
stack_popn(ctx, 2);
|
|
|
|
return stack_push(ctx, v);
|
2011-12-28 12:06:28 +01:00
|
|
|
}
|
|
|
|
|
2008-09-10 21:08:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 13 */
|
2011-12-16 11:42:57 +01:00
|
|
|
static HRESULT interp_func(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-04-24 17:39:09 +02:00
|
|
|
unsigned func_idx = ctx->code->instrs[ctx->ip].arg1.uint;
|
2011-12-16 11:42:57 +01:00
|
|
|
jsdisp_t *dispex;
|
|
|
|
VARIANT v;
|
2008-09-10 21:08:46 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2012-04-24 17:39:09 +02:00
|
|
|
TRACE("%d\n", func_idx);
|
|
|
|
|
2012-04-25 11:25:57 +02:00
|
|
|
hres = create_source_function(ctx->script, ctx->code, ctx->func_code->funcs+func_idx,
|
2012-04-24 17:39:40 +02:00
|
|
|
ctx->scope_chain, &dispex);
|
2011-12-16 11:42:57 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2008-09-10 21:08:46 +02:00
|
|
|
|
2011-12-16 11:42:57 +01:00
|
|
|
var_set_jsdisp(&v, dispex);
|
|
|
|
return stack_push(ctx, &v);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2011-12-07 11:01:13 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.2.1 */
|
|
|
|
static HRESULT interp_array(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
VARIANT v, *namev;
|
|
|
|
IDispatch *obj;
|
|
|
|
DISPID id;
|
|
|
|
BSTR name;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
namev = stack_pop(ctx);
|
|
|
|
|
|
|
|
hres = stack_pop_object(ctx, &obj);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
VariantClear(namev);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = to_string(ctx->script, namev, ctx->ei, &name);
|
2011-12-09 11:04:14 +01:00
|
|
|
VariantClear(namev);
|
2011-12-07 11:01:13 +01:00
|
|
|
if(FAILED(hres)) {
|
|
|
|
IDispatch_Release(obj);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = disp_get_id(ctx->script, obj, name, 0, &id);
|
2011-12-07 11:01:13 +01:00
|
|
|
SysFreeString(name);
|
|
|
|
if(SUCCEEDED(hres)) {
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = disp_propget(ctx->script, obj, id, &v, ctx->ei);
|
2011-12-07 11:01:13 +01:00
|
|
|
}else if(hres == DISP_E_UNKNOWNNAME) {
|
|
|
|
V_VT(&v) = VT_EMPTY;
|
|
|
|
hres = S_OK;
|
|
|
|
}
|
|
|
|
IDispatch_Release(obj);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push(ctx, &v);
|
|
|
|
}
|
|
|
|
|
2011-12-06 10:42:09 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.2.1 */
|
|
|
|
static HRESULT interp_member(exec_ctx_t *ctx)
|
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const BSTR arg = ctx->code->instrs[ctx->ip].arg1.bstr;
|
2011-12-06 10:42:09 +01:00
|
|
|
IDispatch *obj;
|
|
|
|
VARIANT v;
|
|
|
|
DISPID id;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = stack_pop_object(ctx, &obj);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = disp_get_id(ctx->script, obj, arg, 0, &id);
|
2011-12-06 10:42:09 +01:00
|
|
|
if(SUCCEEDED(hres)) {
|
2011-12-12 14:44:20 +01:00
|
|
|
V_VT(&v) = VT_EMPTY;
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = disp_propget(ctx->script, obj, id, &v, ctx->ei);
|
2011-12-06 10:42:09 +01:00
|
|
|
}else if(hres == DISP_E_UNKNOWNNAME) {
|
|
|
|
V_VT(&v) = VT_EMPTY;
|
|
|
|
hres = S_OK;
|
|
|
|
}
|
|
|
|
IDispatch_Release(obj);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push(ctx, &v);
|
|
|
|
}
|
|
|
|
|
2011-12-05 11:11:45 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.2.1 */
|
|
|
|
static HRESULT interp_memberid(exec_ctx_t *ctx)
|
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const unsigned arg = ctx->code->instrs[ctx->ip].arg1.lng;
|
2011-12-05 11:11:45 +01:00
|
|
|
VARIANT *objv, *namev;
|
|
|
|
IDispatch *obj;
|
|
|
|
BSTR name;
|
|
|
|
DISPID id;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-12-07 11:00:20 +01:00
|
|
|
TRACE("%x\n", arg);
|
2011-12-05 11:11:45 +01:00
|
|
|
|
|
|
|
namev = stack_pop(ctx);
|
|
|
|
objv = stack_pop(ctx);
|
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = to_object(ctx->script, objv, &obj);
|
2011-12-05 11:11:45 +01:00
|
|
|
VariantClear(objv);
|
|
|
|
if(SUCCEEDED(hres)) {
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = to_string(ctx->script, namev, ctx->ei, &name);
|
2011-12-05 11:11:45 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
IDispatch_Release(obj);
|
|
|
|
}
|
|
|
|
VariantClear(namev);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = disp_get_id(ctx->script, obj, name, arg, &id);
|
2011-12-05 11:11:45 +01:00
|
|
|
SysFreeString(name);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
IDispatch_Release(obj);
|
2011-12-07 11:00:20 +01:00
|
|
|
if(hres == DISP_E_UNKNOWNNAME && !(arg & fdexNameEnsure)) {
|
|
|
|
obj = NULL;
|
|
|
|
id = JS_E_INVALID_PROPERTY;
|
|
|
|
}else {
|
|
|
|
return hres;
|
|
|
|
}
|
2011-12-05 11:11:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return stack_push_objid(ctx, obj, id);
|
|
|
|
}
|
|
|
|
|
2011-12-05 11:13:02 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.2.1 */
|
|
|
|
static HRESULT interp_refval(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
IDispatch *disp;
|
|
|
|
VARIANT v;
|
|
|
|
DISPID id;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-12-07 11:00:20 +01:00
|
|
|
disp = stack_topn_objid(ctx, 0, &id);
|
2011-12-05 11:13:02 +01:00
|
|
|
if(!disp)
|
2012-03-12 19:23:56 +01:00
|
|
|
return throw_reference_error(ctx->script, ctx->ei, JS_E_ILLEGAL_ASSIGN, NULL);
|
2011-12-05 11:13:02 +01:00
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = disp_propget(ctx->script, disp, id, &v, ctx->ei);
|
2011-12-05 11:13:02 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push(ctx, &v);
|
|
|
|
}
|
|
|
|
|
2011-11-28 12:05:07 +01:00
|
|
|
static void jsstack_to_dp(exec_ctx_t *ctx, unsigned arg_cnt, DISPPARAMS *dp)
|
|
|
|
{
|
|
|
|
VARIANT tmp;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
dp->cArgs = arg_cnt;
|
|
|
|
dp->rgdispidNamedArgs = NULL;
|
|
|
|
dp->cNamedArgs = 0;
|
|
|
|
|
|
|
|
assert(ctx->top >= arg_cnt);
|
|
|
|
|
|
|
|
for(i=1; i*2 <= arg_cnt; i++) {
|
|
|
|
tmp = ctx->stack[ctx->top-i];
|
|
|
|
ctx->stack[ctx->top-i] = ctx->stack[ctx->top-arg_cnt+i-1];
|
|
|
|
ctx->stack[ctx->top-arg_cnt+i-1] = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
dp->rgvarg = ctx->stack + ctx->top-arg_cnt;
|
|
|
|
}
|
|
|
|
|
2008-09-10 21:07:35 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.2.2 */
|
2011-11-30 10:14:04 +01:00
|
|
|
static HRESULT interp_new(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const LONG arg = ctx->code->instrs[ctx->ip].arg1.lng;
|
2011-11-28 12:05:07 +01:00
|
|
|
VARIANT *constr, v;
|
2008-09-10 21:07:35 +02:00
|
|
|
DISPPARAMS dp;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-11-28 12:05:07 +01:00
|
|
|
TRACE("%d\n", arg);
|
2008-09-10 21:07:35 +02:00
|
|
|
|
2011-11-28 12:05:07 +01:00
|
|
|
constr = stack_topn(ctx, arg);
|
2008-09-10 21:07:35 +02:00
|
|
|
|
2010-10-01 20:19:29 +02:00
|
|
|
/* NOTE: Should use to_object here */
|
|
|
|
|
2011-11-28 12:05:07 +01:00
|
|
|
if(V_VT(constr) == VT_NULL)
|
2012-03-12 19:23:56 +01:00
|
|
|
return throw_type_error(ctx->script, ctx->ei, JS_E_OBJECT_EXPECTED, NULL);
|
2011-11-28 12:05:07 +01:00
|
|
|
else if(V_VT(constr) != VT_DISPATCH)
|
2012-03-12 19:23:56 +01:00
|
|
|
return throw_type_error(ctx->script, ctx->ei, JS_E_INVALID_ACTION, NULL);
|
2011-11-28 12:05:07 +01:00
|
|
|
else if(!V_DISPATCH(constr))
|
2012-03-12 19:23:56 +01:00
|
|
|
return throw_type_error(ctx->script, ctx->ei, JS_E_INVALID_PROPERTY, NULL);
|
2008-09-10 21:07:35 +02:00
|
|
|
|
2011-11-28 12:05:07 +01:00
|
|
|
jsstack_to_dp(ctx, arg, &dp);
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = disp_call(ctx->script, V_DISPATCH(constr), DISPID_VALUE,
|
2012-03-08 14:28:33 +01:00
|
|
|
DISPATCH_CONSTRUCT, &dp, &v, ctx->ei);
|
2008-09-10 21:07:35 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-11-28 12:05:07 +01:00
|
|
|
stack_popn(ctx, arg+1);
|
|
|
|
return stack_push(ctx, &v);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:45:50 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.2.3 */
|
2011-12-07 11:00:44 +01:00
|
|
|
static HRESULT interp_call(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const unsigned argn = ctx->code->instrs[ctx->ip].arg1.uint;
|
|
|
|
const int do_ret = ctx->code->instrs[ctx->ip].arg2.lng;
|
2011-12-07 11:00:44 +01:00
|
|
|
VARIANT v, *objv;
|
2008-09-09 01:25:05 +02:00
|
|
|
DISPPARAMS dp;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-12-07 11:00:44 +01:00
|
|
|
TRACE("%d %d\n", argn, do_ret);
|
2008-09-09 01:25:05 +02:00
|
|
|
|
2011-12-07 11:00:44 +01:00
|
|
|
objv = stack_topn(ctx, argn);
|
|
|
|
if(V_VT(objv) != VT_DISPATCH)
|
2012-03-12 19:23:56 +01:00
|
|
|
return throw_type_error(ctx->script, ctx->ei, JS_E_INVALID_PROPERTY, NULL);
|
2008-09-09 01:25:05 +02:00
|
|
|
|
2011-12-07 11:00:44 +01:00
|
|
|
jsstack_to_dp(ctx, argn, &dp);
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = disp_call(ctx->script, V_DISPATCH(objv), DISPID_VALUE, DISPATCH_METHOD, &dp,
|
2012-03-08 14:28:33 +01:00
|
|
|
do_ret ? &v : NULL, ctx->ei);
|
2008-09-09 01:25:05 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-12-07 11:00:44 +01:00
|
|
|
stack_popn(ctx, argn+1);
|
|
|
|
return do_ret ? stack_push(ctx, &v) : S_OK;
|
|
|
|
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2011-12-07 11:00:20 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.2.3 */
|
|
|
|
static HRESULT interp_call_member(exec_ctx_t *ctx)
|
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const unsigned argn = ctx->code->instrs[ctx->ip].arg1.uint;
|
|
|
|
const int do_ret = ctx->code->instrs[ctx->ip].arg2.lng;
|
2011-12-07 11:00:20 +01:00
|
|
|
IDispatch *obj;
|
|
|
|
DISPPARAMS dp;
|
|
|
|
VARIANT v;
|
|
|
|
DISPID id;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("%d %d\n", argn, do_ret);
|
|
|
|
|
|
|
|
obj = stack_topn_objid(ctx, argn, &id);
|
|
|
|
if(!obj)
|
2012-03-12 19:23:56 +01:00
|
|
|
return throw_type_error(ctx->script, ctx->ei, id, NULL);
|
2011-12-07 11:00:20 +01:00
|
|
|
|
|
|
|
jsstack_to_dp(ctx, argn, &dp);
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = disp_call(ctx->script, obj, id, DISPATCH_METHOD, &dp, do_ret ? &v : NULL, ctx->ei);
|
2011-12-07 11:00:20 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
stack_popn(ctx, argn+2);
|
|
|
|
return do_ret ? stack_push(ctx, &v) : S_OK;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-09-19 00:45:50 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.1.1 */
|
2011-11-30 10:14:04 +01:00
|
|
|
static HRESULT interp_this(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-11-24 14:24:14 +01:00
|
|
|
VARIANT v;
|
|
|
|
|
2008-09-10 21:05:14 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-24 14:24:14 +01:00
|
|
|
V_VT(&v) = VT_DISPATCH;
|
|
|
|
V_DISPATCH(&v) = ctx->this_obj;
|
|
|
|
IDispatch_AddRef(ctx->this_obj);
|
|
|
|
return stack_push(ctx, &v);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2011-11-28 12:08:54 +01:00
|
|
|
/* ECMA-262 3rd Edition 10.1.4 */
|
|
|
|
static HRESULT interp_ident(exec_ctx_t *ctx)
|
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const BSTR arg = ctx->code->instrs[ctx->ip].arg1.bstr;
|
2011-11-28 12:08:54 +01:00
|
|
|
exprval_t exprval;
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(arg));
|
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = identifier_eval(ctx->script, arg, &exprval);
|
2011-11-28 12:08:54 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-12-20 11:47:02 +01:00
|
|
|
if(exprval.type == EXPRVAL_INVALID)
|
2012-03-12 19:23:56 +01:00
|
|
|
return throw_type_error(ctx->script, ctx->ei, JS_E_UNDEFINED_VARIABLE, arg);
|
2011-12-20 11:47:02 +01:00
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = exprval_to_value(ctx->script, &exprval, ctx->ei, &v);
|
2011-11-28 12:08:54 +01:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push(ctx, &v);
|
|
|
|
}
|
|
|
|
|
2011-12-05 11:11:29 +01:00
|
|
|
/* ECMA-262 3rd Edition 10.1.4 */
|
|
|
|
static HRESULT interp_identid(exec_ctx_t *ctx)
|
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const BSTR arg = ctx->code->instrs[ctx->ip].arg1.bstr;
|
|
|
|
const unsigned flags = ctx->code->instrs[ctx->ip].arg2.uint;
|
2011-12-05 11:11:29 +01:00
|
|
|
exprval_t exprval;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-12-07 11:00:20 +01:00
|
|
|
TRACE("%s %x\n", debugstr_w(arg), flags);
|
2011-12-05 11:11:29 +01:00
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = identifier_eval(ctx->script, arg, &exprval);
|
2011-12-05 11:11:29 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-01-18 13:28:29 +01:00
|
|
|
if(exprval.type == EXPRVAL_INVALID && (flags & fdexNameEnsure)) {
|
|
|
|
DISPID id;
|
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = jsdisp_get_id(ctx->script->global, arg, fdexNameEnsure, &id);
|
2012-01-18 13:28:29 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
exprval_set_idref(&exprval, to_disp(ctx->script->global), id);
|
2012-01-18 13:28:29 +01:00
|
|
|
}
|
|
|
|
|
2011-12-05 11:11:29 +01:00
|
|
|
if(exprval.type != EXPRVAL_IDREF) {
|
|
|
|
WARN("invalid ref\n");
|
|
|
|
exprval_release(&exprval);
|
2011-12-07 11:00:20 +01:00
|
|
|
return stack_push_objid(ctx, NULL, JS_E_OBJECT_EXPECTED);
|
2011-12-05 11:11:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return stack_push_objid(ctx, exprval.u.idref.disp, exprval.u.idref.id);
|
|
|
|
}
|
|
|
|
|
2011-11-24 14:23:26 +01:00
|
|
|
/* ECMA-262 3rd Edition 7.8.1 */
|
2011-11-30 10:14:04 +01:00
|
|
|
static HRESULT interp_null(exec_ctx_t *ctx)
|
2011-11-24 14:23:26 +01:00
|
|
|
{
|
|
|
|
VARIANT v;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
V_VT(&v) = VT_NULL;
|
|
|
|
return stack_push(ctx, &v);
|
|
|
|
}
|
|
|
|
|
2011-11-23 12:13:57 +01:00
|
|
|
/* ECMA-262 3rd Edition 7.8.2 */
|
2011-11-30 10:14:04 +01:00
|
|
|
static HRESULT interp_bool(exec_ctx_t *ctx)
|
2011-11-23 12:13:57 +01:00
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const LONG arg = ctx->code->instrs[ctx->ip].arg1.lng;
|
2011-11-23 12:13:57 +01:00
|
|
|
|
|
|
|
TRACE("%s\n", arg ? "true" : "false");
|
|
|
|
|
|
|
|
return stack_push_bool(ctx, arg);
|
|
|
|
}
|
|
|
|
|
2011-11-23 12:13:46 +01:00
|
|
|
/* ECMA-262 3rd Edition 7.8.3 */
|
2011-11-30 10:14:04 +01:00
|
|
|
static HRESULT interp_int(exec_ctx_t *ctx)
|
2011-11-23 12:13:46 +01:00
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const LONG arg = ctx->code->instrs[ctx->ip].arg1.lng;
|
2011-11-23 12:13:46 +01:00
|
|
|
VARIANT v;
|
|
|
|
|
|
|
|
TRACE("%d\n", arg);
|
|
|
|
|
|
|
|
V_VT(&v) = VT_I4;
|
|
|
|
V_I4(&v) = arg;
|
|
|
|
return stack_push(ctx, &v);
|
|
|
|
}
|
|
|
|
|
2011-11-23 12:14:31 +01:00
|
|
|
/* ECMA-262 3rd Edition 7.8.3 */
|
2011-11-30 10:14:04 +01:00
|
|
|
static HRESULT interp_double(exec_ctx_t *ctx)
|
2011-11-23 12:14:31 +01:00
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const double arg = *ctx->code->instrs[ctx->ip].arg1.dbl;
|
2011-11-23 12:14:31 +01:00
|
|
|
VARIANT v;
|
|
|
|
|
|
|
|
TRACE("%lf\n", arg);
|
|
|
|
|
|
|
|
V_VT(&v) = VT_R8;
|
|
|
|
V_R8(&v) = arg;
|
|
|
|
return stack_push(ctx, &v);
|
|
|
|
}
|
|
|
|
|
2011-11-23 12:14:15 +01:00
|
|
|
/* ECMA-262 3rd Edition 7.8.4 */
|
2011-11-30 10:14:04 +01:00
|
|
|
static HRESULT interp_str(exec_ctx_t *ctx)
|
2011-11-23 12:14:15 +01:00
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const WCHAR *str = ctx->code->instrs[ctx->ip].arg1.str;
|
2011-11-23 12:14:15 +01:00
|
|
|
VARIANT v;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(str));
|
|
|
|
|
|
|
|
V_VT(&v) = VT_BSTR;
|
|
|
|
V_BSTR(&v) = SysAllocString(str);
|
|
|
|
if(!V_BSTR(&v))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
return stack_push(ctx, &v);
|
|
|
|
}
|
|
|
|
|
2011-11-24 14:23:39 +01:00
|
|
|
/* ECMA-262 3rd Edition 7.8 */
|
2011-11-30 10:14:04 +01:00
|
|
|
static HRESULT interp_regexp(exec_ctx_t *ctx)
|
2011-11-24 14:23:39 +01:00
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const WCHAR *source = ctx->code->instrs[ctx->ip].arg1.str;
|
|
|
|
const LONG flags = ctx->code->instrs[ctx->ip].arg2.lng;
|
2011-11-24 14:23:39 +01:00
|
|
|
jsdisp_t *regexp;
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("%s %x\n", debugstr_w(source), flags);
|
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = create_regexp(ctx->script, source, strlenW(source), flags, ®exp);
|
2011-11-24 14:23:39 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
var_set_jsdisp(&v, regexp);
|
|
|
|
return stack_push(ctx, &v);
|
|
|
|
}
|
|
|
|
|
2008-09-17 23:34:23 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.1.4 */
|
2011-12-08 12:02:40 +01:00
|
|
|
static HRESULT interp_carray(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const unsigned arg = ctx->code->instrs[ctx->ip].arg1.uint;
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *array;
|
2011-12-08 12:02:40 +01:00
|
|
|
VARIANT *v, r;
|
|
|
|
unsigned i;
|
2008-09-17 23:34:23 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2011-12-08 12:02:40 +01:00
|
|
|
TRACE("%u\n", arg);
|
2008-09-17 23:34:23 +02:00
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = create_array(ctx->script, arg, &array);
|
2008-09-17 23:34:23 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-12-08 12:02:40 +01:00
|
|
|
i = arg;
|
|
|
|
while(i--) {
|
|
|
|
v = stack_pop(ctx);
|
2012-03-12 12:14:25 +01:00
|
|
|
hres = jsdisp_propput_idx(array, i, v, ctx->ei);
|
2011-12-08 12:02:40 +01:00
|
|
|
VariantClear(v);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
jsdisp_release(array);
|
|
|
|
return hres;
|
|
|
|
}
|
2008-09-17 23:34:23 +02:00
|
|
|
}
|
|
|
|
|
2011-12-08 12:02:40 +01:00
|
|
|
var_set_jsdisp(&r, array);
|
|
|
|
return stack_push(ctx, &r);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-10 21:10:23 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.1.5 */
|
2012-01-09 09:33:13 +01:00
|
|
|
static HRESULT interp_new_obj(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *obj;
|
2011-12-16 11:43:31 +01:00
|
|
|
VARIANT v;
|
2008-09-10 21:10:23 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = create_object(ctx->script, NULL, &obj);
|
2008-09-10 21:10:23 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-12-16 11:43:31 +01:00
|
|
|
var_set_jsdisp(&v, obj);
|
|
|
|
return stack_push(ctx, &v);
|
|
|
|
}
|
2008-09-10 21:10:23 +02:00
|
|
|
|
2011-12-16 11:43:31 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.1.5 */
|
2012-01-09 09:33:13 +01:00
|
|
|
static HRESULT interp_obj_prop(exec_ctx_t *ctx)
|
2011-12-16 11:43:31 +01:00
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const BSTR name = ctx->code->instrs[ctx->ip].arg1.bstr;
|
2011-12-16 11:43:31 +01:00
|
|
|
jsdisp_t *obj;
|
|
|
|
VARIANT *v;
|
|
|
|
HRESULT hres;
|
2008-09-10 21:10:23 +02:00
|
|
|
|
2011-12-16 11:43:31 +01:00
|
|
|
TRACE("%s\n", debugstr_w(name));
|
2008-09-10 21:10:23 +02:00
|
|
|
|
2011-12-16 11:43:31 +01:00
|
|
|
v = stack_pop(ctx);
|
2008-09-10 21:10:23 +02:00
|
|
|
|
2011-12-16 11:43:31 +01:00
|
|
|
assert(V_VT(stack_top(ctx)) == VT_DISPATCH);
|
|
|
|
obj = as_jsdisp(V_DISPATCH(stack_top(ctx)));
|
2008-09-10 21:10:23 +02:00
|
|
|
|
2012-03-12 12:14:10 +01:00
|
|
|
hres = jsdisp_propput_name(obj, name, v, ctx->ei);
|
2011-12-16 11:43:31 +01:00
|
|
|
VariantClear(v);
|
|
|
|
return hres;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-11 23:55:14 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.11 */
|
2011-12-20 11:47:23 +01:00
|
|
|
static HRESULT interp_cnd_nz(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const unsigned arg = ctx->code->instrs[ctx->ip].arg1.uint;
|
2008-09-11 23:55:14 +02:00
|
|
|
VARIANT_BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-28 12:03:57 +01:00
|
|
|
hres = to_boolean(stack_top(ctx), &b);
|
2008-09-11 23:55:14 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-11-28 12:03:57 +01:00
|
|
|
if(b) {
|
|
|
|
ctx->ip = arg;
|
|
|
|
}else {
|
|
|
|
stack_popn(ctx, 1);
|
|
|
|
ctx->ip++;
|
2008-09-11 23:55:14 +02:00
|
|
|
}
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-11 23:55:38 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.11 */
|
2011-12-20 11:47:23 +01:00
|
|
|
static HRESULT interp_cnd_z(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const unsigned arg = ctx->code->instrs[ctx->ip].arg1.uint;
|
2008-09-11 23:55:38 +02:00
|
|
|
VARIANT_BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-28 12:04:33 +01:00
|
|
|
hres = to_boolean(stack_top(ctx), &b);
|
2008-09-11 23:55:38 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-11-28 12:04:33 +01:00
|
|
|
if(b) {
|
|
|
|
stack_popn(ctx, 1);
|
|
|
|
ctx->ip++;
|
|
|
|
}else {
|
|
|
|
ctx->ip = arg;
|
2008-09-11 23:55:38 +02:00
|
|
|
}
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:31:02 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.10 */
|
2011-11-29 11:09:35 +01:00
|
|
|
static HRESULT interp_or(exec_ctx_t *ctx)
|
2008-09-17 23:31:02 +02:00
|
|
|
{
|
2011-11-29 11:09:35 +01:00
|
|
|
INT l, r;
|
|
|
|
HRESULT hres;
|
2008-09-17 23:31:02 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-29 11:09:35 +01:00
|
|
|
hres = stack_pop_int(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_int(ctx, &l);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push_int(ctx, l|r);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:32:11 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.10 */
|
2011-11-29 11:09:49 +01:00
|
|
|
static HRESULT interp_xor(exec_ctx_t *ctx)
|
2008-09-17 23:32:11 +02:00
|
|
|
{
|
2011-11-29 11:09:49 +01:00
|
|
|
INT l, r;
|
|
|
|
HRESULT hres;
|
2008-09-17 23:32:11 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-29 11:09:49 +01:00
|
|
|
hres = stack_pop_int(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_int(ctx, &l);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push_int(ctx, l^r);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:31:38 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.10 */
|
2011-12-08 12:02:53 +01:00
|
|
|
static HRESULT interp_and(exec_ctx_t *ctx)
|
2008-09-17 23:31:38 +02:00
|
|
|
{
|
2011-12-08 12:02:53 +01:00
|
|
|
INT l, r;
|
|
|
|
HRESULT hres;
|
2008-09-17 23:31:38 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-12-08 12:02:53 +01:00
|
|
|
hres = stack_pop_int(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_int(ctx, &l);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push_int(ctx, l&r);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:45:50 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.8.6 */
|
2011-12-12 14:43:54 +01:00
|
|
|
static HRESULT interp_instanceof(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *obj, *iter, *tmp = NULL;
|
2011-12-12 14:43:54 +01:00
|
|
|
VARIANT prot, *v;
|
|
|
|
BOOL ret = FALSE;
|
2009-08-29 00:01:25 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
static const WCHAR prototypeW[] = {'p','r','o','t','o','t', 'y', 'p','e',0};
|
|
|
|
|
2011-12-12 14:43:54 +01:00
|
|
|
v = stack_pop(ctx);
|
|
|
|
if(V_VT(v) != VT_DISPATCH || !V_DISPATCH(v)) {
|
|
|
|
VariantClear(v);
|
2012-03-12 19:23:56 +01:00
|
|
|
return throw_type_error(ctx->script, ctx->ei, JS_E_FUNCTION_EXPECTED, NULL);
|
2011-12-12 14:43:54 +01:00
|
|
|
}
|
2009-08-29 00:01:25 +02:00
|
|
|
|
2011-12-12 14:43:54 +01:00
|
|
|
obj = iface_to_jsdisp((IUnknown*)V_DISPATCH(v));
|
|
|
|
IDispatch_Release(V_DISPATCH(v));
|
2009-08-29 00:01:25 +02:00
|
|
|
if(!obj) {
|
2011-06-21 17:46:04 +02:00
|
|
|
FIXME("non-jsdisp objects not supported\n");
|
2009-08-29 00:01:25 +02:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(is_class(obj, JSCLASS_FUNCTION)) {
|
2012-03-12 12:14:38 +01:00
|
|
|
hres = jsdisp_propget_name(obj, prototypeW, &prot, ctx->ei);
|
2009-08-29 00:01:25 +02:00
|
|
|
}else {
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = throw_type_error(ctx->script, ctx->ei, JS_E_FUNCTION_EXPECTED, NULL);
|
2009-08-29 00:01:25 +02:00
|
|
|
}
|
|
|
|
jsdisp_release(obj);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-12-12 14:43:54 +01:00
|
|
|
v = stack_pop(ctx);
|
|
|
|
|
|
|
|
if(V_VT(&prot) == VT_DISPATCH) {
|
|
|
|
if(V_VT(v) == VT_DISPATCH)
|
|
|
|
tmp = iface_to_jsdisp((IUnknown*)V_DISPATCH(v));
|
|
|
|
for(iter = tmp; !ret && iter; iter = iter->prototype) {
|
|
|
|
hres = disp_cmp(V_DISPATCH(&prot), to_disp(iter), &ret);
|
2009-08-29 00:01:25 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tmp)
|
|
|
|
jsdisp_release(tmp);
|
|
|
|
}else {
|
|
|
|
FIXME("prototype is not an object\n");
|
|
|
|
hres = E_FAIL;
|
|
|
|
}
|
|
|
|
|
2011-12-12 14:43:54 +01:00
|
|
|
VariantClear(&prot);
|
|
|
|
VariantClear(v);
|
2009-08-29 00:01:25 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-12-12 14:43:54 +01:00
|
|
|
return stack_push_bool(ctx, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:45:50 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.8.7 */
|
2011-11-30 10:14:04 +01:00
|
|
|
static HRESULT interp_in(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-11-23 12:13:35 +01:00
|
|
|
VARIANT *obj, *v;
|
|
|
|
DISPID id = 0;
|
|
|
|
BOOL ret;
|
2009-09-06 19:10:06 +02:00
|
|
|
BSTR str;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-11-23 12:13:35 +01:00
|
|
|
TRACE("\n");
|
2009-09-06 19:10:06 +02:00
|
|
|
|
2011-11-23 12:13:35 +01:00
|
|
|
obj = stack_pop(ctx);
|
|
|
|
v = stack_pop(ctx);
|
|
|
|
|
|
|
|
if(V_VT(obj) != VT_DISPATCH || !V_DISPATCH(obj)) {
|
|
|
|
VariantClear(obj);
|
|
|
|
VariantClear(v);
|
2012-03-12 19:23:56 +01:00
|
|
|
return throw_type_error(ctx->script, ctx->ei, JS_E_OBJECT_EXPECTED, NULL);
|
2011-11-23 12:13:35 +01:00
|
|
|
}
|
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = to_string(ctx->script, v, ctx->ei, &str);
|
2011-11-23 12:13:35 +01:00
|
|
|
VariantClear(v);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
IDispatch_Release(V_DISPATCH(obj));
|
2009-09-06 19:10:06 +02:00
|
|
|
return hres;
|
2011-11-23 12:13:35 +01:00
|
|
|
}
|
2009-09-06 19:10:06 +02:00
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = disp_get_id(ctx->script, V_DISPATCH(obj), str, 0, &id);
|
2011-11-23 12:13:35 +01:00
|
|
|
IDispatch_Release(V_DISPATCH(obj));
|
2009-09-06 19:10:06 +02:00
|
|
|
SysFreeString(str);
|
|
|
|
if(SUCCEEDED(hres))
|
2011-11-23 12:13:35 +01:00
|
|
|
ret = TRUE;
|
2009-09-06 19:10:06 +02:00
|
|
|
else if(hres == DISP_E_UNKNOWNNAME)
|
2011-11-23 12:13:35 +01:00
|
|
|
ret = FALSE;
|
2009-09-06 19:10:06 +02:00
|
|
|
else
|
|
|
|
return hres;
|
|
|
|
|
2011-11-23 12:13:35 +01:00
|
|
|
return stack_push_bool(ctx, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-10 21:12:45 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.6.1 */
|
2010-10-23 16:41:55 +02:00
|
|
|
static HRESULT add_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-10 21:12:45 +02:00
|
|
|
VARIANT r, l;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_primitive(ctx, lval, ei, &l, NO_HINT);
|
2008-09-10 21:12:45 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_primitive(ctx, rval, ei, &r, NO_HINT);
|
2008-09-10 21:12:45 +02:00
|
|
|
if(FAILED(hres)) {
|
|
|
|
VariantClear(&l);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(V_VT(&l) == VT_BSTR || V_VT(&r) == VT_BSTR) {
|
|
|
|
BSTR lstr = NULL, rstr = NULL;
|
|
|
|
|
|
|
|
if(V_VT(&l) == VT_BSTR)
|
|
|
|
lstr = V_BSTR(&l);
|
|
|
|
else
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_string(ctx, &l, ei, &lstr);
|
2008-09-10 21:12:45 +02:00
|
|
|
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
if(V_VT(&r) == VT_BSTR)
|
|
|
|
rstr = V_BSTR(&r);
|
|
|
|
else
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_string(ctx, &r, ei, &rstr);
|
2008-09-10 21:12:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
int len1, len2;
|
|
|
|
|
|
|
|
len1 = SysStringLen(lstr);
|
|
|
|
len2 = SysStringLen(rstr);
|
|
|
|
|
|
|
|
V_VT(retv) = VT_BSTR;
|
|
|
|
V_BSTR(retv) = SysAllocStringLen(NULL, len1+len2);
|
2012-03-08 14:28:02 +01:00
|
|
|
if(len1)
|
|
|
|
memcpy(V_BSTR(retv), lstr, len1*sizeof(WCHAR));
|
|
|
|
if(len2)
|
|
|
|
memcpy(V_BSTR(retv)+len1, rstr, len2*sizeof(WCHAR));
|
|
|
|
V_BSTR(retv)[len1+len2] = 0;
|
2008-09-10 21:12:45 +02:00
|
|
|
}
|
|
|
|
|
2008-09-24 23:04:20 +02:00
|
|
|
if(V_VT(&l) != VT_BSTR)
|
2008-09-10 21:12:45 +02:00
|
|
|
SysFreeString(lstr);
|
2008-09-24 23:04:20 +02:00
|
|
|
if(V_VT(&r) != VT_BSTR)
|
2008-09-10 21:12:45 +02:00
|
|
|
SysFreeString(rstr);
|
|
|
|
}else {
|
2012-03-27 11:28:51 +02:00
|
|
|
double nl, nr;
|
2008-09-10 21:12:45 +02:00
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_number(ctx, &l, ei, &nl);
|
2008-09-10 21:12:45 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_number(ctx, &r, ei, &nr);
|
2008-09-10 21:12:45 +02:00
|
|
|
if(SUCCEEDED(hres))
|
2012-03-27 11:28:51 +02:00
|
|
|
num_set_val(retv, nl + nr);
|
2008-09-10 21:12:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VariantClear(&r);
|
|
|
|
VariantClear(&l);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.6.1 */
|
2011-11-30 10:14:04 +01:00
|
|
|
static HRESULT interp_add(exec_ctx_t *ctx)
|
2008-09-10 21:12:45 +02:00
|
|
|
{
|
2011-11-22 16:31:44 +01:00
|
|
|
VARIANT *l, *r, ret;
|
|
|
|
HRESULT hres;
|
2008-09-10 21:12:45 +02:00
|
|
|
|
2011-11-22 16:31:44 +01:00
|
|
|
r = stack_pop(ctx);
|
|
|
|
l = stack_pop(ctx);
|
|
|
|
|
|
|
|
TRACE("%s + %s\n", debugstr_variant(l), debugstr_variant(r));
|
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = add_eval(ctx->script, l, r, ctx->ei, &ret);
|
2011-11-25 12:05:31 +01:00
|
|
|
VariantClear(l);
|
|
|
|
VariantClear(r);
|
2011-11-22 16:31:44 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2008-09-10 21:12:45 +02:00
|
|
|
|
2011-11-22 16:31:44 +01:00
|
|
|
return stack_push(ctx, &ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-16 20:46:01 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.6.2 */
|
2011-11-30 10:14:04 +01:00
|
|
|
static HRESULT interp_sub(exec_ctx_t *ctx)
|
2008-09-16 20:46:01 +02:00
|
|
|
{
|
2012-03-27 11:30:03 +02:00
|
|
|
double l, r;
|
2011-11-25 12:06:05 +01:00
|
|
|
HRESULT hres;
|
2008-09-16 20:46:01 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-25 12:06:05 +01:00
|
|
|
hres = stack_pop_number(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_number(ctx, &l);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-03-27 11:30:03 +02:00
|
|
|
return stack_push_number(ctx, l-r);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-16 20:46:33 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.5.1 */
|
2011-11-30 10:14:04 +01:00
|
|
|
static HRESULT interp_mul(exec_ctx_t *ctx)
|
2008-09-16 20:46:33 +02:00
|
|
|
{
|
2012-03-27 11:30:03 +02:00
|
|
|
double l, r;
|
2011-11-29 11:08:54 +01:00
|
|
|
HRESULT hres;
|
2008-09-16 20:46:33 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-29 11:08:54 +01:00
|
|
|
hres = stack_pop_number(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_number(ctx, &l);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-03-27 11:30:03 +02:00
|
|
|
return stack_push_number(ctx, l*r);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-16 20:47:06 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.5.2 */
|
2011-11-29 11:09:04 +01:00
|
|
|
static HRESULT interp_div(exec_ctx_t *ctx)
|
2008-09-16 20:47:06 +02:00
|
|
|
{
|
2012-03-27 11:30:03 +02:00
|
|
|
double l, r;
|
2011-11-29 11:09:04 +01:00
|
|
|
HRESULT hres;
|
2008-09-16 20:47:06 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-29 11:09:04 +01:00
|
|
|
hres = stack_pop_number(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_number(ctx, &l);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-03-27 11:30:03 +02:00
|
|
|
return stack_push_number(ctx, l/r);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-10-09 01:09:17 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.5.3 */
|
2011-11-29 11:09:20 +01:00
|
|
|
static HRESULT interp_mod(exec_ctx_t *ctx)
|
2008-10-09 01:09:17 +02:00
|
|
|
{
|
2012-03-27 11:30:03 +02:00
|
|
|
double l, r;
|
2011-11-29 11:09:20 +01:00
|
|
|
HRESULT hres;
|
2008-10-09 01:09:17 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-29 11:09:20 +01:00
|
|
|
hres = stack_pop_number(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_number(ctx, &l);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-03-27 11:30:03 +02:00
|
|
|
return stack_push_number(ctx, fmod(l, r));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2011-11-30 10:14:22 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.4.2 */
|
|
|
|
static HRESULT interp_delete(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
VARIANT *obj_var, *name_var;
|
|
|
|
IDispatchEx *dispex;
|
|
|
|
IDispatch *obj;
|
|
|
|
BSTR name;
|
|
|
|
BOOL ret;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
name_var = stack_pop(ctx);
|
|
|
|
obj_var = stack_pop(ctx);
|
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = to_object(ctx->script, obj_var, &obj);
|
2011-11-30 10:14:22 +01:00
|
|
|
VariantClear(obj_var);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
VariantClear(name_var);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = to_string(ctx->script, name_var, ctx->ei, &name);
|
2011-11-30 10:14:22 +01:00
|
|
|
VariantClear(name_var);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
IDispatch_Release(obj);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IDispatch_QueryInterface(obj, &IID_IDispatchEx, (void**)&dispex);
|
|
|
|
if(SUCCEEDED(hres)) {
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = IDispatchEx_DeleteMemberByName(dispex, name, make_grfdex(ctx->script, fdexNameCaseSensitive));
|
2011-11-30 10:14:22 +01:00
|
|
|
ret = TRUE;
|
|
|
|
IDispatchEx_Release(dispex);
|
|
|
|
}else {
|
|
|
|
hres = S_OK;
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDispatch_Release(obj);
|
|
|
|
SysFreeString(name);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push_bool(ctx, ret);
|
|
|
|
}
|
|
|
|
|
2011-12-15 15:42:27 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.4.2 */
|
|
|
|
static HRESULT interp_delete_ident(exec_ctx_t *ctx)
|
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const BSTR arg = ctx->code->instrs[ctx->ip].arg1.bstr;
|
2011-12-15 15:42:27 +01:00
|
|
|
IDispatchEx *dispex;
|
|
|
|
exprval_t exprval;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(arg));
|
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = identifier_eval(ctx->script, arg, &exprval);
|
2011-12-15 15:42:27 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(exprval.type != EXPRVAL_IDREF) {
|
|
|
|
FIXME("Unsupported exprval\n");
|
|
|
|
exprval_release(&exprval);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IDispatch_QueryInterface(exprval.u.idref.disp, &IID_IDispatchEx, (void**)&dispex);
|
|
|
|
IDispatch_Release(exprval.u.idref.disp);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = IDispatchEx_DeleteMemberByDispID(dispex, exprval.u.idref.id);
|
|
|
|
IDispatchEx_Release(dispex);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return stack_push_bool(ctx, ret);
|
|
|
|
}
|
|
|
|
|
2008-09-19 00:42:33 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.4.2 */
|
2011-11-30 10:14:04 +01:00
|
|
|
static HRESULT interp_void(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-11-24 14:24:45 +01:00
|
|
|
VARIANT v;
|
2008-09-19 00:42:33 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-24 14:24:45 +01:00
|
|
|
stack_popn(ctx, 1);
|
2008-09-19 00:42:33 +02:00
|
|
|
|
2011-11-24 14:24:45 +01:00
|
|
|
V_VT(&v) = VT_EMPTY;
|
|
|
|
return stack_push(ctx, &v);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:42:33 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.4.3 */
|
2011-12-13 11:57:11 +01:00
|
|
|
static HRESULT typeof_string(VARIANT *v, const WCHAR **ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-12-13 11:57:11 +01:00
|
|
|
switch(V_VT(v)) {
|
2008-09-10 02:36:03 +02:00
|
|
|
case VT_EMPTY:
|
2009-08-27 01:21:56 +02:00
|
|
|
*ret = undefinedW;
|
2008-09-10 02:36:03 +02:00
|
|
|
break;
|
|
|
|
case VT_NULL:
|
2009-08-27 01:21:56 +02:00
|
|
|
*ret = objectW;
|
2008-09-10 02:36:03 +02:00
|
|
|
break;
|
|
|
|
case VT_BOOL:
|
2009-08-27 01:21:56 +02:00
|
|
|
*ret = booleanW;
|
2008-09-10 02:36:03 +02:00
|
|
|
break;
|
|
|
|
case VT_I4:
|
|
|
|
case VT_R8:
|
2009-08-27 01:21:56 +02:00
|
|
|
*ret = numberW;
|
2008-09-10 02:36:03 +02:00
|
|
|
break;
|
|
|
|
case VT_BSTR:
|
2009-08-27 01:21:56 +02:00
|
|
|
*ret = stringW;
|
2008-09-10 02:36:03 +02:00
|
|
|
break;
|
|
|
|
case VT_DISPATCH: {
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *dispex;
|
2008-09-10 02:36:03 +02:00
|
|
|
|
2011-12-13 11:57:11 +01:00
|
|
|
if(V_DISPATCH(v) && (dispex = iface_to_jsdisp((IUnknown*)V_DISPATCH(v)))) {
|
2009-08-27 01:21:56 +02:00
|
|
|
*ret = is_class(dispex, JSCLASS_FUNCTION) ? functionW : objectW;
|
|
|
|
jsdisp_release(dispex);
|
2008-09-10 02:36:03 +02:00
|
|
|
}else {
|
2009-08-27 01:21:56 +02:00
|
|
|
*ret = objectW;
|
2008-09-10 02:36:03 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2011-12-13 11:57:11 +01:00
|
|
|
FIXME("unhandled vt %d\n", V_VT(v));
|
|
|
|
return E_NOTIMPL;
|
2008-09-10 02:36:03 +02:00
|
|
|
}
|
|
|
|
|
2011-12-13 11:57:11 +01:00
|
|
|
return S_OK;
|
2009-08-27 01:21:56 +02:00
|
|
|
}
|
|
|
|
|
2011-12-13 11:57:11 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.4.3 */
|
|
|
|
static HRESULT interp_typeofid(exec_ctx_t *ctx)
|
2009-08-27 01:21:56 +02:00
|
|
|
{
|
2011-12-13 11:57:11 +01:00
|
|
|
const WCHAR *ret;
|
|
|
|
IDispatch *obj;
|
|
|
|
VARIANT v;
|
|
|
|
DISPID id;
|
2009-08-27 01:21:56 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2011-12-13 11:57:11 +01:00
|
|
|
static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
|
|
|
|
|
2009-08-27 01:21:56 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2011-12-13 11:57:11 +01:00
|
|
|
obj = stack_pop_objid(ctx, &id);
|
|
|
|
if(!obj)
|
|
|
|
return stack_push_string(ctx, undefinedW);
|
|
|
|
|
|
|
|
V_VT(&v) = VT_EMPTY;
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = disp_propget(ctx->script, obj, id, &v, ctx->ei);
|
2011-12-13 11:57:11 +01:00
|
|
|
IDispatch_Release(obj);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return stack_push_string(ctx, unknownW);
|
|
|
|
|
|
|
|
hres = typeof_string(&v, &ret);
|
|
|
|
VariantClear(&v);
|
2009-08-27 01:21:56 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-12-13 11:57:11 +01:00
|
|
|
return stack_push_string(ctx, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.4.3 */
|
|
|
|
static HRESULT interp_typeofident(exec_ctx_t *ctx)
|
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const BSTR arg = ctx->code->instrs[ctx->ip].arg1.bstr;
|
2011-12-13 11:57:11 +01:00
|
|
|
exprval_t exprval;
|
|
|
|
const WCHAR *ret;
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(arg));
|
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = identifier_eval(ctx->script, arg, &exprval);
|
2011-12-13 11:57:11 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(exprval.type == EXPRVAL_INVALID) {
|
|
|
|
hres = stack_push_string(ctx, undefinedW);
|
|
|
|
exprval_release(&exprval);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = exprval_to_value(ctx->script, &exprval, ctx->ei, &v);
|
2009-08-27 01:21:56 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2008-09-10 02:36:03 +02:00
|
|
|
|
2011-12-13 11:57:11 +01:00
|
|
|
hres = typeof_string(&v, &ret);
|
|
|
|
VariantClear(&v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2009-08-27 01:21:56 +02:00
|
|
|
|
2011-12-13 11:57:11 +01:00
|
|
|
return stack_push_string(ctx, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.4.3 */
|
|
|
|
static HRESULT interp_typeof(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
const WCHAR *ret;
|
|
|
|
VARIANT *v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
v = stack_pop(ctx);
|
|
|
|
hres = typeof_string(v, &ret);
|
|
|
|
VariantClear(v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push_string(ctx, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-16 20:47:43 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.4.7 */
|
2011-11-30 10:14:04 +01:00
|
|
|
static HRESULT interp_minus(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-03-27 11:30:03 +02:00
|
|
|
double n;
|
2008-09-16 20:47:43 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-25 12:06:30 +01:00
|
|
|
hres = stack_pop_number(ctx, &n);
|
2008-09-16 20:47:43 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-03-27 11:30:03 +02:00
|
|
|
return stack_push_number(ctx, -n);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:33:15 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.4.6 */
|
2011-11-30 10:14:04 +01:00
|
|
|
static HRESULT interp_tonum(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-03-27 11:28:51 +02:00
|
|
|
VARIANT *v;
|
|
|
|
double n;
|
2008-09-17 23:33:15 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-21 15:35:41 +01:00
|
|
|
v = stack_pop(ctx);
|
2012-03-27 11:28:51 +02:00
|
|
|
hres = to_number(ctx->script, v, ctx->ei, &n);
|
2011-11-21 15:35:41 +01:00
|
|
|
VariantClear(v);
|
2008-09-17 23:33:15 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-03-27 11:28:51 +02:00
|
|
|
return stack_push_number(ctx, n);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-11 23:58:28 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.3.1 */
|
2011-12-07 11:01:53 +01:00
|
|
|
static HRESULT interp_postinc(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const int arg = ctx->code->instrs[ctx->ip].arg1.lng;
|
2011-12-07 11:01:53 +01:00
|
|
|
IDispatch *obj;
|
|
|
|
DISPID id;
|
|
|
|
VARIANT v;
|
2008-09-11 23:58:28 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2011-12-07 11:01:53 +01:00
|
|
|
TRACE("%d\n", arg);
|
2008-09-11 23:58:28 +02:00
|
|
|
|
2011-12-07 11:01:53 +01:00
|
|
|
obj = stack_pop_objid(ctx, &id);
|
|
|
|
if(!obj)
|
2012-03-12 19:23:56 +01:00
|
|
|
return throw_type_error(ctx->script, ctx->ei, JS_E_OBJECT_EXPECTED, NULL);
|
2008-09-11 23:58:28 +02:00
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = disp_propget(ctx->script, obj, id, &v, ctx->ei);
|
2008-09-11 23:58:28 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
2012-03-27 11:28:51 +02:00
|
|
|
VARIANT inc;
|
|
|
|
double n;
|
2008-09-11 23:58:28 +02:00
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = to_number(ctx->script, &v, ctx->ei, &n);
|
2011-12-07 11:01:53 +01:00
|
|
|
if(SUCCEEDED(hres)) {
|
2012-03-27 11:28:51 +02:00
|
|
|
num_set_val(&inc, n+(double)arg);
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = disp_propput(ctx->script, obj, id, &inc, ctx->ei);
|
2011-12-07 11:01:53 +01:00
|
|
|
}
|
2011-12-09 11:04:14 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
VariantClear(&v);
|
2008-09-11 23:58:28 +02:00
|
|
|
}
|
2011-12-07 11:01:53 +01:00
|
|
|
IDispatch_Release(obj);
|
2008-09-11 23:58:28 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-12-07 11:01:53 +01:00
|
|
|
return stack_push(ctx, &v);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2011-12-08 12:02:23 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.4.4, 11.4.5 */
|
2011-12-08 12:02:08 +01:00
|
|
|
static HRESULT interp_preinc(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const int arg = ctx->code->instrs[ctx->ip].arg1.lng;
|
2011-12-08 12:02:08 +01:00
|
|
|
IDispatch *obj;
|
|
|
|
DISPID id;
|
|
|
|
VARIANT v;
|
2008-09-11 23:57:40 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2011-12-08 12:02:08 +01:00
|
|
|
TRACE("%d\n", arg);
|
2008-09-11 23:57:40 +02:00
|
|
|
|
2011-12-08 12:02:08 +01:00
|
|
|
obj = stack_pop_objid(ctx, &id);
|
|
|
|
if(!obj)
|
2012-03-12 19:23:56 +01:00
|
|
|
return throw_type_error(ctx->script, ctx->ei, JS_E_OBJECT_EXPECTED, NULL);
|
2008-09-11 23:57:40 +02:00
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = disp_propget(ctx->script, obj, id, &v, ctx->ei);
|
2008-09-11 23:57:40 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
2012-03-27 11:28:51 +02:00
|
|
|
double n;
|
2008-09-11 23:57:40 +02:00
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = to_number(ctx->script, &v, ctx->ei, &n);
|
2011-12-08 12:02:08 +01:00
|
|
|
VariantClear(&v);
|
|
|
|
if(SUCCEEDED(hres)) {
|
2012-03-27 11:28:51 +02:00
|
|
|
num_set_val(&v, n+(double)arg);
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = disp_propput(ctx->script, obj, id, &v, ctx->ei);
|
2011-12-08 12:02:08 +01:00
|
|
|
}
|
2008-09-11 23:57:40 +02:00
|
|
|
}
|
2011-12-08 12:02:08 +01:00
|
|
|
IDispatch_Release(obj);
|
2008-09-11 23:57:40 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-12-08 12:02:08 +01:00
|
|
|
return stack_push(ctx, &v);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:29:16 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.9.3 */
|
2010-10-23 16:41:55 +02:00
|
|
|
static HRESULT equal_values(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, BOOL *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-17 23:29:16 +02:00
|
|
|
if(V_VT(lval) == V_VT(rval) || (is_num_vt(V_VT(lval)) && is_num_vt(V_VT(rval))))
|
|
|
|
return equal2_values(lval, rval, ret);
|
|
|
|
|
|
|
|
/* FIXME: NULL disps should be handled in more general way */
|
|
|
|
if(V_VT(lval) == VT_DISPATCH && !V_DISPATCH(lval)) {
|
|
|
|
VARIANT v;
|
|
|
|
V_VT(&v) = VT_NULL;
|
|
|
|
return equal_values(ctx, &v, rval, ei, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(V_VT(rval) == VT_DISPATCH && !V_DISPATCH(rval)) {
|
|
|
|
VARIANT v;
|
|
|
|
V_VT(&v) = VT_NULL;
|
|
|
|
return equal_values(ctx, lval, &v, ei, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
if((V_VT(lval) == VT_NULL && V_VT(rval) == VT_EMPTY) ||
|
|
|
|
(V_VT(lval) == VT_EMPTY && V_VT(rval) == VT_NULL)) {
|
|
|
|
*ret = TRUE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(V_VT(lval) == VT_BSTR && is_num_vt(V_VT(rval))) {
|
|
|
|
VARIANT v;
|
2012-03-27 11:28:51 +02:00
|
|
|
double n;
|
2008-09-17 23:29:16 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2012-03-27 11:28:51 +02:00
|
|
|
hres = to_number(ctx, lval, ei, &n);
|
2008-09-17 23:29:16 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-03-27 11:28:51 +02:00
|
|
|
/* FIXME: optimize */
|
|
|
|
num_set_val(&v, n);
|
|
|
|
|
2008-09-17 23:29:16 +02:00
|
|
|
return equal_values(ctx, &v, rval, ei, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(V_VT(rval) == VT_BSTR && is_num_vt(V_VT(lval))) {
|
|
|
|
VARIANT v;
|
2012-03-27 11:28:51 +02:00
|
|
|
double n;
|
2008-09-17 23:29:16 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2012-03-27 11:28:51 +02:00
|
|
|
hres = to_number(ctx, rval, ei, &n);
|
2008-09-17 23:29:16 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-03-27 11:28:51 +02:00
|
|
|
/* FIXME: optimize */
|
|
|
|
num_set_val(&v, n);
|
|
|
|
|
2008-09-17 23:29:16 +02:00
|
|
|
return equal_values(ctx, lval, &v, ei, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(V_VT(rval) == VT_BOOL) {
|
|
|
|
VARIANT v;
|
|
|
|
|
|
|
|
V_VT(&v) = VT_I4;
|
|
|
|
V_I4(&v) = V_BOOL(rval) ? 1 : 0;
|
|
|
|
return equal_values(ctx, lval, &v, ei, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(V_VT(lval) == VT_BOOL) {
|
|
|
|
VARIANT v;
|
|
|
|
|
|
|
|
V_VT(&v) = VT_I4;
|
|
|
|
V_I4(&v) = V_BOOL(lval) ? 1 : 0;
|
|
|
|
return equal_values(ctx, &v, rval, ei, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(V_VT(rval) == VT_DISPATCH && (V_VT(lval) == VT_BSTR || is_num_vt(V_VT(lval)))) {
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_primitive(ctx, rval, ei, &v, NO_HINT);
|
2008-09-17 23:29:16 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = equal_values(ctx, lval, &v, ei, ret);
|
|
|
|
|
|
|
|
VariantClear(&v);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(V_VT(lval) == VT_DISPATCH && (V_VT(rval) == VT_BSTR || is_num_vt(V_VT(rval)))) {
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_primitive(ctx, lval, ei, &v, NO_HINT);
|
2008-09-17 23:29:16 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = equal_values(ctx, &v, rval, ei, ret);
|
|
|
|
|
|
|
|
VariantClear(&v);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
*ret = FALSE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.9.1 */
|
2011-11-30 10:14:04 +01:00
|
|
|
static HRESULT interp_eq(exec_ctx_t *ctx)
|
2008-09-17 23:29:16 +02:00
|
|
|
{
|
2011-11-25 12:07:30 +01:00
|
|
|
VARIANT *l, *r;
|
2008-09-17 23:29:16 +02:00
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-11-25 12:07:30 +01:00
|
|
|
r = stack_pop(ctx);
|
|
|
|
l = stack_pop(ctx);
|
2008-09-17 23:29:16 +02:00
|
|
|
|
2011-11-25 12:07:30 +01:00
|
|
|
TRACE("%s == %s\n", debugstr_variant(l), debugstr_variant(r));
|
2008-09-17 23:29:16 +02:00
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = equal_values(ctx->script, l, r, ctx->ei, &b);
|
2011-11-25 12:07:30 +01:00
|
|
|
VariantClear(l);
|
|
|
|
VariantClear(r);
|
2008-09-17 23:29:16 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-11-25 12:07:30 +01:00
|
|
|
return stack_push_bool(ctx, b);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2011-11-25 12:07:30 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.9.2 */
|
2011-11-30 10:14:04 +01:00
|
|
|
static HRESULT interp_neq(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-11-18 14:09:44 +01:00
|
|
|
VARIANT *l, *r;
|
2008-09-09 01:26:20 +02:00
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-11-18 14:09:44 +01:00
|
|
|
r = stack_pop(ctx);
|
|
|
|
l = stack_pop(ctx);
|
2008-09-09 01:26:20 +02:00
|
|
|
|
2011-11-25 12:07:30 +01:00
|
|
|
TRACE("%s != %s\n", debugstr_variant(l), debugstr_variant(r));
|
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = equal_values(ctx->script, l, r, ctx->ei, &b);
|
2011-11-18 14:09:44 +01:00
|
|
|
VariantClear(l);
|
|
|
|
VariantClear(r);
|
2008-09-09 01:26:20 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-11-25 12:07:30 +01:00
|
|
|
return stack_push_bool(ctx, !b);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2011-11-25 12:07:30 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.9.4 */
|
|
|
|
static HRESULT interp_eq2(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-11-25 12:07:30 +01:00
|
|
|
VARIANT *l, *r;
|
2008-09-17 23:29:34 +02:00
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
2008-09-03 00:25:21 +02:00
|
|
|
|
2008-09-17 23:29:34 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-25 12:07:30 +01:00
|
|
|
r = stack_pop(ctx);
|
|
|
|
l = stack_pop(ctx);
|
2008-09-17 23:29:34 +02:00
|
|
|
|
2011-11-25 12:07:30 +01:00
|
|
|
hres = equal2_values(r, l, &b);
|
|
|
|
VariantClear(l);
|
|
|
|
VariantClear(r);
|
2008-09-17 23:29:34 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-11-25 12:07:30 +01:00
|
|
|
return stack_push_bool(ctx, b);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-09 01:26:37 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.9.5 */
|
2011-11-18 14:10:17 +01:00
|
|
|
static HRESULT interp_neq2(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-11-18 14:10:17 +01:00
|
|
|
VARIANT *l, *r;
|
2008-09-09 01:26:37 +02:00
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-18 14:10:17 +01:00
|
|
|
r = stack_pop(ctx);
|
|
|
|
l = stack_pop(ctx);
|
2008-09-09 01:26:37 +02:00
|
|
|
|
2011-11-18 14:10:17 +01:00
|
|
|
hres = equal2_values(r, l, &b);
|
|
|
|
VariantClear(l);
|
|
|
|
VariantClear(r);
|
2008-09-09 01:26:37 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-11-18 14:10:17 +01:00
|
|
|
return stack_push_bool(ctx, !b);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-11 23:56:03 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.8.5 */
|
2010-10-23 16:41:55 +02:00
|
|
|
static HRESULT less_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, BOOL greater, jsexcept_t *ei, BOOL *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-03-27 11:28:51 +02:00
|
|
|
double ln, rn;
|
|
|
|
VARIANT l, r;
|
2008-09-11 23:56:03 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_primitive(ctx, lval, ei, &l, NO_HINT);
|
2008-09-11 23:56:03 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_primitive(ctx, rval, ei, &r, NO_HINT);
|
2008-09-11 23:56:03 +02:00
|
|
|
if(FAILED(hres)) {
|
|
|
|
VariantClear(&l);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(V_VT(&l) == VT_BSTR && V_VT(&r) == VT_BSTR) {
|
2008-10-16 21:31:30 +02:00
|
|
|
*ret = (strcmpW(V_BSTR(&l), V_BSTR(&r)) < 0) ^ greater;
|
2008-09-11 23:56:03 +02:00
|
|
|
SysFreeString(V_BSTR(&l));
|
|
|
|
SysFreeString(V_BSTR(&r));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_number(ctx, &l, ei, &ln);
|
2008-09-11 23:56:03 +02:00
|
|
|
VariantClear(&l);
|
|
|
|
if(SUCCEEDED(hres))
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_number(ctx, &r, ei, &rn);
|
2008-09-11 23:56:03 +02:00
|
|
|
VariantClear(&r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-03-27 11:28:51 +02:00
|
|
|
*ret = !isnan(ln) && !isnan(rn) && ((ln < rn) ^ greater);
|
2008-09-11 23:56:03 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.8.1 */
|
2011-12-01 13:22:52 +01:00
|
|
|
static HRESULT interp_lt(exec_ctx_t *ctx)
|
2008-09-11 23:56:03 +02:00
|
|
|
{
|
2011-12-01 13:22:52 +01:00
|
|
|
VARIANT *l, *r;
|
2008-09-11 23:56:03 +02:00
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-12-01 13:22:52 +01:00
|
|
|
r = stack_pop(ctx);
|
|
|
|
l = stack_pop(ctx);
|
2008-09-11 23:56:03 +02:00
|
|
|
|
2011-12-01 13:22:52 +01:00
|
|
|
TRACE("%s < %s\n", debugstr_variant(l), debugstr_variant(r));
|
2008-09-11 23:56:03 +02:00
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = less_eval(ctx->script, l, r, FALSE, ctx->ei, &b);
|
2011-12-01 13:22:52 +01:00
|
|
|
VariantClear(l);
|
|
|
|
VariantClear(r);
|
2008-09-11 23:56:03 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-12-01 13:22:52 +01:00
|
|
|
return stack_push_bool(ctx, b);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2011-12-01 13:23:03 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.8.1 */
|
|
|
|
static HRESULT interp_lteq(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-12-01 13:23:03 +01:00
|
|
|
VARIANT *l, *r;
|
2008-09-11 23:56:29 +02:00
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-12-01 13:23:03 +01:00
|
|
|
r = stack_pop(ctx);
|
|
|
|
l = stack_pop(ctx);
|
2008-09-11 23:56:29 +02:00
|
|
|
|
2011-12-01 13:23:03 +01:00
|
|
|
TRACE("%s <= %s\n", debugstr_variant(l), debugstr_variant(r));
|
2008-09-11 23:56:29 +02:00
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = less_eval(ctx->script, r, l, TRUE, ctx->ei, &b);
|
2011-12-01 13:23:03 +01:00
|
|
|
VariantClear(l);
|
|
|
|
VariantClear(r);
|
2008-09-11 23:56:29 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-12-01 13:23:03 +01:00
|
|
|
return stack_push_bool(ctx, b);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-11 23:56:51 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.8.2 */
|
2011-12-01 13:23:16 +01:00
|
|
|
static HRESULT interp_gt(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-12-01 13:23:16 +01:00
|
|
|
VARIANT *l, *r;
|
2008-09-11 23:56:51 +02:00
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-12-01 13:23:16 +01:00
|
|
|
r = stack_pop(ctx);
|
|
|
|
l = stack_pop(ctx);
|
2008-09-11 23:56:51 +02:00
|
|
|
|
2011-12-01 13:23:16 +01:00
|
|
|
TRACE("%s > %s\n", debugstr_variant(l), debugstr_variant(r));
|
2008-09-11 23:56:51 +02:00
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = less_eval(ctx->script, r, l, FALSE, ctx->ei, &b);
|
2011-12-01 13:23:16 +01:00
|
|
|
VariantClear(l);
|
|
|
|
VariantClear(r);
|
2008-09-11 23:56:51 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-12-01 13:23:16 +01:00
|
|
|
return stack_push_bool(ctx, b);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-11 23:57:13 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.8.4 */
|
2011-12-01 13:23:36 +01:00
|
|
|
static HRESULT interp_gteq(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-12-01 13:23:36 +01:00
|
|
|
VARIANT *l, *r;
|
2008-09-11 23:57:13 +02:00
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-12-01 13:23:36 +01:00
|
|
|
r = stack_pop(ctx);
|
|
|
|
l = stack_pop(ctx);
|
2008-09-11 23:57:13 +02:00
|
|
|
|
2011-12-01 13:23:36 +01:00
|
|
|
TRACE("%s >= %s\n", debugstr_variant(l), debugstr_variant(r));
|
2008-09-11 23:57:13 +02:00
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = less_eval(ctx->script, l, r, TRUE, ctx->ei, &b);
|
2011-12-01 13:23:36 +01:00
|
|
|
VariantClear(l);
|
|
|
|
VariantClear(r);
|
2008-09-11 23:57:13 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-12-01 13:23:36 +01:00
|
|
|
return stack_push_bool(ctx, b);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:32:59 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.4.8 */
|
2011-11-30 10:14:04 +01:00
|
|
|
static HRESULT interp_bneg(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-04-27 10:49:26 +02:00
|
|
|
VARIANT *v;
|
2008-09-17 23:32:59 +02:00
|
|
|
INT i;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-21 15:35:15 +01:00
|
|
|
v = stack_pop(ctx);
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = to_int32(ctx->script, v, ctx->ei, &i);
|
2011-11-21 15:35:15 +01:00
|
|
|
VariantClear(v);
|
2008-09-17 23:32:59 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-04-27 10:49:26 +02:00
|
|
|
return stack_push_int(ctx, ~i);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-09 01:25:40 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.4.9 */
|
2011-11-30 10:14:04 +01:00
|
|
|
static HRESULT interp_neg(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-11-18 14:10:40 +01:00
|
|
|
VARIANT *v;
|
2008-09-09 01:25:40 +02:00
|
|
|
VARIANT_BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-18 14:10:40 +01:00
|
|
|
v = stack_pop(ctx);
|
|
|
|
hres = to_boolean(v, &b);
|
|
|
|
VariantClear(v);
|
2008-09-09 01:25:40 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-11-18 14:10:40 +01:00
|
|
|
return stack_push_bool(ctx, !b);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:44:11 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.7.1 */
|
2011-12-09 11:04:57 +01:00
|
|
|
static HRESULT interp_lshift(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-12-09 11:04:57 +01:00
|
|
|
DWORD r;
|
|
|
|
INT l;
|
|
|
|
HRESULT hres;
|
2008-09-19 00:44:11 +02:00
|
|
|
|
2011-12-09 11:04:57 +01:00
|
|
|
hres = stack_pop_uint(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_int(ctx, &l);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2008-09-19 00:44:11 +02:00
|
|
|
|
2011-12-09 11:04:57 +01:00
|
|
|
return stack_push_int(ctx, l << (r&0x1f));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2011-12-08 12:03:22 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.7.2 */
|
|
|
|
static HRESULT interp_rshift(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
DWORD r;
|
|
|
|
INT l;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = stack_pop_uint(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_int(ctx, &l);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push_int(ctx, l >> (r&0x1f));
|
|
|
|
}
|
|
|
|
|
2008-09-19 00:44:49 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.7.3 */
|
2011-12-09 11:04:24 +01:00
|
|
|
static HRESULT interp_rshift2(exec_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-12-09 11:04:24 +01:00
|
|
|
DWORD r, l;
|
|
|
|
HRESULT hres;
|
2008-09-19 00:44:49 +02:00
|
|
|
|
2011-12-09 11:04:24 +01:00
|
|
|
hres = stack_pop_uint(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2008-09-19 00:44:49 +02:00
|
|
|
|
2011-12-09 11:04:24 +01:00
|
|
|
hres = stack_pop_uint(ctx, &l);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push_int(ctx, l >> (r&0x1f));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2011-12-05 11:11:29 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.13.1 */
|
|
|
|
static HRESULT interp_assign(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
IDispatch *disp;
|
|
|
|
DISPID id;
|
|
|
|
VARIANT *v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
v = stack_pop(ctx);
|
|
|
|
disp = stack_pop_objid(ctx, &id);
|
|
|
|
|
|
|
|
if(!disp)
|
2012-03-12 19:23:56 +01:00
|
|
|
return throw_reference_error(ctx->script, ctx->ei, JS_E_ILLEGAL_ASSIGN, NULL);
|
2011-12-05 11:11:29 +01:00
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = disp_propput(ctx->script, disp, id, v, ctx->ei);
|
2011-12-05 11:11:29 +01:00
|
|
|
IDispatch_Release(disp);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
VariantClear(v);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
return stack_push(ctx, v);
|
|
|
|
}
|
|
|
|
|
2012-04-17 16:25:58 +02:00
|
|
|
/* JScript extension */
|
|
|
|
static HRESULT interp_assign_call(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
const unsigned arg = ctx->code->instrs[ctx->ip].arg1.uint;
|
|
|
|
DISPID propput_dispid = DISPID_PROPERTYPUT;
|
|
|
|
IDispatch *disp;
|
|
|
|
DISPPARAMS dp;
|
|
|
|
VARIANT *v;
|
|
|
|
DISPID id;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("%u\n", arg);
|
|
|
|
|
|
|
|
disp = stack_topn_objid(ctx, arg+1, &id);
|
|
|
|
if(!disp)
|
|
|
|
return throw_reference_error(ctx->script, ctx->ei, JS_E_ILLEGAL_ASSIGN, NULL);
|
|
|
|
|
|
|
|
jsstack_to_dp(ctx, arg+1, &dp);
|
|
|
|
dp.cNamedArgs = 1;
|
|
|
|
dp.rgdispidNamedArgs = &propput_dispid;
|
|
|
|
hres = disp_call(ctx->script, disp, id, DISPATCH_PROPERTYPUT, &dp, NULL, ctx->ei);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
v = stack_pop(ctx);
|
|
|
|
stack_popn(ctx, arg+2);
|
|
|
|
return stack_push(ctx, v);
|
|
|
|
}
|
|
|
|
|
2011-12-08 12:02:40 +01:00
|
|
|
static HRESULT interp_undefined(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
VARIANT v;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
V_VT(&v) = VT_EMPTY;
|
|
|
|
return stack_push(ctx, &v);
|
|
|
|
}
|
|
|
|
|
2011-11-30 10:14:04 +01:00
|
|
|
static HRESULT interp_jmp(exec_ctx_t *ctx)
|
2011-11-28 12:04:51 +01:00
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const unsigned arg = ctx->code->instrs[ctx->ip].arg1.uint;
|
2011-11-28 12:04:51 +01:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
ctx->ip = arg;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-12-20 11:47:37 +01:00
|
|
|
static HRESULT interp_jmp_z(exec_ctx_t *ctx)
|
|
|
|
{
|
2012-03-12 19:21:27 +01:00
|
|
|
const unsigned arg = ctx->code->instrs[ctx->ip].arg1.uint;
|
2011-12-20 11:47:37 +01:00
|
|
|
VARIANT_BOOL b;
|
|
|
|
VARIANT *v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
v = stack_pop(ctx);
|
|
|
|
hres = to_boolean(v, &b);
|
|
|
|
VariantClear(v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(b)
|
|
|
|
ctx->ip++;
|
|
|
|
else
|
|
|
|
ctx->ip = arg;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-25 12:05:50 +01:00
|
|
|
static HRESULT interp_pop(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
stack_popn(ctx, 1);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-18 14:09:44 +01:00
|
|
|
static HRESULT interp_ret(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
ctx->ip = -1;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef HRESULT (*op_func_t)(exec_ctx_t*);
|
|
|
|
|
|
|
|
static const op_func_t op_funcs[] = {
|
2011-11-24 14:23:39 +01:00
|
|
|
#define X(x,a,b,c) interp_##x,
|
2011-11-18 14:09:44 +01:00
|
|
|
OP_LIST
|
|
|
|
#undef X
|
|
|
|
};
|
|
|
|
|
|
|
|
static const unsigned op_move[] = {
|
2011-11-24 14:23:39 +01:00
|
|
|
#define X(a,x,b,c) x,
|
2011-11-18 14:09:44 +01:00
|
|
|
OP_LIST
|
|
|
|
#undef X
|
|
|
|
};
|
|
|
|
|
2011-12-28 12:06:28 +01:00
|
|
|
static HRESULT unwind_exception(exec_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
except_frame_t *except_frame;
|
|
|
|
VARIANT except_val;
|
|
|
|
BSTR ident;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
except_frame = ctx->except_frame;
|
|
|
|
ctx->except_frame = except_frame->next;
|
|
|
|
|
|
|
|
assert(except_frame->stack_top <= ctx->top);
|
|
|
|
stack_popn(ctx, ctx->top - except_frame->stack_top);
|
|
|
|
|
|
|
|
while(except_frame->scope != ctx->scope_chain)
|
|
|
|
scope_pop(&ctx->scope_chain);
|
|
|
|
|
|
|
|
ctx->ip = except_frame->catch_off;
|
|
|
|
|
2011-12-30 11:21:05 +01:00
|
|
|
except_val = ctx->ei->var;
|
|
|
|
memset(ctx->ei, 0, sizeof(*ctx->ei));
|
2011-12-28 12:06:28 +01:00
|
|
|
|
|
|
|
ident = except_frame->ident;
|
|
|
|
heap_free(except_frame);
|
|
|
|
|
|
|
|
if(ident) {
|
|
|
|
jsdisp_t *scope_obj;
|
|
|
|
|
2012-03-12 19:23:56 +01:00
|
|
|
hres = create_dispex(ctx->script, NULL, NULL, &scope_obj);
|
2011-12-28 12:06:28 +01:00
|
|
|
if(SUCCEEDED(hres)) {
|
2012-03-12 12:14:10 +01:00
|
|
|
hres = jsdisp_propput_name(scope_obj, ident, &except_val, ctx->ei);
|
2011-12-28 12:06:28 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
jsdisp_release(scope_obj);
|
|
|
|
}
|
|
|
|
VariantClear(&except_val);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = scope_push(ctx->scope_chain, scope_obj, &ctx->scope_chain);
|
|
|
|
jsdisp_release(scope_obj);
|
|
|
|
}else {
|
|
|
|
VARIANT v;
|
|
|
|
|
|
|
|
hres = stack_push(ctx, &except_val);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_push_bool(ctx, FALSE);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
V_VT(&v) = VT_EMPTY;
|
|
|
|
hres = stack_push(ctx, &v);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2012-04-24 17:39:09 +02:00
|
|
|
static HRESULT enter_bytecode(script_ctx_t *ctx, bytecode_t *code, function_code_t *func, jsexcept_t *ei, VARIANT *ret)
|
2011-12-19 14:58:42 +01:00
|
|
|
{
|
|
|
|
exec_ctx_t *exec_ctx = ctx->exec_ctx;
|
2011-12-28 12:06:28 +01:00
|
|
|
except_frame_t *prev_except_frame;
|
2012-04-24 17:39:09 +02:00
|
|
|
function_code_t *prev_func;
|
2011-12-19 14:58:42 +01:00
|
|
|
unsigned prev_ip, prev_top;
|
2011-12-27 11:16:26 +01:00
|
|
|
scope_chain_t *prev_scope;
|
2012-03-12 19:21:27 +01:00
|
|
|
bytecode_t *prev_code;
|
2011-12-19 14:59:34 +01:00
|
|
|
jsexcept_t *prev_ei;
|
2011-12-19 14:58:42 +01:00
|
|
|
jsop_t op;
|
|
|
|
HRESULT hres = S_OK;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
prev_top = exec_ctx->top;
|
2011-12-27 11:16:26 +01:00
|
|
|
prev_scope = exec_ctx->scope_chain;
|
2011-12-28 12:06:28 +01:00
|
|
|
prev_except_frame = exec_ctx->except_frame;
|
2011-12-19 14:58:42 +01:00
|
|
|
prev_ip = exec_ctx->ip;
|
2011-12-19 14:59:34 +01:00
|
|
|
prev_ei = exec_ctx->ei;
|
2012-03-12 19:21:27 +01:00
|
|
|
prev_code = exec_ctx->code;
|
2012-04-24 17:39:09 +02:00
|
|
|
prev_func = exec_ctx->func_code;
|
|
|
|
exec_ctx->ip = func->instr_off;
|
2011-12-30 11:21:05 +01:00
|
|
|
exec_ctx->ei = ei;
|
2011-12-28 12:06:28 +01:00
|
|
|
exec_ctx->except_frame = NULL;
|
2012-03-12 19:21:27 +01:00
|
|
|
exec_ctx->code = code;
|
2012-04-24 17:39:09 +02:00
|
|
|
exec_ctx->func_code = func;
|
2011-12-19 14:58:42 +01:00
|
|
|
|
2011-12-30 11:16:08 +01:00
|
|
|
while(exec_ctx->ip != -1) {
|
2012-03-12 19:21:27 +01:00
|
|
|
op = code->instrs[exec_ctx->ip].op;
|
2011-12-19 14:58:42 +01:00
|
|
|
hres = op_funcs[op](exec_ctx);
|
2011-12-28 12:06:28 +01:00
|
|
|
if(FAILED(hres)) {
|
|
|
|
TRACE("EXCEPTION\n");
|
|
|
|
|
|
|
|
if(!exec_ctx->except_frame)
|
|
|
|
break;
|
|
|
|
|
|
|
|
hres = unwind_exception(exec_ctx);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
}else {
|
|
|
|
exec_ctx->ip += op_move[op];
|
|
|
|
}
|
2011-12-19 14:58:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
exec_ctx->ip = prev_ip;
|
2011-12-19 14:59:34 +01:00
|
|
|
exec_ctx->ei = prev_ei;
|
2011-12-28 12:06:28 +01:00
|
|
|
exec_ctx->except_frame = prev_except_frame;
|
2012-03-12 19:21:27 +01:00
|
|
|
exec_ctx->code = prev_code;
|
2012-04-24 17:39:09 +02:00
|
|
|
exec_ctx->func_code = prev_func;
|
2011-12-19 14:58:42 +01:00
|
|
|
|
2011-12-30 11:16:08 +01:00
|
|
|
if(FAILED(hres)) {
|
2011-12-27 11:16:26 +01:00
|
|
|
while(exec_ctx->scope_chain != prev_scope)
|
|
|
|
scope_pop(&exec_ctx->scope_chain);
|
2011-12-28 12:07:06 +01:00
|
|
|
stack_popn(exec_ctx, exec_ctx->top-prev_top);
|
2011-12-19 14:58:42 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(exec_ctx->top == prev_top+1 || exec_ctx->top == prev_top);
|
2011-12-27 11:16:26 +01:00
|
|
|
assert(exec_ctx->scope_chain == prev_scope);
|
2011-12-19 14:58:42 +01:00
|
|
|
|
|
|
|
if(exec_ctx->top == prev_top)
|
|
|
|
V_VT(ret) = VT_EMPTY;
|
|
|
|
else
|
|
|
|
*ret = *stack_pop(exec_ctx);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-24 17:39:09 +02:00
|
|
|
HRESULT exec_source(exec_ctx_t *ctx, bytecode_t *code, function_code_t *func, BOOL from_eval,
|
2011-12-29 11:08:07 +01:00
|
|
|
jsexcept_t *ei, VARIANT *retv)
|
|
|
|
{
|
2012-04-24 17:39:09 +02:00
|
|
|
exec_ctx_t *prev_ctx;
|
2011-12-29 11:08:07 +01:00
|
|
|
VARIANT val;
|
2012-04-24 17:39:09 +02:00
|
|
|
unsigned i;
|
2011-12-29 11:08:07 +01:00
|
|
|
HRESULT hres = S_OK;
|
|
|
|
|
2012-04-24 17:39:09 +02:00
|
|
|
for(i = 0; i < func->func_cnt; i++) {
|
2011-12-29 11:08:07 +01:00
|
|
|
jsdisp_t *func_obj;
|
|
|
|
VARIANT var;
|
|
|
|
|
2012-04-24 17:39:25 +02:00
|
|
|
if(!func->funcs[i].name)
|
2012-03-12 19:22:36 +01:00
|
|
|
continue;
|
|
|
|
|
2012-04-25 11:25:57 +02:00
|
|
|
hres = create_source_function(ctx->script, code, func->funcs+i, ctx->scope_chain, &func_obj);
|
2011-12-29 11:08:07 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
var_set_jsdisp(&var, func_obj);
|
2012-04-24 17:39:25 +02:00
|
|
|
hres = jsdisp_propput_name(ctx->var_disp, func->funcs[i].name, &var, ei);
|
2011-12-29 11:08:07 +01:00
|
|
|
jsdisp_release(func_obj);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2012-04-25 10:47:56 +02:00
|
|
|
for(i=0; i < func->var_cnt; i++) {
|
|
|
|
if(!ctx->is_global || !lookup_global_members(ctx->script, func->variables[i], NULL)) {
|
|
|
|
DISPID id = 0;
|
2011-12-29 11:08:07 +01:00
|
|
|
|
2012-04-25 10:47:56 +02:00
|
|
|
hres = jsdisp_get_id(ctx->var_disp, func->variables[i], fdexNameEnsure, &id);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
2011-12-29 11:08:07 +01:00
|
|
|
}
|
|
|
|
|
2012-03-12 19:24:22 +01:00
|
|
|
prev_ctx = ctx->script->exec_ctx;
|
|
|
|
ctx->script->exec_ctx = ctx;
|
2011-12-29 11:08:07 +01:00
|
|
|
|
2012-04-24 17:39:09 +02:00
|
|
|
hres = enter_bytecode(ctx->script, code, func, ei, &val);
|
2012-03-12 19:24:22 +01:00
|
|
|
assert(ctx->script->exec_ctx == ctx);
|
|
|
|
ctx->script->exec_ctx = prev_ctx;
|
2012-04-04 17:05:07 +02:00
|
|
|
if(FAILED(hres))
|
2011-12-29 11:08:07 +01:00
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(retv)
|
|
|
|
*retv = val;
|
2011-12-30 11:21:05 +01:00
|
|
|
else
|
|
|
|
VariantClear(&val);
|
2011-12-29 11:08:07 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|