jscript: Stub Enumerator object.

Enumerator is an MS extension.
It's needed to succeed VyChat219.msi installation.

Signed-off-by: Andreas Maier <staubim@quantentunnel.de>
Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Andreas Maier 2019-04-18 21:08:40 +02:00 committed by Alexandre Julliard
parent d2f477dd72
commit 6630bc4096
4 changed files with 203 additions and 8 deletions

View File

@ -10,6 +10,7 @@ C_SRCS = \
decode.c \
dispex.c \
engine.c \
enumerator.c \
error.c \
function.c \
global.c \

190
dlls/jscript/enumerator.c Normal file
View File

@ -0,0 +1,190 @@
/*
* Copyright 2019 Andreas Maier
*
* 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
*/
#include <assert.h>
#include "jscript.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(jscript);
typedef struct {
jsdisp_t dispex;
} EnumeratorInstance;
static const WCHAR atEndW[] = {'a','t','E','n','d',0};
static const WCHAR itemW[] = {'i','t','e','m',0};
static const WCHAR moveFirstW[] = {'m','o','v','e','F','i','r','s','t',0};
static const WCHAR moveNextW[] = {'m','o','v','e','N','e','x','t',0};
static void Enumerator_destructor(jsdisp_t *dispex)
{
TRACE("Enumerator_destructor\n");
heap_free(dispex);
}
HRESULT Enumerator_atEnd(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r)
{
TRACE("Enumerator_atEnd\n");
return E_NOTIMPL;
}
HRESULT Enumerator_item(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r)
{
TRACE("Enumerator_item\n");
return E_NOTIMPL;
}
HRESULT Enumerator_moveFirst(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r)
{
TRACE("Enumerator_moveFirst\n");
return E_NOTIMPL;
}
HRESULT Enumerator_moveNext(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r)
{
TRACE("Enumerator_moveNext\n");
return E_NOTIMPL;
}
static const builtin_prop_t Enumerator_props[] = {
{atEndW, Enumerator_atEnd, PROPF_METHOD},
{itemW, Enumerator_item, PROPF_METHOD},
{moveFirstW, Enumerator_moveFirst, PROPF_METHOD},
{moveNextW, Enumerator_moveNext, PROPF_METHOD},
};
static const builtin_info_t Enumerator_info = {
JSCLASS_OBJECT,
{NULL, NULL, 0},
ARRAY_SIZE(Enumerator_props),
Enumerator_props,
NULL,
NULL
};
static const builtin_info_t EnumeratorInst_info = {
JSCLASS_OBJECT,
{NULL, NULL, 0, NULL},
0,
NULL,
Enumerator_destructor,
NULL
};
static HRESULT EnumeratorConstr_value(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r)
{
jsdisp_t *obj;
HRESULT hres;
TRACE("EnumeratorConstr_value\n");
switch(flags) {
case DISPATCH_CONSTRUCT: {
if (argc != 1)
return throw_syntax_error(ctx, JS_E_MISSING_ARG, NULL);
hres = create_enumerator(ctx, &argv[0], &obj);
if(FAILED(hres))
return hres;
*r = jsval_obj(obj);
break;
}
default:
FIXME("unimplemented flags: %x\n", flags);
return E_NOTIMPL;
}
return S_OK;
}
static HRESULT alloc_enumerator(script_ctx_t *ctx, jsdisp_t *object_prototype, EnumeratorInstance **ret)
{
EnumeratorInstance *enumerator;
HRESULT hres;
enumerator = heap_alloc_zero(sizeof(EnumeratorInstance));
if(!enumerator)
return E_OUTOFMEMORY;
if(object_prototype)
hres = init_dispex(&enumerator->dispex, ctx, &Enumerator_info, object_prototype);
else
hres = init_dispex_from_constr(&enumerator->dispex, ctx, &EnumeratorInst_info,
ctx->enumerator_constr);
if(FAILED(hres)) {
heap_free(enumerator);
return hres;
}
*ret = enumerator;
return S_OK;
}
static const builtin_info_t EnumeratorConstr_info = {
JSCLASS_FUNCTION,
DEFAULT_FUNCTION_VALUE,
0,
NULL,
NULL,
NULL
};
HRESULT create_enumerator_constr(script_ctx_t *ctx, jsdisp_t *object_prototype, jsdisp_t **ret)
{
EnumeratorInstance *enumerator;
HRESULT hres;
static const WCHAR EnumeratorW[] = {'E','n','u','m','e','r','a','t','o','r',0};
hres = alloc_enumerator(ctx, object_prototype, &enumerator);
if(FAILED(hres))
return hres;
hres = create_builtin_constructor(ctx, EnumeratorConstr_value,
EnumeratorW, &EnumeratorConstr_info,
PROPF_CONSTR|7, &enumerator->dispex, ret);
jsdisp_release(&enumerator->dispex);
return hres;
}
HRESULT create_enumerator(script_ctx_t *ctx, jsval_t *argv, jsdisp_t **ret)
{
EnumeratorInstance *enumerator;
HRESULT hres;
hres = alloc_enumerator(ctx, NULL, &enumerator);
if(FAILED(hres))
return hres;
*ret = &enumerator->dispex;
return S_OK;
}

View File

@ -113,13 +113,6 @@ static WCHAR int_to_char(int i)
return 'A'+i-10;
}
static HRESULT JSGlobal_Enumerator(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT JSGlobal_escape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r)
{
@ -942,7 +935,6 @@ static HRESULT JSGlobal_decodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, W
static const builtin_prop_t JSGlobal_props[] = {
{CollectGarbageW, JSGlobal_CollectGarbage, PROPF_METHOD},
{EnumeratorW, JSGlobal_Enumerator, PROPF_METHOD|7},
{_GetObjectW, JSGlobal_GetObject, PROPF_METHOD|2},
{ScriptEngineW, JSGlobal_ScriptEngine, PROPF_METHOD},
{ScriptEngineBuildVersionW, JSGlobal_ScriptEngineBuildVersion, PROPF_METHOD},
@ -1019,6 +1011,15 @@ static HRESULT init_constructors(script_ctx_t *ctx, jsdisp_t *object_prototype)
if(FAILED(hres))
return hres;
hres = create_enumerator_constr(ctx, object_prototype, &ctx->enumerator_constr);
if(FAILED(hres))
return hres;
hres = jsdisp_define_data_property(ctx->global, EnumeratorW, PROPF_WRITABLE,
jsval_obj(ctx->enumerator_constr));
if(FAILED(hres))
return hres;
hres = init_error_constr(ctx, object_prototype);
if(FAILED(hres))
return hres;

View File

@ -326,6 +326,7 @@ HRESULT create_bool(script_ctx_t*,BOOL,jsdisp_t**) DECLSPEC_HIDDEN;
HRESULT create_number(script_ctx_t*,double,jsdisp_t**) DECLSPEC_HIDDEN;
HRESULT create_vbarray(script_ctx_t*,SAFEARRAY*,jsdisp_t**) DECLSPEC_HIDDEN;
HRESULT create_json(script_ctx_t*,jsdisp_t**) DECLSPEC_HIDDEN;
HRESULT create_enumerator(script_ctx_t *ctx, jsval_t *argv, jsdisp_t **ret) DECLSPEC_HIDDEN;
typedef enum {
NO_HINT,
@ -436,6 +437,7 @@ struct _script_ctx_t {
jsdisp_t *array_constr;
jsdisp_t *bool_constr;
jsdisp_t *date_constr;
jsdisp_t *enumerator_constr;
jsdisp_t *error_constr;
jsdisp_t *eval_error_constr;
jsdisp_t *range_error_constr;
@ -468,6 +470,7 @@ HRESULT create_array_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
HRESULT create_bool_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
HRESULT create_date_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
HRESULT init_error_constr(script_ctx_t*,jsdisp_t*) DECLSPEC_HIDDEN;
HRESULT create_enumerator_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
HRESULT create_number_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
HRESULT create_object_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
HRESULT create_regexp_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;