[PATCH v3 1/2] jscript: stub Enumerator object

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH v3 1/2] jscript: stub Enumerator object

Andreas Maier-2
Enumerator is an MS extension.
Its needed to succeed VyChat219.msi installation.

Signed-off-by: Andreas Maier <[hidden email]>
---
 dlls/jscript/Makefile.in  |   1 +
 dlls/jscript/enumerator.c | 190 ++++++++++++++++++++++++++++++++++++++++++++++
 dlls/jscript/global.c     |  17 +++--
 dlls/jscript/jscript.h    |   3 +
 4 files changed, 203 insertions(+), 8 deletions(-)
 create mode 100644 dlls/jscript/enumerator.c

diff --git a/dlls/jscript/Makefile.in b/dlls/jscript/Makefile.in
index 34ed193742..1cc58a5ed6 100644
--- a/dlls/jscript/Makefile.in
+++ b/dlls/jscript/Makefile.in
@@ -10,6 +10,7 @@ C_SRCS = \
  decode.c \
  dispex.c \
  engine.c \
+ enumerator.c \
  error.c \
  function.c \
  global.c \
diff --git a/dlls/jscript/enumerator.c b/dlls/jscript/enumerator.c
new file mode 100644
index 0000000000..aa7737ac52
--- /dev/null
+++ b/dlls/jscript/enumerator.c
@@ -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;
+}
diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c
index 33de641483..92b146c83a 100644
--- a/dlls/jscript/global.c
+++ b/dlls/jscript/global.c
@@ -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;
diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h
index 2af5b598bd..baebcc4b6c 100644
--- a/dlls/jscript/jscript.h
+++ b/dlls/jscript/jscript.h
@@ -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;
--
2.11.0



Reply | Threaded
Open this post in threaded view
|

[PATCH v3 2/2] jscript_test: simple test for Enumerator()

Andreas Maier-2
Signed-off-by: Andreas Maier <[hidden email]>
---
 dlls/jscript/tests/api.js | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js
index 38b2e666da..78c0958301 100644
--- a/dlls/jscript/tests/api.js
+++ b/dlls/jscript/tests/api.js
@@ -58,6 +58,8 @@ testNoEnumerables("Function");
 testNoEnumerables("Function.prototype");
 testNoEnumerables("testNoEnumerates");
 testNoEnumerables("VBArray");
+testNoEnumerables("new Enumerator([])");
+testNoEnumerables("Enumerator([])");

 ok(Object.propertyIsEnumerable("prototype") === false, "Object.prototype is enumerable");
 ok(Math.propertyIsEnumerable("E") === false, "Math.E is enumerable");
@@ -341,6 +343,8 @@ ok(tmp === "[object Object]", "toString.call(this) = " + tmp);
 ok(tmp === "[object Object]", "toString.call(arguments) = " + tmp);
 tmp = Object.prototype.toString.call(new VBArray(createArray()));
 ok(tmp === "[object Object]", "toString.call(new VBArray()) = " + tmp);
+(tmp = new Enumerator([])).f = Object.prototype.toString;
+ok(tmp.f() === "[object Object]", "tmp.f() = " + tmp.f());

 function TSTestConstr() {}
 TSTestConstr.prototype = { toString: function() { return "test"; } };
--
2.11.0



Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v3 1/2] jscript: stub Enumerator object

Jacek Caban-3
In reply to this post by Andreas Maier-2
Signed-off-by: Jacek Caban <[hidden email]>


Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v3 2/2] jscript_test: simple test for Enumerator()

Jacek Caban-3
In reply to this post by Andreas Maier-2
Signed-off-by: Jacek Caban <[hidden email]>