Jacek Caban : jscript: Add Set object stub implementation.
Alexandre Julliard
julliard at winehq.org
Thu Apr 22 15:55:24 CDT 2021
Module: wine
Branch: master
Commit: 8dd582ebebaf2f179e15f1a95a6a43594f7479d8
URL: https://source.winehq.org/git/wine.git/?a=commit;h=8dd582ebebaf2f179e15f1a95a6a43594f7479d8
Author: Jacek Caban <jacek at codeweavers.com>
Date: Thu Apr 22 01:47:35 2021 +0200
jscript: Add Set object stub implementation.
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/jscript/Makefile.in | 1 +
dlls/jscript/global.c | 5 +-
dlls/jscript/jscript.c | 5 ++
dlls/jscript/jscript.h | 5 +-
dlls/jscript/object.c | 1 +
dlls/jscript/set.c | 143 ++++++++++++++++++++++++++++++++++++++
dlls/mshtml/tests/documentmode.js | 23 ++++++
7 files changed, 181 insertions(+), 2 deletions(-)
diff --git a/dlls/jscript/Makefile.in b/dlls/jscript/Makefile.in
index f2ab3243823..c81d97c1552 100644
--- a/dlls/jscript/Makefile.in
+++ b/dlls/jscript/Makefile.in
@@ -27,6 +27,7 @@ C_SRCS = \
number.c \
object.c \
regexp.c \
+ set.c \
string.c \
vbarray.c
diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c
index 33869cd5fc6..2665bece04a 100644
--- a/dlls/jscript/global.c
+++ b/dlls/jscript/global.c
@@ -1114,5 +1114,8 @@ HRESULT init_global(script_ctx_t *ctx)
return hres;
hres = jsdisp_define_data_property(ctx->global, L"Infinity", const_flags, jsval_number(INFINITY));
- return hres;
+ if(FAILED(hres))
+ return hres;
+
+ return init_set_constructor(ctx);
}
diff --git a/dlls/jscript/jscript.c b/dlls/jscript/jscript.c
index 67a25d1714b..7a037d09b2d 100644
--- a/dlls/jscript/jscript.c
+++ b/dlls/jscript/jscript.c
@@ -483,6 +483,11 @@ static void decrease_state(JScript *This, SCRIPTSTATE state)
This->ctx->site = NULL;
}
+ if(This->ctx->set_prototype) {
+ jsdisp_release(This->ctx->set_prototype);
+ This->ctx->set_prototype = NULL;
+ }
+
if(This->ctx->object_prototype) {
jsdisp_release(This->ctx->object_prototype);
This->ctx->object_prototype = NULL;
diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h
index 94f8440362e..d64d927c227 100644
--- a/dlls/jscript/jscript.h
+++ b/dlls/jscript/jscript.h
@@ -130,7 +130,8 @@ typedef enum {
JSCLASS_STRING,
JSCLASS_ARGUMENTS,
JSCLASS_VBARRAY,
- JSCLASS_JSON
+ JSCLASS_JSON,
+ JSCLASS_SET,
} jsclass_t;
jsdisp_t *iface_to_jsdisp(IDispatch*) DECLSPEC_HIDDEN;
@@ -466,6 +467,7 @@ struct _script_ctx_t {
jsdisp_t *regexp_constr;
jsdisp_t *string_constr;
jsdisp_t *vbarray_constr;
+ jsdisp_t *set_prototype;
};
void script_release(script_ctx_t*) DECLSPEC_HIDDEN;
@@ -478,6 +480,7 @@ static inline void script_addref(script_ctx_t *ctx)
HRESULT init_global(script_ctx_t*) DECLSPEC_HIDDEN;
HRESULT init_function_constr(script_ctx_t*,jsdisp_t*) DECLSPEC_HIDDEN;
HRESULT create_object_prototype(script_ctx_t*,jsdisp_t**) DECLSPEC_HIDDEN;
+HRESULT init_set_constructor(script_ctx_t*) DECLSPEC_HIDDEN;
HRESULT create_activex_constr(script_ctx_t*,jsdisp_t**) DECLSPEC_HIDDEN;
HRESULT create_array_constr(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;
diff --git a/dlls/jscript/object.c b/dlls/jscript/object.c
index fd5c67833d8..46d50000cc3 100644
--- a/dlls/jscript/object.c
+++ b/dlls/jscript/object.c
@@ -47,6 +47,7 @@ static HRESULT Object_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
L"[object String]",
L"[object Object]",
L"[object Object]",
+ L"[object Object]",
L"[object Object]"
};
diff --git a/dlls/jscript/set.c b/dlls/jscript/set.c
new file mode 100644
index 00000000000..ec22b69eb91
--- /dev/null
+++ b/dlls/jscript/set.c
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2021 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 {
+ jsdisp_t dispex;
+} SetInstance;
+
+static HRESULT Set_add(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
+ jsval_t *r)
+{
+ FIXME("%p\n", jsthis);
+ return E_NOTIMPL;
+}
+
+static HRESULT Set_clear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
+ jsval_t *r)
+{
+ FIXME("%p\n", jsthis);
+ return E_NOTIMPL;
+}
+
+static HRESULT Set_delete(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
+ jsval_t *r)
+{
+ FIXME("%p\n", jsthis);
+ return E_NOTIMPL;
+}
+
+static HRESULT Set_forEach(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
+ jsval_t *r)
+{
+ FIXME("%p\n", jsthis);
+ return E_NOTIMPL;
+}
+
+static HRESULT Set_has(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
+ jsval_t *r)
+{
+ FIXME("%p\n", jsthis);
+ return E_NOTIMPL;
+}
+
+static HRESULT Set_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
+ jsval_t *r)
+{
+ FIXME("\n");
+ return E_NOTIMPL;
+}
+
+static const builtin_prop_t Set_props[] = {
+ {L"add", Set_add, PROPF_METHOD|1},
+ {L"clear", Set_clear, PROPF_METHOD},
+ {L"delete" , Set_delete, PROPF_METHOD|1},
+ {L"forEach", Set_forEach, PROPF_METHOD|1},
+ {L"has", Set_has, PROPF_METHOD|1},
+};
+
+static const builtin_info_t Set_prototype_info = {
+ JSCLASS_SET,
+ {NULL, Set_value, 0},
+ ARRAY_SIZE(Set_props),
+ Set_props,
+ NULL,
+ NULL
+};
+
+static const builtin_info_t Set_info = {
+ JSCLASS_SET,
+ {NULL, Set_value, 0},
+ 0, NULL,
+ NULL,
+ NULL
+};
+
+static HRESULT Set_constructor(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
+ jsval_t *r)
+{
+ SetInstance *set;
+ HRESULT hres;
+
+ switch(flags) {
+ case DISPATCH_CONSTRUCT:
+ TRACE("\n");
+
+ if(!(set = heap_alloc_zero(sizeof(*set))))
+ return E_OUTOFMEMORY;
+
+ hres = init_dispex(&set->dispex, ctx, &Set_info, ctx->set_prototype);
+ if(FAILED(hres))
+ return hres;
+
+ *r = jsval_obj(&set->dispex);
+ return S_OK;
+
+ default:
+ FIXME("unimplemented flags %x\n", flags);
+ return E_NOTIMPL;
+ }
+}
+
+HRESULT init_set_constructor(script_ctx_t *ctx)
+{
+ jsdisp_t *constructor;
+ HRESULT hres;
+
+ if(ctx->version < SCRIPTLANGUAGEVERSION_ES6)
+ return S_OK;
+
+ hres = create_dispex(ctx, &Set_prototype_info, ctx->object_prototype, &ctx->set_prototype);
+ if(FAILED(hres))
+ return hres;
+
+ hres = create_builtin_constructor(ctx, Set_constructor, L"Set", NULL,
+ PROPF_CONSTR, ctx->set_prototype, &constructor);
+ if(FAILED(hres))
+ return hres;
+
+ hres = jsdisp_define_data_property(ctx->global, L"Set", PROPF_WRITABLE,
+ jsval_obj(constructor));
+ jsdisp_release(constructor);
+ return hres;
+}
diff --git a/dlls/mshtml/tests/documentmode.js b/dlls/mshtml/tests/documentmode.js
index bd1255bc960..35b4a001fed 100644
--- a/dlls/mshtml/tests/documentmode.js
+++ b/dlls/mshtml/tests/documentmode.js
@@ -115,6 +115,7 @@ sync_test("window_props", function() {
test_exposed("getSelection", v >= 9);
test_exposed("onfocusout", v >= 9);
test_exposed("getComputedStyle", v >= 9);
+ test_exposed("Set", v >= 11);
if(v >= 9) /* FIXME: native exposes it in all compat modes */
test_exposed("performance", true);
});
@@ -597,3 +598,25 @@ sync_test("func_scope", function() {
}catch(e) {}
})(o);
});
+
+sync_test("set_obj", function() {
+ if(!("Set" in window)) return;
+
+ var s = new Set, r;
+ ok(Object.getPrototypeOf(s) === Set.prototype, "unexpected Set prototype");
+
+ function test_length(name, len) {
+ ok(Set.prototype[name].length === len, "Set.prototype." + name + " = " + Set.prototype[name].length);
+ }
+ test_length("add", 1);
+ test_length("clear", 0);
+ test_length("delete", 1);
+ test_length("forEach", 1);
+ test_length("has", 1);
+ ok(!("entries" in s), "entries are in Set");
+ ok(!("keys" in s), "keys are in Set");
+ ok(!("values" in s), "values are in Set");
+
+ r = Object.prototype.toString.call(s);
+ ok(r === "[object Object]", "toString returned " + r);
+});
More information about the wine-cvs
mailing list