Jacek Caban : jscript: Added string to object conversion implementation.
Alexandre Julliard
julliard at winehq.org
Tue Sep 16 06:54:23 CDT 2008
Module: wine
Branch: master
Commit: 9a752be1a799563e0790d2203917434c6d5ecea1
URL: http://source.winehq.org/git/wine.git/?a=commit;h=9a752be1a799563e0790d2203917434c6d5ecea1
Author: Jacek Caban <jacek at codeweavers.com>
Date: Mon Sep 15 20:40:34 2008 +0200
jscript: Added string to object conversion implementation.
---
dlls/jscript/jscript.h | 1 +
dlls/jscript/jsutils.c | 11 +++++++++++
dlls/jscript/string.c | 43 ++++++++++++++++++++++++++++++++++++++-----
dlls/jscript/tests/lang.js | 3 +++
4 files changed, 53 insertions(+), 5 deletions(-)
diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h
index 8e6fe3c..c4e61d6 100644
--- a/dlls/jscript/jscript.h
+++ b/dlls/jscript/jscript.h
@@ -133,6 +133,7 @@ HRESULT create_object(script_ctx_t*,DispatchEx*,DispatchEx**);
HRESULT create_math(script_ctx_t*,DispatchEx**);
HRESULT create_array(script_ctx_t*,DWORD,DispatchEx**);
HRESULT create_regexp_str(script_ctx_t*,const WCHAR*,DWORD,const WCHAR*,DWORD,DispatchEx**);
+HRESULT create_string(script_ctx_t*,const WCHAR*,DWORD,DispatchEx**);
HRESULT to_primitive(script_ctx_t*,VARIANT*,jsexcept_t*,VARIANT*);
HRESULT to_boolean(VARIANT*,VARIANT_BOOL*);
diff --git a/dlls/jscript/jsutils.c b/dlls/jscript/jsutils.c
index ae39218..2b0c31e 100644
--- a/dlls/jscript/jsutils.c
+++ b/dlls/jscript/jsutils.c
@@ -17,6 +17,7 @@
*/
#include "jscript.h"
+#include "engine.h"
#include "wine/debug.h"
@@ -248,7 +249,17 @@ HRESULT to_string(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, BSTR *str)
/* ECMA-262 3rd Edition 9.9 */
HRESULT to_object(exec_ctx_t *ctx, VARIANT *v, IDispatch **disp)
{
+ DispatchEx *dispex;
+ HRESULT hres;
+
switch(V_VT(v)) {
+ case VT_BSTR:
+ hres = create_string(ctx->parser->script, V_BSTR(v), SysStringLen(V_BSTR(v)), &dispex);
+ if(FAILED(hres))
+ return hres;
+
+ *disp = (IDispatch*)_IDispatchEx_(dispex);
+ break;
case VT_DISPATCH:
IDispatch_AddRef(V_DISPATCH(v));
*disp = V_DISPATCH(v);
diff --git a/dlls/jscript/string.c b/dlls/jscript/string.c
index 26623ca..033e906 100644
--- a/dlls/jscript/string.c
+++ b/dlls/jscript/string.c
@@ -24,6 +24,9 @@ WINE_DEFAULT_DEBUG_CHANNEL(jscript);
typedef struct {
DispatchEx dispex;
+
+ WCHAR *str;
+ DWORD length;
} StringInstance;
static const WCHAR lengthW[] = {'l','e','n','g','t','h',0};
@@ -64,11 +67,6 @@ 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 void String_destructor(DispatchEx *dispex)
-{
- FIXME("\n");
-}
-
static HRESULT String_length(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
@@ -328,6 +326,14 @@ static HRESULT String_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM
return E_NOTIMPL;
}
+static void String_destructor(DispatchEx *dispex)
+{
+ StringInstance *This = (StringInstance*)dispex;
+
+ heap_free(This->str);
+ heap_free(This);
+}
+
static const builtin_prop_t String_props[] = {
{anchorW, String_anchor, PROPF_METHOD},
{bigW, String_big, PROPF_METHOD},
@@ -419,3 +425,30 @@ HRESULT create_string_constr(script_ctx_t *ctx, DispatchEx **ret)
jsdisp_release(&string->dispex);
return hres;
}
+
+HRESULT create_string(script_ctx_t *ctx, const WCHAR *str, DWORD len, DispatchEx **ret)
+{
+ StringInstance *string;
+ HRESULT hres;
+
+ hres = string_alloc(ctx, TRUE, &string);
+ if(FAILED(hres))
+ return hres;
+
+ if(len == -1)
+ len = strlenW(str);
+
+ string->length = len;
+ string->str = heap_alloc((len+1)*sizeof(WCHAR));
+ if(!string->str) {
+ jsdisp_release(&string->dispex);
+ return E_OUTOFMEMORY;
+ }
+
+ memcpy(string->str, str, len*sizeof(WCHAR));
+ string->str[len] = 0;
+
+ *ret = &string->dispex;
+ return S_OK;
+
+}
diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js
index fef8403..7a4e4cd 100644
--- a/dlls/jscript/tests/lang.js
+++ b/dlls/jscript/tests/lang.js
@@ -233,4 +233,7 @@ ok(tmp === 2, "incremented tmp(1) is not 2");
ok(tmp-- === 2, "tmp-- (2) is not 2");
ok(tmp === 1, "decremented tmp is not 1");
+String.prototype.test = true;
+ok("".test === true, "\"\",test is not true");
+
reportSuccess();
More information about the wine-cvs
mailing list