jscript: Added string to object conversion implementation.

This commit is contained in:
Jacek Caban 2008-09-15 20:40:34 +02:00 committed by Alexandre Julliard
parent 5670ca52ae
commit 9a752be1a7
4 changed files with 53 additions and 5 deletions

View File

@ -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*);

View File

@ -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);

View File

@ -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;
}

View File

@ -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();