2008-09-03 00:25:21 +02:00
|
|
|
/*
|
2011-12-30 11:20:43 +01:00
|
|
|
* Copyright 2008,2011 Jacek Caban for CodeWeavers
|
2008-09-03 00:25:21 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2008-10-16 21:31:30 +02:00
|
|
|
|
2008-10-09 01:09:17 +02:00
|
|
|
#include <math.h>
|
2011-11-18 14:09:44 +01:00
|
|
|
#include <assert.h>
|
2008-10-09 01:09:17 +02:00
|
|
|
|
2008-09-03 00:25:21 +02:00
|
|
|
#include "jscript.h"
|
|
|
|
#include "engine.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(jscript);
|
|
|
|
|
2011-12-28 12:06:28 +01:00
|
|
|
struct _except_frame_t {
|
|
|
|
unsigned stack_top;
|
|
|
|
scope_chain_t *scope;
|
|
|
|
unsigned catch_off;
|
2017-05-01 18:30:44 +02:00
|
|
|
unsigned finally_off;
|
2011-12-28 12:06:28 +01:00
|
|
|
|
|
|
|
except_frame_t *next;
|
|
|
|
};
|
|
|
|
|
2014-09-30 16:51:14 +02:00
|
|
|
typedef struct {
|
|
|
|
enum {
|
|
|
|
EXPRVAL_JSVAL,
|
|
|
|
EXPRVAL_IDREF,
|
2016-08-02 17:41:40 +02:00
|
|
|
EXPRVAL_STACK_REF,
|
2014-09-30 16:51:14 +02:00
|
|
|
EXPRVAL_INVALID
|
|
|
|
} type;
|
|
|
|
union {
|
|
|
|
jsval_t val;
|
|
|
|
struct {
|
|
|
|
IDispatch *disp;
|
|
|
|
DISPID id;
|
|
|
|
} idref;
|
2016-08-02 17:41:40 +02:00
|
|
|
unsigned off;
|
2016-08-02 17:40:42 +02:00
|
|
|
HRESULT hres;
|
2014-09-30 16:51:14 +02:00
|
|
|
} u;
|
|
|
|
} exprval_t;
|
|
|
|
|
2021-03-15 18:19:33 +01:00
|
|
|
static const size_t stack_size = 0x40000;
|
2020-06-04 17:28:56 +02:00
|
|
|
|
2016-03-25 17:49:24 +01:00
|
|
|
static HRESULT stack_push(script_ctx_t *ctx, jsval_t v)
|
2011-11-18 14:09:44 +01:00
|
|
|
{
|
2020-06-04 17:28:56 +02:00
|
|
|
if(ctx->stack_top == stack_size)
|
2020-06-04 17:29:11 +02:00
|
|
|
return JS_E_STACK_OVERFLOW;
|
2011-11-18 14:09:44 +01:00
|
|
|
|
2016-03-25 17:49:24 +01:00
|
|
|
ctx->stack[ctx->stack_top++] = v;
|
2011-11-18 14:09:44 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
static inline HRESULT stack_push_string(script_ctx_t *ctx, const WCHAR *str)
|
2011-12-13 11:57:11 +01:00
|
|
|
{
|
2012-10-11 12:16:01 +02:00
|
|
|
jsstr_t *v;
|
2011-12-13 11:57:11 +01:00
|
|
|
|
2012-10-11 12:16:01 +02:00
|
|
|
v = jsstr_alloc(str);
|
2012-09-17 15:17:02 +02:00
|
|
|
if(!v)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
return stack_push(ctx, jsval_string(v));
|
2011-12-13 11:57:11 +01:00
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
static inline jsval_t stack_top(script_ctx_t *ctx)
|
2011-11-28 12:03:57 +01:00
|
|
|
{
|
2016-03-25 17:49:24 +01:00
|
|
|
assert(ctx->stack_top > ctx->call_ctx->stack_base);
|
|
|
|
return ctx->stack[ctx->stack_top-1];
|
2011-11-28 12:03:57 +01:00
|
|
|
}
|
|
|
|
|
2016-08-02 17:41:40 +02:00
|
|
|
static inline jsval_t *stack_top_ref(script_ctx_t *ctx, unsigned n)
|
2011-11-28 12:05:07 +01:00
|
|
|
{
|
2016-03-25 17:49:24 +01:00
|
|
|
assert(ctx->stack_top > ctx->call_ctx->stack_base+n);
|
2016-08-02 17:41:40 +02:00
|
|
|
return ctx->stack+ctx->stack_top-1-n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline jsval_t stack_topn(script_ctx_t *ctx, unsigned n)
|
|
|
|
{
|
|
|
|
return *stack_top_ref(ctx, n);
|
2011-11-28 12:05:07 +01:00
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:24 +01:00
|
|
|
static inline jsval_t *stack_args(script_ctx_t *ctx, unsigned n)
|
2012-06-25 14:08:38 +02:00
|
|
|
{
|
|
|
|
if(!n)
|
|
|
|
return NULL;
|
2016-03-25 17:49:24 +01:00
|
|
|
assert(ctx->stack_top > ctx->call_ctx->stack_base+n-1);
|
|
|
|
return ctx->stack + ctx->stack_top-n;
|
2012-06-25 14:08:38 +02:00
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
static inline jsval_t stack_pop(script_ctx_t *ctx)
|
2011-11-18 14:09:44 +01:00
|
|
|
{
|
2016-03-25 17:49:24 +01:00
|
|
|
assert(ctx->stack_top > ctx->call_ctx->stack_base);
|
|
|
|
return ctx->stack[--ctx->stack_top];
|
2011-11-18 14:09:44 +01:00
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
static void stack_popn(script_ctx_t *ctx, unsigned n)
|
2011-11-18 14:09:44 +01:00
|
|
|
{
|
|
|
|
while(n--)
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(stack_pop(ctx));
|
2011-11-18 14:09:44 +01:00
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT stack_pop_number(script_ctx_t *ctx, double *r)
|
2011-11-25 12:06:05 +01:00
|
|
|
{
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t v;
|
2011-11-25 12:06:05 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
v = stack_pop(ctx);
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = to_number(ctx, v, r);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(v);
|
2012-03-27 11:30:03 +02:00
|
|
|
return hres;
|
2011-11-25 12:06:05 +01:00
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT stack_pop_object(script_ctx_t *ctx, IDispatch **r)
|
2011-12-06 10:42:09 +01:00
|
|
|
{
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t v;
|
2011-12-06 10:42:09 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
v = stack_pop(ctx);
|
2012-09-17 15:17:02 +02:00
|
|
|
if(is_object_instance(v)) {
|
|
|
|
if(!get_object(v))
|
2020-01-31 17:23:33 +01:00
|
|
|
return JS_E_OBJECT_REQUIRED;
|
2012-09-17 15:17:02 +02:00
|
|
|
*r = get_object(v);
|
2011-12-06 10:42:09 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = to_object(ctx, v, r);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(v);
|
2011-12-06 10:42:09 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
static inline HRESULT stack_pop_int(script_ctx_t *ctx, INT *r)
|
2011-11-29 11:09:35 +01:00
|
|
|
{
|
2016-03-25 17:49:14 +01:00
|
|
|
return to_int32(ctx, stack_pop(ctx), r);
|
2011-11-29 11:09:35 +01:00
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
static inline HRESULT stack_pop_uint(script_ctx_t *ctx, DWORD *r)
|
2011-12-08 12:03:22 +01:00
|
|
|
{
|
2016-03-25 17:49:14 +01:00
|
|
|
return to_uint32(ctx, stack_pop(ctx), r);
|
2011-12-08 12:03:22 +01:00
|
|
|
}
|
|
|
|
|
2016-08-04 13:40:37 +02:00
|
|
|
static inline unsigned local_off(call_frame_t *frame, int ref)
|
|
|
|
{
|
|
|
|
return ref < 0
|
|
|
|
? frame->arguments_off - ref-1
|
|
|
|
: frame->variables_off + ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline BSTR local_name(call_frame_t *frame, int ref)
|
|
|
|
{
|
|
|
|
return ref < 0 ? frame->function->params[-ref-1] : frame->function->variables[ref].name;
|
|
|
|
}
|
|
|
|
|
2016-08-02 17:40:54 +02:00
|
|
|
/* Steals input reference even on failure. */
|
|
|
|
static HRESULT stack_push_exprval(script_ctx_t *ctx, exprval_t *val)
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
switch(val->type) {
|
|
|
|
case EXPRVAL_JSVAL:
|
2021-04-12 15:47:45 +02:00
|
|
|
hres = stack_push(ctx, jsval_null());
|
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
hres = stack_push(ctx, val->u.val);
|
|
|
|
return hres;
|
2016-08-02 17:40:54 +02:00
|
|
|
case EXPRVAL_IDREF:
|
|
|
|
hres = stack_push(ctx, jsval_disp(val->u.idref.disp));
|
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
hres = stack_push(ctx, jsval_number(val->u.idref.id));
|
|
|
|
else
|
|
|
|
IDispatch_Release(val->u.idref.disp);
|
|
|
|
return hres;
|
2016-08-02 17:41:40 +02:00
|
|
|
case EXPRVAL_STACK_REF:
|
|
|
|
hres = stack_push(ctx, jsval_number(val->u.off));
|
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
hres = stack_push(ctx, jsval_undefined());
|
|
|
|
return hres;
|
2016-08-02 17:40:54 +02:00
|
|
|
case EXPRVAL_INVALID:
|
|
|
|
hres = stack_push(ctx, jsval_undefined());
|
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
hres = stack_push(ctx, jsval_number(val->u.hres));
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(0);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2016-08-02 17:41:40 +02:00
|
|
|
static BOOL stack_topn_exprval(script_ctx_t *ctx, unsigned n, exprval_t *r)
|
2011-12-05 11:11:29 +01:00
|
|
|
{
|
2016-08-02 17:41:40 +02:00
|
|
|
jsval_t v = stack_topn(ctx, n+1);
|
|
|
|
|
|
|
|
switch(jsval_type(v)) {
|
|
|
|
case JSV_NUMBER: {
|
|
|
|
call_frame_t *frame = ctx->call_ctx;
|
2021-06-18 14:50:18 +02:00
|
|
|
scope_chain_t *scope;
|
2016-08-02 17:41:40 +02:00
|
|
|
unsigned off = get_number(v);
|
|
|
|
|
|
|
|
if(!frame->base_scope->frame && off >= frame->arguments_off) {
|
|
|
|
DISPID id;
|
2016-08-04 13:40:11 +02:00
|
|
|
BSTR name;
|
2021-06-18 14:50:18 +02:00
|
|
|
HRESULT hres = E_FAIL;
|
2016-08-02 17:41:40 +02:00
|
|
|
|
|
|
|
/* Got stack reference in deoptimized code. Need to convert it back to variable object reference. */
|
|
|
|
|
2016-08-04 13:40:11 +02:00
|
|
|
assert(off < frame->variables_off + frame->function->var_cnt);
|
2021-06-18 14:50:18 +02:00
|
|
|
if (off >= frame->variables_off)
|
|
|
|
{
|
|
|
|
name = frame->function->variables[off - frame->variables_off].name;
|
|
|
|
scope = frame->scope;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
name = frame->function->params[off - frame->arguments_off];
|
|
|
|
scope = frame->base_scope;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if (scope->jsobj && SUCCEEDED(hres = jsdisp_get_id(scope->jsobj, name, 0, &id)))
|
|
|
|
break;
|
|
|
|
if (scope == frame->base_scope)
|
|
|
|
{
|
|
|
|
r->type = EXPRVAL_INVALID;
|
|
|
|
r->u.hres = hres;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
scope = scope->next;
|
2016-08-02 17:41:40 +02:00
|
|
|
}
|
|
|
|
|
2021-06-18 14:50:18 +02:00
|
|
|
*stack_top_ref(ctx, n+1) = jsval_obj(jsdisp_addref(scope->jsobj));
|
2016-08-02 17:41:40 +02:00
|
|
|
*stack_top_ref(ctx, n) = jsval_number(id);
|
|
|
|
r->type = EXPRVAL_IDREF;
|
2021-06-18 14:50:18 +02:00
|
|
|
r->u.idref.disp = scope->obj;
|
2016-08-02 17:41:40 +02:00
|
|
|
r->u.idref.id = id;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
r->type = EXPRVAL_STACK_REF;
|
|
|
|
r->u.off = off;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2016-08-02 17:40:54 +02:00
|
|
|
case JSV_OBJECT:
|
|
|
|
r->type = EXPRVAL_IDREF;
|
2016-08-02 17:41:40 +02:00
|
|
|
r->u.idref.disp = get_object(v);
|
|
|
|
assert(is_number(stack_topn(ctx, n)));
|
|
|
|
r->u.idref.id = get_number(stack_topn(ctx, n));
|
2016-08-02 17:40:54 +02:00
|
|
|
return TRUE;
|
|
|
|
case JSV_UNDEFINED:
|
|
|
|
r->type = EXPRVAL_INVALID;
|
2016-08-02 17:41:40 +02:00
|
|
|
assert(is_number(stack_topn(ctx, n)));
|
|
|
|
r->u.hres = get_number(stack_topn(ctx, n));
|
2016-08-02 17:40:54 +02:00
|
|
|
return FALSE;
|
2021-04-12 15:47:45 +02:00
|
|
|
case JSV_NULL:
|
|
|
|
r->type = EXPRVAL_JSVAL;
|
|
|
|
r->u.val = stack_topn(ctx, n);
|
|
|
|
return TRUE;
|
2016-08-02 17:40:54 +02:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2011-12-05 11:11:29 +01:00
|
|
|
|
2016-08-02 17:40:54 +02:00
|
|
|
static inline BOOL stack_pop_exprval(script_ctx_t *ctx, exprval_t *r)
|
|
|
|
{
|
2016-08-02 17:41:40 +02:00
|
|
|
BOOL ret = stack_topn_exprval(ctx, 0, r);
|
|
|
|
ctx->stack_top -= 2;
|
|
|
|
return ret;
|
2016-08-02 17:40:54 +02:00
|
|
|
}
|
2011-12-05 11:13:02 +01:00
|
|
|
|
2016-08-02 17:40:54 +02:00
|
|
|
static HRESULT exprval_propput(script_ctx_t *ctx, exprval_t *ref, jsval_t v)
|
|
|
|
{
|
2016-08-02 17:41:40 +02:00
|
|
|
switch(ref->type) {
|
|
|
|
case EXPRVAL_STACK_REF: {
|
|
|
|
jsval_t *r = ctx->stack + ref->u.off;
|
|
|
|
jsval_release(*r);
|
|
|
|
return jsval_copy(v, r);
|
|
|
|
}
|
|
|
|
case EXPRVAL_IDREF:
|
|
|
|
return disp_propput(ctx, ref->u.idref.disp, ref->u.idref.id, v);
|
2021-04-12 15:47:45 +02:00
|
|
|
case EXPRVAL_JSVAL:
|
|
|
|
WARN("ignoring an attempt to set value reference\n");
|
|
|
|
return S_OK;
|
2016-08-02 17:41:40 +02:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2011-12-05 11:13:02 +01:00
|
|
|
}
|
|
|
|
|
2016-08-02 17:40:54 +02:00
|
|
|
static HRESULT exprval_propget(script_ctx_t *ctx, exprval_t *ref, jsval_t *r)
|
2016-03-28 17:48:57 +02:00
|
|
|
{
|
2016-08-02 17:41:40 +02:00
|
|
|
switch(ref->type) {
|
|
|
|
case EXPRVAL_STACK_REF:
|
|
|
|
return jsval_copy(ctx->stack[ref->u.off], r);
|
|
|
|
case EXPRVAL_IDREF:
|
|
|
|
return disp_propget(ctx, ref->u.idref.disp, ref->u.idref.id, r);
|
2021-04-12 15:47:45 +02:00
|
|
|
case EXPRVAL_JSVAL:
|
|
|
|
return jsval_copy(ref->u.val, r);
|
2016-08-02 17:41:40 +02:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2016-03-28 17:48:57 +02:00
|
|
|
}
|
|
|
|
|
2016-08-02 17:40:54 +02:00
|
|
|
static HRESULT exprval_call(script_ctx_t *ctx, exprval_t *ref, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
|
2016-03-28 17:49:10 +02:00
|
|
|
{
|
2016-08-02 17:41:40 +02:00
|
|
|
switch(ref->type) {
|
|
|
|
case EXPRVAL_STACK_REF: {
|
|
|
|
jsval_t v = ctx->stack[ref->u.off];
|
|
|
|
|
|
|
|
if(!is_object_instance(v)) {
|
|
|
|
FIXME("invoke %s\n", debugstr_jsval(v));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return disp_call_value(ctx, get_object(v), NULL, flags, argc, argv, r);
|
|
|
|
}
|
|
|
|
case EXPRVAL_IDREF:
|
|
|
|
return disp_call(ctx, ref->u.idref.disp, ref->u.idref.id, flags, argc, argv, r);
|
2021-04-12 15:47:45 +02:00
|
|
|
case EXPRVAL_JSVAL: {
|
|
|
|
IDispatch *obj;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = to_object(ctx, ref->u.val, &obj);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = disp_call_value(ctx, obj, NULL, flags, argc, argv, r);
|
|
|
|
IDispatch_Release(obj);
|
|
|
|
}
|
|
|
|
return hres;
|
|
|
|
}
|
2016-08-02 17:41:40 +02:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2016-08-02 17:40:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 8.7.1 */
|
|
|
|
/* Steals input reference. */
|
|
|
|
static HRESULT exprval_to_value(script_ctx_t *ctx, exprval_t *ref, jsval_t *r)
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if(ref->type == EXPRVAL_JSVAL) {
|
|
|
|
*r = ref->u.val;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = exprval_propget(ctx, ref, r);
|
|
|
|
|
|
|
|
if(ref->type == EXPRVAL_IDREF)
|
|
|
|
IDispatch_Release(ref->u.idref.disp);
|
|
|
|
return hres;
|
2016-03-28 17:49:10 +02:00
|
|
|
}
|
|
|
|
|
2008-09-09 01:21:55 +02:00
|
|
|
static void exprval_release(exprval_t *val)
|
|
|
|
{
|
|
|
|
switch(val->type) {
|
2012-09-17 15:17:02 +02:00
|
|
|
case EXPRVAL_JSVAL:
|
|
|
|
jsval_release(val->u.val);
|
2008-09-09 01:21:55 +02:00
|
|
|
return;
|
|
|
|
case EXPRVAL_IDREF:
|
|
|
|
if(val->u.idref.disp)
|
|
|
|
IDispatch_Release(val->u.idref.disp);
|
|
|
|
return;
|
2016-08-02 17:41:40 +02:00
|
|
|
case EXPRVAL_STACK_REF:
|
2009-08-27 01:21:38 +02:00
|
|
|
case EXPRVAL_INVALID:
|
2011-12-20 11:47:02 +01:00
|
|
|
return;
|
2008-09-09 01:21:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-02 17:40:42 +02:00
|
|
|
static inline void exprval_set_exception(exprval_t *val, HRESULT hres)
|
|
|
|
{
|
|
|
|
val->type = EXPRVAL_INVALID;
|
|
|
|
val->u.hres = hres;
|
|
|
|
}
|
|
|
|
|
2016-08-02 17:40:54 +02:00
|
|
|
static inline void exprval_set_disp_ref(exprval_t *ref, IDispatch *obj, DISPID id)
|
2008-09-09 01:21:55 +02:00
|
|
|
{
|
2016-08-02 17:40:54 +02:00
|
|
|
ref->type = EXPRVAL_IDREF;
|
|
|
|
IDispatch_AddRef(ref->u.idref.disp = obj);
|
|
|
|
ref->u.idref.id = id;
|
2008-09-09 01:21:55 +02:00
|
|
|
}
|
|
|
|
|
2016-08-02 17:40:54 +02:00
|
|
|
static inline jsval_t steal_ret(call_frame_t *frame)
|
2008-09-09 01:22:13 +02:00
|
|
|
{
|
2016-08-02 17:40:54 +02:00
|
|
|
jsval_t r = frame->ret;
|
|
|
|
frame->ret = jsval_undefined();
|
|
|
|
return r;
|
|
|
|
}
|
2008-09-09 01:22:13 +02:00
|
|
|
|
2018-06-12 14:04:11 +02:00
|
|
|
static inline void clear_acc(script_ctx_t *ctx)
|
2016-08-02 17:40:54 +02:00
|
|
|
{
|
2018-06-12 14:04:11 +02:00
|
|
|
jsval_release(ctx->acc);
|
|
|
|
ctx->acc = jsval_undefined();
|
2008-09-09 01:22:13 +02:00
|
|
|
}
|
|
|
|
|
2017-01-07 14:46:59 +01:00
|
|
|
static HRESULT scope_push(scope_chain_t *scope, jsdisp_t *jsobj, IDispatch *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;
|
|
|
|
|
2021-06-18 14:50:18 +02:00
|
|
|
if (obj)
|
|
|
|
IDispatch_AddRef(obj);
|
2012-09-13 14:34:25 +02:00
|
|
|
new_scope->jsobj = jsobj;
|
2008-09-10 21:06:09 +02:00
|
|
|
new_scope->obj = obj;
|
2016-07-28 18:44:43 +02:00
|
|
|
new_scope->frame = NULL;
|
|
|
|
new_scope->next = scope ? scope_addref(scope) : NULL;
|
2021-06-18 14:50:18 +02:00
|
|
|
new_scope->scope_index = 0;
|
2008-09-10 21:06:09 +02:00
|
|
|
|
|
|
|
*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);
|
|
|
|
|
2021-06-18 14:50:18 +02:00
|
|
|
if (scope->obj)
|
|
|
|
IDispatch_Release(scope->obj);
|
2008-09-09 01:24:22 +02:00
|
|
|
heap_free(scope);
|
|
|
|
}
|
|
|
|
|
2013-03-27 11:02:42 +01:00
|
|
|
static HRESULT disp_get_id(script_ctx_t *ctx, IDispatch *disp, const WCHAR *name, BSTR name_bstr, DWORD flags, DISPID *id)
|
2008-09-09 01:22:31 +02:00
|
|
|
{
|
|
|
|
IDispatchEx *dispex;
|
2012-10-11 12:16:01 +02:00
|
|
|
jsdisp_t *jsdisp;
|
2013-03-11 16:03:15 +01:00
|
|
|
BSTR bstr;
|
2008-09-09 01:22:31 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2016-07-20 13:40:41 +02:00
|
|
|
jsdisp = iface_to_jsdisp(disp);
|
2012-10-11 12:16:01 +02:00
|
|
|
if(jsdisp) {
|
|
|
|
hres = jsdisp_get_id(jsdisp, name, flags, id);
|
|
|
|
jsdisp_release(jsdisp);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2013-03-11 16:03:15 +01:00
|
|
|
if(name_bstr) {
|
|
|
|
bstr = name_bstr;
|
|
|
|
}else {
|
|
|
|
bstr = SysAllocString(name);
|
|
|
|
if(!bstr)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2012-10-11 12:16:01 +02:00
|
|
|
*id = 0;
|
2008-09-09 01:22:31 +02:00
|
|
|
hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
|
2012-10-11 12:16:01 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
2013-03-11 16:03:15 +01:00
|
|
|
hres = IDispatchEx_GetDispID(dispex, bstr, make_grfdex(ctx, flags|fdexNameCaseSensitive), id);
|
2012-10-11 12:16:01 +02:00
|
|
|
IDispatchEx_Release(dispex);
|
2013-03-11 16:03:15 +01:00
|
|
|
}else {
|
|
|
|
TRACE("using IDispatch\n");
|
2013-03-27 11:02:42 +01:00
|
|
|
hres = IDispatch_GetIDsOfNames(disp, &IID_NULL, &bstr, 1, 0, id);
|
2008-09-09 01:22:31 +02:00
|
|
|
}
|
|
|
|
|
2013-03-11 16:03:15 +01:00
|
|
|
if(name_bstr != bstr)
|
|
|
|
SysFreeString(bstr);
|
|
|
|
return hres;
|
2008-09-09 01:22:31 +02:00
|
|
|
}
|
|
|
|
|
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 */
|
2018-03-01 23:58:55 +01:00
|
|
|
HRESULT jsval_strict_equal(jsval_t lval, jsval_t rval, BOOL *ret)
|
2008-09-09 01:26:20 +02:00
|
|
|
{
|
2012-09-17 15:20:57 +02:00
|
|
|
jsval_type_t type = jsval_type(lval);
|
|
|
|
|
2008-09-09 01:26:20 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2012-09-17 15:20:57 +02:00
|
|
|
if(type != jsval_type(rval)) {
|
2012-09-17 15:17:02 +02:00
|
|
|
if(is_null_instance(lval))
|
|
|
|
*ret = is_null_instance(rval);
|
2009-09-11 18:47:14 +02:00
|
|
|
else
|
|
|
|
*ret = FALSE;
|
2008-09-09 01:26:20 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-17 15:20:57 +02:00
|
|
|
switch(type) {
|
2012-09-17 15:17:02 +02:00
|
|
|
case JSV_UNDEFINED:
|
|
|
|
case JSV_NULL:
|
|
|
|
*ret = TRUE;
|
2008-09-09 01:26:20 +02:00
|
|
|
break;
|
2012-09-17 15:17:02 +02:00
|
|
|
case JSV_OBJECT:
|
|
|
|
return disp_cmp(get_object(lval), get_object(rval), ret);
|
|
|
|
case JSV_STRING:
|
2012-10-11 12:16:01 +02:00
|
|
|
*ret = jsstr_eq(get_string(lval), get_string(rval));
|
2012-09-17 15:17:02 +02:00
|
|
|
break;
|
|
|
|
case JSV_NUMBER:
|
|
|
|
*ret = get_number(lval) == get_number(rval);
|
2008-09-09 01:26:20 +02:00
|
|
|
break;
|
2012-09-17 15:17:02 +02:00
|
|
|
case JSV_BOOL:
|
|
|
|
*ret = !get_bool(lval) == !get_bool(rval);
|
2008-09-09 01:26:20 +02:00
|
|
|
break;
|
2012-09-17 15:17:02 +02:00
|
|
|
case JSV_VARIANT:
|
2021-01-19 14:34:03 +01:00
|
|
|
WARN("VARIANT type, returning false\n");
|
|
|
|
*ret = FALSE;
|
|
|
|
return S_OK;
|
2008-09-09 01:26:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2021-06-18 14:50:18 +02:00
|
|
|
static HRESULT detach_scope(script_ctx_t *ctx, call_frame_t *frame, scope_chain_t *scope)
|
|
|
|
{
|
2021-08-09 15:55:41 +02:00
|
|
|
function_code_t *func = frame->function;
|
2021-06-18 14:50:18 +02:00
|
|
|
unsigned int i, index;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if (!scope->frame)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
assert(scope->frame == frame);
|
|
|
|
scope->frame = NULL;
|
|
|
|
|
|
|
|
if (!scope->jsobj)
|
|
|
|
{
|
|
|
|
assert(!scope->obj);
|
|
|
|
|
|
|
|
if (FAILED(hres = create_object(ctx, NULL, &scope->jsobj)))
|
|
|
|
return hres;
|
|
|
|
scope->obj = to_disp(scope->jsobj);
|
|
|
|
}
|
|
|
|
|
2021-08-09 15:55:41 +02:00
|
|
|
if (scope == frame->base_scope && func->name && ctx->version >= SCRIPTLANGUAGEVERSION_ES5)
|
|
|
|
jsdisp_propput_name(scope->jsobj, func->name, jsval_obj(jsdisp_addref(frame->function_instance)));
|
|
|
|
|
2021-06-18 14:50:18 +02:00
|
|
|
index = scope->scope_index;
|
|
|
|
for(i = 0; i < frame->function->local_scopes[index].locals_cnt; i++)
|
|
|
|
{
|
|
|
|
WCHAR *name = frame->function->local_scopes[index].locals[i].name;
|
|
|
|
int ref = frame->function->local_scopes[index].locals[i].ref;
|
|
|
|
|
|
|
|
if (FAILED(hres = jsdisp_propput_name(scope->jsobj, name, ctx->stack[local_off(frame, ref)])))
|
|
|
|
return hres;
|
2021-06-18 14:50:19 +02:00
|
|
|
if (frame->function->variables[ref].func_id != -1 && scope != frame->base_scope
|
|
|
|
&& FAILED(hres = jsdisp_propput_name(frame->variable_obj, name, ctx->stack[local_off(frame, ref)])))
|
|
|
|
return hres;
|
2021-06-18 14:50:18 +02:00
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT detach_scope_chain(script_ctx_t *ctx, call_frame_t *frame, scope_chain_t *scope)
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
2021-06-18 14:50:19 +02:00
|
|
|
if (scope != frame->base_scope && FAILED(hres = detach_scope_chain(ctx, frame, scope->next)))
|
|
|
|
return hres;
|
|
|
|
return detach_scope(ctx, frame, scope);
|
2021-06-18 14:50:18 +02:00
|
|
|
}
|
|
|
|
|
2016-07-28 18:44:43 +02:00
|
|
|
/*
|
|
|
|
* Transfers local variables from stack to variable object.
|
|
|
|
* It's slow, so we want to avoid it as much as possible.
|
|
|
|
*/
|
2016-08-05 17:15:13 +02:00
|
|
|
static HRESULT detach_variable_object(script_ctx_t *ctx, call_frame_t *frame, BOOL from_release)
|
2016-07-28 18:44:43 +02:00
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if(!frame->base_scope || !frame->base_scope->frame)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
TRACE("detaching %p\n", frame);
|
|
|
|
|
|
|
|
assert(frame == frame->base_scope->frame);
|
|
|
|
assert(frame->variable_obj == frame->base_scope->jsobj);
|
|
|
|
|
2016-08-05 17:15:13 +02:00
|
|
|
if(!from_release && !frame->arguments_obj) {
|
2016-08-03 16:28:26 +02:00
|
|
|
hres = setup_arguments_object(ctx, frame);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2021-06-18 14:50:18 +02:00
|
|
|
TRACE("detaching scope chain %p, frame %p.\n", ctx->call_ctx->scope, frame);
|
|
|
|
return detach_scope_chain(ctx, frame, ctx->call_ctx->scope);
|
2016-07-28 18:44:43 +02:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2020-03-05 17:11:56 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(item, &ctx->named_items, named_item_t, entry) {
|
2009-08-10 12:57:23 +02:00
|
|
|
if(item->flags & SCRIPTITEM_GLOBALMEMBERS) {
|
2012-10-11 12:16:01 +02:00
|
|
|
hres = disp_get_id(ctx, item->disp, identifier, identifier, 0, &id);
|
2009-08-10 12:57:23 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
if(ret)
|
2016-08-02 17:40:54 +02:00
|
|
|
exprval_set_disp_ref(ret, item->disp, id);
|
2009-08-10 12:57:23 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-03-06 14:48:39 +01:00
|
|
|
IDispatch *lookup_global_host(script_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
IDispatch *disp = NULL;
|
|
|
|
named_item_t *item;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(item, &ctx->named_items, named_item_t, entry) {
|
|
|
|
if(!(item->flags & SCRIPTITEM_GLOBALMEMBERS)) continue;
|
|
|
|
disp = item->disp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(!disp) disp = to_disp(ctx->global);
|
|
|
|
|
|
|
|
return disp;
|
|
|
|
}
|
|
|
|
|
2019-06-13 14:47:56 +02:00
|
|
|
static int __cdecl local_ref_cmp(const void *key, const void *ref)
|
2016-08-03 16:27:35 +02:00
|
|
|
{
|
2019-06-13 14:47:56 +02:00
|
|
|
return wcscmp((const WCHAR*)key, ((const local_ref_t*)ref)->name);
|
2016-08-03 16:27:35 +02:00
|
|
|
}
|
|
|
|
|
2021-06-18 14:50:18 +02:00
|
|
|
local_ref_t *lookup_local(const function_code_t *function, const WCHAR *identifier, unsigned int scope)
|
2016-08-04 13:39:46 +02:00
|
|
|
{
|
2021-06-18 14:50:18 +02:00
|
|
|
return bsearch(identifier, function->local_scopes[scope].locals, function->local_scopes[scope].locals_cnt,
|
|
|
|
sizeof(*function->local_scopes[scope].locals), local_ref_cmp);
|
2016-08-04 13:39:46 +02:00
|
|
|
}
|
|
|
|
|
2008-09-09 01:22:13 +02:00
|
|
|
/* ECMA-262 3rd Edition 10.1.4 */
|
2012-01-18 13:28:29 +01:00
|
|
|
static HRESULT identifier_eval(script_ctx_t *ctx, BSTR identifier, exprval_t *ret)
|
2008-09-09 01:22:13 +02:00
|
|
|
{
|
2008-09-09 01:24:22 +02:00
|
|
|
scope_chain_t *scope;
|
2008-09-09 01:22:31 +02:00
|
|
|
named_item_t *item;
|
2008-09-09 01:22:13 +02:00
|
|
|
DISPID id = 0;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(identifier));
|
|
|
|
|
2016-03-25 12:02:35 +01:00
|
|
|
if(ctx->call_ctx) {
|
2016-03-25 12:04:13 +01:00
|
|
|
for(scope = ctx->call_ctx->scope; scope; scope = scope->next) {
|
2016-07-28 18:44:43 +02:00
|
|
|
if(scope->frame) {
|
2016-08-02 17:41:40 +02:00
|
|
|
function_code_t *func = scope->frame->function;
|
2021-06-18 14:50:18 +02:00
|
|
|
local_ref_t *ref = lookup_local(func, identifier, scope->scope_index);
|
2016-08-03 16:27:35 +02:00
|
|
|
|
2016-08-04 13:40:11 +02:00
|
|
|
if(ref) {
|
2016-08-03 16:27:35 +02:00
|
|
|
ret->type = EXPRVAL_STACK_REF;
|
2016-08-04 13:40:11 +02:00
|
|
|
ret->u.off = local_off(scope->frame, ref->ref);
|
|
|
|
TRACE("returning ref %d for %d\n", ret->u.off, ref->ref);
|
2016-08-03 16:27:35 +02:00
|
|
|
return S_OK;
|
2016-08-02 17:41:40 +02:00
|
|
|
}
|
2016-08-03 16:28:26 +02:00
|
|
|
|
2020-11-24 00:49:04 +01:00
|
|
|
if(!wcscmp(identifier, L"arguments")) {
|
2016-08-05 17:15:13 +02:00
|
|
|
hres = detach_variable_object(ctx, scope->frame, FALSE);
|
2016-08-03 16:28:26 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
2021-04-12 15:47:58 +02:00
|
|
|
|
|
|
|
/* ECMA-262 5.1 Edition 13 */
|
|
|
|
if(func->name && ctx->version >= SCRIPTLANGUAGEVERSION_ES5 && !wcscmp(identifier, func->name)) {
|
|
|
|
TRACE("returning a function from scope chain\n");
|
|
|
|
ret->type = EXPRVAL_JSVAL;
|
|
|
|
ret->u.val = jsval_obj(jsdisp_addref(scope->frame->function_instance));
|
|
|
|
return S_OK;
|
|
|
|
}
|
2016-07-28 18:44:43 +02:00
|
|
|
}
|
2021-06-18 14:50:18 +02:00
|
|
|
|
|
|
|
if (!scope->jsobj && !scope->obj)
|
|
|
|
continue;
|
|
|
|
|
2015-06-02 14:45:10 +02:00
|
|
|
if(scope->jsobj)
|
|
|
|
hres = jsdisp_get_id(scope->jsobj, identifier, fdexNameImplicit, &id);
|
|
|
|
else
|
|
|
|
hres = disp_get_id(ctx, scope->obj, identifier, identifier, fdexNameImplicit, &id);
|
|
|
|
if(SUCCEEDED(hres)) {
|
2016-08-02 17:40:54 +02:00
|
|
|
exprval_set_disp_ref(ret, scope->obj, id);
|
2015-06-02 14:45:10 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
2010-10-23 16:41:55 +02:00
|
|
|
}
|
2020-03-18 14:19:49 +01:00
|
|
|
|
2020-03-27 18:34:16 +01:00
|
|
|
item = ctx->call_ctx->bytecode->named_item;
|
|
|
|
if(item) {
|
|
|
|
hres = jsdisp_get_id(item->script_obj, identifier, 0, &id);
|
2020-03-18 14:19:49 +01:00
|
|
|
if(SUCCEEDED(hres)) {
|
2020-03-27 18:34:16 +01:00
|
|
|
exprval_set_disp_ref(ret, to_disp(item->script_obj), id);
|
2020-03-18 14:19:49 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
2020-03-27 18:34:16 +01:00
|
|
|
if(!(item->flags & SCRIPTITEM_CODEONLY)) {
|
|
|
|
hres = disp_get_id(ctx, item->disp, identifier, identifier, 0, &id);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
exprval_set_disp_ref(ret, item->disp, id);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
2020-03-18 14:19:49 +01:00
|
|
|
}
|
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)) {
|
2016-08-02 17:40:54 +02:00
|
|
|
exprval_set_disp_ref(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
|
|
|
|
2020-02-20 21:26:49 +01:00
|
|
|
item = lookup_named_item(ctx, identifier, SCRIPTITEM_ISVISIBLE);
|
|
|
|
if(item) {
|
|
|
|
IDispatch_AddRef(item->disp);
|
|
|
|
ret->type = EXPRVAL_JSVAL;
|
|
|
|
ret->u.val = jsval_disp(item->disp);
|
|
|
|
return S_OK;
|
2008-11-05 01:03:38 +01:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2016-08-02 17:40:42 +02:00
|
|
|
exprval_set_exception(ret, JS_E_UNDEFINED_VARIABLE);
|
2009-08-27 01:21:38 +02:00
|
|
|
return S_OK;
|
2008-09-09 01:22:13 +02:00
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
static inline BSTR get_op_bstr(script_ctx_t *ctx, int i)
|
|
|
|
{
|
|
|
|
call_frame_t *frame = ctx->call_ctx;
|
2016-03-25 12:03:45 +01:00
|
|
|
return frame->bytecode->instrs[frame->ip].u.arg[i].bstr;
|
2012-05-12 16:21:01 +02:00
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
static inline unsigned get_op_uint(script_ctx_t *ctx, int i)
|
|
|
|
{
|
|
|
|
call_frame_t *frame = ctx->call_ctx;
|
2016-03-25 12:03:45 +01:00
|
|
|
return frame->bytecode->instrs[frame->ip].u.arg[i].uint;
|
2012-05-12 16:21:10 +02:00
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
static inline unsigned get_op_int(script_ctx_t *ctx, int i)
|
|
|
|
{
|
|
|
|
call_frame_t *frame = ctx->call_ctx;
|
2016-03-25 12:03:45 +01:00
|
|
|
return frame->bytecode->instrs[frame->ip].u.arg[i].lng;
|
2012-05-12 16:21:20 +02:00
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
static inline jsstr_t *get_op_str(script_ctx_t *ctx, int i)
|
|
|
|
{
|
|
|
|
call_frame_t *frame = ctx->call_ctx;
|
2016-03-25 12:03:45 +01:00
|
|
|
return frame->bytecode->instrs[frame->ip].u.arg[i].str;
|
2012-05-12 16:21:56 +02:00
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
static inline double get_op_double(script_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
call_frame_t *frame = ctx->call_ctx;
|
2016-03-25 12:03:45 +01:00
|
|
|
return frame->bytecode->instrs[frame->ip].u.dbl;
|
2012-05-12 16:21:56 +02:00
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
static inline void jmp_next(script_ctx_t *ctx)
|
2016-03-25 12:03:25 +01:00
|
|
|
{
|
2016-03-25 17:49:14 +01:00
|
|
|
ctx->call_ctx->ip++;
|
2016-03-25 12:03:25 +01:00
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
static inline void jmp_abs(script_ctx_t *ctx, unsigned dst)
|
2016-03-25 12:03:25 +01:00
|
|
|
{
|
2016-03-25 17:49:14 +01:00
|
|
|
ctx->call_ctx->ip = dst;
|
2016-03-25 12:03:25 +01:00
|
|
|
}
|
|
|
|
|
2011-12-28 12:05:53 +01:00
|
|
|
/* ECMA-262 3rd Edition 12.6.4 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_forin(script_ctx_t *ctx)
|
2011-12-28 12:05:53 +01:00
|
|
|
{
|
2012-05-12 16:21:10 +02:00
|
|
|
const HRESULT arg = get_op_uint(ctx, 0);
|
2016-08-02 17:40:54 +02:00
|
|
|
IDispatch *obj = NULL;
|
2011-12-28 12:05:53 +01:00
|
|
|
IDispatchEx *dispex;
|
2016-08-02 17:40:54 +02:00
|
|
|
exprval_t prop_ref;
|
|
|
|
DISPID id;
|
2011-12-28 12:05:53 +01:00
|
|
|
BSTR name = NULL;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
assert(is_number(stack_top(ctx)));
|
|
|
|
id = get_number(stack_top(ctx));
|
2011-12-28 12:05:53 +01:00
|
|
|
|
2016-08-02 17:40:54 +02:00
|
|
|
if(!stack_topn_exprval(ctx, 1, &prop_ref)) {
|
|
|
|
FIXME("invalid ref: %08x\n", prop_ref.u.hres);
|
2011-12-28 12:05:53 +01:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
if(is_object_instance(stack_topn(ctx, 3)))
|
|
|
|
obj = get_object(stack_topn(ctx, 3));
|
2011-12-28 12:05:53 +01:00
|
|
|
|
|
|
|
if(obj) {
|
|
|
|
hres = IDispatch_QueryInterface(obj, &IID_IDispatchEx, (void**)&dispex);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, id, &id);
|
|
|
|
if(hres == S_OK)
|
|
|
|
hres = IDispatchEx_GetMemberName(dispex, id, &name);
|
|
|
|
IDispatchEx_Release(dispex);
|
2012-12-13 12:08:34 +01:00
|
|
|
if(FAILED(hres))
|
2011-12-28 12:05:53 +01:00
|
|
|
return hres;
|
|
|
|
}else {
|
|
|
|
TRACE("No IDispatchEx\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(name) {
|
2012-10-11 12:16:01 +02:00
|
|
|
jsstr_t *str;
|
|
|
|
|
|
|
|
str = jsstr_alloc_len(name, SysStringLen(name));
|
|
|
|
SysFreeString(name);
|
|
|
|
if(!str)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
stack_pop(ctx);
|
|
|
|
stack_push(ctx, jsval_number(id)); /* safe, just after pop() */
|
2011-12-28 12:05:53 +01:00
|
|
|
|
2016-08-02 17:40:54 +02:00
|
|
|
hres = exprval_propput(ctx, &prop_ref, jsval_string(str));
|
2012-10-11 12:16:01 +02:00
|
|
|
jsstr_release(str);
|
2011-12-28 12:05:53 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2016-03-25 12:03:25 +01:00
|
|
|
jmp_next(ctx);
|
2011-12-28 12:05:53 +01:00
|
|
|
}else {
|
|
|
|
stack_popn(ctx, 4);
|
2016-03-25 12:03:25 +01:00
|
|
|
jmp_abs(ctx, arg);
|
2011-12-28 12:05:53 +01:00
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2021-06-18 14:50:18 +02:00
|
|
|
static HRESULT scope_init_locals(script_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
call_frame_t *frame = ctx->call_ctx;
|
|
|
|
unsigned int i, off, index;
|
|
|
|
scope_chain_t *scope;
|
|
|
|
BOOL detached_vars;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
scope = frame->scope;
|
|
|
|
index = scope->scope_index;
|
|
|
|
detached_vars = !(frame->base_scope && frame->base_scope->frame);
|
|
|
|
|
|
|
|
if (!detached_vars)
|
|
|
|
{
|
|
|
|
assert(frame->base_scope->frame == frame);
|
|
|
|
frame->scope->frame = ctx->call_ctx;
|
|
|
|
}
|
|
|
|
else if (!scope->jsobj)
|
|
|
|
{
|
|
|
|
assert(!scope->obj);
|
|
|
|
if (FAILED(hres = create_object(ctx, NULL, &scope->jsobj)))
|
|
|
|
return hres;
|
|
|
|
scope->obj = to_disp(scope->jsobj);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < frame->function->local_scopes[index].locals_cnt; i++)
|
|
|
|
{
|
|
|
|
WCHAR *name = frame->function->local_scopes[index].locals[i].name;
|
|
|
|
int ref = frame->function->local_scopes[index].locals[i].ref;
|
2021-06-18 14:50:19 +02:00
|
|
|
jsdisp_t *func_obj;
|
|
|
|
jsval_t val;
|
|
|
|
|
|
|
|
if (frame->function->variables[ref].func_id != -1)
|
|
|
|
{
|
|
|
|
TRACE("function %s %d\n", debugstr_w(name), i);
|
|
|
|
|
|
|
|
if (FAILED(hres = create_source_function(ctx, frame->bytecode, frame->function->funcs
|
|
|
|
+ frame->function->variables[ref].func_id, ctx->call_ctx->scope, &func_obj)))
|
|
|
|
return hres;
|
|
|
|
val = jsval_obj(func_obj);
|
|
|
|
if (detached_vars && FAILED(hres = jsdisp_propput_name(frame->variable_obj, name, jsval_obj(func_obj))))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
val = jsval_undefined();
|
|
|
|
}
|
2021-06-18 14:50:18 +02:00
|
|
|
|
|
|
|
if (detached_vars)
|
|
|
|
{
|
|
|
|
if (FAILED(hres = jsdisp_propput_name(scope->jsobj, name, val)))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
off = local_off(frame, ref);
|
|
|
|
jsval_release(ctx->stack[off]);
|
|
|
|
ctx->stack[off] = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-12-27 11:16:26 +01:00
|
|
|
/* ECMA-262 3rd Edition 12.10 */
|
2021-06-18 14:50:18 +02:00
|
|
|
static HRESULT interp_push_with_scope(script_ctx_t *ctx)
|
2011-12-27 11:16:26 +01:00
|
|
|
{
|
|
|
|
IDispatch *disp;
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t v;
|
2011-12-27 11:16:26 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
v = stack_pop(ctx);
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = to_object(ctx, v, &disp);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(v);
|
2011-12-27 11:16:26 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = scope_push(ctx->call_ctx->scope, to_jsdisp(disp), disp, &ctx->call_ctx->scope);
|
2012-09-13 14:34:25 +02:00
|
|
|
IDispatch_Release(disp);
|
2011-12-27 11:16:26 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2021-06-18 14:50:18 +02:00
|
|
|
/* ECMA-262 10th Edition 13.3.1 */
|
|
|
|
static HRESULT interp_push_block_scope(script_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
unsigned int scope_index = get_op_uint(ctx, 0);
|
|
|
|
call_frame_t *frame = ctx->call_ctx;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("scope_index %u.\n", scope_index);
|
|
|
|
|
|
|
|
hres = scope_push(ctx->call_ctx->scope, NULL, NULL, &frame->scope);
|
|
|
|
|
|
|
|
if (FAILED(hres) || !scope_index)
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
frame->scope->scope_index = scope_index;
|
|
|
|
|
|
|
|
return scope_init_locals(ctx);
|
|
|
|
}
|
|
|
|
|
2011-12-27 11:16:26 +01:00
|
|
|
/* ECMA-262 3rd Edition 12.10 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_pop_scope(script_ctx_t *ctx)
|
2011-12-27 11:16:26 +01:00
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
|
2021-06-18 14:50:19 +02:00
|
|
|
if(ctx->call_ctx->scope->ref > 1) {
|
|
|
|
HRESULT hres = detach_variable_object(ctx, ctx->call_ctx, FALSE);
|
|
|
|
if(FAILED(hres))
|
|
|
|
ERR("Failed to detach variable object: %08x\n", hres);
|
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
scope_pop(&ctx->call_ctx->scope);
|
2011-12-27 11:16:26 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-12-27 11:16:40 +01:00
|
|
|
/* ECMA-262 3rd Edition 12.13 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_case(script_ctx_t *ctx)
|
2011-12-27 11:16:40 +01:00
|
|
|
{
|
2012-05-12 16:21:10 +02:00
|
|
|
const unsigned arg = get_op_uint(ctx, 0);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t v;
|
2011-12-27 11:16:40 +01:00
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
v = stack_pop(ctx);
|
2018-03-01 23:58:45 +01:00
|
|
|
hres = jsval_strict_equal(stack_top(ctx), v, &b);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(v);
|
2011-12-27 11:16:40 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(b) {
|
|
|
|
stack_popn(ctx, 1);
|
2016-03-25 12:03:25 +01:00
|
|
|
jmp_abs(ctx, arg);
|
2011-12-27 11:16:40 +01:00
|
|
|
}else {
|
2016-03-25 12:03:25 +01:00
|
|
|
jmp_next(ctx);
|
2011-12-27 11:16:40 +01:00
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-01-30 15:50:22 +01:00
|
|
|
static void set_error_value(script_ctx_t *ctx, jsval_t value)
|
|
|
|
{
|
|
|
|
jsexcept_t *ei = ctx->ei;
|
2020-01-30 15:50:33 +01:00
|
|
|
jsdisp_t *obj;
|
2020-01-30 15:50:22 +01:00
|
|
|
|
|
|
|
reset_ei(ei);
|
2020-01-30 15:50:33 +01:00
|
|
|
ei->error = JS_E_EXCEPTION_THROWN;
|
2020-01-30 15:50:22 +01:00
|
|
|
ei->valid_value = TRUE;
|
|
|
|
ei->value = value;
|
2020-01-30 15:50:33 +01:00
|
|
|
|
|
|
|
if(is_object_instance(value) && get_object(value) && (obj = to_jsdisp(get_object(value)))) {
|
|
|
|
UINT32 number;
|
2020-02-03 14:47:25 +01:00
|
|
|
jsstr_t *str;
|
2020-01-30 15:50:33 +01:00
|
|
|
jsval_t v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
/* FIXME: We should check if object is an error instance */
|
|
|
|
|
|
|
|
hres = jsdisp_propget_name(obj, L"number", &v);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = to_uint32(ctx, v, &number);
|
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
ei->error = FAILED(number) ? number : E_FAIL;
|
|
|
|
jsval_release(v);
|
|
|
|
}
|
|
|
|
|
2020-02-03 14:47:25 +01:00
|
|
|
hres = jsdisp_propget_name(obj, L"description", &v);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = to_string(ctx, v, &str);
|
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
ei->message = str;
|
|
|
|
jsval_release(v);
|
|
|
|
}
|
|
|
|
}
|
2020-01-30 15:50:22 +01:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:30:20 +02:00
|
|
|
/* ECMA-262 3rd Edition 12.13 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_throw(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-16 20:45:13 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2020-01-30 15:50:22 +01:00
|
|
|
set_error_value(ctx, stack_pop(ctx));
|
2008-09-16 20:45:13 +02:00
|
|
|
return DISP_E_EXCEPTION;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_throw_ref(script_ctx_t *ctx)
|
2011-12-05 11:12:32 +01:00
|
|
|
{
|
2012-05-12 16:21:10 +02:00
|
|
|
const HRESULT arg = get_op_uint(ctx, 0);
|
2011-12-05 11:12:32 +01:00
|
|
|
|
|
|
|
TRACE("%08x\n", arg);
|
|
|
|
|
2020-01-31 17:23:05 +01:00
|
|
|
return arg;
|
2011-12-05 11:12:32 +01:00
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_throw_type(script_ctx_t *ctx)
|
2011-12-15 15:43:01 +01:00
|
|
|
{
|
2012-05-12 16:21:10 +02:00
|
|
|
const HRESULT hres = get_op_uint(ctx, 0);
|
2012-10-11 12:17:17 +02:00
|
|
|
jsstr_t *str = get_op_str(ctx, 1);
|
2013-03-27 11:02:42 +01:00
|
|
|
const WCHAR *ptr;
|
2011-12-15 15:43:01 +01:00
|
|
|
|
2012-10-11 12:17:17 +02:00
|
|
|
TRACE("%08x %s\n", hres, debugstr_jsstr(str));
|
2011-12-15 15:43:01 +01:00
|
|
|
|
2013-03-27 11:02:42 +01:00
|
|
|
ptr = jsstr_flatten(str);
|
2020-02-03 14:47:32 +01:00
|
|
|
return ptr ? throw_error(ctx, hres, ptr) : E_OUTOFMEMORY;
|
2011-12-15 15:43:01 +01:00
|
|
|
}
|
|
|
|
|
2011-12-28 12:06:28 +01:00
|
|
|
/* ECMA-262 3rd Edition 12.14 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_push_except(script_ctx_t *ctx)
|
2011-12-28 12:06:28 +01:00
|
|
|
{
|
2017-05-01 18:30:44 +02:00
|
|
|
const unsigned catch_off = get_op_uint(ctx, 0);
|
|
|
|
const unsigned finally_off = get_op_uint(ctx, 1);
|
2016-03-25 17:49:14 +01:00
|
|
|
call_frame_t *frame = ctx->call_ctx;
|
2011-12-28 12:06:28 +01:00
|
|
|
except_frame_t *except;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
except = heap_alloc(sizeof(*except));
|
|
|
|
if(!except)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2017-05-01 18:31:02 +02:00
|
|
|
except->stack_top = ctx->stack_top;
|
2016-03-25 12:04:13 +01:00
|
|
|
except->scope = frame->scope;
|
2017-05-01 18:30:44 +02:00
|
|
|
except->catch_off = catch_off;
|
|
|
|
except->finally_off = finally_off;
|
2016-03-25 12:03:35 +01:00
|
|
|
except->next = frame->except_frame;
|
|
|
|
frame->except_frame = except;
|
2011-12-28 12:06:28 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.14 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_pop_except(script_ctx_t *ctx)
|
2011-12-28 12:06:28 +01:00
|
|
|
{
|
2017-05-01 18:31:02 +02:00
|
|
|
const unsigned ret_off = get_op_uint(ctx, 0);
|
2016-03-25 17:49:14 +01:00
|
|
|
call_frame_t *frame = ctx->call_ctx;
|
2011-12-28 12:06:28 +01:00
|
|
|
except_frame_t *except;
|
2017-05-01 18:31:02 +02:00
|
|
|
unsigned finally_off;
|
2011-12-28 12:06:28 +01:00
|
|
|
|
2017-05-01 18:31:02 +02:00
|
|
|
TRACE("%u\n", ret_off);
|
2011-12-28 12:06:28 +01:00
|
|
|
|
2016-03-25 12:03:35 +01:00
|
|
|
except = frame->except_frame;
|
2011-12-28 12:06:28 +01:00
|
|
|
assert(except != NULL);
|
|
|
|
|
2017-05-01 18:31:02 +02:00
|
|
|
finally_off = except->finally_off;
|
2016-03-25 12:03:35 +01:00
|
|
|
frame->except_frame = except->next;
|
2011-12-28 12:06:28 +01:00
|
|
|
heap_free(except);
|
2017-05-01 18:31:02 +02:00
|
|
|
|
|
|
|
if(finally_off) {
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = stack_push(ctx, jsval_number(ret_off));
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
hres = stack_push(ctx, jsval_bool(TRUE));
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
frame->ip = finally_off;
|
|
|
|
}else {
|
|
|
|
frame->ip = ret_off;
|
|
|
|
}
|
|
|
|
|
2011-12-28 12:06:28 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.14 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_end_finally(script_ctx_t *ctx)
|
2011-12-28 12:06:28 +01:00
|
|
|
{
|
2017-05-01 18:31:02 +02:00
|
|
|
call_frame_t *frame = ctx->call_ctx;
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t v;
|
2011-12-28 12:06:28 +01:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2014-04-29 10:17:38 +02:00
|
|
|
v = stack_pop(ctx);
|
|
|
|
assert(is_bool(v));
|
2011-12-28 12:06:28 +01:00
|
|
|
|
2014-04-29 10:17:38 +02:00
|
|
|
if(!get_bool(v)) {
|
|
|
|
TRACE("passing exception\n");
|
2012-09-17 15:17:02 +02:00
|
|
|
|
2020-01-30 15:50:22 +01:00
|
|
|
set_error_value(ctx, stack_pop(ctx));
|
2012-09-20 15:04:01 +02:00
|
|
|
return DISP_E_EXCEPTION;
|
2011-12-28 12:06:28 +01:00
|
|
|
}
|
|
|
|
|
2017-05-01 18:31:02 +02:00
|
|
|
v = stack_pop(ctx);
|
|
|
|
assert(is_number(v));
|
|
|
|
frame->ip = get_number(v);
|
2012-12-13 12:08:34 +01:00
|
|
|
return S_OK;
|
2011-12-28 12:06:28 +01:00
|
|
|
}
|
|
|
|
|
2017-05-01 18:30:06 +02:00
|
|
|
static HRESULT interp_enter_catch(script_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
const BSTR ident = get_op_bstr(ctx, 0);
|
|
|
|
jsdisp_t *scope_obj;
|
|
|
|
jsval_t v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = create_dispex(ctx, NULL, NULL, &scope_obj);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
v = stack_pop(ctx);
|
|
|
|
hres = jsdisp_propput_name(scope_obj, ident, v);
|
|
|
|
jsval_release(v);
|
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
hres = scope_push(ctx->call_ctx->scope, scope_obj, to_disp(scope_obj), &ctx->call_ctx->scope);
|
|
|
|
jsdisp_release(scope_obj);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2008-09-10 21:08:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 13 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_func(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-05-12 16:21:10 +02:00
|
|
|
unsigned func_idx = get_op_uint(ctx, 0);
|
2016-03-25 17:49:14 +01:00
|
|
|
call_frame_t *frame = ctx->call_ctx;
|
2011-12-16 11:42:57 +01:00
|
|
|
jsdisp_t *dispex;
|
2008-09-10 21:08:46 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2012-04-24 17:39:09 +02:00
|
|
|
TRACE("%d\n", func_idx);
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = create_source_function(ctx, frame->bytecode, frame->function->funcs+func_idx,
|
2016-03-25 12:04:13 +01:00
|
|
|
frame->scope, &dispex);
|
2011-12-16 11:42:57 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2008-09-10 21:08:46 +02:00
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_obj(dispex));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2011-12-07 11:01:13 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.2.1 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_array(script_ctx_t *ctx)
|
2011-12-07 11:01:13 +01:00
|
|
|
{
|
2013-03-27 11:02:42 +01:00
|
|
|
jsstr_t *name_str;
|
|
|
|
const WCHAR *name;
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t v, namev;
|
2011-12-07 11:01:13 +01:00
|
|
|
IDispatch *obj;
|
|
|
|
DISPID id;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
namev = stack_pop(ctx);
|
|
|
|
|
|
|
|
hres = stack_pop_object(ctx, &obj);
|
|
|
|
if(FAILED(hres)) {
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(namev);
|
2011-12-07 11:01:13 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = to_flat_string(ctx, namev, &name_str, &name);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(namev);
|
2011-12-07 11:01:13 +01:00
|
|
|
if(FAILED(hres)) {
|
|
|
|
IDispatch_Release(obj);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = disp_get_id(ctx, obj, name, NULL, 0, &id);
|
2013-03-27 11:02:42 +01:00
|
|
|
jsstr_release(name_str);
|
2011-12-07 11:01:13 +01:00
|
|
|
if(SUCCEEDED(hres)) {
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = disp_propget(ctx, obj, id, &v);
|
2011-12-07 11:01:13 +01:00
|
|
|
}else if(hres == DISP_E_UNKNOWNNAME) {
|
2012-09-17 15:17:02 +02:00
|
|
|
v = jsval_undefined();
|
2011-12-07 11:01:13 +01:00
|
|
|
hres = S_OK;
|
|
|
|
}
|
|
|
|
IDispatch_Release(obj);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, v);
|
2011-12-07 11:01:13 +01:00
|
|
|
}
|
|
|
|
|
2011-12-06 10:42:09 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.2.1 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_member(script_ctx_t *ctx)
|
2011-12-06 10:42:09 +01:00
|
|
|
{
|
2012-05-12 16:21:01 +02:00
|
|
|
const BSTR arg = get_op_bstr(ctx, 0);
|
2011-12-06 10:42:09 +01:00
|
|
|
IDispatch *obj;
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t v;
|
2011-12-06 10:42:09 +01:00
|
|
|
DISPID id;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hres = stack_pop_object(ctx, &obj);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = disp_get_id(ctx, obj, arg, arg, 0, &id);
|
2011-12-06 10:42:09 +01:00
|
|
|
if(SUCCEEDED(hres)) {
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = disp_propget(ctx, obj, id, &v);
|
2011-12-06 10:42:09 +01:00
|
|
|
}else if(hres == DISP_E_UNKNOWNNAME) {
|
2012-09-17 15:17:02 +02:00
|
|
|
v = jsval_undefined();
|
2011-12-06 10:42:09 +01:00
|
|
|
hres = S_OK;
|
|
|
|
}
|
|
|
|
IDispatch_Release(obj);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, v);
|
2011-12-06 10:42:09 +01:00
|
|
|
}
|
|
|
|
|
2011-12-05 11:11:45 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.2.1 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_memberid(script_ctx_t *ctx)
|
2011-12-05 11:11:45 +01:00
|
|
|
{
|
2012-05-12 16:21:20 +02:00
|
|
|
const unsigned arg = get_op_uint(ctx, 0);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t objv, namev;
|
2013-03-27 11:02:42 +01:00
|
|
|
const WCHAR *name;
|
|
|
|
jsstr_t *name_str;
|
2011-12-05 11:11:45 +01:00
|
|
|
IDispatch *obj;
|
2016-08-02 17:40:54 +02:00
|
|
|
exprval_t ref;
|
2011-12-05 11:11:45 +01:00
|
|
|
DISPID id;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-12-07 11:00:20 +01:00
|
|
|
TRACE("%x\n", arg);
|
2011-12-05 11:11:45 +01:00
|
|
|
|
|
|
|
namev = stack_pop(ctx);
|
|
|
|
objv = stack_pop(ctx);
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = to_object(ctx, objv, &obj);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(objv);
|
2011-12-05 11:11:45 +01:00
|
|
|
if(SUCCEEDED(hres)) {
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = to_flat_string(ctx, namev, &name_str, &name);
|
2011-12-05 11:11:45 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
IDispatch_Release(obj);
|
|
|
|
}
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(namev);
|
2011-12-05 11:11:45 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = disp_get_id(ctx, obj, name, NULL, arg, &id);
|
2013-03-27 11:02:42 +01:00
|
|
|
jsstr_release(name_str);
|
2016-08-02 17:40:54 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
ref.type = EXPRVAL_IDREF;
|
|
|
|
ref.u.idref.disp = obj;
|
|
|
|
ref.u.idref.id = id;
|
|
|
|
}else {
|
2011-12-05 11:11:45 +01:00
|
|
|
IDispatch_Release(obj);
|
2011-12-07 11:00:20 +01:00
|
|
|
if(hres == DISP_E_UNKNOWNNAME && !(arg & fdexNameEnsure)) {
|
2016-08-02 17:40:54 +02:00
|
|
|
exprval_set_exception(&ref, JS_E_INVALID_PROPERTY);
|
|
|
|
hres = S_OK;
|
2011-12-07 11:00:20 +01:00
|
|
|
}else {
|
2012-09-17 15:17:02 +02:00
|
|
|
ERR("failed %08x\n", hres);
|
2011-12-07 11:00:20 +01:00
|
|
|
return hres;
|
|
|
|
}
|
2011-12-05 11:11:45 +01:00
|
|
|
}
|
|
|
|
|
2016-08-02 17:40:54 +02:00
|
|
|
return stack_push_exprval(ctx, &ref);
|
2011-12-05 11:11:45 +01:00
|
|
|
}
|
|
|
|
|
2011-12-05 11:13:02 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.2.1 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_refval(script_ctx_t *ctx)
|
2011-12-05 11:13:02 +01:00
|
|
|
{
|
2016-08-02 17:40:54 +02:00
|
|
|
exprval_t ref;
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t v;
|
2011-12-05 11:13:02 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2016-08-02 17:40:54 +02:00
|
|
|
if(!stack_topn_exprval(ctx, 0, &ref))
|
2020-01-31 17:23:05 +01:00
|
|
|
return JS_E_ILLEGAL_ASSIGN;
|
2011-12-05 11:13:02 +01:00
|
|
|
|
2016-08-02 17:40:54 +02:00
|
|
|
hres = exprval_propget(ctx, &ref, &v);
|
2011-12-05 11:13:02 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, v);
|
2012-09-17 15:16:42 +02:00
|
|
|
}
|
|
|
|
|
2008-09-10 21:07:35 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.2.2 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_new(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-09-17 15:16:42 +02:00
|
|
|
const unsigned argc = get_op_uint(ctx, 0);
|
2016-03-28 17:49:10 +02:00
|
|
|
jsval_t constr;
|
2008-09-10 21:07:35 +02:00
|
|
|
|
2012-09-17 15:16:42 +02:00
|
|
|
TRACE("%d\n", argc);
|
2008-09-10 21:07:35 +02:00
|
|
|
|
2012-09-17 15:16:42 +02:00
|
|
|
constr = stack_topn(ctx, argc);
|
2008-09-10 21:07:35 +02:00
|
|
|
|
2010-10-01 20:19:29 +02:00
|
|
|
/* NOTE: Should use to_object here */
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
if(is_null(constr))
|
2020-01-31 17:23:33 +01:00
|
|
|
return JS_E_OBJECT_EXPECTED;
|
2012-09-17 15:17:02 +02:00
|
|
|
else if(!is_object_instance(constr))
|
2020-01-31 17:23:33 +01:00
|
|
|
return JS_E_INVALID_ACTION;
|
2012-09-17 15:17:02 +02:00
|
|
|
else if(!get_object(constr))
|
2020-01-31 17:23:33 +01:00
|
|
|
return JS_E_INVALID_PROPERTY;
|
2008-09-10 21:07:35 +02:00
|
|
|
|
2018-06-12 14:04:11 +02:00
|
|
|
clear_acc(ctx);
|
2016-03-29 17:49:19 +02:00
|
|
|
return disp_call_value(ctx, get_object(constr), NULL, DISPATCH_CONSTRUCT | DISPATCH_JSCRIPT_CALLEREXECSSOURCE,
|
2018-06-12 14:04:11 +02:00
|
|
|
argc, stack_args(ctx, argc), &ctx->acc);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:45:50 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.2.3 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_call(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-05-12 16:21:10 +02:00
|
|
|
const unsigned argn = get_op_uint(ctx, 0);
|
2012-05-12 16:21:20 +02:00
|
|
|
const int do_ret = get_op_int(ctx, 1);
|
2016-03-28 17:49:24 +02:00
|
|
|
jsval_t obj;
|
2008-09-09 01:25:05 +02:00
|
|
|
|
2011-12-07 11:00:44 +01:00
|
|
|
TRACE("%d %d\n", argn, do_ret);
|
2008-09-09 01:25:05 +02:00
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
obj = stack_topn(ctx, argn);
|
|
|
|
if(!is_object_instance(obj))
|
2020-01-31 17:23:33 +01:00
|
|
|
return JS_E_INVALID_PROPERTY;
|
2008-09-09 01:25:05 +02:00
|
|
|
|
2018-06-12 14:04:11 +02:00
|
|
|
clear_acc(ctx);
|
2016-03-29 17:49:08 +02:00
|
|
|
return disp_call_value(ctx, get_object(obj), NULL, DISPATCH_METHOD | DISPATCH_JSCRIPT_CALLEREXECSSOURCE,
|
2018-06-12 14:04:11 +02:00
|
|
|
argn, stack_args(ctx, argn), do_ret ? &ctx->acc : NULL);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2011-12-07 11:00:20 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.2.3 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_call_member(script_ctx_t *ctx)
|
2011-12-07 11:00:20 +01:00
|
|
|
{
|
2012-05-12 16:21:10 +02:00
|
|
|
const unsigned argn = get_op_uint(ctx, 0);
|
2012-05-12 16:21:20 +02:00
|
|
|
const int do_ret = get_op_int(ctx, 1);
|
2016-08-02 17:40:54 +02:00
|
|
|
exprval_t ref;
|
2011-12-07 11:00:20 +01:00
|
|
|
|
|
|
|
TRACE("%d %d\n", argn, do_ret);
|
|
|
|
|
2016-08-02 17:40:54 +02:00
|
|
|
if(!stack_topn_exprval(ctx, argn, &ref))
|
2020-01-31 17:23:33 +01:00
|
|
|
return ref.u.hres;
|
2011-12-07 11:00:20 +01:00
|
|
|
|
2018-06-12 14:04:11 +02:00
|
|
|
clear_acc(ctx);
|
2016-08-02 17:40:54 +02:00
|
|
|
return exprval_call(ctx, &ref, DISPATCH_METHOD | DISPATCH_JSCRIPT_CALLEREXECSSOURCE,
|
2018-06-12 14:04:11 +02:00
|
|
|
argn, stack_args(ctx, argn), do_ret ? &ctx->acc : NULL);
|
2011-12-07 11:00:20 +01:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:45:50 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.1.1 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_this(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2020-03-06 14:48:38 +01:00
|
|
|
IDispatch *this_obj = ctx->call_ctx->this_obj;
|
2016-03-25 17:49:14 +01:00
|
|
|
|
2008-09-10 21:05:14 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2020-03-11 14:06:30 +01:00
|
|
|
if(!this_obj) {
|
|
|
|
named_item_t *item = ctx->call_ctx->bytecode->named_item;
|
|
|
|
|
|
|
|
if(item)
|
|
|
|
this_obj = (item->flags & SCRIPTITEM_CODEONLY) ? to_disp(item->script_obj) : item->disp;
|
|
|
|
else
|
|
|
|
this_obj = lookup_global_host(ctx);
|
|
|
|
}
|
2020-03-06 14:48:38 +01:00
|
|
|
|
|
|
|
IDispatch_AddRef(this_obj);
|
|
|
|
return stack_push(ctx, jsval_disp(this_obj));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2016-08-04 13:40:37 +02:00
|
|
|
static HRESULT interp_identifier_ref(script_ctx_t *ctx, BSTR identifier, unsigned flags)
|
|
|
|
{
|
|
|
|
exprval_t exprval;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = identifier_eval(ctx, identifier, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(exprval.type == EXPRVAL_INVALID && (flags & fdexNameEnsure)) {
|
2020-03-18 14:19:49 +01:00
|
|
|
jsdisp_t *script_obj = ctx->global;
|
2016-08-04 13:40:37 +02:00
|
|
|
DISPID id;
|
|
|
|
|
2020-03-18 14:19:49 +01:00
|
|
|
if(ctx->call_ctx->bytecode->named_item)
|
|
|
|
script_obj = ctx->call_ctx->bytecode->named_item->script_obj;
|
|
|
|
|
|
|
|
hres = jsdisp_get_id(script_obj, identifier, fdexNameEnsure, &id);
|
2016-08-04 13:40:37 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2020-03-18 14:19:49 +01:00
|
|
|
exprval_set_disp_ref(&exprval, to_disp(script_obj), id);
|
2016-08-04 13:40:37 +02:00
|
|
|
}
|
|
|
|
|
2021-04-12 15:47:51 +02:00
|
|
|
if(exprval.type == EXPRVAL_INVALID ||
|
|
|
|
(exprval.type == EXPRVAL_JSVAL && ctx->version < SCRIPTLANGUAGEVERSION_ES5)) {
|
2016-08-04 13:40:37 +02:00
|
|
|
WARN("invalid ref\n");
|
|
|
|
exprval_release(&exprval);
|
|
|
|
exprval_set_exception(&exprval, JS_E_OBJECT_EXPECTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
return stack_push_exprval(ctx, &exprval);
|
|
|
|
}
|
|
|
|
|
2016-08-04 13:40:44 +02:00
|
|
|
static HRESULT identifier_value(script_ctx_t *ctx, BSTR identifier)
|
|
|
|
{
|
|
|
|
exprval_t exprval;
|
|
|
|
jsval_t v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = identifier_eval(ctx, identifier, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(exprval.type == EXPRVAL_INVALID)
|
2020-02-03 14:47:32 +01:00
|
|
|
return throw_error(ctx, exprval.u.hres, identifier);
|
2016-08-04 13:40:44 +02:00
|
|
|
|
|
|
|
hres = exprval_to_value(ctx, &exprval, &v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push(ctx, v);
|
|
|
|
}
|
|
|
|
|
2016-08-04 13:40:37 +02:00
|
|
|
static HRESULT interp_local_ref(script_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
const int arg = get_op_int(ctx, 0);
|
|
|
|
const unsigned flags = get_op_uint(ctx, 1);
|
|
|
|
call_frame_t *frame = ctx->call_ctx;
|
|
|
|
exprval_t ref;
|
|
|
|
|
2021-03-12 18:39:23 +01:00
|
|
|
TRACE("%s\n", debugstr_w(local_name(frame, arg)));
|
2016-08-04 13:40:37 +02:00
|
|
|
|
|
|
|
if(!frame->base_scope || !frame->base_scope->frame)
|
|
|
|
return interp_identifier_ref(ctx, local_name(frame, arg), flags);
|
|
|
|
|
|
|
|
ref.type = EXPRVAL_STACK_REF;
|
|
|
|
ref.u.off = local_off(frame, arg);
|
|
|
|
return stack_push_exprval(ctx, &ref);
|
|
|
|
}
|
|
|
|
|
2016-08-04 13:40:44 +02:00
|
|
|
static HRESULT interp_local(script_ctx_t *ctx)
|
2011-11-28 12:08:54 +01:00
|
|
|
{
|
2016-08-04 13:40:44 +02:00
|
|
|
const int arg = get_op_int(ctx, 0);
|
|
|
|
call_frame_t *frame = ctx->call_ctx;
|
|
|
|
jsval_t copy;
|
2011-11-28 12:08:54 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
2021-03-12 18:39:23 +01:00
|
|
|
if(!frame->base_scope || !frame->base_scope->frame) {
|
|
|
|
TRACE("%s\n", debugstr_w(local_name(frame, arg)));
|
2016-08-04 13:40:44 +02:00
|
|
|
return identifier_value(ctx, local_name(frame, arg));
|
2021-03-12 18:39:23 +01:00
|
|
|
}
|
2011-11-28 12:08:54 +01:00
|
|
|
|
2016-08-04 13:40:44 +02:00
|
|
|
hres = jsval_copy(ctx->stack[local_off(frame, arg)], ©);
|
2011-11-28 12:08:54 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2021-03-12 18:39:23 +01:00
|
|
|
TRACE("%s: %s\n", debugstr_w(local_name(frame, arg)), debugstr_jsval(copy));
|
2016-08-04 13:40:44 +02:00
|
|
|
return stack_push(ctx, copy);
|
|
|
|
}
|
2011-12-20 11:47:02 +01:00
|
|
|
|
2016-08-04 13:40:44 +02:00
|
|
|
/* ECMA-262 3rd Edition 10.1.4 */
|
|
|
|
static HRESULT interp_ident(script_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
const BSTR arg = get_op_bstr(ctx, 0);
|
2011-11-28 12:08:54 +01:00
|
|
|
|
2016-08-04 13:40:44 +02:00
|
|
|
TRACE("%s\n", debugstr_w(arg));
|
|
|
|
|
|
|
|
return identifier_value(ctx, arg);
|
2011-11-28 12:08:54 +01:00
|
|
|
}
|
|
|
|
|
2011-12-05 11:11:29 +01:00
|
|
|
/* ECMA-262 3rd Edition 10.1.4 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_identid(script_ctx_t *ctx)
|
2011-12-05 11:11:29 +01:00
|
|
|
{
|
2012-05-12 16:21:01 +02:00
|
|
|
const BSTR arg = get_op_bstr(ctx, 0);
|
2012-05-12 16:21:10 +02:00
|
|
|
const unsigned flags = get_op_uint(ctx, 1);
|
2011-12-05 11:11:29 +01:00
|
|
|
|
2011-12-07 11:00:20 +01:00
|
|
|
TRACE("%s %x\n", debugstr_w(arg), flags);
|
2011-12-05 11:11:29 +01:00
|
|
|
|
2016-08-04 13:40:37 +02:00
|
|
|
return interp_identifier_ref(ctx, arg, flags);
|
2011-12-05 11:11:29 +01:00
|
|
|
}
|
|
|
|
|
2011-11-24 14:23:26 +01:00
|
|
|
/* ECMA-262 3rd Edition 7.8.1 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_null(script_ctx_t *ctx)
|
2011-11-24 14:23:26 +01:00
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_null());
|
2011-11-24 14:23:26 +01:00
|
|
|
}
|
|
|
|
|
2011-11-23 12:13:57 +01:00
|
|
|
/* ECMA-262 3rd Edition 7.8.2 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_bool(script_ctx_t *ctx)
|
2011-11-23 12:13:57 +01:00
|
|
|
{
|
2012-05-12 16:21:20 +02:00
|
|
|
const int arg = get_op_int(ctx, 0);
|
2011-11-23 12:13:57 +01:00
|
|
|
|
|
|
|
TRACE("%s\n", arg ? "true" : "false");
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_bool(arg));
|
2011-11-23 12:13:57 +01:00
|
|
|
}
|
|
|
|
|
2011-11-23 12:13:46 +01:00
|
|
|
/* ECMA-262 3rd Edition 7.8.3 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_int(script_ctx_t *ctx)
|
2011-11-23 12:13:46 +01:00
|
|
|
{
|
2012-05-12 16:21:20 +02:00
|
|
|
const int arg = get_op_int(ctx, 0);
|
2011-11-23 12:13:46 +01:00
|
|
|
|
|
|
|
TRACE("%d\n", arg);
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_number(arg));
|
2011-11-23 12:13:46 +01:00
|
|
|
}
|
|
|
|
|
2011-11-23 12:14:31 +01:00
|
|
|
/* ECMA-262 3rd Edition 7.8.3 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_double(script_ctx_t *ctx)
|
2011-11-23 12:14:31 +01:00
|
|
|
{
|
2012-05-12 16:21:56 +02:00
|
|
|
const double arg = get_op_double(ctx);
|
2011-11-23 12:14:31 +01:00
|
|
|
|
|
|
|
TRACE("%lf\n", arg);
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_number(arg));
|
2011-11-23 12:14:31 +01:00
|
|
|
}
|
|
|
|
|
2011-11-23 12:14:15 +01:00
|
|
|
/* ECMA-262 3rd Edition 7.8.4 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_str(script_ctx_t *ctx)
|
2011-11-23 12:14:15 +01:00
|
|
|
{
|
2012-10-11 12:17:17 +02:00
|
|
|
jsstr_t *str = get_op_str(ctx, 0);
|
2011-11-23 12:14:15 +01:00
|
|
|
|
2012-10-11 12:17:17 +02:00
|
|
|
TRACE("%s\n", debugstr_jsstr(str));
|
2011-11-23 12:14:15 +01:00
|
|
|
|
2012-10-11 12:17:17 +02:00
|
|
|
return stack_push(ctx, jsval_string(jsstr_addref(str)));
|
2011-11-23 12:14:15 +01:00
|
|
|
}
|
|
|
|
|
2011-11-24 14:23:39 +01:00
|
|
|
/* ECMA-262 3rd Edition 7.8 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_regexp(script_ctx_t *ctx)
|
2011-11-24 14:23:39 +01:00
|
|
|
{
|
2012-10-11 12:17:17 +02:00
|
|
|
jsstr_t *source = get_op_str(ctx, 0);
|
2012-05-12 16:21:44 +02:00
|
|
|
const unsigned flags = get_op_uint(ctx, 1);
|
2011-11-24 14:23:39 +01:00
|
|
|
jsdisp_t *regexp;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2012-10-11 12:17:17 +02:00
|
|
|
TRACE("%s %x\n", debugstr_jsstr(source), flags);
|
2012-10-11 12:16:50 +02:00
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = create_regexp(ctx, source, flags, ®exp);
|
2011-11-24 14:23:39 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_obj(regexp));
|
2011-11-24 14:23:39 +01:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:34:23 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.1.4 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_carray(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-05-12 16:21:10 +02:00
|
|
|
const unsigned arg = get_op_uint(ctx, 0);
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *array;
|
2008-09-17 23:34:23 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2011-12-08 12:02:40 +01:00
|
|
|
TRACE("%u\n", arg);
|
2008-09-17 23:34:23 +02:00
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = create_array(ctx, arg, &array);
|
2008-09-17 23:34:23 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_obj(array));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2018-03-01 23:58:38 +01:00
|
|
|
static HRESULT interp_carray_set(script_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
const unsigned index = get_op_uint(ctx, 0);
|
|
|
|
jsval_t value, array;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
value = stack_pop(ctx);
|
|
|
|
|
|
|
|
TRACE("[%u] = %s\n", index, debugstr_jsval(value));
|
|
|
|
|
|
|
|
array = stack_top(ctx);
|
|
|
|
assert(is_object_instance(array));
|
|
|
|
|
|
|
|
hres = jsdisp_propput_idx(iface_to_jsdisp(get_object(array)), index, value);
|
|
|
|
jsval_release(value);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2008-09-10 21:10:23 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.1.5 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_new_obj(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *obj;
|
2008-09-10 21:10:23 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = create_object(ctx, NULL, &obj);
|
2008-09-10 21:10:23 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_obj(obj));
|
2011-12-16 11:43:31 +01:00
|
|
|
}
|
2008-09-10 21:10:23 +02:00
|
|
|
|
2011-12-16 11:43:31 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.1.5 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_obj_prop(script_ctx_t *ctx)
|
2011-12-16 11:43:31 +01:00
|
|
|
{
|
2019-03-01 17:43:52 +01:00
|
|
|
jsstr_t *name_arg = get_op_str(ctx, 0);
|
2018-11-30 22:44:40 +01:00
|
|
|
unsigned type = get_op_uint(ctx, 1);
|
2019-03-01 17:43:52 +01:00
|
|
|
const WCHAR *name;
|
2011-12-16 11:43:31 +01:00
|
|
|
jsdisp_t *obj;
|
2012-09-17 15:16:42 +02:00
|
|
|
jsval_t val;
|
2011-12-16 11:43:31 +01:00
|
|
|
HRESULT hres;
|
2008-09-10 21:10:23 +02:00
|
|
|
|
2019-03-01 17:43:52 +01:00
|
|
|
TRACE("%s\n", debugstr_jsstr(name_arg));
|
2008-09-10 21:10:23 +02:00
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
val = stack_pop(ctx);
|
2008-09-10 21:10:23 +02:00
|
|
|
|
2019-03-01 17:43:52 +01:00
|
|
|
/* FIXME: we should pass it as jsstr_t */
|
|
|
|
name = jsstr_flatten(name_arg);
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
assert(is_object_instance(stack_top(ctx)));
|
|
|
|
obj = as_jsdisp(get_object(stack_top(ctx)));
|
2008-09-10 21:10:23 +02:00
|
|
|
|
2018-11-30 22:44:40 +01:00
|
|
|
if(type == PROPERTY_DEFINITION_VALUE) {
|
|
|
|
hres = jsdisp_propput_name(obj, name, val);
|
|
|
|
}else {
|
|
|
|
property_desc_t desc = {PROPF_ENUMERABLE | PROPF_CONFIGURABLE};
|
|
|
|
jsdisp_t *func;
|
|
|
|
|
|
|
|
assert(is_object_instance(val));
|
|
|
|
func = iface_to_jsdisp(get_object(val));
|
|
|
|
|
|
|
|
desc.mask = desc.flags;
|
|
|
|
if(type == PROPERTY_DEFINITION_GETTER) {
|
|
|
|
desc.explicit_getter = TRUE;
|
|
|
|
desc.getter = func;
|
|
|
|
}else {
|
|
|
|
desc.explicit_setter = TRUE;
|
|
|
|
desc.setter = func;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = jsdisp_define_property(obj, name, &desc);
|
|
|
|
jsdisp_release(func);
|
|
|
|
}
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(val);
|
2011-12-16 11:43:31 +01:00
|
|
|
return hres;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-11 23:55:14 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.11 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_cnd_nz(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-05-12 16:21:10 +02:00
|
|
|
const unsigned arg = get_op_uint(ctx, 0);
|
2012-09-17 15:17:02 +02:00
|
|
|
BOOL b;
|
2008-09-11 23:55:14 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2012-09-17 15:18:03 +02:00
|
|
|
hres = to_boolean(stack_top(ctx), &b);
|
2008-09-11 23:55:14 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-11-28 12:03:57 +01:00
|
|
|
if(b) {
|
2016-03-25 12:03:25 +01:00
|
|
|
jmp_abs(ctx, arg);
|
2011-11-28 12:03:57 +01:00
|
|
|
}else {
|
|
|
|
stack_popn(ctx, 1);
|
2016-03-25 12:03:25 +01:00
|
|
|
jmp_next(ctx);
|
2008-09-11 23:55:14 +02:00
|
|
|
}
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-11 23:55:38 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.11 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_cnd_z(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-05-12 16:21:10 +02:00
|
|
|
const unsigned arg = get_op_uint(ctx, 0);
|
2012-09-17 15:17:02 +02:00
|
|
|
BOOL b;
|
2008-09-11 23:55:38 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2012-09-17 15:18:03 +02:00
|
|
|
hres = to_boolean(stack_top(ctx), &b);
|
2008-09-11 23:55:38 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-11-28 12:04:33 +01:00
|
|
|
if(b) {
|
|
|
|
stack_popn(ctx, 1);
|
2016-03-25 12:03:25 +01:00
|
|
|
jmp_next(ctx);
|
2011-11-28 12:04:33 +01:00
|
|
|
}else {
|
2016-03-25 12:03:25 +01:00
|
|
|
jmp_abs(ctx, arg);
|
2008-09-11 23:55:38 +02:00
|
|
|
}
|
|
|
|
return S_OK;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:31:02 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.10 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_or(script_ctx_t *ctx)
|
2008-09-17 23:31:02 +02:00
|
|
|
{
|
2011-11-29 11:09:35 +01:00
|
|
|
INT l, r;
|
|
|
|
HRESULT hres;
|
2008-09-17 23:31:02 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-29 11:09:35 +01:00
|
|
|
hres = stack_pop_int(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_int(ctx, &l);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_number(l|r));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:32:11 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.10 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_xor(script_ctx_t *ctx)
|
2008-09-17 23:32:11 +02:00
|
|
|
{
|
2011-11-29 11:09:49 +01:00
|
|
|
INT l, r;
|
|
|
|
HRESULT hres;
|
2008-09-17 23:32:11 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-29 11:09:49 +01:00
|
|
|
hres = stack_pop_int(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_int(ctx, &l);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_number(l^r));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:31:38 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.10 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_and(script_ctx_t *ctx)
|
2008-09-17 23:31:38 +02:00
|
|
|
{
|
2011-12-08 12:02:53 +01:00
|
|
|
INT l, r;
|
|
|
|
HRESULT hres;
|
2008-09-17 23:31:38 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-12-08 12:02:53 +01:00
|
|
|
hres = stack_pop_int(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_int(ctx, &l);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_number(l&r));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:45:50 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.8.6 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_instanceof(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *obj, *iter, *tmp = NULL;
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t prot, v;
|
2011-12-12 14:43:54 +01:00
|
|
|
BOOL ret = FALSE;
|
2009-08-29 00:01:25 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2011-12-12 14:43:54 +01:00
|
|
|
v = stack_pop(ctx);
|
2012-09-17 15:17:02 +02:00
|
|
|
if(!is_object_instance(v) || !get_object(v)) {
|
|
|
|
jsval_release(v);
|
2020-01-31 17:23:33 +01:00
|
|
|
return JS_E_FUNCTION_EXPECTED;
|
2011-12-12 14:43:54 +01:00
|
|
|
}
|
2009-08-29 00:01:25 +02:00
|
|
|
|
2016-07-20 13:40:41 +02:00
|
|
|
obj = iface_to_jsdisp(get_object(v));
|
2012-09-17 15:17:02 +02:00
|
|
|
IDispatch_Release(get_object(v));
|
2009-08-29 00:01:25 +02:00
|
|
|
if(!obj) {
|
2011-06-21 17:46:04 +02:00
|
|
|
FIXME("non-jsdisp objects not supported\n");
|
2009-08-29 00:01:25 +02:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(is_class(obj, JSCLASS_FUNCTION)) {
|
2020-11-24 00:49:04 +01:00
|
|
|
hres = jsdisp_propget_name(obj, L"prototype", &prot);
|
2009-08-29 00:01:25 +02:00
|
|
|
}else {
|
2020-01-31 17:23:33 +01:00
|
|
|
hres = JS_E_FUNCTION_EXPECTED;
|
2009-08-29 00:01:25 +02:00
|
|
|
}
|
|
|
|
jsdisp_release(obj);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-12-12 14:43:54 +01:00
|
|
|
v = stack_pop(ctx);
|
|
|
|
|
2012-09-17 15:16:42 +02:00
|
|
|
if(is_object_instance(prot)) {
|
2012-09-17 15:17:02 +02:00
|
|
|
if(is_object_instance(v))
|
2016-07-20 13:40:41 +02:00
|
|
|
tmp = iface_to_jsdisp(get_object(v));
|
2011-12-12 14:43:54 +01:00
|
|
|
for(iter = tmp; !ret && iter; iter = iter->prototype) {
|
2012-09-17 15:16:42 +02:00
|
|
|
hres = disp_cmp(get_object(prot), to_disp(iter), &ret);
|
2009-08-29 00:01:25 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tmp)
|
|
|
|
jsdisp_release(tmp);
|
|
|
|
}else {
|
|
|
|
FIXME("prototype is not an object\n");
|
|
|
|
hres = E_FAIL;
|
|
|
|
}
|
|
|
|
|
2012-09-17 15:16:42 +02:00
|
|
|
jsval_release(prot);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(v);
|
2009-08-29 00:01:25 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_bool(ret));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:45:50 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.8.7 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_in(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2013-03-27 11:02:42 +01:00
|
|
|
const WCHAR *str;
|
|
|
|
jsstr_t *jsstr;
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t obj, v;
|
2011-11-23 12:13:35 +01:00
|
|
|
DISPID id = 0;
|
|
|
|
BOOL ret;
|
2009-09-06 19:10:06 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2011-11-23 12:13:35 +01:00
|
|
|
TRACE("\n");
|
2009-09-06 19:10:06 +02:00
|
|
|
|
2011-11-23 12:13:35 +01:00
|
|
|
obj = stack_pop(ctx);
|
2012-09-17 15:17:02 +02:00
|
|
|
if(!is_object_instance(obj) || !get_object(obj)) {
|
|
|
|
jsval_release(obj);
|
2020-01-31 17:23:33 +01:00
|
|
|
return JS_E_OBJECT_EXPECTED;
|
2011-11-23 12:13:35 +01:00
|
|
|
}
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
v = stack_pop(ctx);
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = to_flat_string(ctx, v, &jsstr, &str);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(v);
|
2011-11-23 12:13:35 +01:00
|
|
|
if(FAILED(hres)) {
|
2012-09-17 15:17:02 +02:00
|
|
|
IDispatch_Release(get_object(obj));
|
2009-09-06 19:10:06 +02:00
|
|
|
return hres;
|
2011-11-23 12:13:35 +01:00
|
|
|
}
|
2009-09-06 19:10:06 +02:00
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = disp_get_id(ctx, get_object(obj), str, NULL, 0, &id);
|
2012-09-17 15:17:02 +02:00
|
|
|
IDispatch_Release(get_object(obj));
|
2013-03-27 11:02:42 +01:00
|
|
|
jsstr_release(jsstr);
|
2009-09-06 19:10:06 +02:00
|
|
|
if(SUCCEEDED(hres))
|
2011-11-23 12:13:35 +01:00
|
|
|
ret = TRUE;
|
2009-09-06 19:10:06 +02:00
|
|
|
else if(hres == DISP_E_UNKNOWNNAME)
|
2011-11-23 12:13:35 +01:00
|
|
|
ret = FALSE;
|
2009-09-06 19:10:06 +02:00
|
|
|
else
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_bool(ret));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-10 21:12:45 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.6.1 */
|
2020-06-04 17:28:03 +02:00
|
|
|
static HRESULT interp_add(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2020-06-04 17:28:03 +02:00
|
|
|
jsval_t l, r, lval, rval, ret;
|
2008-09-10 21:12:45 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2020-06-04 17:28:03 +02:00
|
|
|
rval = stack_pop(ctx);
|
|
|
|
lval = stack_pop(ctx);
|
|
|
|
|
|
|
|
TRACE("%s + %s\n", debugstr_jsval(lval), debugstr_jsval(rval));
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_primitive(ctx, lval, &l, NO_HINT);
|
2020-06-04 17:28:03 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = to_primitive(ctx, rval, &r, NO_HINT);
|
|
|
|
if(FAILED(hres))
|
|
|
|
jsval_release(l);
|
|
|
|
}
|
|
|
|
jsval_release(lval);
|
|
|
|
jsval_release(rval);
|
2008-09-10 21:12:45 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
if(is_string(l) || is_string(r)) {
|
2012-10-11 12:16:01 +02:00
|
|
|
jsstr_t *lstr, *rstr = NULL;
|
2008-09-10 21:12:45 +02:00
|
|
|
|
2012-10-11 12:16:01 +02:00
|
|
|
hres = to_string(ctx, l, &lstr);
|
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
hres = to_string(ctx, r, &rstr);
|
2008-09-10 21:12:45 +02:00
|
|
|
|
|
|
|
if(SUCCEEDED(hres)) {
|
2012-10-11 12:16:01 +02:00
|
|
|
jsstr_t *ret_str;
|
|
|
|
|
2012-12-18 11:16:24 +01:00
|
|
|
ret_str = jsstr_concat(lstr, rstr);
|
|
|
|
if(ret_str)
|
2020-06-04 17:28:03 +02:00
|
|
|
ret = jsval_string(ret_str);
|
2012-12-18 11:16:24 +01:00
|
|
|
else
|
2012-10-11 12:16:01 +02:00
|
|
|
hres = E_OUTOFMEMORY;
|
2008-09-10 21:12:45 +02:00
|
|
|
}
|
|
|
|
|
2012-10-11 12:16:01 +02:00
|
|
|
jsstr_release(lstr);
|
|
|
|
if(rstr)
|
|
|
|
jsstr_release(rstr);
|
2008-09-10 21:12:45 +02:00
|
|
|
}else {
|
2012-03-27 11:28:51 +02:00
|
|
|
double nl, nr;
|
2008-09-10 21:12:45 +02:00
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, l, &nl);
|
2008-09-10 21:12:45 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, r, &nr);
|
2008-09-10 21:12:45 +02:00
|
|
|
if(SUCCEEDED(hres))
|
2020-06-04 17:28:03 +02:00
|
|
|
ret = jsval_number(nl+nr);
|
2008-09-10 21:12:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(r);
|
|
|
|
jsval_release(l);
|
2011-11-22 16:31:44 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2008-09-10 21:12:45 +02:00
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-16 20:46:01 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.6.2 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_sub(script_ctx_t *ctx)
|
2008-09-16 20:46:01 +02:00
|
|
|
{
|
2012-03-27 11:30:03 +02:00
|
|
|
double l, r;
|
2011-11-25 12:06:05 +01:00
|
|
|
HRESULT hres;
|
2008-09-16 20:46:01 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-25 12:06:05 +01:00
|
|
|
hres = stack_pop_number(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_number(ctx, &l);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_number(l-r));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-16 20:46:33 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.5.1 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_mul(script_ctx_t *ctx)
|
2008-09-16 20:46:33 +02:00
|
|
|
{
|
2012-03-27 11:30:03 +02:00
|
|
|
double l, r;
|
2011-11-29 11:08:54 +01:00
|
|
|
HRESULT hres;
|
2008-09-16 20:46:33 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-29 11:08:54 +01:00
|
|
|
hres = stack_pop_number(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_number(ctx, &l);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_number(l*r));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-16 20:47:06 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.5.2 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_div(script_ctx_t *ctx)
|
2008-09-16 20:47:06 +02:00
|
|
|
{
|
2012-03-27 11:30:03 +02:00
|
|
|
double l, r;
|
2011-11-29 11:09:04 +01:00
|
|
|
HRESULT hres;
|
2008-09-16 20:47:06 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-29 11:09:04 +01:00
|
|
|
hres = stack_pop_number(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_number(ctx, &l);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_number(l/r));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-10-09 01:09:17 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.5.3 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_mod(script_ctx_t *ctx)
|
2008-10-09 01:09:17 +02:00
|
|
|
{
|
2012-03-27 11:30:03 +02:00
|
|
|
double l, r;
|
2011-11-29 11:09:20 +01:00
|
|
|
HRESULT hres;
|
2008-10-09 01:09:17 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-29 11:09:20 +01:00
|
|
|
hres = stack_pop_number(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_number(ctx, &l);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_number(fmod(l, r)));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2011-11-30 10:14:22 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.4.2 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_delete(script_ctx_t *ctx)
|
2011-11-30 10:14:22 +01:00
|
|
|
{
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t objv, namev;
|
2011-11-30 10:14:22 +01:00
|
|
|
IDispatch *obj;
|
2012-10-11 12:16:01 +02:00
|
|
|
jsstr_t *name;
|
2011-11-30 10:14:22 +01:00
|
|
|
BOOL ret;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
namev = stack_pop(ctx);
|
|
|
|
objv = stack_pop(ctx);
|
2011-11-30 10:14:22 +01:00
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = to_object(ctx, objv, &obj);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(objv);
|
2011-11-30 10:14:22 +01:00
|
|
|
if(FAILED(hres)) {
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(namev);
|
2011-11-30 10:14:22 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = to_string(ctx, namev, &name);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(namev);
|
2011-11-30 10:14:22 +01:00
|
|
|
if(FAILED(hres)) {
|
|
|
|
IDispatch_Release(obj);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = disp_delete_name(ctx, obj, name, &ret);
|
2011-11-30 10:14:22 +01:00
|
|
|
IDispatch_Release(obj);
|
2012-10-11 12:16:01 +02:00
|
|
|
jsstr_release(name);
|
2011-11-30 10:14:22 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_bool(ret));
|
2011-11-30 10:14:22 +01:00
|
|
|
}
|
|
|
|
|
2011-12-15 15:42:27 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.4.2 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_delete_ident(script_ctx_t *ctx)
|
2011-12-15 15:42:27 +01:00
|
|
|
{
|
2012-05-12 16:21:01 +02:00
|
|
|
const BSTR arg = get_op_bstr(ctx, 0);
|
2011-12-15 15:42:27 +01:00
|
|
|
exprval_t exprval;
|
2012-11-30 13:02:05 +01:00
|
|
|
BOOL ret;
|
2011-12-15 15:42:27 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(arg));
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = identifier_eval(ctx, arg, &exprval);
|
2011-12-15 15:42:27 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-12-17 13:36:18 +01:00
|
|
|
switch(exprval.type) {
|
2016-08-02 17:41:40 +02:00
|
|
|
case EXPRVAL_STACK_REF:
|
|
|
|
ret = FALSE;
|
|
|
|
break;
|
2012-12-17 13:36:18 +01:00
|
|
|
case EXPRVAL_IDREF:
|
|
|
|
hres = disp_delete(exprval.u.idref.disp, exprval.u.idref.id, &ret);
|
|
|
|
IDispatch_Release(exprval.u.idref.disp);
|
|
|
|
if(FAILED(hres))
|
2015-10-15 12:18:53 +02:00
|
|
|
return hres;
|
2012-12-17 13:36:18 +01:00
|
|
|
break;
|
|
|
|
case EXPRVAL_INVALID:
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
2011-12-15 15:42:27 +01:00
|
|
|
FIXME("Unsupported exprval\n");
|
|
|
|
exprval_release(&exprval);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_bool(ret));
|
2011-12-15 15:42:27 +01:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:42:33 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.4.2 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_void(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2008-09-19 00:42:33 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-24 14:24:45 +01:00
|
|
|
stack_popn(ctx, 1);
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_undefined());
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:42:33 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.4.3 */
|
2012-09-17 15:17:02 +02:00
|
|
|
static HRESULT typeof_string(jsval_t v, const WCHAR **ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-09-17 15:20:57 +02:00
|
|
|
switch(jsval_type(v)) {
|
2012-09-17 15:17:02 +02:00
|
|
|
case JSV_UNDEFINED:
|
2020-11-24 00:49:04 +01:00
|
|
|
*ret = L"undefined";
|
2008-09-10 02:36:03 +02:00
|
|
|
break;
|
2012-09-17 15:17:02 +02:00
|
|
|
case JSV_NULL:
|
2020-11-24 00:49:04 +01:00
|
|
|
*ret = L"object";
|
2008-09-10 02:36:03 +02:00
|
|
|
break;
|
2012-09-17 15:17:02 +02:00
|
|
|
case JSV_OBJECT: {
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *dispex;
|
2008-09-10 02:36:03 +02:00
|
|
|
|
2016-07-20 13:40:41 +02:00
|
|
|
if(get_object(v) && (dispex = iface_to_jsdisp(get_object(v)))) {
|
2020-11-24 00:49:04 +01:00
|
|
|
*ret = is_class(dispex, JSCLASS_FUNCTION) ? L"function" : L"object";
|
2009-08-27 01:21:56 +02:00
|
|
|
jsdisp_release(dispex);
|
2008-09-10 02:36:03 +02:00
|
|
|
}else {
|
2020-11-24 00:49:04 +01:00
|
|
|
*ret = L"object";
|
2008-09-10 02:36:03 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-09-17 15:17:02 +02:00
|
|
|
case JSV_STRING:
|
2020-11-24 00:49:04 +01:00
|
|
|
*ret = L"string";
|
2012-09-17 15:17:02 +02:00
|
|
|
break;
|
|
|
|
case JSV_NUMBER:
|
2020-11-24 00:49:04 +01:00
|
|
|
*ret = L"number";
|
2012-09-17 15:17:02 +02:00
|
|
|
break;
|
|
|
|
case JSV_BOOL:
|
2020-11-24 00:49:04 +01:00
|
|
|
*ret = L"boolean";
|
2012-09-17 15:17:02 +02:00
|
|
|
break;
|
|
|
|
case JSV_VARIANT:
|
|
|
|
FIXME("unhandled variant %s\n", debugstr_variant(get_variant(v)));
|
2011-12-13 11:57:11 +01:00
|
|
|
return E_NOTIMPL;
|
2008-09-10 02:36:03 +02:00
|
|
|
}
|
|
|
|
|
2011-12-13 11:57:11 +01:00
|
|
|
return S_OK;
|
2009-08-27 01:21:56 +02:00
|
|
|
}
|
|
|
|
|
2011-12-13 11:57:11 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.4.3 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_typeofid(script_ctx_t *ctx)
|
2009-08-27 01:21:56 +02:00
|
|
|
{
|
2011-12-13 11:57:11 +01:00
|
|
|
const WCHAR *ret;
|
2016-08-02 17:40:54 +02:00
|
|
|
exprval_t ref;
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t v;
|
2009-08-27 01:21:56 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2016-08-02 17:40:54 +02:00
|
|
|
if(!stack_pop_exprval(ctx, &ref))
|
2013-03-08 11:37:56 +01:00
|
|
|
return stack_push(ctx, jsval_string(jsstr_undefined()));
|
2011-12-13 11:57:11 +01:00
|
|
|
|
2016-08-02 17:40:54 +02:00
|
|
|
hres = exprval_propget(ctx, &ref, &v);
|
|
|
|
exprval_release(&ref);
|
2011-12-13 11:57:11 +01:00
|
|
|
if(FAILED(hres))
|
2020-11-24 00:49:04 +01:00
|
|
|
return stack_push_string(ctx, L"unknown");
|
2011-12-13 11:57:11 +01:00
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
hres = typeof_string(v, &ret);
|
|
|
|
jsval_release(v);
|
2009-08-27 01:21:56 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-12-13 11:57:11 +01:00
|
|
|
return stack_push_string(ctx, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.4.3 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_typeofident(script_ctx_t *ctx)
|
2011-12-13 11:57:11 +01:00
|
|
|
{
|
2012-05-12 16:21:01 +02:00
|
|
|
const BSTR arg = get_op_bstr(ctx, 0);
|
2011-12-13 11:57:11 +01:00
|
|
|
exprval_t exprval;
|
|
|
|
const WCHAR *ret;
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t v;
|
2011-12-13 11:57:11 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(arg));
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = identifier_eval(ctx, arg, &exprval);
|
2011-12-13 11:57:11 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2016-08-02 17:40:54 +02:00
|
|
|
if(exprval.type == EXPRVAL_INVALID)
|
|
|
|
return stack_push(ctx, jsval_string(jsstr_undefined()));
|
2011-12-13 11:57:11 +01:00
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = exprval_to_value(ctx, &exprval, &v);
|
2009-08-27 01:21:56 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2008-09-10 02:36:03 +02:00
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
hres = typeof_string(v, &ret);
|
|
|
|
jsval_release(v);
|
2011-12-13 11:57:11 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2009-08-27 01:21:56 +02:00
|
|
|
|
2011-12-13 11:57:11 +01:00
|
|
|
return stack_push_string(ctx, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.4.3 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_typeof(script_ctx_t *ctx)
|
2011-12-13 11:57:11 +01:00
|
|
|
{
|
|
|
|
const WCHAR *ret;
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t v;
|
2011-12-13 11:57:11 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
v = stack_pop(ctx);
|
|
|
|
hres = typeof_string(v, &ret);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(v);
|
2011-12-13 11:57:11 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return stack_push_string(ctx, ret);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-16 20:47:43 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.4.7 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_minus(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-03-27 11:30:03 +02:00
|
|
|
double n;
|
2008-09-16 20:47:43 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-25 12:06:30 +01:00
|
|
|
hres = stack_pop_number(ctx, &n);
|
2008-09-16 20:47:43 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_number(-n));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:33:15 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.4.6 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_tonum(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t v;
|
2012-03-27 11:28:51 +02:00
|
|
|
double n;
|
2008-09-17 23:33:15 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-21 15:35:41 +01:00
|
|
|
v = stack_pop(ctx);
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = to_number(ctx, v, &n);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(v);
|
2008-09-17 23:33:15 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_number(n));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-11 23:58:28 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.3.1 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_postinc(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-05-12 16:21:20 +02:00
|
|
|
const int arg = get_op_int(ctx, 0);
|
2016-08-02 17:40:54 +02:00
|
|
|
exprval_t ref;
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t v;
|
2008-09-11 23:58:28 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2011-12-07 11:01:53 +01:00
|
|
|
TRACE("%d\n", arg);
|
2008-09-11 23:58:28 +02:00
|
|
|
|
2016-08-02 17:40:54 +02:00
|
|
|
if(!stack_pop_exprval(ctx, &ref))
|
2020-01-31 17:23:33 +01:00
|
|
|
return JS_E_OBJECT_EXPECTED;
|
2008-09-11 23:58:28 +02:00
|
|
|
|
2016-08-02 17:40:54 +02:00
|
|
|
hres = exprval_propget(ctx, &ref, &v);
|
2008-09-11 23:58:28 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
2012-03-27 11:28:51 +02:00
|
|
|
double n;
|
2008-09-11 23:58:28 +02:00
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = to_number(ctx, v, &n);
|
2012-09-17 15:17:02 +02:00
|
|
|
if(SUCCEEDED(hres))
|
2016-08-02 17:40:54 +02:00
|
|
|
hres = exprval_propput(ctx, &ref, jsval_number(n+(double)arg));
|
2011-12-09 11:04:14 +01:00
|
|
|
if(FAILED(hres))
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(v);
|
2008-09-11 23:58:28 +02:00
|
|
|
}
|
2016-08-02 17:40:54 +02:00
|
|
|
exprval_release(&ref);
|
2008-09-11 23:58:28 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, v);
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2011-12-08 12:02:23 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.4.4, 11.4.5 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_preinc(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-05-12 16:21:20 +02:00
|
|
|
const int arg = get_op_int(ctx, 0);
|
2016-08-02 17:40:54 +02:00
|
|
|
exprval_t ref;
|
2012-09-17 15:17:02 +02:00
|
|
|
double ret;
|
|
|
|
jsval_t v;
|
2008-09-11 23:57:40 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2011-12-08 12:02:08 +01:00
|
|
|
TRACE("%d\n", arg);
|
2008-09-11 23:57:40 +02:00
|
|
|
|
2016-08-02 17:40:54 +02:00
|
|
|
if(!stack_pop_exprval(ctx, &ref))
|
2020-01-31 17:23:33 +01:00
|
|
|
return JS_E_OBJECT_EXPECTED;
|
2008-09-11 23:57:40 +02:00
|
|
|
|
2016-08-02 17:40:54 +02:00
|
|
|
hres = exprval_propget(ctx, &ref, &v);
|
2008-09-11 23:57:40 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
2012-03-27 11:28:51 +02:00
|
|
|
double n;
|
2008-09-11 23:57:40 +02:00
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = to_number(ctx, v, &n);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(v);
|
2011-12-08 12:02:08 +01:00
|
|
|
if(SUCCEEDED(hres)) {
|
2012-09-17 15:17:02 +02:00
|
|
|
ret = n+(double)arg;
|
2016-08-02 17:40:54 +02:00
|
|
|
hres = exprval_propput(ctx, &ref, jsval_number(ret));
|
2011-12-08 12:02:08 +01:00
|
|
|
}
|
2008-09-11 23:57:40 +02:00
|
|
|
}
|
2016-08-02 17:40:54 +02:00
|
|
|
exprval_release(&ref);
|
2008-09-11 23:57:40 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_number(ret));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:29:16 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.9.3 */
|
2012-09-18 19:01:49 +02:00
|
|
|
static HRESULT equal_values(script_ctx_t *ctx, jsval_t lval, jsval_t rval, BOOL *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-09-17 15:20:57 +02:00
|
|
|
if(jsval_type(lval) == jsval_type(rval) || (is_number(lval) && is_number(rval)))
|
2018-03-01 23:58:45 +01:00
|
|
|
return jsval_strict_equal(lval, rval, ret);
|
2008-09-17 23:29:16 +02:00
|
|
|
|
|
|
|
/* FIXME: NULL disps should be handled in more general way */
|
2012-09-17 15:17:02 +02:00
|
|
|
if(is_object_instance(lval) && !get_object(lval))
|
2012-09-18 19:01:49 +02:00
|
|
|
return equal_values(ctx, jsval_null(), rval, ret);
|
2012-09-17 15:17:02 +02:00
|
|
|
if(is_object_instance(rval) && !get_object(rval))
|
2012-09-18 19:01:49 +02:00
|
|
|
return equal_values(ctx, lval, jsval_null(), ret);
|
2008-09-17 23:29:16 +02:00
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
if((is_null(lval) && is_undefined(rval)) || (is_undefined(lval) && is_null(rval))) {
|
2008-09-17 23:29:16 +02:00
|
|
|
*ret = TRUE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
if(is_string(lval) && is_number(rval)) {
|
2012-03-27 11:28:51 +02:00
|
|
|
double n;
|
2008-09-17 23:29:16 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, lval, &n);
|
2008-09-17 23:29:16 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-03-27 11:28:51 +02:00
|
|
|
/* FIXME: optimize */
|
2012-09-18 19:01:49 +02:00
|
|
|
return equal_values(ctx, jsval_number(n), rval, ret);
|
2008-09-17 23:29:16 +02:00
|
|
|
}
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
if(is_string(rval) && is_number(lval)) {
|
2012-03-27 11:28:51 +02:00
|
|
|
double n;
|
2008-09-17 23:29:16 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, rval, &n);
|
2008-09-17 23:29:16 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-03-27 11:28:51 +02:00
|
|
|
/* FIXME: optimize */
|
2012-09-18 19:01:49 +02:00
|
|
|
return equal_values(ctx, lval, jsval_number(n), ret);
|
2008-09-17 23:29:16 +02:00
|
|
|
}
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
if(is_bool(rval))
|
2012-09-18 19:01:49 +02:00
|
|
|
return equal_values(ctx, lval, jsval_number(get_bool(rval) ? 1 : 0), ret);
|
2008-09-17 23:29:16 +02:00
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
if(is_bool(lval))
|
2012-09-18 19:01:49 +02:00
|
|
|
return equal_values(ctx, jsval_number(get_bool(lval) ? 1 : 0), rval, ret);
|
2008-09-17 23:29:16 +02:00
|
|
|
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
if(is_object_instance(rval) && (is_string(lval) || is_number(lval))) {
|
|
|
|
jsval_t prim;
|
2008-09-17 23:29:16 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_primitive(ctx, rval, &prim, NO_HINT);
|
2008-09-17 23:29:16 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = equal_values(ctx, lval, prim, ret);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(prim);
|
2008-09-17 23:29:16 +02:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
if(is_object_instance(lval) && (is_string(rval) || is_number(rval))) {
|
|
|
|
jsval_t prim;
|
2008-09-17 23:29:16 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_primitive(ctx, lval, &prim, NO_HINT);
|
2008-09-17 23:29:16 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = equal_values(ctx, prim, rval, ret);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(prim);
|
2008-09-17 23:29:16 +02:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
*ret = FALSE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.9.1 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_eq(script_ctx_t *ctx)
|
2008-09-17 23:29:16 +02:00
|
|
|
{
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t l, r;
|
2008-09-17 23:29:16 +02:00
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-11-25 12:07:30 +01:00
|
|
|
r = stack_pop(ctx);
|
|
|
|
l = stack_pop(ctx);
|
2008-09-17 23:29:16 +02:00
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
TRACE("%s == %s\n", debugstr_jsval(l), debugstr_jsval(r));
|
2008-09-17 23:29:16 +02:00
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = equal_values(ctx, l, r, &b);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(l);
|
|
|
|
jsval_release(r);
|
2008-09-17 23:29:16 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_bool(b));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2011-11-25 12:07:30 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.9.2 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_neq(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t l, r;
|
2008-09-09 01:26:20 +02:00
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-11-18 14:09:44 +01:00
|
|
|
r = stack_pop(ctx);
|
|
|
|
l = stack_pop(ctx);
|
2008-09-09 01:26:20 +02:00
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
TRACE("%s != %s\n", debugstr_jsval(l), debugstr_jsval(r));
|
2011-11-25 12:07:30 +01:00
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = equal_values(ctx, l, r, &b);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(l);
|
|
|
|
jsval_release(r);
|
2008-09-09 01:26:20 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_bool(!b));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2011-11-25 12:07:30 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.9.4 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_eq2(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t l, r;
|
2008-09-17 23:29:34 +02:00
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
2008-09-03 00:25:21 +02:00
|
|
|
|
2011-11-25 12:07:30 +01:00
|
|
|
r = stack_pop(ctx);
|
|
|
|
l = stack_pop(ctx);
|
2008-09-17 23:29:34 +02:00
|
|
|
|
2013-03-25 12:28:38 +01:00
|
|
|
TRACE("%s === %s\n", debugstr_jsval(l), debugstr_jsval(r));
|
|
|
|
|
2018-03-01 23:58:45 +01:00
|
|
|
hres = jsval_strict_equal(r, l, &b);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(l);
|
|
|
|
jsval_release(r);
|
2008-09-17 23:29:34 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_bool(b));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-09 01:26:37 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.9.5 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_neq2(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t l, r;
|
2008-09-09 01:26:37 +02:00
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-18 14:10:17 +01:00
|
|
|
r = stack_pop(ctx);
|
|
|
|
l = stack_pop(ctx);
|
2008-09-09 01:26:37 +02:00
|
|
|
|
2018-03-01 23:58:45 +01:00
|
|
|
hres = jsval_strict_equal(r, l, &b);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(l);
|
|
|
|
jsval_release(r);
|
2008-09-09 01:26:37 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_bool(!b));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-11 23:56:03 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.8.5 */
|
2012-09-18 19:01:49 +02:00
|
|
|
static HRESULT less_eval(script_ctx_t *ctx, jsval_t lval, jsval_t rval, BOOL greater, BOOL *ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-03-27 11:28:51 +02:00
|
|
|
double ln, rn;
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t l, r;
|
2008-09-11 23:56:03 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_primitive(ctx, lval, &l, NO_HINT);
|
2008-09-11 23:56:03 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_primitive(ctx, rval, &r, NO_HINT);
|
2008-09-11 23:56:03 +02:00
|
|
|
if(FAILED(hres)) {
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(l);
|
2008-09-11 23:56:03 +02:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
if(is_string(l) && is_string(r)) {
|
2012-10-11 12:16:01 +02:00
|
|
|
*ret = (jsstr_cmp(get_string(l), get_string(r)) < 0) ^ greater;
|
|
|
|
jsstr_release(get_string(l));
|
|
|
|
jsstr_release(get_string(r));
|
2008-09-11 23:56:03 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, l, &ln);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(l);
|
2008-09-11 23:56:03 +02:00
|
|
|
if(SUCCEEDED(hres))
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, r, &rn);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(r);
|
2008-09-11 23:56:03 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-03-27 11:28:51 +02:00
|
|
|
*ret = !isnan(ln) && !isnan(rn) && ((ln < rn) ^ greater);
|
2008-09-11 23:56:03 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.8.1 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_lt(script_ctx_t *ctx)
|
2008-09-11 23:56:03 +02:00
|
|
|
{
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t l, r;
|
2008-09-11 23:56:03 +02:00
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-12-01 13:22:52 +01:00
|
|
|
r = stack_pop(ctx);
|
|
|
|
l = stack_pop(ctx);
|
2008-09-11 23:56:03 +02:00
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
TRACE("%s < %s\n", debugstr_jsval(l), debugstr_jsval(r));
|
2008-09-11 23:56:03 +02:00
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = less_eval(ctx, l, r, FALSE, &b);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(l);
|
|
|
|
jsval_release(r);
|
2008-09-11 23:56:03 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_bool(b));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2011-12-01 13:23:03 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.8.1 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_lteq(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t l, r;
|
2008-09-11 23:56:29 +02:00
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-12-01 13:23:03 +01:00
|
|
|
r = stack_pop(ctx);
|
|
|
|
l = stack_pop(ctx);
|
2008-09-11 23:56:29 +02:00
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
TRACE("%s <= %s\n", debugstr_jsval(l), debugstr_jsval(r));
|
2008-09-11 23:56:29 +02:00
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = less_eval(ctx, r, l, TRUE, &b);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(l);
|
|
|
|
jsval_release(r);
|
2008-09-11 23:56:29 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_bool(b));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-11 23:56:51 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.8.2 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_gt(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t l, r;
|
2008-09-11 23:56:51 +02:00
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-12-01 13:23:16 +01:00
|
|
|
r = stack_pop(ctx);
|
|
|
|
l = stack_pop(ctx);
|
2008-09-11 23:56:51 +02:00
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
TRACE("%s > %s\n", debugstr_jsval(l), debugstr_jsval(r));
|
2008-09-11 23:56:51 +02:00
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = less_eval(ctx, r, l, FALSE, &b);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(l);
|
|
|
|
jsval_release(r);
|
2008-09-11 23:56:51 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_bool(b));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-11 23:57:13 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.8.4 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_gteq(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t l, r;
|
2008-09-11 23:57:13 +02:00
|
|
|
BOOL b;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-12-01 13:23:36 +01:00
|
|
|
r = stack_pop(ctx);
|
|
|
|
l = stack_pop(ctx);
|
2008-09-11 23:57:13 +02:00
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
TRACE("%s >= %s\n", debugstr_jsval(l), debugstr_jsval(r));
|
2008-09-11 23:57:13 +02:00
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = less_eval(ctx, l, r, TRUE, &b);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(l);
|
|
|
|
jsval_release(r);
|
2008-09-11 23:57:13 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_bool(b));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 23:32:59 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.4.8 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_bneg(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t v;
|
2008-09-17 23:32:59 +02:00
|
|
|
INT i;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-21 15:35:15 +01:00
|
|
|
v = stack_pop(ctx);
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = to_int32(ctx, v, &i);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(v);
|
2008-09-17 23:32:59 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_number(~i));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-09 01:25:40 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.4.9 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_neg(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t v;
|
|
|
|
BOOL b;
|
2008-09-09 01:25:40 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-11-18 14:10:40 +01:00
|
|
|
v = stack_pop(ctx);
|
2012-09-17 15:18:03 +02:00
|
|
|
hres = to_boolean(v, &b);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(v);
|
2008-09-09 01:25:40 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_bool(!b));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:44:11 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.7.1 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_lshift(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-12-09 11:04:57 +01:00
|
|
|
DWORD r;
|
|
|
|
INT l;
|
|
|
|
HRESULT hres;
|
2008-09-19 00:44:11 +02:00
|
|
|
|
2011-12-09 11:04:57 +01:00
|
|
|
hres = stack_pop_uint(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_int(ctx, &l);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2008-09-19 00:44:11 +02:00
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_number(l << (r&0x1f)));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2011-12-08 12:03:22 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.7.2 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_rshift(script_ctx_t *ctx)
|
2011-12-08 12:03:22 +01:00
|
|
|
{
|
|
|
|
DWORD r;
|
|
|
|
INT l;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = stack_pop_uint(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = stack_pop_int(ctx, &l);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_number(l >> (r&0x1f)));
|
2011-12-08 12:03:22 +01:00
|
|
|
}
|
|
|
|
|
2008-09-19 00:44:49 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.7.3 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_rshift2(script_ctx_t *ctx)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-12-09 11:04:24 +01:00
|
|
|
DWORD r, l;
|
|
|
|
HRESULT hres;
|
2008-09-19 00:44:49 +02:00
|
|
|
|
2011-12-09 11:04:24 +01:00
|
|
|
hres = stack_pop_uint(ctx, &r);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2008-09-19 00:44:49 +02:00
|
|
|
|
2011-12-09 11:04:24 +01:00
|
|
|
hres = stack_pop_uint(ctx, &l);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_number(l >> (r&0x1f)));
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
2021-04-01 18:18:31 +02:00
|
|
|
/* ECMA-262 3rd Edition 9.8 */
|
|
|
|
static HRESULT interp_to_string(script_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
jsstr_t *str;
|
|
|
|
jsval_t v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
v = stack_pop(ctx);
|
|
|
|
TRACE("%s\n", debugstr_jsval(v));
|
|
|
|
hres = to_string(ctx, v, &str);
|
|
|
|
jsval_release(v);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
WARN("failed %08x\n", hres);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
return stack_push(ctx, jsval_string(str));
|
|
|
|
}
|
|
|
|
|
2011-12-05 11:11:29 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.13.1 */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_assign(script_ctx_t *ctx)
|
2011-12-05 11:11:29 +01:00
|
|
|
{
|
2016-08-02 17:40:54 +02:00
|
|
|
exprval_t ref;
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t v;
|
2011-12-05 11:11:29 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
v = stack_pop(ctx);
|
|
|
|
|
2016-08-02 17:40:54 +02:00
|
|
|
if(!stack_pop_exprval(ctx, &ref)) {
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(v);
|
2020-01-31 17:23:05 +01:00
|
|
|
return JS_E_ILLEGAL_ASSIGN;
|
2012-09-17 15:17:02 +02:00
|
|
|
}
|
2011-12-05 11:11:29 +01:00
|
|
|
|
2016-08-02 17:40:54 +02:00
|
|
|
hres = exprval_propput(ctx, &ref, v);
|
|
|
|
exprval_release(&ref);
|
2011-12-05 11:11:29 +01:00
|
|
|
if(FAILED(hres)) {
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(v);
|
2011-12-05 11:11:29 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
return stack_push(ctx, v);
|
|
|
|
}
|
|
|
|
|
2021-04-01 18:18:31 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.13.1 */
|
|
|
|
static HRESULT interp_set_member(script_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
jsval_t objv, namev, value;
|
|
|
|
const WCHAR *name;
|
|
|
|
IDispatch *obj;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
value = stack_pop(ctx);
|
|
|
|
namev = stack_pop(ctx);
|
|
|
|
assert(is_string(namev));
|
|
|
|
objv = stack_pop(ctx);
|
|
|
|
|
|
|
|
TRACE("%s.%s = %s\n", debugstr_jsval(objv), debugstr_jsval(namev), debugstr_jsval(value));
|
|
|
|
|
|
|
|
hres = to_object(ctx, objv, &obj);
|
|
|
|
jsval_release(objv);
|
|
|
|
if(SUCCEEDED(hres) && !(name = jsstr_flatten(get_string(namev)))) {
|
|
|
|
IDispatch_Release(obj);
|
|
|
|
hres = E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = disp_propput_name(ctx, obj, name, value);
|
|
|
|
IDispatch_Release(obj);
|
|
|
|
jsstr_release(get_string(namev));
|
|
|
|
}
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
WARN("failed %08x\n", hres);
|
|
|
|
jsval_release(value);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
return stack_push(ctx, value);
|
|
|
|
}
|
|
|
|
|
2012-04-17 16:25:58 +02:00
|
|
|
/* JScript extension */
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_assign_call(script_ctx_t *ctx)
|
2012-04-17 16:25:58 +02:00
|
|
|
{
|
2012-09-17 15:16:42 +02:00
|
|
|
const unsigned argc = get_op_uint(ctx, 0);
|
2016-08-02 17:40:54 +02:00
|
|
|
exprval_t ref;
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_t v;
|
2012-04-17 16:25:58 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2012-09-17 15:16:42 +02:00
|
|
|
TRACE("%u\n", argc);
|
2012-04-17 16:25:58 +02:00
|
|
|
|
2016-08-02 17:40:54 +02:00
|
|
|
if(!stack_topn_exprval(ctx, argc+1, &ref))
|
2020-01-31 17:23:05 +01:00
|
|
|
return JS_E_ILLEGAL_ASSIGN;
|
2012-04-17 16:25:58 +02:00
|
|
|
|
2016-08-02 17:40:54 +02:00
|
|
|
hres = exprval_call(ctx, &ref, DISPATCH_PROPERTYPUT, argc+1, stack_args(ctx, argc+1), NULL);
|
2012-04-17 16:25:58 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
v = stack_pop(ctx);
|
2012-09-17 15:16:42 +02:00
|
|
|
stack_popn(ctx, argc+2);
|
2012-04-17 16:25:58 +02:00
|
|
|
return stack_push(ctx, v);
|
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_undefined(script_ctx_t *ctx)
|
2011-12-08 12:02:40 +01:00
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
return stack_push(ctx, jsval_undefined());
|
2011-12-08 12:02:40 +01:00
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_jmp(script_ctx_t *ctx)
|
2011-11-28 12:04:51 +01:00
|
|
|
{
|
2012-05-12 16:21:10 +02:00
|
|
|
const unsigned arg = get_op_uint(ctx, 0);
|
2011-11-28 12:04:51 +01:00
|
|
|
|
2012-05-12 16:21:10 +02:00
|
|
|
TRACE("%u\n", arg);
|
2011-11-28 12:04:51 +01:00
|
|
|
|
2016-03-25 12:03:25 +01:00
|
|
|
jmp_abs(ctx, arg);
|
2011-11-28 12:04:51 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_jmp_z(script_ctx_t *ctx)
|
2011-12-20 11:47:37 +01:00
|
|
|
{
|
2012-05-12 16:21:10 +02:00
|
|
|
const unsigned arg = get_op_uint(ctx, 0);
|
2012-09-17 15:17:02 +02:00
|
|
|
BOOL b;
|
|
|
|
jsval_t v;
|
2011-12-20 11:47:37 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
v = stack_pop(ctx);
|
2012-09-17 15:18:03 +02:00
|
|
|
hres = to_boolean(v, &b);
|
2012-09-17 15:17:02 +02:00
|
|
|
jsval_release(v);
|
2011-12-20 11:47:37 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(b)
|
2016-03-25 12:03:25 +01:00
|
|
|
jmp_next(ctx);
|
2011-12-20 11:47:37 +01:00
|
|
|
else
|
2016-03-25 12:03:25 +01:00
|
|
|
jmp_abs(ctx, arg);
|
2011-12-20 11:47:37 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_pop(script_ctx_t *ctx)
|
2011-11-25 12:05:50 +01:00
|
|
|
{
|
2012-12-14 11:06:43 +01:00
|
|
|
const unsigned arg = get_op_uint(ctx, 0);
|
2011-11-25 12:05:50 +01:00
|
|
|
|
2012-12-14 11:06:43 +01:00
|
|
|
TRACE("%u\n", arg);
|
|
|
|
|
|
|
|
stack_popn(ctx, arg);
|
2011-11-25 12:05:50 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_ret(script_ctx_t *ctx)
|
2011-11-18 14:09:44 +01:00
|
|
|
{
|
2016-03-28 17:48:57 +02:00
|
|
|
const unsigned clear_ret = get_op_uint(ctx, 0);
|
|
|
|
call_frame_t *frame = ctx->call_ctx;
|
|
|
|
|
2011-11-18 14:09:44 +01:00
|
|
|
TRACE("\n");
|
|
|
|
|
2016-03-28 17:48:57 +02:00
|
|
|
if(clear_ret)
|
|
|
|
jsval_release(steal_ret(frame));
|
|
|
|
|
2016-03-28 17:49:53 +02:00
|
|
|
if((frame->flags & EXEC_CONSTRUCTOR) && !is_object_instance(frame->ret)) {
|
|
|
|
jsval_release(frame->ret);
|
|
|
|
IDispatch_AddRef(frame->this_obj);
|
|
|
|
frame->ret = jsval_disp(frame->this_obj);
|
|
|
|
}
|
|
|
|
|
2016-03-25 12:03:25 +01:00
|
|
|
jmp_abs(ctx, -1);
|
2011-11-18 14:09:44 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
static HRESULT interp_setret(script_ctx_t *ctx)
|
2012-12-13 12:08:34 +01:00
|
|
|
{
|
2016-03-25 17:49:56 +01:00
|
|
|
call_frame_t *frame = ctx->call_ctx;
|
|
|
|
|
2012-12-13 12:08:34 +01:00
|
|
|
TRACE("\n");
|
|
|
|
|
2016-03-25 17:49:56 +01:00
|
|
|
jsval_release(frame->ret);
|
|
|
|
frame->ret = stack_pop(ctx);
|
2012-12-13 12:08:34 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2018-06-12 14:04:11 +02:00
|
|
|
static HRESULT interp_push_acc(script_ctx_t *ctx)
|
2016-03-28 17:49:10 +02:00
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2018-06-12 14:04:11 +02:00
|
|
|
hres = stack_push(ctx, ctx->acc);
|
2016-03-28 17:49:10 +02:00
|
|
|
if(SUCCEEDED(hres))
|
2018-06-12 14:04:11 +02:00
|
|
|
ctx->acc = jsval_undefined();
|
2016-03-28 17:49:10 +02:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2016-03-25 17:49:14 +01:00
|
|
|
typedef HRESULT (*op_func_t)(script_ctx_t*);
|
2011-11-18 14:09:44 +01:00
|
|
|
|
|
|
|
static const op_func_t op_funcs[] = {
|
2011-11-24 14:23:39 +01:00
|
|
|
#define X(x,a,b,c) interp_##x,
|
2011-11-18 14:09:44 +01:00
|
|
|
OP_LIST
|
|
|
|
#undef X
|
|
|
|
};
|
|
|
|
|
|
|
|
static const unsigned op_move[] = {
|
2011-11-24 14:23:39 +01:00
|
|
|
#define X(a,x,b,c) x,
|
2011-11-18 14:09:44 +01:00
|
|
|
OP_LIST
|
|
|
|
#undef X
|
|
|
|
};
|
|
|
|
|
2016-07-28 18:44:43 +02:00
|
|
|
static void pop_call_frame(script_ctx_t *ctx)
|
2016-03-25 12:02:35 +01:00
|
|
|
{
|
2016-07-28 18:44:43 +02:00
|
|
|
call_frame_t *frame = ctx->call_ctx;
|
|
|
|
|
2016-08-04 13:40:11 +02:00
|
|
|
frame->stack_base -= frame->pop_locals + frame->pop_variables;
|
|
|
|
|
|
|
|
assert(frame->scope == frame->base_scope);
|
|
|
|
|
|
|
|
/* If current scope will be kept alive, we need to transfer local variables to its variable object. */
|
|
|
|
if(frame->scope && frame->scope->ref > 1) {
|
2016-08-05 17:15:13 +02:00
|
|
|
HRESULT hres = detach_variable_object(ctx, frame, TRUE);
|
2016-08-04 13:40:11 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
ERR("Failed to detach variable object: %08x\n", hres);
|
|
|
|
}
|
|
|
|
|
2016-08-03 16:28:19 +02:00
|
|
|
if(frame->arguments_obj)
|
|
|
|
detach_arguments_object(frame->arguments_obj);
|
2016-08-04 13:40:11 +02:00
|
|
|
if(frame->scope)
|
2016-07-28 18:44:43 +02:00
|
|
|
scope_release(frame->scope);
|
|
|
|
|
2016-08-04 13:40:11 +02:00
|
|
|
if(frame->pop_variables)
|
|
|
|
stack_popn(ctx, frame->pop_variables);
|
2016-07-28 18:44:43 +02:00
|
|
|
stack_popn(ctx, frame->pop_locals);
|
|
|
|
|
|
|
|
ctx->call_ctx = frame->prev_frame;
|
|
|
|
|
2016-03-28 17:51:28 +02:00
|
|
|
if(frame->function_instance)
|
|
|
|
jsdisp_release(frame->function_instance);
|
2016-03-25 17:49:48 +01:00
|
|
|
if(frame->variable_obj)
|
|
|
|
jsdisp_release(frame->variable_obj);
|
2016-03-25 17:49:37 +01:00
|
|
|
if(frame->this_obj)
|
|
|
|
IDispatch_Release(frame->this_obj);
|
2016-03-25 17:49:56 +01:00
|
|
|
jsval_release(frame->ret);
|
2016-03-28 17:50:18 +02:00
|
|
|
release_bytecode(frame->bytecode);
|
2016-03-25 12:02:35 +01:00
|
|
|
heap_free(frame);
|
|
|
|
}
|
|
|
|
|
2017-05-05 17:22:57 +02:00
|
|
|
static void print_backtrace(script_ctx_t *ctx)
|
|
|
|
{
|
2021-03-10 14:59:57 +01:00
|
|
|
unsigned depth = 0, i, line, char_pos;
|
2017-05-05 17:22:57 +02:00
|
|
|
call_frame_t *frame;
|
|
|
|
|
|
|
|
for(frame = ctx->call_ctx; frame; frame = frame->prev_frame) {
|
2017-12-20 16:03:37 +01:00
|
|
|
WARN("%u\t", depth);
|
2017-05-05 17:22:57 +02:00
|
|
|
depth++;
|
|
|
|
|
2020-03-06 14:48:38 +01:00
|
|
|
if(frame->this_obj)
|
2017-12-20 16:03:37 +01:00
|
|
|
WARN("%p->", frame->this_obj);
|
|
|
|
WARN("%s(", frame->function->name ? debugstr_w(frame->function->name) : "[unnamed]");
|
2017-05-05 17:22:57 +02:00
|
|
|
if(frame->base_scope && frame->base_scope->frame) {
|
|
|
|
for(i=0; i < frame->argc; i++) {
|
|
|
|
if(i < frame->function->param_cnt)
|
2017-12-20 16:03:37 +01:00
|
|
|
WARN("%s%s=%s", i ? ", " : "", debugstr_w(frame->function->params[i]),
|
|
|
|
debugstr_jsval(ctx->stack[local_off(frame, -i-1)]));
|
2017-05-05 17:22:57 +02:00
|
|
|
else
|
2017-12-20 16:03:37 +01:00
|
|
|
WARN("%s%s", i ? ", " : "", debugstr_jsval(ctx->stack[local_off(frame, -i-1)]));
|
2017-05-05 17:22:57 +02:00
|
|
|
}
|
|
|
|
}else {
|
2017-12-20 16:03:37 +01:00
|
|
|
WARN("[detached frame]");
|
2017-05-05 17:22:57 +02:00
|
|
|
}
|
2021-03-10 14:59:57 +01:00
|
|
|
line = get_location_line(frame->bytecode, frame->bytecode->instrs[frame->ip].loc, &char_pos);
|
|
|
|
WARN(") context %s line %u char %u\n", wine_dbgstr_longlong(frame->bytecode->source_context), line, char_pos);
|
2017-05-05 17:22:57 +02:00
|
|
|
|
|
|
|
if(!(frame->flags & EXEC_RETURN_TO_INTERP)) {
|
2017-12-20 16:03:37 +01:00
|
|
|
WARN("%u\t[native code]\n", depth);
|
2017-05-05 17:22:57 +02:00
|
|
|
depth++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-28 17:50:39 +02:00
|
|
|
static HRESULT unwind_exception(script_ctx_t *ctx, HRESULT exception_hres)
|
2011-12-28 12:06:28 +01:00
|
|
|
{
|
|
|
|
except_frame_t *except_frame;
|
2020-01-30 15:50:22 +01:00
|
|
|
jsexcept_t *ei = ctx->ei;
|
2016-03-29 17:49:01 +02:00
|
|
|
call_frame_t *frame;
|
2012-09-17 15:17:36 +02:00
|
|
|
jsval_t except_val;
|
2017-05-01 18:30:44 +02:00
|
|
|
unsigned catch_off;
|
2011-12-28 12:06:28 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
2017-12-20 16:03:37 +01:00
|
|
|
if(WARN_ON(jscript)) {
|
2017-05-05 17:22:57 +02:00
|
|
|
jsdisp_t *error_obj;
|
|
|
|
jsval_t msg;
|
|
|
|
|
2020-01-30 15:50:22 +01:00
|
|
|
WARN("Exception %08x %s", exception_hres, debugstr_jsval(ei->valid_value ? ei->value : jsval_undefined()));
|
2020-01-31 17:22:42 +01:00
|
|
|
if(ei->valid_value && jsval_type(ei->value) == JSV_OBJECT) {
|
|
|
|
error_obj = to_jsdisp(get_object(ei->value));
|
2017-05-05 17:22:57 +02:00
|
|
|
if(error_obj) {
|
2020-11-24 00:49:04 +01:00
|
|
|
hres = jsdisp_propget_name(error_obj, L"message", &msg);
|
2017-05-05 17:22:57 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
2017-12-20 16:03:37 +01:00
|
|
|
WARN(" (message %s)", debugstr_jsval(msg));
|
2017-05-05 17:22:57 +02:00
|
|
|
jsval_release(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-12-20 16:03:37 +01:00
|
|
|
WARN(" in:\n");
|
2017-05-05 17:22:57 +02:00
|
|
|
|
|
|
|
print_backtrace(ctx);
|
|
|
|
}
|
|
|
|
|
2020-02-03 14:47:15 +01:00
|
|
|
frame = ctx->call_ctx;
|
2020-02-03 14:47:32 +01:00
|
|
|
if(exception_hres != DISP_E_EXCEPTION)
|
|
|
|
throw_error(ctx, exception_hres, NULL);
|
2020-02-04 20:28:38 +01:00
|
|
|
set_error_location(ei, frame->bytecode, frame->bytecode->instrs[frame->ip].loc, IDS_RUNTIME_ERROR, NULL);
|
2020-01-31 17:22:42 +01:00
|
|
|
|
2020-02-03 14:47:15 +01:00
|
|
|
while(!frame->except_frame) {
|
2016-03-29 17:49:01 +02:00
|
|
|
DWORD flags;
|
|
|
|
|
2016-03-28 17:50:39 +02:00
|
|
|
while(frame->scope != frame->base_scope)
|
|
|
|
scope_pop(&frame->scope);
|
|
|
|
|
|
|
|
stack_popn(ctx, ctx->stack_top-frame->stack_base);
|
|
|
|
|
2016-03-29 17:49:01 +02:00
|
|
|
flags = frame->flags;
|
2016-07-28 18:44:43 +02:00
|
|
|
pop_call_frame(ctx);
|
2016-03-29 17:49:01 +02:00
|
|
|
if(!(flags & EXEC_RETURN_TO_INTERP))
|
2020-01-31 17:22:42 +01:00
|
|
|
return DISP_E_EXCEPTION;
|
2020-02-03 14:47:15 +01:00
|
|
|
frame = ctx->call_ctx;
|
2016-03-28 17:50:39 +02:00
|
|
|
}
|
|
|
|
|
2016-03-25 12:03:35 +01:00
|
|
|
except_frame = frame->except_frame;
|
2017-05-01 18:30:44 +02:00
|
|
|
catch_off = except_frame->catch_off;
|
2011-12-28 12:06:28 +01:00
|
|
|
|
2016-03-25 17:49:24 +01:00
|
|
|
assert(except_frame->stack_top <= ctx->stack_top);
|
|
|
|
stack_popn(ctx, ctx->stack_top - except_frame->stack_top);
|
2011-12-28 12:06:28 +01:00
|
|
|
|
2016-03-25 12:04:13 +01:00
|
|
|
while(except_frame->scope != frame->scope)
|
|
|
|
scope_pop(&frame->scope);
|
2011-12-28 12:06:28 +01:00
|
|
|
|
2017-05-01 18:30:44 +02:00
|
|
|
frame->ip = catch_off ? catch_off : except_frame->finally_off;
|
2020-01-31 17:22:42 +01:00
|
|
|
assert(!catch_off || frame->bytecode->instrs[frame->ip].op == OP_enter_catch);
|
2011-12-28 12:06:28 +01:00
|
|
|
|
2020-01-30 15:50:22 +01:00
|
|
|
if(ei->valid_value) {
|
|
|
|
except_val = ctx->ei->value;
|
2020-01-31 17:22:42 +01:00
|
|
|
ei->valid_value = FALSE;
|
2020-01-30 15:50:22 +01:00
|
|
|
}else {
|
2020-01-31 17:22:42 +01:00
|
|
|
jsdisp_t *err;
|
|
|
|
if(!(err = create_builtin_error(ctx)))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
except_val = jsval_obj(err);
|
2020-01-30 15:50:22 +01:00
|
|
|
}
|
2011-12-28 12:06:28 +01:00
|
|
|
|
2017-05-01 18:31:02 +02:00
|
|
|
/* keep current except_frame if we're entering catch block with finally block associated */
|
|
|
|
if(catch_off && except_frame->finally_off) {
|
|
|
|
except_frame->catch_off = 0;
|
|
|
|
}else {
|
|
|
|
frame->except_frame = except_frame->next;
|
|
|
|
heap_free(except_frame);
|
|
|
|
}
|
2011-12-28 12:06:28 +01:00
|
|
|
|
2017-05-01 18:30:06 +02:00
|
|
|
hres = stack_push(ctx, except_val);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2011-12-28 12:06:28 +01:00
|
|
|
|
2017-05-01 18:30:44 +02:00
|
|
|
if(!catch_off)
|
2012-09-17 15:17:02 +02:00
|
|
|
hres = stack_push(ctx, jsval_bool(FALSE));
|
2011-12-28 12:06:28 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2016-03-28 17:50:39 +02:00
|
|
|
static HRESULT enter_bytecode(script_ctx_t *ctx, jsval_t *r)
|
2011-12-19 14:58:42 +01:00
|
|
|
{
|
2016-03-25 12:02:35 +01:00
|
|
|
call_frame_t *frame;
|
2011-12-19 14:58:42 +01:00
|
|
|
jsop_t op;
|
|
|
|
HRESULT hres = S_OK;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2016-03-28 17:50:39 +02:00
|
|
|
while(1) {
|
2016-03-29 17:49:01 +02:00
|
|
|
frame = ctx->call_ctx;
|
2016-03-25 12:03:45 +01:00
|
|
|
op = frame->bytecode->instrs[frame->ip].op;
|
2016-03-25 17:49:14 +01:00
|
|
|
hres = op_funcs[op](ctx);
|
2011-12-28 12:06:28 +01:00
|
|
|
if(FAILED(hres)) {
|
2016-03-28 17:50:39 +02:00
|
|
|
hres = unwind_exception(ctx, hres);
|
2011-12-28 12:06:28 +01:00
|
|
|
if(FAILED(hres))
|
2016-03-28 17:50:39 +02:00
|
|
|
return hres;
|
|
|
|
}else if(frame->ip == -1) {
|
2016-03-29 17:49:01 +02:00
|
|
|
const DWORD return_to_interp = frame->flags & EXEC_RETURN_TO_INTERP;
|
|
|
|
|
2016-03-28 17:50:39 +02:00
|
|
|
assert(ctx->stack_top == frame->stack_base);
|
|
|
|
assert(frame->scope == frame->base_scope);
|
|
|
|
|
2016-03-29 17:49:01 +02:00
|
|
|
if(return_to_interp) {
|
2018-06-12 14:04:11 +02:00
|
|
|
jsval_release(ctx->acc);
|
|
|
|
ctx->acc = steal_ret(frame);
|
2016-03-29 17:49:01 +02:00
|
|
|
}else if(r) {
|
2016-03-28 17:50:39 +02:00
|
|
|
*r = steal_ret(frame);
|
2016-03-29 17:49:01 +02:00
|
|
|
}
|
2016-07-28 18:44:43 +02:00
|
|
|
pop_call_frame(ctx);
|
2016-03-29 17:49:01 +02:00
|
|
|
if(!return_to_interp)
|
|
|
|
break;
|
2011-12-28 12:06:28 +01:00
|
|
|
}else {
|
2016-03-25 12:03:45 +01:00
|
|
|
frame->ip += op_move[op];
|
2011-12-28 12:06:28 +01:00
|
|
|
}
|
2011-12-19 14:58:42 +01:00
|
|
|
}
|
|
|
|
|
2016-03-28 17:50:39 +02:00
|
|
|
return S_OK;
|
2011-12-19 14:58:42 +01:00
|
|
|
}
|
|
|
|
|
2015-06-02 14:45:10 +02:00
|
|
|
static HRESULT bind_event_target(script_ctx_t *ctx, function_code_t *func, jsdisp_t *func_obj)
|
|
|
|
{
|
|
|
|
IBindEventHandler *target;
|
|
|
|
exprval_t exprval;
|
|
|
|
IDispatch *disp;
|
|
|
|
jsval_t v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = identifier_eval(ctx, func->event_target, &exprval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = exprval_to_value(ctx, &exprval, &v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(!is_object_instance(v)) {
|
|
|
|
FIXME("Can't bind to %s\n", debugstr_jsval(v));
|
|
|
|
jsval_release(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
disp = get_object(v);
|
|
|
|
hres = IDispatch_QueryInterface(disp, &IID_IBindEventHandler, (void**)&target);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = IBindEventHandler_BindHandler(target, func->name, (IDispatch*)&func_obj->IDispatchEx_iface);
|
|
|
|
IBindEventHandler_Release(target);
|
|
|
|
if(FAILED(hres))
|
|
|
|
WARN("BindEvent failed: %08x\n", hres);
|
|
|
|
}else {
|
|
|
|
FIXME("No IBindEventHandler, not yet supported binding\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
IDispatch_Release(disp);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2016-08-05 17:15:06 +02:00
|
|
|
static HRESULT setup_scope(script_ctx_t *ctx, call_frame_t *frame, scope_chain_t *scope_chain, jsdisp_t *variable_object, unsigned argc, jsval_t *argv)
|
2016-07-28 18:44:43 +02:00
|
|
|
{
|
2016-07-28 18:44:57 +02:00
|
|
|
const unsigned orig_stack = ctx->stack_top;
|
2016-08-05 17:15:06 +02:00
|
|
|
scope_chain_t *scope;
|
2016-07-28 18:44:43 +02:00
|
|
|
unsigned i;
|
|
|
|
jsval_t v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2016-07-28 18:44:57 +02:00
|
|
|
/* If arguments are already on the stack, we may use them. */
|
|
|
|
if(argv + argc == ctx->stack + ctx->stack_top) {
|
|
|
|
frame->arguments_off = argv - ctx->stack;
|
|
|
|
i = argc;
|
|
|
|
}else {
|
|
|
|
frame->arguments_off = ctx->stack_top;
|
|
|
|
for(i = 0; i < argc; i++) {
|
|
|
|
hres = jsval_copy(argv[i], &v);
|
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
hres = stack_push(ctx, v);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
stack_popn(ctx, i);
|
|
|
|
return hres;
|
|
|
|
}
|
2016-07-28 18:44:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If fewer than declared arguments were passed, fill remaining with undefined value. */
|
|
|
|
for(; i < frame->function->param_cnt; i++) {
|
|
|
|
hres = stack_push(ctx, jsval_undefined());
|
|
|
|
if(FAILED(hres)) {
|
2016-07-28 18:44:57 +02:00
|
|
|
stack_popn(ctx, ctx->stack_top - orig_stack);
|
2016-07-28 18:44:43 +02:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-28 18:44:57 +02:00
|
|
|
frame->pop_locals = ctx->stack_top - orig_stack;
|
2016-08-04 13:40:11 +02:00
|
|
|
|
|
|
|
frame->variables_off = ctx->stack_top;
|
|
|
|
|
|
|
|
for(i = 0; i < frame->function->var_cnt; i++) {
|
|
|
|
hres = stack_push(ctx, jsval_undefined());
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
stack_popn(ctx, ctx->stack_top - orig_stack);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
frame->pop_variables = i;
|
|
|
|
|
2016-08-05 17:15:06 +02:00
|
|
|
hres = scope_push(scope_chain, variable_object, to_disp(variable_object), &scope);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
stack_popn(ctx, ctx->stack_top - orig_stack);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2016-08-04 13:40:11 +02:00
|
|
|
for(i = 0; i < frame->function->func_cnt; i++) {
|
2021-06-18 14:50:19 +02:00
|
|
|
if(frame->function->funcs[i].local_ref != INVALID_LOCAL_REF
|
|
|
|
&& !frame->function->funcs[i].scope_index)
|
|
|
|
{
|
2016-08-04 13:40:11 +02:00
|
|
|
jsdisp_t *func_obj;
|
|
|
|
unsigned off;
|
|
|
|
|
2016-08-05 17:15:06 +02:00
|
|
|
hres = create_source_function(ctx, frame->bytecode, frame->function->funcs+i, scope, &func_obj);
|
2016-08-04 13:40:11 +02:00
|
|
|
if(FAILED(hres)) {
|
|
|
|
stack_popn(ctx, ctx->stack_top - orig_stack);
|
2016-08-05 17:15:06 +02:00
|
|
|
scope_release(scope);
|
2016-08-04 13:40:11 +02:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
off = local_off(frame, frame->function->funcs[i].local_ref);
|
|
|
|
jsval_release(ctx->stack[off]);
|
|
|
|
ctx->stack[off] = jsval_obj(func_obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-05 17:15:06 +02:00
|
|
|
scope->frame = frame;
|
|
|
|
frame->base_scope = frame->scope = scope;
|
2016-08-03 16:28:26 +02:00
|
|
|
return S_OK;
|
2016-07-28 18:44:43 +02:00
|
|
|
}
|
|
|
|
|
2016-03-28 17:50:08 +02:00
|
|
|
HRESULT exec_source(script_ctx_t *ctx, DWORD flags, bytecode_t *bytecode, function_code_t *function, scope_chain_t *scope,
|
2020-03-17 19:19:25 +01:00
|
|
|
IDispatch *this_obj, jsdisp_t *function_instance, unsigned argc, jsval_t *argv, jsval_t *r)
|
2016-03-25 12:02:35 +01:00
|
|
|
{
|
2020-03-17 19:19:25 +01:00
|
|
|
jsdisp_t *variable_obj;
|
2016-03-25 12:02:35 +01:00
|
|
|
call_frame_t *frame;
|
2016-03-28 17:50:08 +02:00
|
|
|
unsigned i;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2020-06-04 17:28:56 +02:00
|
|
|
if(!ctx->stack) {
|
|
|
|
ctx->stack = heap_alloc(stack_size * sizeof(*ctx->stack));
|
|
|
|
if(!ctx->stack)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2020-03-07 14:40:32 +01:00
|
|
|
if(bytecode->named_item) {
|
|
|
|
if(!bytecode->named_item->script_obj) {
|
|
|
|
hres = create_named_item_script_obj(ctx, bytecode->named_item);
|
|
|
|
if(FAILED(hres)) return hres;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-30 15:50:39 +01:00
|
|
|
if(!ctx->ei->enter_notified) {
|
|
|
|
ctx->ei->enter_notified = TRUE;
|
|
|
|
IActiveScriptSite_OnEnterScript(ctx->site);
|
|
|
|
}
|
|
|
|
|
2016-03-28 17:50:08 +02:00
|
|
|
for(i = 0; i < function->func_cnt; i++) {
|
|
|
|
jsdisp_t *func_obj;
|
|
|
|
|
2016-08-04 13:40:11 +02:00
|
|
|
if(!function->funcs[i].event_target)
|
2016-03-28 17:50:08 +02:00
|
|
|
continue;
|
|
|
|
|
2021-06-18 14:50:19 +02:00
|
|
|
if (function->funcs[i].scope_index)
|
|
|
|
{
|
|
|
|
/* TODO: Add tests and handle in interp_push_scope(). */
|
|
|
|
FIXME("Event target with scope index are not properly handled.\n");
|
|
|
|
}
|
|
|
|
|
2016-03-28 17:50:08 +02:00
|
|
|
hres = create_source_function(ctx, bytecode, function->funcs+i, scope, &func_obj);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2016-08-04 13:40:11 +02:00
|
|
|
hres = bind_event_target(ctx, function->funcs+i, func_obj);
|
2016-03-28 17:50:08 +02:00
|
|
|
jsdisp_release(func_obj);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2020-03-17 19:19:25 +01:00
|
|
|
if((flags & EXEC_EVAL) && ctx->call_ctx) {
|
|
|
|
variable_obj = jsdisp_addref(ctx->call_ctx->variable_obj);
|
|
|
|
}else if(!(flags & (EXEC_GLOBAL | EXEC_EVAL))) {
|
|
|
|
hres = create_dispex(ctx, NULL, NULL, &variable_obj);
|
|
|
|
if(FAILED(hres)) return hres;
|
2020-03-18 14:19:48 +01:00
|
|
|
}else if(bytecode->named_item) {
|
|
|
|
variable_obj = jsdisp_addref(bytecode->named_item->script_obj);
|
2020-03-17 19:19:25 +01:00
|
|
|
}else {
|
|
|
|
variable_obj = jsdisp_addref(ctx->global);
|
|
|
|
}
|
|
|
|
|
2016-08-04 13:40:11 +02:00
|
|
|
if(flags & (EXEC_GLOBAL | EXEC_EVAL)) {
|
2020-03-27 18:34:16 +01:00
|
|
|
named_item_t *item = bytecode->named_item;
|
|
|
|
DISPID id;
|
2020-03-10 18:48:42 +01:00
|
|
|
|
2016-08-04 13:40:11 +02:00
|
|
|
for(i=0; i < function->var_cnt; i++) {
|
|
|
|
TRACE("[%d] %s %d\n", i, debugstr_w(function->variables[i].name), function->variables[i].func_id);
|
|
|
|
if(function->variables[i].func_id != -1) {
|
|
|
|
jsdisp_t *func_obj;
|
2016-08-04 13:39:46 +02:00
|
|
|
|
2021-06-18 14:50:19 +02:00
|
|
|
if (function->funcs[function->variables[i].func_id].scope_index && flags & EXEC_EVAL)
|
|
|
|
{
|
|
|
|
/* TODO: Add tests and handle in interp_push_scope(). */
|
|
|
|
FIXME("Functions with scope index inside eval() are not properly handled.\n");
|
|
|
|
}
|
|
|
|
|
2016-08-04 13:40:11 +02:00
|
|
|
hres = create_source_function(ctx, bytecode, function->funcs+function->variables[i].func_id, scope, &func_obj);
|
|
|
|
if(FAILED(hres))
|
2020-03-17 19:19:25 +01:00
|
|
|
goto fail;
|
2016-03-28 17:50:08 +02:00
|
|
|
|
2016-08-04 13:40:11 +02:00
|
|
|
hres = jsdisp_propput_name(variable_obj, function->variables[i].name, jsval_obj(func_obj));
|
|
|
|
jsdisp_release(func_obj);
|
2020-03-27 18:34:16 +01:00
|
|
|
continue;
|
2016-08-04 13:40:11 +02:00
|
|
|
}
|
2020-03-27 18:34:16 +01:00
|
|
|
|
|
|
|
if(item && !(item->flags & SCRIPTITEM_CODEONLY)
|
|
|
|
&& SUCCEEDED(disp_get_id(ctx, item->disp, function->variables[i].name, function->variables[i].name, 0, &id)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(!item && (flags & EXEC_GLOBAL) && lookup_global_members(ctx, function->variables[i].name, NULL))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
hres = jsdisp_get_id(variable_obj, function->variables[i].name, fdexNameEnsure, &id);
|
|
|
|
if(FAILED(hres))
|
|
|
|
goto fail;
|
2016-03-28 17:50:08 +02:00
|
|
|
}
|
|
|
|
}
|
2016-03-25 12:02:35 +01:00
|
|
|
|
2016-03-25 17:49:37 +01:00
|
|
|
/* ECMA-262 3rd Edition 11.2.3.7 */
|
|
|
|
if(this_obj) {
|
|
|
|
jsdisp_t *jsthis;
|
|
|
|
|
2016-07-20 13:40:41 +02:00
|
|
|
jsthis = iface_to_jsdisp(this_obj);
|
2016-03-25 17:49:37 +01:00
|
|
|
if(jsthis) {
|
|
|
|
if(jsthis->builtin_info->class == JSCLASS_GLOBAL || jsthis->builtin_info->class == JSCLASS_NONE)
|
|
|
|
this_obj = NULL;
|
|
|
|
jsdisp_release(jsthis);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-28 18:44:43 +02:00
|
|
|
if(ctx->call_ctx && (flags & EXEC_EVAL)) {
|
2016-08-05 17:15:13 +02:00
|
|
|
hres = detach_variable_object(ctx, ctx->call_ctx, FALSE);
|
2016-07-28 18:44:43 +02:00
|
|
|
if(FAILED(hres))
|
2020-03-17 19:19:25 +01:00
|
|
|
goto fail;
|
2016-07-28 18:44:43 +02:00
|
|
|
}
|
|
|
|
|
2016-03-25 12:02:35 +01:00
|
|
|
frame = heap_alloc_zero(sizeof(*frame));
|
2020-03-17 19:19:25 +01:00
|
|
|
if(!frame) {
|
|
|
|
hres = E_OUTOFMEMORY;
|
|
|
|
goto fail;
|
|
|
|
}
|
2016-03-25 12:02:35 +01:00
|
|
|
|
2016-03-25 12:03:11 +01:00
|
|
|
frame->function = function;
|
2016-03-25 17:49:56 +01:00
|
|
|
frame->ret = jsval_undefined();
|
2016-08-03 16:28:26 +02:00
|
|
|
frame->argc = argc;
|
2016-08-04 13:40:11 +02:00
|
|
|
frame->bytecode = bytecode_addref(bytecode);
|
2016-07-28 18:44:43 +02:00
|
|
|
|
2016-08-05 17:15:06 +02:00
|
|
|
if(!(flags & (EXEC_GLOBAL|EXEC_EVAL))) {
|
|
|
|
hres = setup_scope(ctx, frame, scope, variable_obj, argc, argv);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
release_bytecode(frame->bytecode);
|
|
|
|
heap_free(frame);
|
2020-03-17 19:19:25 +01:00
|
|
|
goto fail;
|
2016-07-28 18:44:43 +02:00
|
|
|
}
|
2016-08-05 17:15:06 +02:00
|
|
|
}else if(scope) {
|
|
|
|
frame->base_scope = frame->scope = scope_addref(scope);
|
2016-07-28 18:44:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
frame->ip = function->instr_off;
|
|
|
|
frame->stack_base = ctx->stack_top;
|
2020-03-06 14:48:38 +01:00
|
|
|
if(this_obj) {
|
2016-03-25 17:49:37 +01:00
|
|
|
frame->this_obj = this_obj;
|
2020-03-06 14:48:38 +01:00
|
|
|
IDispatch_AddRef(frame->this_obj);
|
|
|
|
}
|
2016-03-25 17:49:37 +01:00
|
|
|
|
2016-03-28 17:51:28 +02:00
|
|
|
if(function_instance)
|
|
|
|
frame->function_instance = jsdisp_addref(function_instance);
|
2016-03-28 17:50:59 +02:00
|
|
|
|
2016-03-28 17:49:33 +02:00
|
|
|
frame->flags = flags;
|
2020-03-17 19:19:25 +01:00
|
|
|
frame->variable_obj = variable_obj;
|
2016-03-25 17:49:48 +01:00
|
|
|
|
2016-03-25 17:50:16 +01:00
|
|
|
frame->prev_frame = ctx->call_ctx;
|
|
|
|
ctx->call_ctx = frame;
|
2011-12-29 11:08:07 +01:00
|
|
|
|
2016-03-29 17:49:01 +02:00
|
|
|
if(flags & EXEC_RETURN_TO_INTERP) {
|
|
|
|
/*
|
|
|
|
* We're called directly from interpreter, so we may just setup call frame and return.
|
|
|
|
* Already running interpreter will take care of execution.
|
|
|
|
*/
|
|
|
|
if(r)
|
|
|
|
*r = jsval_undefined();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-03-28 17:50:39 +02:00
|
|
|
return enter_bytecode(ctx, r);
|
2020-03-17 19:19:25 +01:00
|
|
|
|
|
|
|
fail:
|
|
|
|
jsdisp_release(variable_obj);
|
|
|
|
return hres;
|
2011-12-29 11:08:07 +01:00
|
|
|
}
|