2008-09-03 00:25:21 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Jacek Caban for CodeWeavers
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
|
2008-09-03 00:25:21 +02:00
|
|
|
#include "jscript.h"
|
|
|
|
#include "engine.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(jscript);
|
|
|
|
|
2008-09-09 01:21:55 +02:00
|
|
|
#define EXPR_NOVAL 0x0001
|
|
|
|
#define EXPR_NEWREF 0x0002
|
|
|
|
#define EXPR_STRREF 0x0004
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
static inline HRESULT stat_eval(script_ctx_t *ctx, statement_t *stat, return_type_t *rt, VARIANT *ret)
|
2008-09-05 02:37:59 +02:00
|
|
|
{
|
|
|
|
return stat->eval(ctx, stat, rt, ret);
|
|
|
|
}
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
static inline HRESULT expr_eval(script_ctx_t *ctx, expression_t *expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-09 01:21:55 +02:00
|
|
|
{
|
2010-10-23 16:41:55 +02:00
|
|
|
return expr->eval(ctx, expr, flags, ei, ret);
|
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;
|
|
|
|
case EXPRVAL_NAMEREF:
|
|
|
|
if(val->u.nameref.disp)
|
|
|
|
IDispatch_Release(val->u.nameref.disp);
|
|
|
|
SysFreeString(val->u.nameref.name);
|
2009-08-27 01:21:38 +02:00
|
|
|
return;
|
|
|
|
case EXPRVAL_INVALID:
|
|
|
|
SysFreeString(val->u.identifier);
|
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;
|
|
|
|
}
|
|
|
|
|
2009-09-23 16:10:36 +02:00
|
|
|
return disp_propget(ctx, val->u.idref.disp, val->u.idref.id, ret, ei, NULL/*FIXME*/);
|
2009-08-27 01:21:38 +02:00
|
|
|
case EXPRVAL_NAMEREF:
|
|
|
|
break;
|
|
|
|
case EXPRVAL_INVALID:
|
2010-12-28 15:04:59 +01:00
|
|
|
return throw_type_error(ctx, ei, JS_E_UNDEFINED_VARIABLE, val->u.identifier);
|
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:25:40 +02:00
|
|
|
static HRESULT exprval_to_boolean(script_ctx_t *ctx, exprval_t *exprval, jsexcept_t *ei, VARIANT_BOOL *b)
|
|
|
|
{
|
|
|
|
if(exprval->type != EXPRVAL_VARIANT) {
|
|
|
|
VARIANT val;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = exprval_to_value(ctx, exprval, ei, &val);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = to_boolean(&val, b);
|
|
|
|
VariantClear(&val);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
return to_boolean(&exprval->u.var, b);
|
|
|
|
}
|
|
|
|
|
2008-09-09 01:27:18 +02:00
|
|
|
static void exprval_init(exprval_t *val)
|
|
|
|
{
|
|
|
|
val->type = EXPRVAL_VARIANT;
|
|
|
|
V_VT(&val->u.var) = VT_EMPTY;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
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);
|
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)) {
|
|
|
|
TRACE("unsing IDispatch\n");
|
|
|
|
|
|
|
|
*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;
|
|
|
|
}
|
|
|
|
|
2008-09-09 01:23:21 +02:00
|
|
|
/* ECMA-262 3rd Edition 8.7.2 */
|
|
|
|
static HRESULT put_value(script_ctx_t *ctx, exprval_t *ref, VARIANT *v, jsexcept_t *ei)
|
|
|
|
{
|
2009-07-24 09:36:16 +02:00
|
|
|
if(ref->type != EXPRVAL_IDREF)
|
2010-12-28 15:04:59 +01:00
|
|
|
return throw_reference_error(ctx, ei, JS_E_ILLEGAL_ASSIGN, NULL);
|
2008-09-09 01:23:21 +02:00
|
|
|
|
2009-09-23 16:11:11 +02:00
|
|
|
return disp_propput(ctx, ref->u.idref.disp, ref->u.idref.id, v, ei, NULL/*FIXME*/);
|
2008-09-09 01:23:21 +02:00
|
|
|
}
|
|
|
|
|
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-10-14 14:43:01 +02:00
|
|
|
static HRESULT literal_to_var(script_ctx_t *ctx, literal_t *literal, VARIANT *v)
|
2008-09-09 01:23:41 +02:00
|
|
|
{
|
2009-10-14 14:41:50 +02:00
|
|
|
switch(literal->type) {
|
|
|
|
case LT_NULL:
|
|
|
|
V_VT(v) = VT_NULL;
|
|
|
|
break;
|
|
|
|
case LT_INT:
|
|
|
|
V_VT(v) = VT_I4;
|
2008-09-09 01:23:41 +02:00
|
|
|
V_I4(v) = literal->u.lval;
|
|
|
|
break;
|
2009-10-14 14:41:50 +02:00
|
|
|
case LT_DOUBLE:
|
|
|
|
V_VT(v) = VT_R8;
|
2008-09-09 01:23:41 +02:00
|
|
|
V_R8(v) = literal->u.dval;
|
|
|
|
break;
|
2009-10-14 14:43:01 +02:00
|
|
|
case LT_STRING: {
|
|
|
|
BSTR str = SysAllocString(literal->u.wstr);
|
|
|
|
if(!str)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2009-10-14 14:41:50 +02:00
|
|
|
V_VT(v) = VT_BSTR;
|
2009-10-14 14:43:01 +02:00
|
|
|
V_BSTR(v) = str;
|
2008-09-09 01:23:41 +02:00
|
|
|
break;
|
2009-10-14 14:43:01 +02:00
|
|
|
}
|
2009-10-14 14:41:50 +02:00
|
|
|
case LT_BOOL:
|
|
|
|
V_VT(v) = VT_BOOL;
|
2008-09-09 01:23:41 +02:00
|
|
|
V_BOOL(v) = literal->u.bval;
|
|
|
|
break;
|
2009-10-14 14:43:01 +02:00
|
|
|
case LT_REGEXP: {
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *regexp;
|
2009-10-14 14:43:01 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = create_regexp(ctx, literal->u.regexp.str, literal->u.regexp.str_len,
|
|
|
|
literal->u.regexp.flags, ®exp);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-09-07 15:41:40 +02:00
|
|
|
var_set_jsdisp(v, regexp);
|
2009-10-14 14:43:01 +02:00
|
|
|
}
|
2008-09-09 01:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-10-14 15:21:13 +02:00
|
|
|
HRESULT exec_source(exec_ctx_t *ctx, parser_ctx_t *parser, source_elements_t *source, BOOL from_eval,
|
2009-11-04 23:19:11 +01:00
|
|
|
jsexcept_t *ei, VARIANT *retv)
|
2008-09-05 02:37:59 +02:00
|
|
|
{
|
|
|
|
script_ctx_t *script = parser->script;
|
2008-09-09 01:27:57 +02:00
|
|
|
function_declaration_t *func;
|
2008-09-05 02:37:59 +02:00
|
|
|
parser_ctx_t *prev_parser;
|
2008-09-30 17:47:40 +02:00
|
|
|
var_list_t *var;
|
2008-09-05 02:37:59 +02:00
|
|
|
VARIANT val, tmp;
|
|
|
|
statement_t *stat;
|
|
|
|
exec_ctx_t *prev_ctx;
|
|
|
|
return_type_t rt;
|
|
|
|
HRESULT hres = S_OK;
|
|
|
|
|
2008-09-09 01:27:57 +02:00
|
|
|
for(func = source->functions; func; func = func->next) {
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *func_obj;
|
2008-09-09 01:27:57 +02:00
|
|
|
VARIANT var;
|
|
|
|
|
2008-10-20 22:12:42 +02:00
|
|
|
hres = create_source_function(parser, func->expr->parameter_list, func->expr->source_elements,
|
|
|
|
ctx->scope_chain, func->expr->src_str, func->expr->src_len, &func_obj);
|
2008-09-09 01:27:57 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-09-07 15:41:40 +02:00
|
|
|
var_set_jsdisp(&var, func_obj);
|
2009-09-23 16:11:11 +02:00
|
|
|
hres = jsdisp_propput_name(ctx->var_disp, func->expr->identifier, &var, ei, NULL);
|
2008-09-30 17:47:40 +02:00
|
|
|
jsdisp_release(func_obj);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(var = source->variables; var; var = var->next) {
|
|
|
|
DISPID id = 0;
|
2009-08-10 12:57:42 +02:00
|
|
|
BSTR name;
|
2008-09-30 17:47:40 +02:00
|
|
|
|
2009-08-10 12:57:42 +02:00
|
|
|
name = SysAllocString(var->identifier);
|
|
|
|
if(!name)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2010-10-14 15:21:13 +02:00
|
|
|
if(!ctx->is_global || !lookup_global_members(parser->script, name, NULL))
|
2009-08-10 12:57:42 +02:00
|
|
|
hres = jsdisp_get_id(ctx->var_disp, var->identifier, fdexNameEnsure, &id);
|
|
|
|
SysFreeString(name);
|
2008-09-09 01:27:57 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2008-09-05 02:37:59 +02:00
|
|
|
prev_ctx = script->exec_ctx;
|
|
|
|
script->exec_ctx = ctx;
|
|
|
|
|
|
|
|
prev_parser = ctx->parser;
|
|
|
|
ctx->parser = parser;
|
|
|
|
|
|
|
|
V_VT(&val) = VT_EMPTY;
|
|
|
|
memset(&rt, 0, sizeof(rt));
|
|
|
|
rt.type = RT_NORMAL;
|
|
|
|
|
|
|
|
for(stat = source->statement; stat; stat = stat->next) {
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = stat_eval(script, stat, &rt, &tmp);
|
2008-09-05 02:37:59 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
|
|
|
VariantClear(&val);
|
|
|
|
val = tmp;
|
|
|
|
if(rt.type != RT_NORMAL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
script->exec_ctx = prev_ctx;
|
|
|
|
ctx->parser = prev_parser;
|
|
|
|
|
|
|
|
if(rt.type != RT_NORMAL && rt.type != RT_RETURN) {
|
|
|
|
FIXME("wrong rt %d\n", rt.type);
|
|
|
|
hres = E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ei = rt.ei;
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
VariantClear(&val);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2010-10-14 15:21:13 +02:00
|
|
|
if(!retv || (!from_eval && rt.type != RT_RETURN))
|
2008-09-05 02:37:59 +02:00
|
|
|
VariantClear(&val);
|
2010-10-14 15:21:13 +02:00
|
|
|
if(retv)
|
|
|
|
*retv = val;
|
2008-09-05 02:37:59 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-09-09 01:22:13 +02:00
|
|
|
/* ECMA-262 3rd Edition 10.1.4 */
|
2010-10-23 16:41:55 +02:00
|
|
|
static HRESULT identifier_eval(script_ctx_t *ctx, BSTR identifier, DWORD flags, jsexcept_t *ei, 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;
|
|
|
|
|
2008-09-09 01:22:13 +02:00
|
|
|
if(flags & EXPR_NEWREF) {
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = jsdisp_get_id(ctx->global, identifier, fdexNameEnsure, &id);
|
2008-09-09 01:24:49 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
exprval_set_idref(ret, to_disp(ctx->global), id);
|
2008-09-09 01:24:49 +02:00
|
|
|
return S_OK;
|
2008-09-09 01:22:13 +02:00
|
|
|
}
|
|
|
|
|
2009-08-27 01:21:38 +02:00
|
|
|
ret->type = EXPRVAL_INVALID;
|
|
|
|
ret->u.identifier = SysAllocString(identifier);
|
|
|
|
if(!ret->u.identifier)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
return S_OK;
|
2008-09-09 01:22:13 +02:00
|
|
|
}
|
|
|
|
|
2008-09-10 21:10:41 +02:00
|
|
|
/* ECMA-262 3rd Edition 12.1 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT block_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-10 21:10:41 +02:00
|
|
|
block_statement_t *stat = (block_statement_t*)_stat;
|
|
|
|
VARIANT val, tmp;
|
|
|
|
statement_t *iter;
|
|
|
|
HRESULT hres = S_OK;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
V_VT(&val) = VT_EMPTY;
|
|
|
|
for(iter = stat->stat_list; iter; iter = iter->next) {
|
|
|
|
hres = stat_eval(ctx, iter, rt, &tmp);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
|
|
|
VariantClear(&val);
|
|
|
|
val = tmp;
|
|
|
|
if(rt->type != RT_NORMAL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
VariantClear(&val);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret = val;
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-09 01:25:59 +02:00
|
|
|
/* ECMA-262 3rd Edition 12.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
static HRESULT variable_list_eval(script_ctx_t *ctx, variable_declaration_t *var_list, jsexcept_t *ei)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-09 01:25:59 +02:00
|
|
|
variable_declaration_t *iter;
|
2008-10-02 16:22:27 +02:00
|
|
|
HRESULT hres = S_OK;
|
2008-09-09 01:25:59 +02:00
|
|
|
|
|
|
|
for(iter = var_list; iter; iter = iter->next) {
|
2008-10-02 16:22:27 +02:00
|
|
|
exprval_t exprval;
|
2008-09-09 01:25:59 +02:00
|
|
|
VARIANT val;
|
|
|
|
|
2008-10-02 16:22:27 +02:00
|
|
|
if(!iter->expr)
|
|
|
|
continue;
|
2008-09-09 01:25:59 +02:00
|
|
|
|
2008-10-02 16:22:27 +02:00
|
|
|
hres = expr_eval(ctx, iter->expr, 0, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
2008-09-09 01:25:59 +02:00
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, ei, &val);
|
2008-10-02 16:22:27 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
2008-09-09 01:25:59 +02:00
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = jsdisp_propput_name(ctx->exec_ctx->var_disp, iter->identifier, &val, ei, NULL/*FIXME*/);
|
2008-09-09 01:25:59 +02:00
|
|
|
VariantClear(&val);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT var_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
|
2008-09-09 01:25:59 +02:00
|
|
|
{
|
|
|
|
var_statement_t *stat = (var_statement_t*)_stat;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = variable_list_eval(ctx, stat->variable_list, &rt->ei);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
V_VT(ret) = VT_EMPTY;
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-09 01:21:55 +02:00
|
|
|
/* ECMA-262 3rd Edition 12.3 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT empty_statement_eval(script_ctx_t *ctx, statement_t *stat, return_type_t *rt, VARIANT *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-05 02:39:07 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
V_VT(ret) = VT_EMPTY;
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-09 01:21:55 +02:00
|
|
|
/* ECMA-262 3rd Edition 12.4 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT expression_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-09 01:21:55 +02:00
|
|
|
expression_statement_t *stat = (expression_statement_t*)_stat;
|
|
|
|
exprval_t exprval;
|
|
|
|
VARIANT val;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, stat->expr, EXPR_NOVAL, &rt->ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, &rt->ei, &val);
|
2008-09-09 01:21:55 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
*ret = val;
|
|
|
|
TRACE("= %s\n", debugstr_variant(ret));
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-10 21:10:06 +02:00
|
|
|
/* ECMA-262 3rd Edition 12.5 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT if_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-10 21:10:06 +02:00
|
|
|
if_statement_t *stat = (if_statement_t*)_stat;
|
|
|
|
exprval_t exprval;
|
|
|
|
VARIANT_BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_boolean(ctx, &exprval, &rt->ei, &b);
|
2008-09-10 21:10:06 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(b)
|
|
|
|
hres = stat_eval(ctx, stat->if_stat, rt, ret);
|
|
|
|
else if(stat->else_stat)
|
|
|
|
hres = stat_eval(ctx, stat->else_stat, rt, ret);
|
|
|
|
else
|
|
|
|
V_VT(ret) = VT_EMPTY;
|
|
|
|
|
|
|
|
return hres;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:35:38 +02:00
|
|
|
/* ECMA-262 3rd Edition 12.6.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT while_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-17 23:35:38 +02:00
|
|
|
while_statement_t *stat = (while_statement_t*)_stat;
|
|
|
|
exprval_t exprval;
|
|
|
|
VARIANT val, tmp;
|
|
|
|
VARIANT_BOOL b;
|
|
|
|
BOOL test_expr;
|
|
|
|
HRESULT hres;
|
2008-09-03 00:25:21 +02:00
|
|
|
|
2008-09-17 23:35:38 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
V_VT(&val) = VT_EMPTY;
|
|
|
|
test_expr = !stat->do_while;
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
if(test_expr) {
|
|
|
|
hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_boolean(ctx, &exprval, &rt->ei, &b);
|
2008-09-17 23:35:38 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres) || !b)
|
|
|
|
break;
|
|
|
|
}else {
|
|
|
|
test_expr = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = stat_eval(ctx, stat->statement, rt, &tmp);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
|
|
|
VariantClear(&val);
|
|
|
|
val = tmp;
|
|
|
|
|
|
|
|
if(rt->type == RT_CONTINUE)
|
|
|
|
rt->type = RT_NORMAL;
|
|
|
|
if(rt->type != RT_NORMAL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
VariantClear(&val);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(rt->type == RT_BREAK)
|
|
|
|
rt->type = RT_NORMAL;
|
|
|
|
|
|
|
|
*ret = val;
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:36:19 +02:00
|
|
|
/* ECMA-262 3rd Edition 12.6.3 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT for_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-17 23:36:19 +02:00
|
|
|
for_statement_t *stat = (for_statement_t*)_stat;
|
|
|
|
VARIANT val, tmp, retv;
|
|
|
|
exprval_t exprval;
|
|
|
|
VARIANT_BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
if(stat->variable_list) {
|
|
|
|
hres = variable_list_eval(ctx, stat->variable_list, &rt->ei);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}else if(stat->begin_expr) {
|
|
|
|
hres = expr_eval(ctx, stat->begin_expr, EXPR_NEWREF, &rt->ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, &rt->ei, &val);
|
2008-09-17 23:36:19 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
VariantClear(&val);
|
|
|
|
}
|
|
|
|
|
|
|
|
V_VT(&retv) = VT_EMPTY;
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
if(stat->expr) {
|
|
|
|
hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_boolean(ctx, &exprval, &rt->ei, &b);
|
2008-09-17 23:36:19 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres) || !b)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = stat_eval(ctx, stat->statement, rt, &tmp);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
|
|
|
VariantClear(&retv);
|
|
|
|
retv = tmp;
|
|
|
|
|
|
|
|
if(rt->type == RT_CONTINUE)
|
|
|
|
rt->type = RT_NORMAL;
|
|
|
|
else if(rt->type != RT_NORMAL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if(stat->end_expr) {
|
|
|
|
hres = expr_eval(ctx, stat->end_expr, 0, &rt->ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, &rt->ei, &val);
|
2008-09-17 23:36:19 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
|
|
|
VariantClear(&val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
VariantClear(&retv);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(rt->type == RT_BREAK)
|
|
|
|
rt->type = RT_NORMAL;
|
|
|
|
|
|
|
|
*ret = retv;
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:43:21 +02:00
|
|
|
/* ECMA-262 3rd Edition 12.6.4 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT forin_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
|
2008-09-19 00:43:21 +02:00
|
|
|
{
|
|
|
|
forin_statement_t *stat = (forin_statement_t*)_stat;
|
|
|
|
VARIANT val, name, retv, tmp;
|
|
|
|
DISPID id = DISPID_STARTENUM;
|
|
|
|
BSTR str, identifier = NULL;
|
|
|
|
IDispatchEx *in_obj;
|
|
|
|
exprval_t exprval;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
if(stat->variable) {
|
|
|
|
hres = variable_list_eval(ctx, stat->variable, &rt->ei);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, stat->in_expr, EXPR_NEWREF, &rt->ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, &rt->ei, &val);
|
2008-09-19 00:43:21 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(V_VT(&val) != VT_DISPATCH) {
|
2008-09-21 15:40:04 +02:00
|
|
|
TRACE("in vt %d\n", V_VT(&val));
|
2008-09-19 00:43:21 +02:00
|
|
|
VariantClear(&val);
|
2008-09-21 15:40:04 +02:00
|
|
|
V_VT(ret) = VT_EMPTY;
|
|
|
|
return S_OK;
|
2008-09-19 00:43:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hres = IDispatch_QueryInterface(V_DISPATCH(&val), &IID_IDispatchEx, (void**)&in_obj);
|
|
|
|
IDispatch_Release(V_DISPATCH(&val));
|
|
|
|
if(FAILED(hres)) {
|
2011-06-21 17:45:50 +02:00
|
|
|
TRACE("Object doesn't support IDispatchEx\n");
|
|
|
|
V_VT(ret) = VT_EMPTY;
|
|
|
|
return S_OK;
|
2008-09-19 00:43:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
V_VT(&retv) = VT_EMPTY;
|
|
|
|
|
|
|
|
if(stat->variable)
|
|
|
|
identifier = SysAllocString(stat->variable->identifier);
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
hres = IDispatchEx_GetNextDispID(in_obj, fdexEnumDefault, id, &id);
|
|
|
|
if(FAILED(hres) || hres == S_FALSE)
|
|
|
|
break;
|
|
|
|
|
|
|
|
hres = IDispatchEx_GetMemberName(in_obj, id, &str);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
|
|
|
TRACE("iter %s\n", debugstr_w(str));
|
|
|
|
|
|
|
|
if(stat->variable)
|
2009-07-22 13:01:59 +02:00
|
|
|
hres = identifier_eval(ctx, identifier, 0, NULL, &exprval);
|
2008-09-19 00:43:21 +02:00
|
|
|
else
|
|
|
|
hres = expr_eval(ctx, stat->expr, EXPR_NEWREF, &rt->ei, &exprval);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
V_VT(&name) = VT_BSTR;
|
|
|
|
V_BSTR(&name) = str;
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = put_value(ctx, &exprval, &name, &rt->ei);
|
2008-09-19 00:43:21 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
}
|
|
|
|
SysFreeString(str);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
|
|
|
hres = stat_eval(ctx, stat->statement, rt, &tmp);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
|
|
|
VariantClear(&retv);
|
|
|
|
retv = tmp;
|
|
|
|
|
|
|
|
if(rt->type == RT_CONTINUE)
|
|
|
|
rt->type = RT_NORMAL;
|
|
|
|
else if(rt->type != RT_NORMAL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
SysFreeString(identifier);
|
|
|
|
IDispatchEx_Release(in_obj);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
VariantClear(&retv);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(rt->type == RT_BREAK)
|
|
|
|
rt->type = RT_NORMAL;
|
|
|
|
|
|
|
|
*ret = retv;
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:35:57 +02:00
|
|
|
/* ECMA-262 3rd Edition 12.7 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT continue_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-17 23:35:57 +02:00
|
|
|
branch_statement_t *stat = (branch_statement_t*)_stat;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
if(stat->identifier) {
|
|
|
|
FIXME("indentifier not implemented\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rt->type = RT_CONTINUE;
|
|
|
|
V_VT(ret) = VT_EMPTY;
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:30:37 +02:00
|
|
|
/* ECMA-262 3rd Edition 12.8 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT break_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-17 23:30:37 +02:00
|
|
|
branch_statement_t *stat = (branch_statement_t*)_stat;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
if(stat->identifier) {
|
|
|
|
FIXME("indentifier not implemented\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rt->type = RT_BREAK;
|
|
|
|
V_VT(ret) = VT_EMPTY;
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-10 21:05:37 +02:00
|
|
|
/* ECMA-262 3rd Edition 12.9 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT return_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-10 21:05:37 +02:00
|
|
|
expression_statement_t *stat = (expression_statement_t*)_stat;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
if(stat->expr) {
|
|
|
|
exprval_t exprval;
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, &rt->ei, ret);
|
2008-09-10 21:05:37 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}else {
|
|
|
|
V_VT(ret) = VT_EMPTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("= %s\n", debugstr_variant(ret));
|
|
|
|
rt->type = RT_RETURN;
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:43:53 +02:00
|
|
|
/* ECMA-262 3rd Edition 12.10 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT with_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-19 00:43:53 +02:00
|
|
|
with_statement_t *stat = (with_statement_t*)_stat;
|
|
|
|
exprval_t exprval;
|
|
|
|
IDispatch *disp;
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *obj;
|
2008-09-19 00:43:53 +02:00
|
|
|
VARIANT val;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, &rt->ei, &val);
|
2008-09-19 00:43:53 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_object(ctx, &val, &disp);
|
2008-09-19 00:43:53 +02:00
|
|
|
VariantClear(&val);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
obj = iface_to_jsdisp((IUnknown*)disp);
|
|
|
|
IDispatch_Release(disp);
|
|
|
|
if(!obj) {
|
|
|
|
FIXME("disp id not jsdisp\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = scope_push(ctx->exec_ctx->scope_chain, obj, &ctx->exec_ctx->scope_chain);
|
2008-09-19 00:43:53 +02:00
|
|
|
jsdisp_release(obj);
|
2008-09-24 01:48:57 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2008-09-19 00:43:53 +02:00
|
|
|
|
|
|
|
hres = stat_eval(ctx, stat->statement, rt, ret);
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
scope_pop(&ctx->exec_ctx->scope_chain);
|
2008-09-19 00:43:53 +02:00
|
|
|
return hres;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:43:53 +02:00
|
|
|
/* ECMA-262 3rd Edition 12.12 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT labelled_statement_eval(script_ctx_t *ctx, statement_t *stat, return_type_t *rt, VARIANT *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
|
|
|
FIXME("\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2008-09-17 23:30:20 +02:00
|
|
|
/* ECMA-262 3rd Edition 12.13 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT switch_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-17 23:30:20 +02:00
|
|
|
switch_statement_t *stat = (switch_statement_t*)_stat;
|
|
|
|
case_clausule_t *iter, *default_clausule = NULL;
|
|
|
|
statement_t *stat_iter;
|
|
|
|
VARIANT val, cval;
|
|
|
|
exprval_t exprval;
|
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, &rt->ei, &val);
|
2008-09-17 23:30:20 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
for(iter = stat->case_list; iter; iter = iter->next) {
|
|
|
|
if(!iter->expr) {
|
|
|
|
default_clausule = iter;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, iter->expr, 0, &rt->ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, &rt->ei, &cval);
|
2008-09-17 23:30:20 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
|
|
|
hres = equal2_values(&val, &cval, &b);
|
|
|
|
VariantClear(&cval);
|
|
|
|
if(FAILED(hres) || b)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
VariantClear(&val);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(!iter)
|
|
|
|
iter = default_clausule;
|
|
|
|
|
|
|
|
V_VT(&val) = VT_EMPTY;
|
|
|
|
if(iter) {
|
|
|
|
VARIANT tmp;
|
|
|
|
|
|
|
|
for(stat_iter = iter->stat; stat_iter; stat_iter = stat_iter->next) {
|
|
|
|
hres = stat_eval(ctx, stat_iter, rt, &tmp);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
|
|
|
VariantClear(&val);
|
|
|
|
val = tmp;
|
|
|
|
|
|
|
|
if(rt->type != RT_NORMAL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
VariantClear(&val);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(rt->type == RT_BREAK)
|
|
|
|
rt->type = RT_NORMAL;
|
|
|
|
|
|
|
|
*ret = val;
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-16 20:45:13 +02:00
|
|
|
/* ECMA-262 3rd Edition 12.13 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT throw_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-16 20:45:13 +02:00
|
|
|
expression_statement_t *stat = (expression_statement_t*)_stat;
|
|
|
|
exprval_t exprval;
|
|
|
|
VARIANT val;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, &rt->ei, &val);
|
2008-09-16 20:45:13 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
rt->ei.var = val;
|
|
|
|
return DISP_E_EXCEPTION;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-16 20:44:54 +02:00
|
|
|
/* ECMA-262 3rd Edition 12.14 */
|
2010-10-23 16:41:55 +02:00
|
|
|
static HRESULT catch_eval(script_ctx_t *ctx, catch_block_t *block, return_type_t *rt, VARIANT *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *var_disp;
|
2008-09-16 20:44:54 +02:00
|
|
|
VARIANT ex, val;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
ex = rt->ei.var;
|
|
|
|
memset(&rt->ei, 0, sizeof(jsexcept_t));
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = create_dispex(ctx, NULL, NULL, &var_disp);
|
2008-09-16 20:44:54 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
2009-09-23 16:11:11 +02:00
|
|
|
hres = jsdisp_propput_name(var_disp, block->identifier, &ex, &rt->ei, NULL/*FIXME*/);
|
2008-09-16 20:44:54 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = scope_push(ctx->exec_ctx->scope_chain, var_disp, &ctx->exec_ctx->scope_chain);
|
2008-09-16 20:44:54 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = stat_eval(ctx, block->statement, rt, &val);
|
2010-10-23 16:41:55 +02:00
|
|
|
scope_pop(&ctx->exec_ctx->scope_chain);
|
2008-09-16 20:44:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
jsdisp_release(var_disp);
|
|
|
|
}
|
|
|
|
|
|
|
|
VariantClear(&ex);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
*ret = val;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.14 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT try_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
|
2008-09-16 20:44:54 +02:00
|
|
|
{
|
|
|
|
try_statement_t *stat = (try_statement_t*)_stat;
|
|
|
|
VARIANT val;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = stat_eval(ctx, stat->try_statement, rt, &val);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
TRACE("EXCEPTION\n");
|
|
|
|
if(!stat->catch_block)
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = catch_eval(ctx, stat->catch_block, rt, &val);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(stat->finally_statement) {
|
|
|
|
VariantClear(&val);
|
|
|
|
hres = stat_eval(ctx, stat->finally_statement, rt, &val);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret = val;
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-09 01:25:40 +02:00
|
|
|
static HRESULT return_bool(exprval_t *ret, DWORD b)
|
|
|
|
{
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
|
|
|
V_VT(&ret->u.var) = VT_BOOL;
|
|
|
|
V_BOOL(&ret->u.var) = b ? VARIANT_TRUE : VARIANT_FALSE;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
static HRESULT get_binary_expr_values(script_ctx_t *ctx, binary_expression_t *expr, jsexcept_t *ei, VARIANT *lval, VARIANT *rval)
|
2008-09-09 01:26:20 +02:00
|
|
|
{
|
|
|
|
exprval_t exprval;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, ei, lval);
|
2008-09-09 01:26:20 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
|
|
|
|
if(SUCCEEDED(hres)) {
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, ei, rval);
|
2008-09-09 01:26:20 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
VariantClear(lval);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
typedef HRESULT (*oper_t)(script_ctx_t*,VARIANT*,VARIANT*,jsexcept_t*,VARIANT*);
|
2008-09-10 21:12:45 +02:00
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
static HRESULT binary_expr_eval(script_ctx_t *ctx, binary_expression_t *expr, oper_t oper, jsexcept_t *ei,
|
2008-09-10 21:12:45 +02:00
|
|
|
exprval_t *ret)
|
|
|
|
{
|
|
|
|
VARIANT lval, rval, retv;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = oper(ctx, &lval, &rval, ei, &retv);
|
|
|
|
VariantClear(&lval);
|
|
|
|
VariantClear(&rval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
|
|
|
ret->u.var = retv;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-09-11 23:54:45 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.13.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
static HRESULT assign_oper_eval(script_ctx_t *ctx, expression_t *lexpr, expression_t *rexpr, oper_t oper,
|
2008-09-11 23:54:45 +02:00
|
|
|
jsexcept_t *ei, exprval_t *ret)
|
|
|
|
{
|
|
|
|
VARIANT retv, lval, rval;
|
|
|
|
exprval_t exprval, exprvalr;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, lexpr, EXPR_NEWREF, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_value(ctx, &exprval, ei, &lval);
|
2008-09-11 23:54:45 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = expr_eval(ctx, rexpr, 0, ei, &exprvalr);
|
|
|
|
if(SUCCEEDED(hres)) {
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_value(ctx, &exprvalr, ei, &rval);
|
2008-09-11 23:54:45 +02:00
|
|
|
exprval_release(&exprvalr);
|
|
|
|
}
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = oper(ctx, &lval, &rval, ei, &retv);
|
|
|
|
VariantClear(&rval);
|
|
|
|
}
|
|
|
|
VariantClear(&lval);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(SUCCEEDED(hres)) {
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = put_value(ctx, &exprval, &retv, ei);
|
2008-09-11 23:54:45 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
VariantClear(&retv);
|
|
|
|
}
|
|
|
|
exprval_release(&exprval);
|
|
|
|
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
|
|
|
ret->u.var = retv;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-09-10 21:08:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 13 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT function_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-10 21:08:46 +02:00
|
|
|
function_expression_t *expr = (function_expression_t*)_expr;
|
|
|
|
VARIANT var;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
if(expr->identifier) {
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = jsdisp_propget_name(ctx->exec_ctx->var_disp, expr->identifier, &var, ei, NULL/*FIXME*/);
|
2008-10-20 22:12:42 +02:00
|
|
|
if(FAILED(hres))
|
2008-09-10 21:08:46 +02:00
|
|
|
return hres;
|
2008-10-20 22:12:42 +02:00
|
|
|
}else {
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *dispex;
|
2008-10-20 22:12:42 +02:00
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = create_source_function(ctx->exec_ctx->parser, expr->parameter_list, expr->source_elements, ctx->exec_ctx->scope_chain,
|
2008-10-20 22:12:42 +02:00
|
|
|
expr->src_str, expr->src_len, &dispex);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-09-07 15:41:40 +02:00
|
|
|
var_set_jsdisp(&var, dispex);
|
2008-09-10 21:08:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
|
|
|
ret->u.var = var;
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-10 21:11:15 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.12 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT conditional_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-10 21:11:15 +02:00
|
|
|
conditional_expression_t *expr = (conditional_expression_t*)_expr;
|
|
|
|
exprval_t exprval;
|
|
|
|
VARIANT_BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_boolean(ctx, &exprval, ei, &b);
|
2008-09-10 21:11:15 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return expr_eval(ctx, b ? expr->true_expression : expr->false_expression, flags, ei, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-10 21:07:06 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.2.1 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT array_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-10 21:07:06 +02:00
|
|
|
array_expression_t *expr = (array_expression_t*)_expr;
|
|
|
|
exprval_t exprval;
|
|
|
|
VARIANT member, val;
|
|
|
|
DISPID id;
|
|
|
|
BSTR str;
|
|
|
|
IDispatch *obj = NULL;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-12-06 22:10:44 +01:00
|
|
|
hres = expr_eval(ctx, expr->member_expr, 0, ei, &exprval);
|
2008-09-10 21:07:06 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, ei, &member);
|
2008-09-10 21:07:06 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
|
|
|
|
if(SUCCEEDED(hres)) {
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, ei, &val);
|
2008-09-10 21:07:06 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
}
|
|
|
|
|
2009-12-31 13:03:01 +01:00
|
|
|
if(SUCCEEDED(hres)) {
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_object(ctx, &member, &obj);
|
2009-12-31 13:03:01 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
VariantClear(&val);
|
|
|
|
}
|
2008-09-10 21:07:06 +02:00
|
|
|
VariantClear(&member);
|
|
|
|
if(SUCCEEDED(hres)) {
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_string(ctx, &val, ei, &str);
|
2009-12-31 13:03:01 +01:00
|
|
|
VariantClear(&val);
|
2008-09-10 21:07:06 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
if(flags & EXPR_STRREF) {
|
|
|
|
ret->type = EXPRVAL_NAMEREF;
|
|
|
|
ret->u.nameref.disp = obj;
|
|
|
|
ret->u.nameref.name = str;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = disp_get_id(ctx, obj, str, flags & EXPR_NEWREF ? fdexNameEnsure : 0, &id);
|
2009-12-31 13:03:01 +01:00
|
|
|
SysFreeString(str);
|
2008-09-10 21:07:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
exprval_set_idref(ret, obj, id);
|
|
|
|
}else if(!(flags & EXPR_NEWREF) && hres == DISP_E_UNKNOWNNAME) {
|
|
|
|
exprval_init(ret);
|
|
|
|
hres = S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDispatch_Release(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hres;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-09 01:27:18 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.2.1 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT member_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-09 01:27:18 +02:00
|
|
|
member_expression_t *expr = (member_expression_t*)_expr;
|
|
|
|
IDispatch *obj = NULL;
|
|
|
|
exprval_t exprval;
|
|
|
|
VARIANT member;
|
|
|
|
DISPID id;
|
|
|
|
BSTR str;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, ei, &member);
|
2008-09-09 01:27:18 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_object(ctx, &member, &obj);
|
2008-09-09 01:27:18 +02:00
|
|
|
VariantClear(&member);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
str = SysAllocString(expr->identifier);
|
|
|
|
if(flags & EXPR_STRREF) {
|
|
|
|
ret->type = EXPRVAL_NAMEREF;
|
|
|
|
ret->u.nameref.disp = obj;
|
|
|
|
ret->u.nameref.name = str;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = disp_get_id(ctx, obj, str, flags & EXPR_NEWREF ? fdexNameEnsure : 0, &id);
|
2008-09-09 01:27:18 +02:00
|
|
|
SysFreeString(str);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
exprval_set_idref(ret, obj, id);
|
|
|
|
}else if(!(flags & EXPR_NEWREF) && hres == DISP_E_UNKNOWNNAME) {
|
|
|
|
exprval_init(ret);
|
|
|
|
hres = S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDispatch_Release(obj);
|
|
|
|
return hres;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-09 01:25:05 +02:00
|
|
|
static void free_dp(DISPPARAMS *dp)
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
for(i=0; i < dp->cArgs; i++)
|
|
|
|
VariantClear(dp->rgvarg+i);
|
|
|
|
heap_free(dp->rgvarg);
|
|
|
|
}
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
static HRESULT args_to_param(script_ctx_t *ctx, argument_t *args, jsexcept_t *ei, DISPPARAMS *dp)
|
2008-09-09 01:25:05 +02:00
|
|
|
{
|
|
|
|
VARIANTARG *vargs;
|
|
|
|
exprval_t exprval;
|
|
|
|
argument_t *iter;
|
|
|
|
DWORD cnt = 0, i;
|
|
|
|
HRESULT hres = S_OK;
|
|
|
|
|
|
|
|
memset(dp, 0, sizeof(*dp));
|
2008-09-17 23:29:58 +02:00
|
|
|
if(!args)
|
|
|
|
return S_OK;
|
2008-09-09 01:25:05 +02:00
|
|
|
|
|
|
|
for(iter = args; iter; iter = iter->next)
|
|
|
|
cnt++;
|
|
|
|
|
|
|
|
vargs = heap_alloc_zero(cnt * sizeof(*vargs));
|
|
|
|
if(!vargs)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
for(i = cnt, iter = args; iter; iter = iter->next) {
|
|
|
|
hres = expr_eval(ctx, iter->expr, 0, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, ei, vargs + (--i));
|
2008-09-09 01:25:05 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
free_dp(dp);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
dp->rgvarg = vargs;
|
|
|
|
dp->cArgs = cnt;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-09-10 21:07:35 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.2.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT new_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-10 21:07:35 +02:00
|
|
|
call_expression_t *expr = (call_expression_t*)_expr;
|
|
|
|
exprval_t exprval;
|
|
|
|
VARIANT constr, var;
|
|
|
|
DISPPARAMS dp;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = args_to_param(ctx, expr->argument_list, ei, &dp);
|
|
|
|
if(SUCCEEDED(hres))
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, ei, &constr);
|
2008-09-10 21:07:35 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-01 20:19:29 +02:00
|
|
|
/* NOTE: Should use to_object here */
|
|
|
|
|
|
|
|
if(V_VT(&constr) == VT_NULL) {
|
|
|
|
VariantClear(&constr);
|
2010-12-28 15:04:59 +01:00
|
|
|
return throw_type_error(ctx, ei, JS_E_OBJECT_EXPECTED, NULL);
|
2010-10-01 20:19:29 +02:00
|
|
|
} else if(V_VT(&constr) != VT_DISPATCH) {
|
|
|
|
VariantClear(&constr);
|
2010-12-28 15:04:59 +01:00
|
|
|
return throw_type_error(ctx, ei, JS_E_INVALID_ACTION, NULL);
|
2010-10-01 20:19:29 +02:00
|
|
|
} else if(!V_DISPATCH(&constr)) {
|
2008-09-10 21:07:35 +02:00
|
|
|
VariantClear(&constr);
|
2010-12-28 15:04:59 +01:00
|
|
|
return throw_type_error(ctx, ei, JS_E_INVALID_PROPERTY, NULL);
|
2008-09-10 21:07:35 +02:00
|
|
|
}
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = disp_call(ctx, V_DISPATCH(&constr), DISPID_VALUE,
|
|
|
|
DISPATCH_CONSTRUCT, &dp, &var, ei, NULL/*FIXME*/);
|
2008-09-10 21:07:35 +02:00
|
|
|
IDispatch_Release(V_DISPATCH(&constr));
|
2009-12-31 13:03:01 +01:00
|
|
|
free_dp(&dp);
|
2008-09-10 21:07:35 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
|
|
|
ret->u.var = var;
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:45:50 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.2.3 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT call_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-09 01:25:05 +02:00
|
|
|
call_expression_t *expr = (call_expression_t*)_expr;
|
2008-12-10 10:05:50 +01:00
|
|
|
VARIANT var;
|
2008-09-09 01:25:05 +02:00
|
|
|
exprval_t exprval;
|
|
|
|
DISPPARAMS dp;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = args_to_param(ctx, expr->argument_list, ei, &dp);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
switch(exprval.type) {
|
2009-07-14 01:36:27 +02:00
|
|
|
case EXPRVAL_VARIANT:
|
2009-09-02 12:33:08 +02:00
|
|
|
if(V_VT(&exprval.u.var) == VT_DISPATCH)
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = disp_call(ctx, V_DISPATCH(&exprval.u.var), DISPID_VALUE,
|
2009-09-02 12:33:08 +02:00
|
|
|
DISPATCH_METHOD, &dp, flags & EXPR_NOVAL ? NULL : &var, ei, NULL/*FIXME*/);
|
|
|
|
else
|
2010-12-28 15:04:59 +01:00
|
|
|
hres = throw_type_error(ctx, ei, JS_E_INVALID_PROPERTY, NULL);
|
2009-07-14 01:36:27 +02:00
|
|
|
break;
|
2008-09-09 01:25:05 +02:00
|
|
|
case EXPRVAL_IDREF:
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = disp_call(ctx, exprval.u.idref.disp, exprval.u.idref.id,
|
2009-07-14 01:36:27 +02:00
|
|
|
DISPATCH_METHOD, &dp, flags & EXPR_NOVAL ? NULL : &var, ei, NULL/*FIXME*/);
|
2008-09-09 01:25:05 +02:00
|
|
|
break;
|
2009-09-02 12:33:08 +02:00
|
|
|
case EXPRVAL_INVALID:
|
2010-12-28 15:04:59 +01:00
|
|
|
hres = throw_type_error(ctx, ei, JS_E_OBJECT_EXPECTED, NULL);
|
2009-09-02 12:33:08 +02:00
|
|
|
break;
|
2008-09-09 01:25:05 +02:00
|
|
|
default:
|
2008-12-10 10:05:50 +01:00
|
|
|
FIXME("unimplemented type %d\n", exprval.type);
|
2008-09-09 01:25:05 +02:00
|
|
|
hres = E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
free_dp(&dp);
|
|
|
|
}
|
|
|
|
|
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
2009-07-14 01:36:27 +02:00
|
|
|
if(flags & EXPR_NOVAL) {
|
|
|
|
V_VT(&ret->u.var) = VT_EMPTY;
|
|
|
|
}else {
|
|
|
|
TRACE("= %s\n", debugstr_variant(&var));
|
|
|
|
ret->u.var = var;
|
|
|
|
}
|
2008-09-09 01:25:05 +02:00
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:45:50 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.1.1 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT this_expression_eval(script_ctx_t *ctx, expression_t *expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-10 21:05:14 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
|
|
|
V_VT(&ret->u.var) = VT_DISPATCH;
|
2010-10-23 16:41:55 +02:00
|
|
|
V_DISPATCH(&ret->u.var) = ctx->exec_ctx->this_obj;
|
|
|
|
IDispatch_AddRef(ctx->exec_ctx->this_obj);
|
2008-09-10 21:05:14 +02:00
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-09 01:22:13 +02:00
|
|
|
/* ECMA-262 3rd Edition 10.1.4 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT identifier_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-09 01:22:13 +02:00
|
|
|
identifier_expression_t *expr = (identifier_expression_t*)_expr;
|
|
|
|
BSTR identifier;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
identifier = SysAllocString(expr->identifier);
|
|
|
|
if(!identifier)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2009-07-22 13:01:59 +02:00
|
|
|
hres = identifier_eval(ctx, identifier, flags, ei, ret);
|
2008-09-09 01:22:13 +02:00
|
|
|
|
|
|
|
SysFreeString(identifier);
|
|
|
|
return hres;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-09 01:23:41 +02:00
|
|
|
/* ECMA-262 3rd Edition 7.8 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT literal_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-09 01:23:41 +02:00
|
|
|
literal_expression_t *expr = (literal_expression_t*)_expr;
|
|
|
|
VARIANT var;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = literal_to_var(ctx, expr->literal, &var);
|
2008-09-09 01:23:41 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
|
|
|
ret->u.var = var;
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:34:23 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.1.4 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT array_literal_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-17 23:34:23 +02:00
|
|
|
array_literal_expression_t *expr = (array_literal_expression_t*)_expr;
|
|
|
|
DWORD length = 0, i = 0;
|
|
|
|
array_element_t *elem;
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *array;
|
2008-09-17 23:34:23 +02:00
|
|
|
exprval_t exprval;
|
|
|
|
VARIANT val;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
for(elem = expr->element_list; elem; elem = elem->next)
|
|
|
|
length += elem->elision+1;
|
|
|
|
length += expr->length;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = create_array(ctx, length, &array);
|
2008-09-17 23:34:23 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
for(elem = expr->element_list; elem; elem = elem->next) {
|
|
|
|
i += elem->elision;
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, elem->expr, 0, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, ei, &val);
|
2008-09-17 23:34:23 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
2009-09-23 16:11:11 +02:00
|
|
|
hres = jsdisp_propput_idx(array, i, &val, ei, NULL/*FIXME*/);
|
2008-09-17 23:34:23 +02:00
|
|
|
VariantClear(&val);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
jsdisp_release(array);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
2010-09-07 15:41:40 +02:00
|
|
|
var_set_jsdisp(&ret->u.var, array);
|
2008-09-17 23:34:23 +02:00
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-10 21:10:23 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.1.5 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT property_value_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-10 21:10:23 +02:00
|
|
|
property_value_expression_t *expr = (property_value_expression_t*)_expr;
|
|
|
|
VARIANT val, tmp;
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *obj;
|
2008-09-10 21:10:23 +02:00
|
|
|
prop_val_t *iter;
|
|
|
|
exprval_t exprval;
|
|
|
|
BSTR name;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = create_object(ctx, NULL, &obj);
|
2008-09-10 21:10:23 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
for(iter = expr->property_list; iter; iter = iter->next) {
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = literal_to_var(ctx, iter->name, &tmp);
|
2008-09-10 21:10:23 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_string(ctx, &tmp, ei, &name);
|
2008-09-10 21:10:23 +02:00
|
|
|
VariantClear(&tmp);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, iter->value, 0, ei, &exprval);
|
|
|
|
if(SUCCEEDED(hres)) {
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, ei, &val);
|
2008-09-10 21:10:23 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(SUCCEEDED(hres)) {
|
2009-09-23 16:11:11 +02:00
|
|
|
hres = jsdisp_propput_name(obj, name, &val, ei, NULL/*FIXME*/);
|
2008-09-10 21:10:23 +02:00
|
|
|
VariantClear(&val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SysFreeString(name);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
jsdisp_release(obj);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
2010-09-07 15:41:40 +02:00
|
|
|
var_set_jsdisp(&ret->u.var, obj);
|
2008-09-10 21:10:23 +02:00
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:32:43 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.14 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT comma_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-17 23:32:43 +02:00
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
VARIANT lval, rval;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
VariantClear(&lval);
|
|
|
|
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
|
|
|
ret->u.var = rval;
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-11 23:55:14 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.11 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT logical_or_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-11 23:55:14 +02:00
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
exprval_t exprval;
|
|
|
|
VARIANT_BOOL b;
|
|
|
|
VARIANT val;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, ei, &val);
|
2008-09-11 23:55:14 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = to_boolean(&val, &b);
|
|
|
|
if(SUCCEEDED(hres) && b) {
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
|
|
|
ret->u.var = val;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
VariantClear(&val);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, ei, &val);
|
2008-09-11 23:55:14 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
|
|
|
ret->u.var = val;
|
|
|
|
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 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT logical_and_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-11 23:55:38 +02:00
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
exprval_t exprval;
|
|
|
|
VARIANT_BOOL b;
|
|
|
|
VARIANT val;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, ei, &val);
|
2008-09-11 23:55:38 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = to_boolean(&val, &b);
|
|
|
|
if(SUCCEEDED(hres) && !b) {
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
|
|
|
ret->u.var = val;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
VariantClear(&val);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, ei, &val);
|
2008-09-11 23:55:38 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
|
|
|
ret->u.var = val;
|
|
|
|
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 */
|
2010-10-23 16:41:55 +02:00
|
|
|
static HRESULT bitor_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-17 23:31:02 +02:00
|
|
|
INT li, ri;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_int32(ctx, lval, ei, &li);
|
2008-09-17 23:31:02 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_int32(ctx, rval, ei, &ri);
|
2008-09-17 23:31:02 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
V_VT(retv) = VT_I4;
|
|
|
|
V_I4(retv) = li|ri;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.10 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT binary_or_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-17 23:31:02 +02:00
|
|
|
{
|
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return binary_expr_eval(ctx, expr, bitor_eval, ei, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:32:11 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.10 */
|
2010-10-23 16:41:55 +02:00
|
|
|
static HRESULT xor_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-17 23:32:11 +02:00
|
|
|
INT li, ri;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_int32(ctx, lval, ei, &li);
|
2008-09-17 23:32:11 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_int32(ctx, rval, ei, &ri);
|
2008-09-17 23:32:11 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
V_VT(retv) = VT_I4;
|
|
|
|
V_I4(retv) = li^ri;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.10 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT binary_xor_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-17 23:32:11 +02:00
|
|
|
{
|
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return binary_expr_eval(ctx, expr, xor_eval, ei, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:31:38 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.10 */
|
2010-10-23 16:41:55 +02:00
|
|
|
static HRESULT bitand_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-17 23:31:38 +02:00
|
|
|
INT li, ri;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_int32(ctx, lval, ei, &li);
|
2008-09-17 23:31:38 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_int32(ctx, rval, ei, &ri);
|
2008-09-17 23:31:38 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
V_VT(retv) = VT_I4;
|
|
|
|
V_I4(retv) = li&ri;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.10 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT binary_and_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-17 23:31:38 +02:00
|
|
|
{
|
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return binary_expr_eval(ctx, expr, bitand_eval, ei, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:45:50 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.8.6 */
|
2010-10-23 16:41:55 +02:00
|
|
|
static HRESULT instanceof_eval(script_ctx_t *ctx, VARIANT *inst, VARIANT *objv, jsexcept_t *ei, VARIANT *retv)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *obj, *iter, *tmp = NULL;
|
2009-08-29 00:01:25 +02:00
|
|
|
VARIANT_BOOL ret = VARIANT_FALSE;
|
|
|
|
BOOL b;
|
|
|
|
VARIANT var;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
static const WCHAR prototypeW[] = {'p','r','o','t','o','t', 'y', 'p','e',0};
|
|
|
|
|
2010-08-16 12:36:34 +02:00
|
|
|
if(V_VT(objv) != VT_DISPATCH || !V_DISPATCH(objv))
|
2010-12-28 15:04:59 +01:00
|
|
|
return throw_type_error(ctx, ei, JS_E_FUNCTION_EXPECTED, NULL);
|
2009-08-29 00:01:25 +02:00
|
|
|
|
|
|
|
obj = iface_to_jsdisp((IUnknown*)V_DISPATCH(objv));
|
|
|
|
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)) {
|
2009-09-23 16:10:36 +02:00
|
|
|
hres = jsdisp_propget_name(obj, prototypeW, &var, ei, NULL/*FIXME*/);
|
2009-08-29 00:01:25 +02:00
|
|
|
}else {
|
2011-06-21 17:46:04 +02:00
|
|
|
hres = throw_type_error(ctx, ei, JS_E_FUNCTION_EXPECTED, NULL);
|
2009-08-29 00:01:25 +02:00
|
|
|
}
|
|
|
|
jsdisp_release(obj);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(V_VT(&var) == VT_DISPATCH) {
|
|
|
|
if(V_VT(inst) == VT_DISPATCH)
|
|
|
|
tmp = iface_to_jsdisp((IUnknown*)V_DISPATCH(inst));
|
|
|
|
for(iter = tmp; iter; iter = iter->prototype) {
|
2010-09-07 15:42:01 +02:00
|
|
|
hres = disp_cmp(V_DISPATCH(&var), to_disp(iter), &b);
|
2009-08-29 00:01:25 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
if(b) {
|
|
|
|
ret = VARIANT_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tmp)
|
|
|
|
jsdisp_release(tmp);
|
|
|
|
}else {
|
|
|
|
FIXME("prototype is not an object\n");
|
|
|
|
hres = E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
VariantClear(&var);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
V_VT(retv) = VT_BOOL;
|
|
|
|
V_BOOL(retv) = ret;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.8.6 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT instanceof_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2009-08-29 00:01:25 +02:00
|
|
|
{
|
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return binary_expr_eval(ctx, expr, instanceof_eval, ei, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:45:50 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.8.7 */
|
2010-10-23 16:41:55 +02:00
|
|
|
static HRESULT in_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *obj, jsexcept_t *ei, VARIANT *retv)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2009-09-06 19:10:06 +02:00
|
|
|
VARIANT_BOOL ret;
|
|
|
|
DISPID id;
|
|
|
|
BSTR str;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2010-08-16 12:36:59 +02:00
|
|
|
if(V_VT(obj) != VT_DISPATCH || !V_DISPATCH(obj))
|
2010-12-28 15:04:59 +01:00
|
|
|
return throw_type_error(ctx, ei, JS_E_OBJECT_EXPECTED, NULL);
|
2009-09-06 19:10:06 +02:00
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_string(ctx, lval, ei, &str);
|
2009-09-06 19:10:06 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = disp_get_id(ctx, V_DISPATCH(obj), str, 0, &id);
|
2009-09-06 19:10:06 +02:00
|
|
|
SysFreeString(str);
|
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
ret = VARIANT_TRUE;
|
|
|
|
else if(hres == DISP_E_UNKNOWNNAME)
|
|
|
|
ret = VARIANT_FALSE;
|
|
|
|
else
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
V_VT(retv) = VT_BOOL;
|
|
|
|
V_BOOL(retv) = ret;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.8.7 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT in_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2009-09-06 19:10:06 +02:00
|
|
|
{
|
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return binary_expr_eval(ctx, expr, in_eval, ei, 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);
|
|
|
|
memcpy(V_BSTR(retv), lstr, len1*sizeof(WCHAR));
|
|
|
|
memcpy(V_BSTR(retv)+len1, rstr, (len2+1)*sizeof(WCHAR));
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
VARIANT nl, nr;
|
|
|
|
|
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))
|
|
|
|
num_set_val(retv, num_val(&nl) + num_val(&nr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VariantClear(&r);
|
|
|
|
VariantClear(&l);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.6.1 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT add_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-10 21:12:45 +02:00
|
|
|
{
|
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return binary_expr_eval(ctx, expr, add_eval, ei, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-16 20:46:01 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.6.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
static HRESULT sub_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-16 20:46:01 +02:00
|
|
|
VARIANT lnum, rnum;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_number(ctx, lval, ei, &lnum);
|
2008-09-16 20:46:01 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_number(ctx, rval, ei, &rnum);
|
2008-09-16 20:46:01 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
num_set_val(retv, num_val(&lnum) - num_val(&rnum));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.6.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT sub_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-16 20:46:01 +02:00
|
|
|
{
|
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return binary_expr_eval(ctx, expr, sub_eval, ei, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-16 20:46:33 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.5.1 */
|
2010-10-23 16:41:55 +02:00
|
|
|
static HRESULT mul_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-16 20:46:33 +02:00
|
|
|
VARIANT lnum, rnum;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_number(ctx, lval, ei, &lnum);
|
2008-09-16 20:46:33 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_number(ctx, rval, ei, &rnum);
|
2008-09-16 20:46:33 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
num_set_val(retv, num_val(&lnum) * num_val(&rnum));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.5.1 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT mul_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-16 20:46:33 +02:00
|
|
|
{
|
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return binary_expr_eval(ctx, expr, mul_eval, ei, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-16 20:47:06 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.5.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
static HRESULT div_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-16 20:47:06 +02:00
|
|
|
VARIANT lnum, rnum;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_number(ctx, lval, ei, &lnum);
|
2008-09-16 20:47:06 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_number(ctx, rval, ei, &rnum);
|
2008-09-16 20:47:06 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
num_set_val(retv, num_val(&lnum) / num_val(&rnum));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.5.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT div_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-16 20:47:06 +02:00
|
|
|
{
|
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return binary_expr_eval(ctx, expr, div_eval, ei, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:45:50 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.5.3 */
|
2010-10-23 16:41:55 +02:00
|
|
|
static HRESULT mod_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-10-09 01:09:17 +02:00
|
|
|
VARIANT lnum, rnum;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_number(ctx, lval, ei, &lnum);
|
2008-10-09 01:09:17 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_number(ctx, rval, ei, &rnum);
|
2008-10-09 01:09:17 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
num_set_val(retv, fmod(num_val(&lnum), num_val(&rnum)));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.5.3 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT mod_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-10-09 01:09:17 +02:00
|
|
|
{
|
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return binary_expr_eval(ctx, expr, mod_eval, ei, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:43:37 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.4.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT delete_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-19 00:43:37 +02:00
|
|
|
unary_expression_t *expr = (unary_expression_t*)_expr;
|
|
|
|
VARIANT_BOOL b = VARIANT_FALSE;
|
|
|
|
exprval_t exprval;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, expr->expression, EXPR_STRREF, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
switch(exprval.type) {
|
2008-09-30 17:48:45 +02:00
|
|
|
case EXPRVAL_IDREF: {
|
|
|
|
IDispatchEx *dispex;
|
|
|
|
|
|
|
|
hres = IDispatch_QueryInterface(exprval.u.nameref.disp, &IID_IDispatchEx, (void**)&dispex);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = IDispatchEx_DeleteMemberByDispID(dispex, exprval.u.idref.id);
|
|
|
|
b = VARIANT_TRUE;
|
|
|
|
IDispatchEx_Release(dispex);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-09-19 00:43:37 +02:00
|
|
|
case EXPRVAL_NAMEREF: {
|
|
|
|
IDispatchEx *dispex;
|
|
|
|
|
|
|
|
hres = IDispatch_QueryInterface(exprval.u.nameref.disp, &IID_IDispatchEx, (void**)&dispex);
|
|
|
|
if(SUCCEEDED(hres)) {
|
2009-10-19 20:40:17 +02:00
|
|
|
hres = IDispatchEx_DeleteMemberByName(dispex, exprval.u.nameref.name,
|
2010-10-23 16:41:55 +02:00
|
|
|
make_grfdex(ctx, fdexNameCaseSensitive));
|
2008-09-19 00:43:37 +02:00
|
|
|
b = VARIANT_TRUE;
|
|
|
|
IDispatchEx_Release(dispex);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
FIXME("unsupported type %d\n", exprval.type);
|
|
|
|
hres = E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return return_bool(ret, b);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:42:33 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.4.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT void_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-19 00:42:33 +02:00
|
|
|
unary_expression_t *expr = (unary_expression_t*)_expr;
|
|
|
|
exprval_t exprval;
|
|
|
|
VARIANT tmp;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, ei, &tmp);
|
2008-09-19 00:42:33 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
VariantClear(&tmp);
|
|
|
|
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
|
|
|
V_VT(&ret->u.var) = VT_EMPTY;
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:42:33 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.4.3 */
|
2010-10-23 16:41:55 +02:00
|
|
|
static HRESULT typeof_exprval(script_ctx_t *ctx, exprval_t *exprval, jsexcept_t *ei, const WCHAR **ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-10 02:36:03 +02:00
|
|
|
VARIANT val;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
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};
|
2010-12-29 16:02:25 +01:00
|
|
|
static const WCHAR unknownW[] = {'u','n','k','n','o','w','n',0};
|
2008-09-10 02:36:03 +02:00
|
|
|
|
2009-08-27 01:21:56 +02:00
|
|
|
if(exprval->type == EXPRVAL_INVALID) {
|
|
|
|
*ret = undefinedW;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2008-09-10 02:36:03 +02:00
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, exprval, ei, &val);
|
2010-12-29 16:02:25 +01:00
|
|
|
if(FAILED(hres)) {
|
|
|
|
if(exprval->type == EXPRVAL_IDREF) {
|
|
|
|
*ret = unknownW;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2008-09-10 02:36:03 +02:00
|
|
|
return hres;
|
2010-12-29 16:02:25 +01:00
|
|
|
}
|
2008-09-10 02:36:03 +02:00
|
|
|
|
|
|
|
switch(V_VT(&val)) {
|
|
|
|
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
|
|
|
|
2009-09-06 19:09:30 +02:00
|
|
|
if(V_DISPATCH(&val) && (dispex = iface_to_jsdisp((IUnknown*)V_DISPATCH(&val)))) {
|
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:
|
|
|
|
FIXME("unhandled vt %d\n", V_VT(&val));
|
2009-08-27 01:21:56 +02:00
|
|
|
hres = E_NOTIMPL;
|
2008-09-10 02:36:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VariantClear(&val);
|
2011-01-27 13:38:36 +01:00
|
|
|
return hres;
|
2009-08-27 01:21:56 +02:00
|
|
|
}
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT typeof_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2009-08-27 01:21:56 +02:00
|
|
|
{
|
|
|
|
unary_expression_t *expr = (unary_expression_t*)_expr;
|
|
|
|
const WCHAR *str = NULL;
|
|
|
|
exprval_t exprval;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = typeof_exprval(ctx, &exprval, ei, &str);
|
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2008-09-10 02:36:03 +02:00
|
|
|
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
|
|
|
V_VT(&ret->u.var) = VT_BSTR;
|
|
|
|
V_BSTR(&ret->u.var) = SysAllocString(str);
|
2009-08-27 01:21:56 +02:00
|
|
|
if(!V_BSTR(&ret->u.var))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2008-09-10 02:36:03 +02:00
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-16 20:47:43 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.4.7 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT minus_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-16 20:47:43 +02:00
|
|
|
unary_expression_t *expr = (unary_expression_t*)_expr;
|
|
|
|
exprval_t exprval;
|
|
|
|
VARIANT val, num;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, ei, &val);
|
2008-09-16 20:47:43 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_number(ctx, &val, ei, &num);
|
2008-09-16 20:47:43 +02:00
|
|
|
VariantClear(&val);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
|
|
|
num_set_val(&ret->u.var, -num_val(&num));
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:33:15 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.4.6 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT plus_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-17 23:33:15 +02:00
|
|
|
unary_expression_t *expr = (unary_expression_t*)_expr;
|
|
|
|
exprval_t exprval;
|
|
|
|
VARIANT val, num;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, ei, &val);
|
2008-09-17 23:33:15 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_number(ctx, &val, ei, &num);
|
2009-12-31 13:03:01 +01:00
|
|
|
VariantClear(&val);
|
2008-09-17 23:33:15 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
|
|
|
ret->u.var = num;
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-11 23:58:28 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.3.1 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT post_increment_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-11 23:58:28 +02:00
|
|
|
unary_expression_t *expr = (unary_expression_t*)_expr;
|
|
|
|
VARIANT val, num;
|
|
|
|
exprval_t exprval;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_value(ctx, &exprval, ei, &val);
|
2008-09-11 23:58:28 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_number(ctx, &val, ei, &num);
|
2008-09-11 23:58:28 +02:00
|
|
|
VariantClear(&val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
VARIANT inc;
|
|
|
|
num_set_val(&inc, num_val(&num)+1.0);
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = put_value(ctx, &exprval, &inc, ei);
|
2008-09-11 23:58:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
|
|
|
ret->u.var = num;
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-11 23:58:48 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.3.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT post_decrement_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-11 23:58:48 +02:00
|
|
|
unary_expression_t *expr = (unary_expression_t*)_expr;
|
|
|
|
VARIANT val, num;
|
|
|
|
exprval_t exprval;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_value(ctx, &exprval, ei, &val);
|
2008-09-11 23:58:48 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_number(ctx, &val, ei, &num);
|
2008-09-11 23:58:48 +02:00
|
|
|
VariantClear(&val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
VARIANT dec;
|
|
|
|
num_set_val(&dec, num_val(&num)-1.0);
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = put_value(ctx, &exprval, &dec, ei);
|
2008-09-11 23:58:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
|
|
|
ret->u.var = num;
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-11 23:57:40 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.4.4 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT pre_increment_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-11 23:57:40 +02:00
|
|
|
unary_expression_t *expr = (unary_expression_t*)_expr;
|
|
|
|
VARIANT val, num;
|
|
|
|
exprval_t exprval;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_value(ctx, &exprval, ei, &val);
|
2008-09-11 23:57:40 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_number(ctx, &val, ei, &num);
|
2008-09-11 23:57:40 +02:00
|
|
|
VariantClear(&val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
num_set_val(&val, num_val(&num)+1.0);
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = put_value(ctx, &exprval, &val, ei);
|
2008-09-11 23:57:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
|
|
|
ret->u.var = val;
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-11 23:58:03 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.4.5 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT pre_decrement_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-11 23:58:03 +02:00
|
|
|
unary_expression_t *expr = (unary_expression_t*)_expr;
|
|
|
|
VARIANT val, num;
|
|
|
|
exprval_t exprval;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_value(ctx, &exprval, ei, &val);
|
2008-09-11 23:58:03 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_number(ctx, &val, ei, &num);
|
2008-09-11 23:58:03 +02:00
|
|
|
VariantClear(&val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
num_set_val(&val, num_val(&num)-1.0);
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = put_value(ctx, &exprval, &val, ei);
|
2008-09-11 23:58:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
|
|
|
ret->u.var = val;
|
|
|
|
return S_OK;
|
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;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_number(ctx, lval, ei, &v);
|
2008-09-17 23:29:16 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return equal_values(ctx, &v, rval, ei, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(V_VT(rval) == VT_BSTR && is_num_vt(V_VT(lval))) {
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_number(ctx, rval, ei, &v);
|
2008-09-17 23:29:16 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
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 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT equal_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-17 23:29:16 +02:00
|
|
|
{
|
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
VARIANT rval, lval;
|
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = get_binary_expr_values(ctx, expr, ei, &rval, &lval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = equal_values(ctx, &rval, &lval, ei, &b);
|
2009-12-31 13:03:01 +01:00
|
|
|
VariantClear(&lval);
|
|
|
|
VariantClear(&rval);
|
2008-09-17 23:29:16 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return return_bool(ret, b);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-09 01:26:20 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.9.4 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT equal2_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-09 01:26:20 +02:00
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
VARIANT rval, lval;
|
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = get_binary_expr_values(ctx, expr, ei, &rval, &lval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = equal2_values(&rval, &lval, &b);
|
2009-12-31 13:03:01 +01:00
|
|
|
VariantClear(&lval);
|
|
|
|
VariantClear(&rval);
|
2008-09-09 01:26:20 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return return_bool(ret, b);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:29:34 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.9.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT not_equal_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-17 23:29:34 +02:00
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
VARIANT rval, lval;
|
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
2008-09-03 00:25:21 +02:00
|
|
|
|
2008-09-17 23:29:34 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = equal_values(ctx, &lval, &rval, ei, &b);
|
2009-12-31 13:03:01 +01:00
|
|
|
VariantClear(&lval);
|
|
|
|
VariantClear(&rval);
|
2008-09-17 23:29:34 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return return_bool(ret, !b);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-09 01:26:37 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.9.5 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT not_equal2_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-09 01:26:37 +02:00
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
VARIANT rval, lval;
|
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2008-09-19 00:45:50 +02:00
|
|
|
hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
|
2008-09-09 01:26:37 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2008-09-19 00:45:50 +02:00
|
|
|
hres = equal2_values(&lval, &rval, &b);
|
2009-12-31 13:03:01 +01:00
|
|
|
VariantClear(&lval);
|
|
|
|
VariantClear(&rval);
|
2008-09-09 01:26:37 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return return_bool(ret, !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
|
|
|
{
|
2008-09-11 23:56:03 +02:00
|
|
|
VARIANT l, r, ln, rn;
|
|
|
|
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;
|
|
|
|
|
2008-10-16 21:31:30 +02:00
|
|
|
if(V_VT(&ln) == VT_I4 && V_VT(&rn) == VT_I4) {
|
|
|
|
*ret = (V_I4(&ln) < V_I4(&rn)) ^ greater;
|
|
|
|
}else {
|
|
|
|
DOUBLE ld = num_val(&ln);
|
|
|
|
DOUBLE rd = num_val(&rn);
|
|
|
|
|
|
|
|
*ret = !isnan(ld) && !isnan(rd) && ((ld < rd) ^ greater);
|
|
|
|
}
|
2008-09-11 23:56:03 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.8.1 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT less_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-11 23:56:03 +02:00
|
|
|
{
|
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
VARIANT rval, lval;
|
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2008-10-16 21:31:30 +02:00
|
|
|
hres = less_eval(ctx, &lval, &rval, FALSE, ei, &b);
|
2008-09-11 23:56:03 +02:00
|
|
|
VariantClear(&lval);
|
|
|
|
VariantClear(&rval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return return_bool(ret, b);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-11 23:56:29 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.8.3 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT lesseq_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-11 23:56:29 +02:00
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
VARIANT rval, lval;
|
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2008-10-16 21:31:30 +02:00
|
|
|
hres = less_eval(ctx, &rval, &lval, TRUE, ei, &b);
|
2008-09-11 23:56:29 +02:00
|
|
|
VariantClear(&lval);
|
|
|
|
VariantClear(&rval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2008-10-16 21:31:30 +02:00
|
|
|
return return_bool(ret, b);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-11 23:56:51 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.8.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT greater_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-11 23:56:51 +02:00
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
VARIANT rval, lval;
|
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2008-10-16 21:31:30 +02:00
|
|
|
hres = less_eval(ctx, &rval, &lval, FALSE, ei, &b);
|
2008-09-11 23:56:51 +02:00
|
|
|
VariantClear(&lval);
|
|
|
|
VariantClear(&rval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return return_bool(ret, b);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-11 23:57:13 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.8.4 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT greatereq_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-11 23:57:13 +02:00
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
VARIANT rval, lval;
|
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2008-10-16 21:31:30 +02:00
|
|
|
hres = less_eval(ctx, &lval, &rval, TRUE, ei, &b);
|
2008-09-11 23:57:13 +02:00
|
|
|
VariantClear(&lval);
|
|
|
|
VariantClear(&rval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2008-10-16 21:31:30 +02:00
|
|
|
return return_bool(ret, b);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:32:59 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.4.8 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT binary_negation_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-17 23:32:59 +02:00
|
|
|
unary_expression_t *expr = (unary_expression_t*)_expr;
|
|
|
|
exprval_t exprval;
|
|
|
|
VARIANT val;
|
|
|
|
INT i;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprval, ei, &val);
|
2008-09-17 23:32:59 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_int32(ctx, &val, ei, &i);
|
2008-09-17 23:32:59 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
|
|
|
V_VT(&ret->u.var) = VT_I4;
|
|
|
|
V_I4(&ret->u.var) = ~i;
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-09 01:25:40 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.4.9 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT logical_negation_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-09 01:25:40 +02:00
|
|
|
unary_expression_t *expr = (unary_expression_t*)_expr;
|
|
|
|
exprval_t exprval;
|
|
|
|
VARIANT_BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_boolean(ctx, &exprval, ei, &b);
|
2008-09-09 01:25:40 +02:00
|
|
|
exprval_release(&exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return return_bool(ret, !b);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:44:11 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.7.1 */
|
2010-10-23 16:41:55 +02:00
|
|
|
static HRESULT lshift_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
|
2008-09-19 00:44:11 +02:00
|
|
|
{
|
|
|
|
DWORD ri;
|
|
|
|
INT li;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_int32(ctx, lval, ei, &li);
|
2008-09-19 00:44:11 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_uint32(ctx, rval, ei, &ri);
|
2008-09-19 00:44:11 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
V_VT(retv) = VT_I4;
|
|
|
|
V_I4(retv) = li << (ri&0x1f);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.7.1 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT left_shift_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-19 00:44:11 +02:00
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return binary_expr_eval(ctx, expr, lshift_eval, ei, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:44:29 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.7.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
static HRESULT rshift_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
|
2008-09-19 00:44:29 +02:00
|
|
|
{
|
|
|
|
DWORD ri;
|
|
|
|
INT li;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_int32(ctx, lval, ei, &li);
|
2008-09-19 00:44:29 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_uint32(ctx, rval, ei, &ri);
|
2008-09-19 00:44:29 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
V_VT(retv) = VT_I4;
|
|
|
|
V_I4(retv) = li >> (ri&0x1f);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.7.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT right_shift_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-19 00:44:29 +02:00
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return binary_expr_eval(ctx, expr, rshift_eval, ei, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:44:49 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.7.3 */
|
2010-10-23 16:41:55 +02:00
|
|
|
static HRESULT rshift2_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
|
2008-09-19 00:44:49 +02:00
|
|
|
{
|
|
|
|
DWORD li, ri;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_uint32(ctx, lval, ei, &li);
|
2008-09-19 00:44:49 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = to_uint32(ctx, rval, ei, &ri);
|
2008-09-19 00:44:49 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
V_VT(retv) = VT_I4;
|
|
|
|
V_I4(retv) = li >> (ri&0x1f);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.7.3 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT right2_shift_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-19 00:44:49 +02:00
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return binary_expr_eval(ctx, expr, rshift2_eval, ei, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-09 01:23:21 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.13.1 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT assign_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-09 01:23:21 +02:00
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
exprval_t exprval, exprvalr;
|
|
|
|
VARIANT rval;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, expr->expression1, EXPR_NEWREF, ei, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = expr_eval(ctx, expr->expression2, 0, ei, &exprvalr);
|
|
|
|
if(SUCCEEDED(hres)) {
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = exprval_to_value(ctx, &exprvalr, ei, &rval);
|
2008-09-09 01:23:21 +02:00
|
|
|
exprval_release(&exprvalr);
|
|
|
|
}
|
|
|
|
|
2009-12-31 13:03:01 +01:00
|
|
|
if(SUCCEEDED(hres)) {
|
2010-10-23 16:41:55 +02:00
|
|
|
hres = put_value(ctx, &exprval, &rval, ei);
|
2009-12-31 13:03:01 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
VariantClear(&rval);
|
|
|
|
}
|
2008-09-09 01:23:21 +02:00
|
|
|
|
|
|
|
exprval_release(&exprval);
|
2008-09-30 17:47:55 +02:00
|
|
|
if(FAILED(hres))
|
2008-09-09 01:23:21 +02:00
|
|
|
return hres;
|
|
|
|
|
|
|
|
ret->type = EXPRVAL_VARIANT;
|
|
|
|
ret->u.var = rval;
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:45:05 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.13.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT assign_lshift_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-19 00:45:05 +02:00
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return assign_oper_eval(ctx, expr->expression1, expr->expression2, lshift_eval, ei, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:45:20 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.13.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT assign_rshift_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-19 00:45:20 +02:00
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return assign_oper_eval(ctx, expr->expression1, expr->expression2, rshift_eval, ei, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:45:35 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.13.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT assign_rrshift_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-19 00:45:35 +02:00
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return assign_oper_eval(ctx, expr->expression1, expr->expression2, rshift2_eval, ei, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-11 23:54:45 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.13.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT assign_add_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-11 23:54:45 +02:00
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return assign_oper_eval(ctx, expr->expression1, expr->expression2, add_eval, ei, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-16 20:46:17 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.13.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT assign_sub_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-16 20:46:17 +02:00
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return assign_oper_eval(ctx, expr->expression1, expr->expression2, sub_eval, ei, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-16 20:46:49 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.13.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT assign_mul_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-16 20:46:49 +02:00
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return assign_oper_eval(ctx, expr->expression1, expr->expression2, mul_eval, ei, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-16 20:47:27 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.13.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT assign_div_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-16 20:47:27 +02:00
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return assign_oper_eval(ctx, expr->expression1, expr->expression2, div_eval, ei, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:45:50 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.13.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT assign_mod_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-10-09 01:09:27 +02:00
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return assign_oper_eval(ctx, expr->expression1, expr->expression2, mod_eval, ei, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:31:54 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.13.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT assign_and_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-17 23:31:54 +02:00
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return assign_oper_eval(ctx, expr->expression1, expr->expression2, bitand_eval, ei, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:31:22 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.13.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT assign_or_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-17 23:31:22 +02:00
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return assign_oper_eval(ctx, expr->expression1, expr->expression2, bitor_eval, ei, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:32:27 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.13.2 */
|
2010-10-23 16:41:55 +02:00
|
|
|
HRESULT assign_xor_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-17 23:32:27 +02:00
|
|
|
binary_expression_t *expr = (binary_expression_t*)_expr;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
return assign_oper_eval(ctx, expr->expression1, expr->expression2, xor_eval, ei, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|