diff --git a/dlls/jscript/Makefile.in b/dlls/jscript/Makefile.in index 76eabc1fae4..07fc1be16a5 100644 --- a/dlls/jscript/Makefile.in +++ b/dlls/jscript/Makefile.in @@ -41,7 +41,8 @@ C_SRCS = \ number.c \ object.c \ regexp.c \ - string.c + string.c \ + vbarray.c IDL_TLB_SRCS = jsglobal.idl diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c index 8655d8ad670..81aee508752 100644 --- a/dlls/jscript/global.c +++ b/dlls/jscript/global.c @@ -248,8 +248,9 @@ static HRESULT JSGlobal_ActiveXObject(script_ctx_t *ctx, vdisp_t *jsthis, WORD f static HRESULT JSGlobal_VBArray(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) { - FIXME("\n"); - return E_NOTIMPL; + TRACE("\n"); + + return constructor_call(ctx->vbarray_constr, flags, dp, retv, ei, sp); } static HRESULT JSGlobal_Enumerator(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, @@ -1039,7 +1040,7 @@ static const builtin_prop_t JSGlobal_props[] = { {SyntaxErrorW, JSGlobal_SyntaxError, PROPF_CONSTR|1}, {TypeErrorW, JSGlobal_TypeError, PROPF_CONSTR|1}, {URIErrorW, JSGlobal_URIError, PROPF_CONSTR|1}, - {VBArrayW, JSGlobal_VBArray, PROPF_METHOD|1}, + {VBArrayW, JSGlobal_VBArray, PROPF_CONSTR|1}, {decodeURIW, JSGlobal_decodeURI, PROPF_METHOD|1}, {decodeURIComponentW, JSGlobal_decodeURIComponent, PROPF_METHOD|1}, {encodeURIW, JSGlobal_encodeURI, PROPF_METHOD|1}, @@ -1106,6 +1107,10 @@ static HRESULT init_constructors(script_ctx_t *ctx, jsdisp_t *object_prototype) if(FAILED(hres)) return hres; + hres = create_vbarray_constr(ctx, object_prototype, &ctx->vbarray_constr); + if(FAILED(hres)) + return hres; + return S_OK; } diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h index e9318e5a152..ab63bced813 100644 --- a/dlls/jscript/jscript.h +++ b/dlls/jscript/jscript.h @@ -84,7 +84,8 @@ typedef enum { JSCLASS_OBJECT, JSCLASS_REGEXP, JSCLASS_STRING, - JSCLASS_ARGUMENTS + JSCLASS_ARGUMENTS, + JSCLASS_VBARRAY } jsclass_t; jsdisp_t *iface_to_jsdisp(IUnknown*); @@ -304,6 +305,7 @@ struct _script_ctx_t { jsdisp_t *object_constr; jsdisp_t *regexp_constr; jsdisp_t *string_constr; + jsdisp_t *vbarray_constr; }; void script_release(script_ctx_t*); @@ -326,6 +328,7 @@ HRESULT create_number_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**); HRESULT create_object_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**); HRESULT create_regexp_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**); HRESULT create_string_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**); +HRESULT create_vbarray_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**); IUnknown *create_ax_site(script_ctx_t*); diff --git a/dlls/jscript/object.c b/dlls/jscript/object.c index bbb0372fffa..eb1d4359222 100644 --- a/dlls/jscript/object.c +++ b/dlls/jscript/object.c @@ -52,7 +52,7 @@ static HRESULT Object_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, D static const WCHAR stringW[] = {'S','t','r','i','n','g',0}; /* Keep in sync with jsclass_t enum */ static const WCHAR *names[] = {objectW, arrayW, booleanW, dateW, errorW, - functionW, NULL, mathW, numberW, objectW, regexpW, stringW, objectW}; + functionW, NULL, mathW, numberW, objectW, regexpW, stringW, objectW, objectW}; TRACE("\n"); diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js index 956ea559b03..f792968a2e9 100644 --- a/dlls/jscript/tests/api.js +++ b/dlls/jscript/tests/api.js @@ -2194,6 +2194,14 @@ testFunctions(Function.prototype, [ ["toString", 0] ]); +testFunctions(VBArray.prototype, [ + ["dimensions", 0], + ["getItem", 1], + ["lbound", 0], + ["toArray", 0], + ["ubound", 0] + ]); + ok(ActiveXObject.length == 1, "ActiveXObject.length = " + ActiveXObject.length); ok(Array.length == 1, "Array.length = " + Array.length); ok(Boolean.length == 1, "Boolean.length = " + Boolean.length); diff --git a/dlls/jscript/vbarray.c b/dlls/jscript/vbarray.c new file mode 100644 index 00000000000..27ec5338544 --- /dev/null +++ b/dlls/jscript/vbarray.c @@ -0,0 +1,160 @@ +/* + * Copyright 2010 Piotr Caban for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "jscript.h" + +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(jscript); + +typedef struct { + jsdisp_t dispex; + + SAFEARRAY *safearray; +} VBArrayInstance; + +static const WCHAR dimensionsW[] = {'d','i','m','e','n','s','i','o','n','s',0}; +static const WCHAR getItemW[] = {'g','e','t','I','t','e','m',0}; +static const WCHAR lboundW[] = {'l','b','o','u','n','d',0}; +static const WCHAR toArrayW[] = {'t','o','A','r','r','a','y',0}; +static const WCHAR uboundW[] = {'u','b','o','u','n','d',0}; + +static HRESULT VBArray_dimensions(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT VBArray_getItem(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT VBArray_lbound(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT VBArray_toArray(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT VBArray_ubound(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT VBArray_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + + switch(flags) { + default: + FIXME("unimplemented flags %x\n", flags); + return E_NOTIMPL; + } + + return S_OK; +} + +static void VBArray_destructor(jsdisp_t *dispex) +{ + heap_free(dispex); +} + +static const builtin_prop_t VBArray_props[] = { + {dimensionsW, VBArray_dimensions, PROPF_METHOD}, + {getItemW, VBArray_getItem, PROPF_METHOD|1}, + {lboundW, VBArray_lbound, PROPF_METHOD}, + {toArrayW, VBArray_toArray, PROPF_METHOD}, + {uboundW, VBArray_ubound, PROPF_METHOD} +}; + +static const builtin_info_t VBArray_info = { + JSCLASS_VBARRAY, + {NULL, VBArray_value, 0}, + sizeof(VBArray_props)/sizeof(*VBArray_props), + VBArray_props, + VBArray_destructor, + NULL +}; + +static HRESULT alloc_vbarray(script_ctx_t *ctx, jsdisp_t *object_prototype, VBArrayInstance **ret) +{ + VBArrayInstance *vbarray; + HRESULT hres; + + vbarray = heap_alloc_zero(sizeof(VBArrayInstance)); + if(!vbarray) + return E_OUTOFMEMORY; + + if(object_prototype) + hres = init_dispex(&vbarray->dispex, ctx, &VBArray_info, object_prototype); + else + hres = init_dispex_from_constr(&vbarray->dispex, ctx, &VBArray_info, ctx->vbarray_constr); + + if(FAILED(hres)) { + heap_free(vbarray); + return hres; + } + + *ret = vbarray; + return S_OK; +} + +static HRESULT VBArrayConstr_value(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller) +{ + FIXME("\n"); + + switch(flags) { + default: + FIXME("unimplemented flags: %x\n", flags); + return E_NOTIMPL; + } + + return S_OK; +} + +HRESULT create_vbarray_constr(script_ctx_t *ctx, jsdisp_t *object_prototype, jsdisp_t **ret) +{ + VBArrayInstance *vbarray; + HRESULT hres; + + static const WCHAR VBArrayW[] = {'V','B','A','r','r','a','y',0}; + + hres = alloc_vbarray(ctx, object_prototype, &vbarray); + if(FAILED(hres)) + return hres; + + hres = create_builtin_function(ctx, VBArrayConstr_value, VBArrayW, NULL, PROPF_CONSTR|1, &vbarray->dispex, ret); + + jsdisp_release(&vbarray->dispex); + return hres; +}