Piotr Caban : jscript: Added String_fromCharCode implementation.
Alexandre Julliard
julliard at winehq.org
Tue Jul 14 10:37:25 CDT 2009
Module: wine
Branch: master
Commit: c44056d4b2b34e838a305d29a385c96677d08d64
URL: http://source.winehq.org/git/wine.git/?a=commit;h=c44056d4b2b34e838a305d29a385c96677d08d64
Author: Piotr Caban <piotr.caban at gmail.com>
Date: Tue Jul 14 01:36:58 2009 +0200
jscript: Added String_fromCharCode implementation.
---
dlls/jscript/string.c | 47 ++++++++++++++++++++++++++++++++++++++++++++-
dlls/jscript/tests/api.js | 7 ++++++
2 files changed, 53 insertions(+), 1 deletions(-)
diff --git a/dlls/jscript/string.c b/dlls/jscript/string.c
index 6aa6302..cf3c5be 100644
--- a/dlls/jscript/string.c
+++ b/dlls/jscript/string.c
@@ -66,6 +66,7 @@ static const WCHAR hasOwnPropertyW[] = {'h','a','s','O','w','n','P','r','o','p',
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 const WCHAR fromCharCodeW[] = {'f','r','o','m','C','h','a','r','C','o','d','e',0};
static HRESULT String_length(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
@@ -1557,6 +1558,37 @@ static const builtin_info_t String_info = {
NULL
};
+/* ECMA-262 3rd Edition 15.5.3.2 */
+static HRESULT StringConstr_fromCharCode(DispatchEx *dispex, LCID lcid, WORD flags,
+ DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
+{
+ DWORD i, code;
+ BSTR ret;
+ HRESULT hres;
+
+ ret = SysAllocStringLen(NULL, arg_cnt(dp));
+ if(!ret)
+ return E_OUTOFMEMORY;
+
+ for(i=0; i<arg_cnt(dp); i++) {
+ hres = to_uint32(dispex->ctx, get_arg(dp, i), ei, &code);
+ if(FAILED(hres)) {
+ SysFreeString(ret);
+ return hres;
+ }
+
+ ret[i] = code;
+ }
+
+ if(retv) {
+ V_VT(retv) = VT_BSTR;
+ V_BSTR(retv) = ret;
+ }
+ else SysFreeString(ret);
+
+ return S_OK;
+}
+
static HRESULT StringConstr_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
@@ -1636,6 +1668,19 @@ static HRESULT string_alloc(script_ctx_t *ctx, BOOL use_constr, StringInstance *
return S_OK;
}
+static const builtin_prop_t StringConstr_props[] = {
+ {fromCharCodeW, StringConstr_fromCharCode, PROPF_METHOD},
+};
+
+static const builtin_info_t StringConstr_info = {
+ JSCLASS_FUNCTION,
+ {NULL, Function_value, 0},
+ sizeof(StringConstr_props)/sizeof(*StringConstr_props),
+ StringConstr_props,
+ NULL,
+ NULL
+};
+
HRESULT create_string_constr(script_ctx_t *ctx, DispatchEx **ret)
{
StringInstance *string;
@@ -1645,7 +1690,7 @@ HRESULT create_string_constr(script_ctx_t *ctx, DispatchEx **ret)
if(FAILED(hres))
return hres;
- hres = create_builtin_function(ctx, StringConstr_value, NULL, PROPF_CONSTR, &string->dispex, ret);
+ hres = create_builtin_function(ctx, StringConstr_value, &StringConstr_info, PROPF_CONSTR, &string->dispex, ret);
jsdisp_release(&string->dispex);
return hres;
diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js
index 1e3a6dc..cf70ebc 100644
--- a/dlls/jscript/tests/api.js
+++ b/dlls/jscript/tests/api.js
@@ -405,6 +405,13 @@ ok(tmp === "<SUP>test</SUP>", "'test'.sup() = " + tmp);
tmp = "test".sup(3);
ok(tmp === "<SUP>test</SUP>", "'test'.sup(3) = " + tmp);
+ok(String.fromCharCode() === "", "String.fromCharCode() = " + String.fromCharCode());
+ok(String.fromCharCode(65,"66",67) === "ABC", "String.fromCharCode(65,'66',67) = " + String.fromCharCode(65,"66",67));
+ok(String.fromCharCode(1024*64+65, -1024*64+65) === "AA",
+ "String.fromCharCode(1024*64+65, -1024*64+65) = " + String.fromCharCode(1024*64+65, -1024*64+65));
+ok(String.fromCharCode(65, NaN, undefined).length === 3,
+ "String.fromCharCode(65, NaN, undefined).length = " + String.fromCharCode(65, NaN, undefined).length);
+
var arr = new Array();
ok(typeof(arr) === "object", "arr () is not object");
ok((arr.length === 0), "arr.length is not 0");
More information about the wine-cvs
mailing list