Jacek Caban : jscript: Added JSON object stub implementation.
Alexandre Julliard
julliard at wine.codeweavers.com
Thu Jan 28 10:06:44 CST 2016
Module: wine
Branch: master
Commit: 4e1e2ee451d5559dd12b81a9ff94580573d0c05f
URL: http://source.winehq.org/git/wine.git/?a=commit;h=4e1e2ee451d5559dd12b81a9ff94580573d0c05f
Author: Jacek Caban <jacek at codeweavers.com>
Date: Wed Jan 27 20:43:26 2016 +0100
jscript: Added JSON 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 | 14 +++++++++
dlls/jscript/jscript.h | 4 ++-
dlls/jscript/json.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++
dlls/jscript/object.c | 2 +-
dlls/jscript/tests/api.js | 8 +++++
6 files changed, 101 insertions(+), 2 deletions(-)
diff --git a/dlls/jscript/Makefile.in b/dlls/jscript/Makefile.in
index 67ec4c8..34ed193 100644
--- a/dlls/jscript/Makefile.in
+++ b/dlls/jscript/Makefile.in
@@ -15,6 +15,7 @@ C_SRCS = \
global.c \
jscript.c \
jscript_main.c \
+ json.c \
jsregexp.c \
jsstr.c \
jsutils.c \
diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c
index 1889dc8..03a26302 100644
--- a/dlls/jscript/global.c
+++ b/dlls/jscript/global.c
@@ -67,6 +67,7 @@ static const WCHAR ScriptEngineBuildVersionW[] =
{'S','c','r','i','p','t','E','n','g','i','n','e','B','u','i','l','d','V','e','r','s','i','o','n',0};
static const WCHAR CollectGarbageW[] = {'C','o','l','l','e','c','t','G','a','r','b','a','g','e',0};
static const WCHAR MathW[] = {'M','a','t','h',0};
+static const WCHAR JSONW[] = {'J','S','O','N',0};
static const WCHAR encodeURIW[] = {'e','n','c','o','d','e','U','R','I',0};
static const WCHAR decodeURIW[] = {'d','e','c','o','d','e','U','R','I',0};
static const WCHAR encodeURIComponentW[] = {'e','n','c','o','d','e','U','R','I','C','o','m','p','o','n','e','n','t',0};
@@ -1107,6 +1108,19 @@ HRESULT init_global(script_ctx_t *ctx)
if(FAILED(hres))
return hres;
+ if(ctx->version >= 2) {
+ jsdisp_t *json;
+
+ hres = create_json(ctx, &json);
+ if(FAILED(hres))
+ return hres;
+
+ hres = jsdisp_propput_dontenum(ctx->global, JSONW, jsval_obj(json));
+ jsdisp_release(json);
+ if(FAILED(hres))
+ return hres;
+ }
+
hres = create_activex_constr(ctx, &constr);
if(FAILED(hres))
return hres;
diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h
index c0c546a..98cd5b8 100644
--- a/dlls/jscript/jscript.h
+++ b/dlls/jscript/jscript.h
@@ -117,7 +117,8 @@ typedef enum {
JSCLASS_REGEXP,
JSCLASS_STRING,
JSCLASS_ARGUMENTS,
- JSCLASS_VBARRAY
+ JSCLASS_VBARRAY,
+ JSCLASS_JSON
} jsclass_t;
jsdisp_t *iface_to_jsdisp(IUnknown*) DECLSPEC_HIDDEN;
@@ -317,6 +318,7 @@ HRESULT create_string(script_ctx_t*,jsstr_t*,jsdisp_t**) DECLSPEC_HIDDEN;
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;
typedef enum {
NO_HINT,
diff --git a/dlls/jscript/json.c b/dlls/jscript/json.c
new file mode 100644
index 0000000..6e33a88
--- /dev/null
+++ b/dlls/jscript/json.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2016 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 <math.h>
+
+#include "jscript.h"
+
+#include "wine/debug.h"
+#include "wine/unicode.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(jscript);
+
+static const WCHAR parseW[] = {'p','a','r','s','e',0};
+static const WCHAR stringifyW[] = {'s','t','r','i','n','g','i','f','y',0};
+
+static HRESULT JSON_parse(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
+{
+ FIXME("\n");
+ return E_NOTIMPL;
+}
+
+static HRESULT JSON_stringify(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 JSON_props[] = {
+ {parseW, JSON_parse, PROPF_METHOD|2},
+ {stringifyW, JSON_stringify, PROPF_METHOD|3}
+};
+
+static const builtin_info_t JSON_info = {
+ JSCLASS_JSON,
+ {NULL, NULL, 0},
+ sizeof(JSON_props)/sizeof(*JSON_props),
+ JSON_props,
+ NULL,
+ NULL
+};
+
+HRESULT create_json(script_ctx_t *ctx, jsdisp_t **ret)
+{
+ jsdisp_t *json;
+ HRESULT hres;
+
+ json = heap_alloc_zero(sizeof(*json));
+ if(!json)
+ return E_OUTOFMEMORY;
+
+ hres = init_dispex_from_constr(json, ctx, &JSON_info, ctx->object_constr);
+ if(FAILED(hres)) {
+ heap_free(json);
+ return hres;
+ }
+
+ *ret = json;
+ return S_OK;
+}
diff --git a/dlls/jscript/object.c b/dlls/jscript/object.c
index ffb7ff8..71bed7b 100644
--- a/dlls/jscript/object.c
+++ b/dlls/jscript/object.c
@@ -54,7 +54,7 @@ static HRESULT Object_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
static const WCHAR stringW[] = {'S','t','r','i','n','g',0};
/* Keep in sync with jsclass_t enum */
static const WCHAR *names[] = {NULL, arrayW, booleanW, dateW, errorW,
- functionW, NULL, mathW, numberW, objectW, regexpW, stringW, objectW, objectW};
+ functionW, NULL, mathW, numberW, objectW, regexpW, stringW, objectW, objectW, objectW};
TRACE("\n");
diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js
index 78145c6..82d2670 100644
--- a/dlls/jscript/tests/api.js
+++ b/dlls/jscript/tests/api.js
@@ -2717,6 +2717,14 @@ testFunctions(VBArray.prototype, [
["lbound", 0],
["toArray", 0],
["ubound", 0]
+]);
+
+if(invokeVersion < 2)
+ ok(typeof(JSON) === "undefined", "JSON is not undefined");
+else
+ testFunctions(JSON, [
+ ["parse", 2],
+ ["stringify", 3]
]);
ok(ActiveXObject.length == 1, "ActiveXObject.length = " + ActiveXObject.length);
More information about the wine-cvs
mailing list