Jacek Caban : jscript: Added Boolean constructor object.

Alexandre Julliard julliard at winehq.org
Wed Sep 10 06:01:39 CDT 2008


Module: wine
Branch: master
Commit: f8be53fcf33208861887351be6f97861b1133763
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=f8be53fcf33208861887351be6f97861b1133763

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Sep 10 02:34:16 2008 +0200

jscript: Added Boolean constructor object.

---

 dlls/jscript/Makefile.in   |    1 +
 dlls/jscript/bool.c        |  147 ++++++++++++++++++++++++++++++++++++++++++++
 dlls/jscript/global.c      |    9 ++-
 dlls/jscript/jscript.h     |    3 +
 dlls/jscript/tests/lang.js |    1 +
 5 files changed, 159 insertions(+), 2 deletions(-)

diff --git a/dlls/jscript/Makefile.in b/dlls/jscript/Makefile.in
index c761787..1fb34d0 100644
--- a/dlls/jscript/Makefile.in
+++ b/dlls/jscript/Makefile.in
@@ -9,6 +9,7 @@ RC_SRCS = rsrc.rc
 
 C_SRCS = \
 	array.c \
+	bool.c \
 	dispex.c \
 	engine.c \
 	function.c \
diff --git a/dlls/jscript/bool.c b/dlls/jscript/bool.c
new file mode 100644
index 0000000..a98a4ff
--- /dev/null
+++ b/dlls/jscript/bool.c
@@ -0,0 +1,147 @@
+/*
+ * 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;
+} BoolInstance;
+
+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 valueOfW[] = {'v','a','l','u','e','O','f',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 Bool_toString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
+        VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
+{
+    FIXME("\n");
+    return E_NOTIMPL;
+}
+
+static HRESULT Bool_toLocaleString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
+        VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
+{
+    FIXME("\n");
+    return E_NOTIMPL;
+}
+
+static HRESULT Bool_valueOf(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
+        VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
+{
+    FIXME("\n");
+    return E_NOTIMPL;
+}
+
+static HRESULT Bool_hasOwnProperty(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
+        VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
+{
+    FIXME("\n");
+    return E_NOTIMPL;
+}
+
+static HRESULT Bool_propertyIsEnumerable(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
+        VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
+{
+    FIXME("\n");
+    return E_NOTIMPL;
+}
+
+static HRESULT Bool_isPrototypeOf(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
+        VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
+{
+    FIXME("\n");
+    return E_NOTIMPL;
+}
+
+static HRESULT Bool_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
+        VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
+{
+    FIXME("\n");
+    return E_NOTIMPL;
+}
+
+static const builtin_prop_t Bool_props[] = {
+    {hasOwnPropertyW,        Bool_hasOwnProperty,       PROPF_METHOD},
+    {isPrototypeOfW,         Bool_isPrototypeOf,        PROPF_METHOD},
+    {propertyIsEnumerableW,  Bool_propertyIsEnumerable, PROPF_METHOD},
+    {toLocaleStringW,        Bool_toLocaleString,       PROPF_METHOD},
+    {toStringW,              Bool_toString,             PROPF_METHOD},
+    {valueOfW,               Bool_valueOf,              PROPF_METHOD}
+};
+
+static const builtin_info_t Bool_info = {
+    JSCLASS_BOOLEAN,
+    {NULL, Bool_value, 0},
+    sizeof(Bool_props)/sizeof(*Bool_props),
+    Bool_props,
+    NULL,
+    NULL
+};
+
+static HRESULT BoolConstr_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
+        VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
+{
+    FIXME("\n");
+    return E_NOTIMPL;
+}
+
+static HRESULT alloc_bool(script_ctx_t *ctx, BOOL use_constr, BoolInstance **ret)
+{
+    BoolInstance *bool;
+    HRESULT hres;
+
+    bool = heap_alloc_zero(sizeof(BoolInstance));
+    if(!bool)
+        return E_OUTOFMEMORY;
+
+    if(use_constr)
+        hres = init_dispex_from_constr(&bool->dispex, ctx, &Bool_info, ctx->bool_constr);
+    else
+        hres = init_dispex(&bool->dispex, ctx, &Bool_info, NULL);
+
+    if(FAILED(hres)) {
+        heap_free(bool);
+        return hres;
+    }
+
+    *ret = bool;
+    return S_OK;
+}
+
+HRESULT create_bool_constr(script_ctx_t *ctx, DispatchEx **ret)
+{
+    BoolInstance *bool;
+    HRESULT hres;
+
+    hres = alloc_bool(ctx, FALSE, &bool);
+    if(FAILED(hres))
+        return hres;
+
+    hres = create_builtin_function(ctx, BoolConstr_value, PROPF_CONSTR, &bool->dispex, ret);
+
+    jsdisp_release(&bool->dispex);
+    return hres;
+}
diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c
index bc4f14a..2f78231 100644
--- a/dlls/jscript/global.c
+++ b/dlls/jscript/global.c
@@ -90,8 +90,9 @@ static HRESULT JSGlobal_Array(DispatchEx *dispex, LCID lcid, WORD flags, DISPPAR
 static HRESULT JSGlobal_Boolean(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->bool_constr, lcid, flags, dp, retv, ei, sp);
 }
 
 static HRESULT JSGlobal_Date(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
@@ -303,6 +304,10 @@ static HRESULT init_constructors(script_ctx_t *ctx)
     if(FAILED(hres))
         return hres;
 
+    hres = create_bool_constr(ctx, &ctx->bool_constr);
+    if(FAILED(hres))
+        return hres;
+
     hres = create_object_constr(ctx, &ctx->object_constr);
     if(FAILED(hres))
         return hres;
diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h
index d5ba1c4..9515c51 100644
--- a/dlls/jscript/jscript.h
+++ b/dlls/jscript/jscript.h
@@ -50,6 +50,7 @@ typedef struct DispatchEx DispatchEx;
 typedef enum {
     JSCLASS_NONE,
     JSCLASS_ARRAY,
+    JSCLASS_BOOLEAN,
     JSCLASS_FUNCTION,
     JSCLASS_GLOBAL,
     JSCLASS_OBJECT,
@@ -130,6 +131,7 @@ struct _script_ctx_t {
     DispatchEx *script_disp;
     DispatchEx *global;
     DispatchEx *array_constr;
+    DispatchEx *bool_constr;
     DispatchEx *object_constr;
     DispatchEx *string_constr;
 };
@@ -144,6 +146,7 @@ static inline void script_addref(script_ctx_t *ctx)
 HRESULT init_global(script_ctx_t*);
 
 HRESULT create_array_constr(script_ctx_t*,DispatchEx**);
+HRESULT create_bool_constr(script_ctx_t*,DispatchEx**);
 HRESULT create_object_constr(script_ctx_t*,DispatchEx**);
 HRESULT create_string_constr(script_ctx_t*,DispatchEx**);
 
diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js
index b5f2512..e6587cf 100644
--- a/dlls/jscript/tests/lang.js
+++ b/dlls/jscript/tests/lang.js
@@ -50,5 +50,6 @@ ok(Object.prototype !== undefined, "Object.prototype is undefined");
 ok(Object.prototype.prototype === undefined, "Object.prototype is not undefined");
 ok(String.prototype !== undefined, "String.prototype is undefined");
 ok(Array.prototype !== undefined, "Array.prototype is undefined");
+ok(Boolean.prototype !== undefined, "Boolean.prototype is undefined");
 
 reportSuccess();




More information about the wine-cvs mailing list