Jacek Caban : jscript: Added String.charCodeAt implementation.

Alexandre Julliard julliard at winehq.org
Mon Sep 22 07:04:21 CDT 2008


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Sun Sep 21 15:42:23 2008 +0200

jscript: Added String.charCodeAt implementation.

---

 dlls/jscript/string.c     |   39 +++++++++++++++++++++++++++++++++++++--
 dlls/jscript/tests/api.js |   13 +++++++++++++
 2 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/dlls/jscript/string.c b/dlls/jscript/string.c
index e690477..d6a7a71 100644
--- a/dlls/jscript/string.c
+++ b/dlls/jscript/string.c
@@ -199,11 +199,46 @@ static HRESULT String_charAt(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARA
     return S_OK;
 }
 
+/* ECMA-262 3rd Edition    15.5.4.5 */
 static HRESULT String_charCodeAt(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
 {
-    FIXME("\n");
-    return E_NOTIMPL;
+    const WCHAR *str;
+    DWORD length, idx = 0;
+    HRESULT hres;
+
+    TRACE("\n");
+
+    if(dispex->builtin_info->class == JSCLASS_STRING) {
+        StringInstance *string = (StringInstance*)dispex;
+
+        str = string->str;
+        length = string->length;
+    }else {
+        FIXME("not string this not supported\n");
+        return E_NOTIMPL;
+    }
+
+    if(arg_cnt(dp) > 0) {
+        VARIANT v;
+
+        hres = to_integer(dispex->ctx, get_arg(dp, 0), ei, &v);
+        if(FAILED(hres))
+            return hres;
+
+        if(V_VT(&v) != VT_I4 || V_I4(&v) < 0 || V_I4(&v) >= length) {
+            FIXME("NAN\n");
+            return E_FAIL;
+        }
+
+        idx = V_I4(&v);
+    }
+
+    if(retv) {
+        V_VT(retv) = VT_I4;
+        V_I4(retv) = str[idx];
+    }
+    return S_OK;
 }
 
 static HRESULT String_concat(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js
index b220bdb..f8b6607 100644
--- a/dlls/jscript/tests/api.js
+++ b/dlls/jscript/tests/api.js
@@ -57,6 +57,19 @@ ok(tmp === "", "'abc',charAt(-1) = " + tmp);
 tmp = "abc".charAt(0,2);
 ok(tmp === "a", "'abc',charAt(0.2) = " + tmp);
 
+tmp = "abc".charCodeAt(0);
+ok(tmp === 0x61, "'abc'.charCodeAt(0) = " + tmp);
+tmp = "abc".charCodeAt(1);
+ok(tmp === 0x62, "'abc'.charCodeAt(1) = " + tmp);
+tmp = "abc".charCodeAt(2);
+ok(tmp === 0x63, "'abc'.charCodeAt(2) = " + tmp);
+tmp = "abc".charCodeAt();
+ok(tmp === 0x61, "'abc'.charCodeAt() = " + tmp);
+tmp = "abc".charCodeAt(true);
+ok(tmp === 0x62, "'abc'.charCodeAt(true) = " + tmp);
+tmp = "abc".charCodeAt(0,2);
+ok(tmp === 0x61, "'abc'.charCodeAt(0,2) = " + tmp);
+
 tmp = "abcd".substring(1,3);
 ok(tmp === "bc", "'abcd'.substring(1,3) = " + tmp);
 tmp = "abcd".substring(-1,3);




More information about the wine-cvs mailing list