Jacek Caban : jscript: Added RegExp constructor object implementation.
Alexandre Julliard
julliard at winehq.org
Wed Sep 10 06:01:40 CDT 2008
Module: wine
Branch: master
Commit: e2f743fad8b8ddc0ac3073f33d92855e1abee2fe
URL: http://source.winehq.org/git/wine.git/?a=commit;h=e2f743fad8b8ddc0ac3073f33d92855e1abee2fe
Author: Jacek Caban <jacek at codeweavers.com>
Date: Wed Sep 10 02:34:54 2008 +0200
jscript: Added RegExp constructor object implementation.
---
dlls/jscript/Makefile.in | 1 +
dlls/jscript/global.c | 9 ++-
dlls/jscript/jscript.h | 3 +
dlls/jscript/regexp.c | 143 ++++++++++++++++++++++++++++++++++++++++++++
dlls/jscript/tests/lang.js | 1 +
5 files changed, 155 insertions(+), 2 deletions(-)
diff --git a/dlls/jscript/Makefile.in b/dlls/jscript/Makefile.in
index 72d908c..cdb878c 100644
--- a/dlls/jscript/Makefile.in
+++ b/dlls/jscript/Makefile.in
@@ -20,6 +20,7 @@ C_SRCS = \
lex.c \
number.c \
object.c \
+ regexp.c \
string.c
IDL_TLB_SRCS = jsglobal.idl
diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c
index b90991b..6f6ca94 100644
--- a/dlls/jscript/global.c
+++ b/dlls/jscript/global.c
@@ -136,8 +136,9 @@ static HRESULT JSGlobal_String(DispatchEx *dispex, LCID lcid, WORD flags, DISPPA
static HRESULT JSGlobal_RegExp(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
- FIXME("\n");
- return E_NOTIMPL;
+ TRACE("\n");
+
+ return constructor_call(dispex->ctx->regexp_constr, lcid, flags, dp, retv, ei, sp);
}
static HRESULT JSGlobal_ActiveXObject(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
@@ -317,6 +318,10 @@ static HRESULT init_constructors(script_ctx_t *ctx)
if(FAILED(hres))
return hres;
+ hres = create_object_constr(ctx, &ctx->regexp_constr);
+ if(FAILED(hres))
+ return hres;
+
hres = create_string_constr(ctx, &ctx->string_constr);
if(FAILED(hres))
return hres;
diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h
index 9f91290..d9b1c46 100644
--- a/dlls/jscript/jscript.h
+++ b/dlls/jscript/jscript.h
@@ -55,6 +55,7 @@ typedef enum {
JSCLASS_GLOBAL,
JSCLASS_NUMBER,
JSCLASS_OBJECT,
+ JSCLASS_REGEXP,
JSCLASS_STRING
} jsclass_t;
@@ -135,6 +136,7 @@ struct _script_ctx_t {
DispatchEx *bool_constr;
DispatchEx *number_constr;
DispatchEx *object_constr;
+ DispatchEx *regexp_constr;
DispatchEx *string_constr;
};
@@ -151,6 +153,7 @@ HRESULT create_array_constr(script_ctx_t*,DispatchEx**);
HRESULT create_bool_constr(script_ctx_t*,DispatchEx**);
HRESULT create_number_constr(script_ctx_t*,DispatchEx**);
HRESULT create_object_constr(script_ctx_t*,DispatchEx**);
+HRESULT create_regexp_constr(script_ctx_t*,DispatchEx**);
HRESULT create_string_constr(script_ctx_t*,DispatchEx**);
const char *debugstr_variant(const VARIANT*);
diff --git a/dlls/jscript/regexp.c b/dlls/jscript/regexp.c
new file mode 100644
index 0000000..8bbaa6c
--- /dev/null
+++ b/dlls/jscript/regexp.c
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2008 Jacek Caban for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "jscript.h"
+
+#include "wine/debug.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(jscript);
+
+typedef struct {
+ DispatchEx dispex;
+} RegExpInstance;
+
+static const WCHAR toStringW[] = {'t','o','S','t','r','i','n','g',0};
+static const WCHAR toLocaleStringW[] = {'t','o','L','o','c','a','l','e','S','t','r','i','n','g',0};
+static const WCHAR hasOwnPropertyW[] = {'h','a','s','O','w','n','P','r','o','p','e','r','t','y',0};
+static const WCHAR propertyIsEnumerableW[] =
+ {'p','r','o','p','e','r','t','y','I','s','E','n','u','m','e','r','a','b','l','e',0};
+static const WCHAR isPrototypeOfW[] = {'i','s','P','r','o','t','o','t','y','p','e','O','f',0};
+
+static HRESULT RegExp_toString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
+ VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
+{
+ FIXME("\n");
+ return E_NOTIMPL;
+}
+
+static HRESULT RegExp_toLocaleString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
+ VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
+{
+ FIXME("\n");
+ return E_NOTIMPL;
+}
+
+static HRESULT RegExp_hasOwnProperty(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
+ VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
+{
+ FIXME("\n");
+ return E_NOTIMPL;
+}
+
+static HRESULT RegExp_propertyIsEnumerable(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
+ VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
+{
+ FIXME("\n");
+ return E_NOTIMPL;
+}
+
+static HRESULT RegExp_isPrototypeOf(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
+ VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
+{
+ FIXME("\n");
+ return E_NOTIMPL;
+}
+
+static HRESULT RegExp_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
+ VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
+{
+ FIXME("\n");
+ return E_NOTIMPL;
+}
+
+static void RegExp_destructor(DispatchEx *dispex)
+{
+ heap_free(dispex);
+}
+
+static const builtin_prop_t RegExp_props[] = {
+ {hasOwnPropertyW, RegExp_hasOwnProperty, PROPF_METHOD},
+ {isPrototypeOfW, RegExp_isPrototypeOf, PROPF_METHOD},
+ {propertyIsEnumerableW, RegExp_propertyIsEnumerable, PROPF_METHOD},
+ {toLocaleStringW, RegExp_toLocaleString, PROPF_METHOD},
+ {toStringW, RegExp_toString, PROPF_METHOD}
+};
+
+static const builtin_info_t RegExp_info = {
+ JSCLASS_REGEXP,
+ {NULL, RegExp_value, 0},
+ sizeof(RegExp_props)/sizeof(*RegExp_props),
+ RegExp_props,
+ RegExp_destructor,
+ NULL
+};
+
+static HRESULT alloc_regexp(script_ctx_t *ctx, BOOL use_constr, RegExpInstance **ret)
+{
+ RegExpInstance *regexp;
+ HRESULT hres;
+
+ regexp = heap_alloc_zero(sizeof(RegExpInstance));
+ if(!regexp)
+ return E_OUTOFMEMORY;
+
+ if(use_constr)
+ hres = init_dispex_from_constr(®exp->dispex, ctx, &RegExp_info, ctx->regexp_constr);
+ else
+ hres = init_dispex(®exp->dispex, ctx, &RegExp_info, NULL);
+
+ if(FAILED(hres)) {
+ heap_free(regexp);
+ return hres;
+ }
+
+ *ret = regexp;
+ return S_OK;
+}
+
+static HRESULT RegExpConstr_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
+ VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
+{
+ FIXME("\n");
+ return E_NOTIMPL;
+}
+
+HRESULT create_regexp_constr(script_ctx_t *ctx, DispatchEx **ret)
+{
+ RegExpInstance *regexp;
+ HRESULT hres;
+
+ hres = alloc_regexp(ctx, FALSE, ®exp);
+ if(FAILED(hres))
+ return hres;
+
+ hres = create_builtin_function(ctx, RegExpConstr_value, PROPF_CONSTR, ®exp->dispex, ret);
+
+ jsdisp_release(®exp->dispex);
+ return hres;
+}
diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js
index 1f20e50..1799c4a 100644
--- a/dlls/jscript/tests/lang.js
+++ b/dlls/jscript/tests/lang.js
@@ -52,5 +52,6 @@ ok(String.prototype !== undefined, "String.prototype is undefined");
ok(Array.prototype !== undefined, "Array.prototype is undefined");
ok(Boolean.prototype !== undefined, "Boolean.prototype is undefined");
ok(Number.prototype !== undefined, "Number.prototype is undefined");
+ok(RegExp.prototype !== undefined, "RegExp.prototype is undefined");
reportSuccess();
More information about the wine-cvs
mailing list