2008-09-10 00:33:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2008 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
|
|
|
|
*/
|
|
|
|
|
2012-05-29 10:54:11 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2008-09-10 00:33:37 +00:00
|
|
|
#include "jscript.h"
|
2013-02-19 09:12:27 +00:00
|
|
|
#include "regexp.h"
|
2008-09-10 00:33:37 +00:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(jscript);
|
|
|
|
|
|
|
|
typedef struct {
|
2010-09-06 14:11:49 +00:00
|
|
|
jsdisp_t dispex;
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_t *str;
|
2008-09-10 00:33:37 +00:00
|
|
|
} StringInstance;
|
|
|
|
|
|
|
|
static const WCHAR lengthW[] = {'l','e','n','g','t','h',0};
|
|
|
|
static const WCHAR toStringW[] = {'t','o','S','t','r','i','n','g',0};
|
|
|
|
static const WCHAR valueOfW[] = {'v','a','l','u','e','O','f',0};
|
|
|
|
static const WCHAR anchorW[] = {'a','n','c','h','o','r',0};
|
|
|
|
static const WCHAR bigW[] = {'b','i','g',0};
|
|
|
|
static const WCHAR blinkW[] = {'b','l','i','n','k',0};
|
|
|
|
static const WCHAR boldW[] = {'b','o','l','d',0};
|
|
|
|
static const WCHAR charAtW[] = {'c','h','a','r','A','t',0};
|
|
|
|
static const WCHAR charCodeAtW[] = {'c','h','a','r','C','o','d','e','A','t',0};
|
|
|
|
static const WCHAR concatW[] = {'c','o','n','c','a','t',0};
|
|
|
|
static const WCHAR fixedW[] = {'f','i','x','e','d',0};
|
|
|
|
static const WCHAR fontcolorW[] = {'f','o','n','t','c','o','l','o','r',0};
|
|
|
|
static const WCHAR fontsizeW[] = {'f','o','n','t','s','i','z','e',0};
|
|
|
|
static const WCHAR indexOfW[] = {'i','n','d','e','x','O','f',0};
|
|
|
|
static const WCHAR italicsW[] = {'i','t','a','l','i','c','s',0};
|
|
|
|
static const WCHAR lastIndexOfW[] = {'l','a','s','t','I','n','d','e','x','O','f',0};
|
|
|
|
static const WCHAR linkW[] = {'l','i','n','k',0};
|
|
|
|
static const WCHAR matchW[] = {'m','a','t','c','h',0};
|
|
|
|
static const WCHAR replaceW[] = {'r','e','p','l','a','c','e',0};
|
|
|
|
static const WCHAR searchW[] = {'s','e','a','r','c','h',0};
|
|
|
|
static const WCHAR sliceW[] = {'s','l','i','c','e',0};
|
|
|
|
static const WCHAR smallW[] = {'s','m','a','l','l',0};
|
|
|
|
static const WCHAR splitW[] = {'s','p','l','i','t',0};
|
|
|
|
static const WCHAR strikeW[] = {'s','t','r','i','k','e',0};
|
|
|
|
static const WCHAR subW[] = {'s','u','b',0};
|
|
|
|
static const WCHAR substringW[] = {'s','u','b','s','t','r','i','n','g',0};
|
|
|
|
static const WCHAR substrW[] = {'s','u','b','s','t','r',0};
|
|
|
|
static const WCHAR supW[] = {'s','u','p',0};
|
|
|
|
static const WCHAR toLowerCaseW[] = {'t','o','L','o','w','e','r','C','a','s','e',0};
|
|
|
|
static const WCHAR toUpperCaseW[] = {'t','o','U','p','p','e','r','C','a','s','e',0};
|
|
|
|
static const WCHAR toLocaleLowerCaseW[] = {'t','o','L','o','c','a','l','e','L','o','w','e','r','C','a','s','e',0};
|
|
|
|
static const WCHAR toLocaleUpperCaseW[] = {'t','o','L','o','c','a','l','e','U','p','p','e','r','C','a','s','e',0};
|
|
|
|
static const WCHAR localeCompareW[] = {'l','o','c','a','l','e','C','o','m','p','a','r','e',0};
|
2009-07-13 23:36:58 +00:00
|
|
|
static const WCHAR fromCharCodeW[] = {'f','r','o','m','C','h','a','r','C','o','d','e',0};
|
2008-09-10 00:33:37 +00:00
|
|
|
|
2015-02-06 11:09:40 +00:00
|
|
|
static inline StringInstance *string_from_jsdisp(jsdisp_t *jsdisp)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(jsdisp, StringInstance, dispex);
|
|
|
|
}
|
|
|
|
|
2009-09-23 14:18:39 +00:00
|
|
|
static inline StringInstance *string_from_vdisp(vdisp_t *vdisp)
|
|
|
|
{
|
2015-02-06 11:09:40 +00:00
|
|
|
return string_from_jsdisp(vdisp->u.jsdisp);
|
2009-09-23 14:18:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline StringInstance *string_this(vdisp_t *jsthis)
|
|
|
|
{
|
|
|
|
return is_vclass(jsthis, JSCLASS_STRING) ? string_from_vdisp(jsthis) : NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
static HRESULT get_string_val(script_ctx_t *ctx, vdisp_t *jsthis, jsstr_t **val)
|
2009-09-23 14:18:39 +00:00
|
|
|
{
|
|
|
|
StringInstance *string;
|
|
|
|
|
|
|
|
if((string = string_this(jsthis))) {
|
2012-10-11 10:16:01 +00:00
|
|
|
*val = jsstr_addref(string->str);
|
2009-09-23 14:18:39 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
return to_string(ctx, jsval_disp(jsthis->u.disp), val);
|
2009-09-23 14:18:39 +00:00
|
|
|
}
|
|
|
|
|
2013-03-28 10:02:25 +00:00
|
|
|
static HRESULT get_string_flat_val(script_ctx_t *ctx, vdisp_t *jsthis, jsstr_t **jsval, const WCHAR **val)
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = get_string_val(ctx, jsthis, jsval);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
*val = jsstr_flatten(*jsval);
|
|
|
|
if(*val)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
jsstr_release(*jsval);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2015-02-06 11:09:40 +00:00
|
|
|
static HRESULT String_get_length(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2015-02-06 11:09:40 +00:00
|
|
|
StringInstance *string = (StringInstance*)jsthis;
|
2008-09-17 21:35:12 +00:00
|
|
|
|
2015-02-05 13:49:01 +00:00
|
|
|
TRACE("%p\n", jsthis);
|
2008-09-17 21:35:12 +00:00
|
|
|
|
2015-02-05 13:49:01 +00:00
|
|
|
*r = jsval_number(jsstr_length(string->str));
|
2008-09-17 21:35:12 +00:00
|
|
|
return S_OK;
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2015-02-06 11:09:47 +00:00
|
|
|
static HRESULT String_set_length(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t value)
|
2015-02-05 13:49:01 +00:00
|
|
|
{
|
|
|
|
FIXME("%p\n", jsthis);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:20 +00:00
|
|
|
static HRESULT stringobj_to_string(vdisp_t *jsthis, jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2008-09-21 13:41:25 +00:00
|
|
|
StringInstance *string;
|
|
|
|
|
2009-09-23 14:18:39 +00:00
|
|
|
if(!(string = string_this(jsthis))) {
|
2008-09-21 13:41:25 +00:00
|
|
|
WARN("this is not a string object\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
if(r)
|
|
|
|
*r = jsval_string(jsstr_addref(string->str));
|
2008-09-21 13:41:25 +00:00
|
|
|
return S_OK;
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2009-09-23 14:14:25 +00:00
|
|
|
/* ECMA-262 3rd Edition 15.5.4.2 */
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2009-09-23 14:14:25 +00:00
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
|
2012-09-17 13:16:20 +00:00
|
|
|
return stringobj_to_string(jsthis, r);
|
2009-09-23 14:14:25 +00:00
|
|
|
}
|
|
|
|
|
2008-09-21 13:41:42 +00:00
|
|
|
/* ECMA-262 3rd Edition 15.5.4.2 */
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_valueOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2008-09-21 13:41:42 +00:00
|
|
|
TRACE("\n");
|
|
|
|
|
2012-09-17 13:16:20 +00:00
|
|
|
return stringobj_to_string(jsthis, r);
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2012-09-18 17:01:49 +00:00
|
|
|
static HRESULT do_attributeless_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, jsval_t *r, const WCHAR *tagname)
|
2008-11-30 12:40:01 +00:00
|
|
|
{
|
2013-03-06 11:39:27 +00:00
|
|
|
unsigned tagname_len;
|
|
|
|
jsstr_t *str, *ret;
|
|
|
|
WCHAR *ptr;
|
2009-07-12 17:50:22 +00:00
|
|
|
HRESULT hres;
|
2008-11-30 12:40:01 +00:00
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
hres = get_string_val(ctx, jsthis, &str);
|
2009-09-23 14:18:39 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2008-11-30 12:40:01 +00:00
|
|
|
|
2013-03-06 11:39:27 +00:00
|
|
|
if(!r) {
|
|
|
|
jsstr_release(str);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
tagname_len = strlenW(tagname);
|
2008-11-30 12:40:01 +00:00
|
|
|
|
2013-03-25 11:28:38 +00:00
|
|
|
ptr = jsstr_alloc_buf(jsstr_length(str) + 2*tagname_len + 5, &ret);
|
2013-03-06 11:39:27 +00:00
|
|
|
if(!ret) {
|
|
|
|
jsstr_release(str);
|
|
|
|
return E_OUTOFMEMORY;
|
2008-11-30 12:40:01 +00:00
|
|
|
}
|
2009-07-12 17:50:22 +00:00
|
|
|
|
2013-03-06 11:39:27 +00:00
|
|
|
*ptr++ = '<';
|
|
|
|
memcpy(ptr, tagname, tagname_len*sizeof(WCHAR));
|
|
|
|
ptr += tagname_len;
|
|
|
|
*ptr++ = '>';
|
|
|
|
|
|
|
|
ptr += jsstr_flush(str, ptr);
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(str);
|
2013-03-06 11:39:27 +00:00
|
|
|
|
|
|
|
*ptr++ = '<';
|
|
|
|
*ptr++ = '/';
|
|
|
|
memcpy(ptr, tagname, tagname_len*sizeof(WCHAR));
|
|
|
|
ptr += tagname_len;
|
|
|
|
*ptr = '>';
|
|
|
|
|
|
|
|
*r = jsval_string(ret);
|
2008-11-30 12:40:01 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT do_attribute_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, unsigned argc, jsval_t *argv, jsval_t *r,
|
2013-03-06 11:39:38 +00:00
|
|
|
const WCHAR *tagname, const WCHAR *attrname)
|
2009-07-09 20:41:27 +00:00
|
|
|
{
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_t *str, *attr_value = NULL;
|
2009-07-09 20:41:27 +00:00
|
|
|
HRESULT hres;
|
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
hres = get_string_val(ctx, jsthis, &str);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2009-07-09 20:41:27 +00:00
|
|
|
|
2012-06-25 12:08:38 +00:00
|
|
|
if(argc) {
|
2012-09-18 17:01:49 +00:00
|
|
|
hres = to_string(ctx, argv[0], &attr_value);
|
2009-07-12 20:05:00 +00:00
|
|
|
if(FAILED(hres)) {
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(str);
|
2009-07-09 20:41:27 +00:00
|
|
|
return hres;
|
2009-07-12 20:05:00 +00:00
|
|
|
}
|
2012-10-11 10:16:01 +00:00
|
|
|
}else {
|
2013-03-08 10:37:56 +00:00
|
|
|
attr_value = jsstr_undefined();
|
2009-07-09 20:41:27 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:20 +00:00
|
|
|
if(r) {
|
2013-03-06 11:39:38 +00:00
|
|
|
unsigned attrname_len = strlenW(attrname);
|
|
|
|
unsigned tagname_len = strlenW(tagname);
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_t *ret;
|
2013-03-25 11:28:38 +00:00
|
|
|
WCHAR *ptr;
|
2009-07-09 20:41:27 +00:00
|
|
|
|
2013-03-25 11:28:38 +00:00
|
|
|
ptr = jsstr_alloc_buf(2*tagname_len + attrname_len + jsstr_length(attr_value) + jsstr_length(str) + 9, &ret);
|
|
|
|
if(ptr) {
|
2013-03-06 11:39:38 +00:00
|
|
|
*ptr++ = '<';
|
|
|
|
memcpy(ptr, tagname, tagname_len*sizeof(WCHAR));
|
|
|
|
ptr += tagname_len;
|
|
|
|
*ptr++ = ' ';
|
|
|
|
memcpy(ptr, attrname, attrname_len*sizeof(WCHAR));
|
|
|
|
ptr += attrname_len;
|
|
|
|
*ptr++ = '=';
|
|
|
|
*ptr++ = '"';
|
2013-03-08 10:37:56 +00:00
|
|
|
ptr += jsstr_flush(attr_value, ptr);
|
2013-03-06 11:39:38 +00:00
|
|
|
*ptr++ = '"';
|
|
|
|
*ptr++ = '>';
|
|
|
|
ptr += jsstr_flush(str, ptr);
|
|
|
|
|
|
|
|
*ptr++ = '<';
|
|
|
|
*ptr++ = '/';
|
|
|
|
memcpy(ptr, tagname, tagname_len*sizeof(WCHAR));
|
|
|
|
ptr += tagname_len;
|
|
|
|
*ptr = '>';
|
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
*r = jsval_string(ret);
|
|
|
|
}else {
|
|
|
|
hres = E_OUTOFMEMORY;
|
|
|
|
}
|
2009-07-09 20:41:27 +00:00
|
|
|
}
|
|
|
|
|
2013-03-08 10:37:56 +00:00
|
|
|
jsstr_release(attr_value);
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(str);
|
|
|
|
return hres;
|
2009-07-09 20:41:27 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_anchor(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2009-07-09 18:09:20 +00:00
|
|
|
static const WCHAR fontW[] = {'A',0};
|
|
|
|
static const WCHAR colorW[] = {'N','A','M','E',0};
|
|
|
|
|
2012-09-18 17:01:49 +00:00
|
|
|
return do_attribute_tag_format(ctx, jsthis, argc, argv, r, fontW, colorW);
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_big(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2008-11-30 12:40:01 +00:00
|
|
|
static const WCHAR bigtagW[] = {'B','I','G',0};
|
2012-09-18 17:01:49 +00:00
|
|
|
return do_attributeless_tag_format(ctx, jsthis, r, bigtagW);
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_blink(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2008-11-30 12:40:08 +00:00
|
|
|
static const WCHAR blinktagW[] = {'B','L','I','N','K',0};
|
2012-09-18 17:01:49 +00:00
|
|
|
return do_attributeless_tag_format(ctx, jsthis, r, blinktagW);
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_bold(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2008-11-30 12:40:15 +00:00
|
|
|
static const WCHAR boldtagW[] = {'B',0};
|
2012-09-18 17:01:49 +00:00
|
|
|
return do_attributeless_tag_format(ctx, jsthis, r, boldtagW);
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2008-09-18 22:43:03 +00:00
|
|
|
/* ECMA-262 3rd Edition 15.5.4.5 */
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_charAt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_t *str, *ret;
|
2008-09-18 22:43:03 +00:00
|
|
|
INT pos = 0;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
hres = get_string_val(ctx, jsthis, &str);
|
2009-09-23 14:18:39 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2008-09-18 22:43:03 +00:00
|
|
|
|
2012-06-25 12:08:38 +00:00
|
|
|
if(argc) {
|
2012-05-03 08:40:13 +00:00
|
|
|
double d;
|
2008-09-18 22:43:03 +00:00
|
|
|
|
2012-09-18 17:01:49 +00:00
|
|
|
hres = to_integer(ctx, argv[0], &d);
|
2009-07-12 17:50:50 +00:00
|
|
|
if(FAILED(hres)) {
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(str);
|
2008-09-18 22:43:03 +00:00
|
|
|
return hres;
|
2009-07-12 17:50:50 +00:00
|
|
|
}
|
2012-05-03 08:40:13 +00:00
|
|
|
pos = is_int32(d) ? d : -1;
|
2008-09-18 22:43:03 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:20 +00:00
|
|
|
if(!r) {
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(str);
|
2008-09-18 22:43:03 +00:00
|
|
|
return S_OK;
|
2009-07-12 17:50:50 +00:00
|
|
|
}
|
2008-09-18 22:43:03 +00:00
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
if(0 <= pos && pos < jsstr_length(str)) {
|
2013-03-04 09:57:14 +00:00
|
|
|
ret = jsstr_substr(str, pos, 1);
|
2012-10-11 10:16:01 +00:00
|
|
|
if(!ret)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}else {
|
|
|
|
ret = jsstr_empty();
|
2009-07-12 17:50:50 +00:00
|
|
|
}
|
2008-09-18 22:43:03 +00:00
|
|
|
|
2012-09-17 13:16:20 +00:00
|
|
|
*r = jsval_string(ret);
|
2008-09-18 22:43:03 +00:00
|
|
|
return S_OK;
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2008-09-21 13:42:23 +00:00
|
|
|
/* ECMA-262 3rd Edition 15.5.4.5 */
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_charCodeAt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_t *str;
|
|
|
|
DWORD idx = 0;
|
2008-09-21 13:42:23 +00:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
hres = get_string_val(ctx, jsthis, &str);
|
2009-09-23 14:18:39 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2008-09-21 13:42:23 +00:00
|
|
|
|
2012-06-25 12:08:38 +00:00
|
|
|
if(argc > 0) {
|
2012-05-03 08:40:27 +00:00
|
|
|
double d;
|
2008-09-21 13:42:23 +00:00
|
|
|
|
2012-09-18 17:01:49 +00:00
|
|
|
hres = to_integer(ctx, argv[0], &d);
|
2009-07-12 20:05:57 +00:00
|
|
|
if(FAILED(hres)) {
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(str);
|
2008-09-21 13:42:23 +00:00
|
|
|
return hres;
|
2009-07-12 20:05:57 +00:00
|
|
|
}
|
2008-09-21 13:42:23 +00:00
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
if(!is_int32(d) || d < 0 || d >= jsstr_length(str)) {
|
|
|
|
jsstr_release(str);
|
2012-09-17 13:16:20 +00:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(NAN);
|
2009-06-03 19:11:20 +00:00
|
|
|
return S_OK;
|
2008-09-21 13:42:23 +00:00
|
|
|
}
|
|
|
|
|
2012-05-03 08:40:27 +00:00
|
|
|
idx = d;
|
2008-09-21 13:42:23 +00:00
|
|
|
}
|
|
|
|
|
2013-03-28 10:01:52 +00:00
|
|
|
if(r) {
|
|
|
|
WCHAR c;
|
|
|
|
jsstr_extract(str, idx, 1, &c);
|
|
|
|
*r = jsval_number(c);
|
|
|
|
}
|
2009-07-12 20:05:57 +00:00
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(str);
|
2008-09-21 13:42:23 +00:00
|
|
|
return S_OK;
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2008-09-21 13:44:13 +00:00
|
|
|
/* ECMA-262 3rd Edition 15.5.4.6 */
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_concat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2013-04-25 13:23:48 +00:00
|
|
|
jsstr_t *ret, *str;
|
2008-09-21 13:44:13 +00:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2013-04-25 13:23:48 +00:00
|
|
|
hres = get_string_val(ctx, jsthis, &str);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
switch(argc) {
|
|
|
|
case 0:
|
|
|
|
ret = str;
|
|
|
|
break;
|
|
|
|
case 1: {
|
|
|
|
jsstr_t *arg_str;
|
|
|
|
|
|
|
|
hres = to_string(ctx, argv[0], &arg_str);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
jsstr_release(str);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = jsstr_concat(str, arg_str);
|
|
|
|
jsstr_release(str);
|
|
|
|
if(!ret)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
const unsigned str_cnt = argc+1;
|
|
|
|
unsigned len = 0, i;
|
|
|
|
jsstr_t **strs;
|
|
|
|
WCHAR *ptr;
|
2008-09-21 13:44:13 +00:00
|
|
|
|
2013-04-25 13:23:48 +00:00
|
|
|
strs = heap_alloc_zero(str_cnt * sizeof(*strs));
|
|
|
|
if(!strs) {
|
|
|
|
jsstr_release(str);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
strs[0] = str;
|
2012-06-25 12:08:38 +00:00
|
|
|
for(i=0; i < argc; i++) {
|
2012-09-18 17:01:49 +00:00
|
|
|
hres = to_string(ctx, argv[i], strs+i+1);
|
2008-09-21 13:44:13 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-04-25 13:23:48 +00:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
for(i=0; i < str_cnt; i++) {
|
|
|
|
len += jsstr_length(strs[i]);
|
|
|
|
if(len > JSSTR_MAX_LENGTH) {
|
|
|
|
hres = E_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
}
|
2012-10-11 10:16:01 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 13:23:48 +00:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
ptr = jsstr_alloc_buf(len, &ret);
|
|
|
|
if(ptr) {
|
|
|
|
for(i=0; i < str_cnt; i++)
|
|
|
|
ptr += jsstr_flush(strs[i], ptr);
|
|
|
|
}else {
|
|
|
|
hres = E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
}
|
2008-09-21 13:44:13 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 13:23:48 +00:00
|
|
|
while(i--)
|
|
|
|
jsstr_release(strs[i]);
|
|
|
|
heap_free(strs);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
}
|
2008-09-21 13:44:13 +00:00
|
|
|
|
2012-09-17 13:16:20 +00:00
|
|
|
if(r)
|
|
|
|
*r = jsval_string(ret);
|
|
|
|
else
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(ret);
|
2008-09-21 13:44:13 +00:00
|
|
|
return S_OK;
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_fixed(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2008-11-30 12:40:22 +00:00
|
|
|
static const WCHAR fixedtagW[] = {'T','T',0};
|
2012-09-18 17:01:49 +00:00
|
|
|
return do_attributeless_tag_format(ctx, jsthis, r, fixedtagW);
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_fontcolor(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2009-07-09 20:41:27 +00:00
|
|
|
static const WCHAR fontW[] = {'F','O','N','T',0};
|
|
|
|
static const WCHAR colorW[] = {'C','O','L','O','R',0};
|
|
|
|
|
2012-09-18 17:01:49 +00:00
|
|
|
return do_attribute_tag_format(ctx, jsthis, argc, argv, r, fontW, colorW);
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_fontsize(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2009-07-09 18:09:10 +00:00
|
|
|
static const WCHAR fontW[] = {'F','O','N','T',0};
|
|
|
|
static const WCHAR colorW[] = {'S','I','Z','E',0};
|
|
|
|
|
2012-09-18 17:01:49 +00:00
|
|
|
return do_attribute_tag_format(ctx, jsthis, argc, argv, r, fontW, colorW);
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_indexOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2013-03-28 10:02:25 +00:00
|
|
|
jsstr_t *search_jsstr, *jsstr;
|
|
|
|
const WCHAR *search_str, *str;
|
2012-10-11 10:16:01 +00:00
|
|
|
int length, pos = 0;
|
2008-10-06 14:57:03 +00:00
|
|
|
INT ret = -1;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2013-03-28 10:02:25 +00:00
|
|
|
hres = get_string_flat_val(ctx, jsthis, &jsstr, &str);
|
2009-09-23 14:18:39 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2008-10-06 14:57:03 +00:00
|
|
|
|
2013-03-28 10:02:25 +00:00
|
|
|
length = jsstr_length(jsstr);
|
2012-06-25 12:08:38 +00:00
|
|
|
if(!argc) {
|
2012-09-17 13:16:20 +00:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(-1);
|
2013-03-28 10:02:25 +00:00
|
|
|
jsstr_release(jsstr);
|
2008-10-06 14:57:03 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2013-03-28 10:02:25 +00:00
|
|
|
hres = to_flat_string(ctx, argv[0], &search_jsstr, &search_str);
|
2009-07-12 17:51:08 +00:00
|
|
|
if(FAILED(hres)) {
|
2013-03-28 10:02:25 +00:00
|
|
|
jsstr_release(jsstr);
|
2008-10-06 14:57:03 +00:00
|
|
|
return hres;
|
2009-07-12 17:51:08 +00:00
|
|
|
}
|
2008-10-06 14:57:03 +00:00
|
|
|
|
2012-06-25 12:08:38 +00:00
|
|
|
if(argc >= 2) {
|
2012-05-03 08:40:45 +00:00
|
|
|
double d;
|
2008-10-06 14:57:03 +00:00
|
|
|
|
2012-09-18 17:01:49 +00:00
|
|
|
hres = to_integer(ctx, argv[1], &d);
|
2012-05-03 08:42:42 +00:00
|
|
|
if(SUCCEEDED(hres) && d > 0.0)
|
|
|
|
pos = is_int32(d) ? min(length, d) : length;
|
2008-10-06 14:57:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
const WCHAR *ptr;
|
|
|
|
|
2013-03-28 10:02:25 +00:00
|
|
|
ptr = strstrW(str+pos, search_str);
|
2008-10-06 14:57:03 +00:00
|
|
|
if(ptr)
|
2013-03-28 10:02:25 +00:00
|
|
|
ret = ptr - str;
|
2008-10-06 14:57:03 +00:00
|
|
|
else
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
2013-03-28 10:02:25 +00:00
|
|
|
jsstr_release(search_jsstr);
|
|
|
|
jsstr_release(jsstr);
|
2008-10-06 14:57:03 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 13:16:20 +00:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(ret);
|
2008-10-06 14:57:03 +00:00
|
|
|
return S_OK;
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_italics(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2008-11-30 12:40:30 +00:00
|
|
|
static const WCHAR italicstagW[] = {'I',0};
|
2012-09-18 17:01:49 +00:00
|
|
|
return do_attributeless_tag_format(ctx, jsthis, r, italicstagW);
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2009-09-01 11:27:08 +00:00
|
|
|
/* ECMA-262 3rd Edition 15.5.4.8 */
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_lastIndexOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2012-10-11 10:16:01 +00:00
|
|
|
unsigned pos = 0, search_len, length;
|
2013-03-28 10:02:25 +00:00
|
|
|
jsstr_t *search_jsstr, *jsstr;
|
|
|
|
const WCHAR *search_str, *str;
|
2009-09-01 11:27:08 +00:00
|
|
|
INT ret = -1;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2013-03-28 10:02:25 +00:00
|
|
|
hres = get_string_flat_val(ctx, jsthis, &jsstr, &str);
|
2009-09-23 14:18:39 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2009-09-01 11:27:08 +00:00
|
|
|
|
2012-06-25 12:08:38 +00:00
|
|
|
if(!argc) {
|
2012-09-17 13:16:20 +00:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(-1);
|
2013-03-28 10:02:25 +00:00
|
|
|
jsstr_release(jsstr);
|
2009-09-01 11:27:08 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2013-03-28 10:02:25 +00:00
|
|
|
hres = to_flat_string(ctx, argv[0], &search_jsstr, &search_str);
|
2009-09-01 11:27:08 +00:00
|
|
|
if(FAILED(hres)) {
|
2013-03-28 10:02:25 +00:00
|
|
|
jsstr_release(jsstr);
|
2009-09-01 11:27:08 +00:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2013-03-28 10:02:25 +00:00
|
|
|
search_len = jsstr_length(search_jsstr);
|
|
|
|
length = jsstr_length(jsstr);
|
2009-09-01 11:27:08 +00:00
|
|
|
|
2012-06-25 12:08:38 +00:00
|
|
|
if(argc >= 2) {
|
2012-05-03 08:40:57 +00:00
|
|
|
double d;
|
2009-09-01 11:27:08 +00:00
|
|
|
|
2012-09-18 17:01:49 +00:00
|
|
|
hres = to_integer(ctx, argv[1], &d);
|
2012-05-03 08:42:42 +00:00
|
|
|
if(SUCCEEDED(hres) && d > 0)
|
|
|
|
pos = is_int32(d) ? min(length, d) : length;
|
2009-09-01 11:27:08 +00:00
|
|
|
}else {
|
|
|
|
pos = length;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(SUCCEEDED(hres) && length >= search_len) {
|
|
|
|
const WCHAR *ptr;
|
|
|
|
|
2013-03-28 10:02:25 +00:00
|
|
|
for(ptr = str+min(pos, length-search_len); ptr >= str; ptr--) {
|
|
|
|
if(!memcmp(ptr, search_str, search_len*sizeof(WCHAR))) {
|
|
|
|
ret = ptr-str;
|
2009-09-01 11:27:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-28 10:02:25 +00:00
|
|
|
jsstr_release(search_jsstr);
|
|
|
|
jsstr_release(jsstr);
|
2009-09-01 11:27:08 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 13:16:20 +00:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(ret);
|
2009-09-01 11:27:08 +00:00
|
|
|
return S_OK;
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_link(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2009-07-09 18:09:32 +00:00
|
|
|
static const WCHAR fontW[] = {'A',0};
|
|
|
|
static const WCHAR colorW[] = {'H','R','E','F',0};
|
|
|
|
|
2012-09-18 17:01:49 +00:00
|
|
|
return do_attribute_tag_format(ctx, jsthis, argc, argv, r, fontW, colorW);
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2008-09-18 22:43:03 +00:00
|
|
|
/* ECMA-262 3rd Edition 15.5.4.10 */
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_match(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2012-09-17 13:16:42 +00:00
|
|
|
jsdisp_t *regexp = NULL;
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_t *str;
|
|
|
|
HRESULT hres;
|
2008-09-15 18:41:04 +00:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2012-06-25 12:08:38 +00:00
|
|
|
if(!argc) {
|
2012-09-17 13:16:20 +00:00
|
|
|
if(r)
|
|
|
|
*r = jsval_null();
|
2009-07-12 17:52:21 +00:00
|
|
|
return S_OK;
|
2008-09-15 18:41:04 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
if(is_object_instance(argv[0])) {
|
|
|
|
regexp = iface_to_jsdisp((IUnknown*)get_object(argv[0]));
|
|
|
|
if(regexp && !is_class(regexp, JSCLASS_REGEXP)) {
|
2008-09-15 18:41:04 +00:00
|
|
|
jsdisp_release(regexp);
|
2012-09-17 13:16:42 +00:00
|
|
|
regexp = NULL;
|
2008-09-15 18:41:04 +00:00
|
|
|
}
|
2012-09-17 13:16:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!regexp) {
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_t *match_str;
|
2008-09-24 22:53:53 +00:00
|
|
|
|
2012-09-18 17:01:49 +00:00
|
|
|
hres = to_string(ctx, argv[0], &match_str);
|
2008-09-24 22:53:53 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-10-11 10:16:50 +00:00
|
|
|
hres = create_regexp(ctx, match_str, 0, ®exp);
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(match_str);
|
2008-09-24 22:53:53 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2008-09-15 18:41:04 +00:00
|
|
|
}
|
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
hres = get_string_val(ctx, jsthis, &str);
|
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
hres = regexp_string_match(ctx, regexp, str, r);
|
2008-09-15 18:41:04 +00:00
|
|
|
|
2010-04-15 10:38:38 +00:00
|
|
|
jsdisp_release(regexp);
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(str);
|
2008-09-24 22:53:53 +00:00
|
|
|
return hres;
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2008-09-24 22:53:29 +00:00
|
|
|
typedef struct {
|
|
|
|
WCHAR *buf;
|
|
|
|
DWORD size;
|
|
|
|
DWORD len;
|
|
|
|
} strbuf_t;
|
|
|
|
|
2013-03-30 17:00:20 +00:00
|
|
|
static BOOL strbuf_ensure_size(strbuf_t *buf, unsigned len)
|
|
|
|
{
|
|
|
|
WCHAR *new_buf;
|
|
|
|
DWORD new_size;
|
|
|
|
|
|
|
|
if(len <= buf->size)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
new_size = buf->size ? buf->size<<1 : 16;
|
|
|
|
if(new_size < len)
|
|
|
|
new_size = len;
|
|
|
|
if(buf->buf)
|
|
|
|
new_buf = heap_realloc(buf->buf, new_size*sizeof(WCHAR));
|
|
|
|
else
|
|
|
|
new_buf = heap_alloc(new_size*sizeof(WCHAR));
|
|
|
|
if(!new_buf)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
buf->buf = new_buf;
|
|
|
|
buf->size = new_size;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-24 22:53:29 +00:00
|
|
|
static HRESULT strbuf_append(strbuf_t *buf, const WCHAR *str, DWORD len)
|
|
|
|
{
|
|
|
|
if(!len)
|
|
|
|
return S_OK;
|
|
|
|
|
2013-03-30 17:00:20 +00:00
|
|
|
if(!strbuf_ensure_size(buf, buf->len+len))
|
|
|
|
return E_OUTOFMEMORY;
|
2008-09-24 22:53:29 +00:00
|
|
|
|
|
|
|
memcpy(buf->buf+buf->len, str, len*sizeof(WCHAR));
|
|
|
|
buf->len += len;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2013-03-30 17:00:20 +00:00
|
|
|
static HRESULT strbuf_append_jsstr(strbuf_t *buf, jsstr_t *str)
|
|
|
|
{
|
|
|
|
if(!strbuf_ensure_size(buf, buf->len+jsstr_length(str)))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
jsstr_flush(str, buf->buf+buf->len);
|
|
|
|
buf->len += jsstr_length(str);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2013-02-19 09:12:27 +00:00
|
|
|
static HRESULT rep_call(script_ctx_t *ctx, jsdisp_t *func,
|
2013-03-30 17:00:20 +00:00
|
|
|
jsstr_t *jsstr, const WCHAR *str, match_state_t *match, jsstr_t **ret)
|
2008-09-24 22:53:29 +00:00
|
|
|
{
|
2012-09-17 13:16:42 +00:00
|
|
|
jsval_t *argv;
|
2012-06-25 12:08:38 +00:00
|
|
|
unsigned argc;
|
2012-09-17 13:16:20 +00:00
|
|
|
jsval_t val;
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_t *tmp_str;
|
2008-09-24 22:53:29 +00:00
|
|
|
DWORD i;
|
|
|
|
HRESULT hres = S_OK;
|
|
|
|
|
2013-02-19 09:12:27 +00:00
|
|
|
argc = match->paren_count+3;
|
2012-09-17 13:16:42 +00:00
|
|
|
argv = heap_alloc_zero(sizeof(*argv)*argc);
|
2012-06-25 12:08:38 +00:00
|
|
|
if(!argv)
|
2008-09-24 22:53:29 +00:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2013-02-19 09:12:27 +00:00
|
|
|
tmp_str = jsstr_alloc_len(match->cp-match->match_len, match->match_len);
|
2012-09-17 13:16:42 +00:00
|
|
|
if(!tmp_str)
|
2008-09-24 22:53:29 +00:00
|
|
|
hres = E_OUTOFMEMORY;
|
2012-09-17 13:16:42 +00:00
|
|
|
argv[0] = jsval_string(tmp_str);
|
2008-09-24 22:53:29 +00:00
|
|
|
|
|
|
|
if(SUCCEEDED(hres)) {
|
2013-02-19 09:12:27 +00:00
|
|
|
for(i=0; i < match->paren_count; i++) {
|
2013-03-04 09:57:14 +00:00
|
|
|
if(match->parens[i].index != -1)
|
2013-03-30 17:00:20 +00:00
|
|
|
tmp_str = jsstr_substr(jsstr, match->parens[i].index, match->parens[i].length);
|
2013-02-19 09:12:27 +00:00
|
|
|
else
|
2013-03-04 09:57:14 +00:00
|
|
|
tmp_str = jsstr_empty();
|
2012-09-17 13:16:42 +00:00
|
|
|
if(!tmp_str) {
|
2008-09-24 22:53:29 +00:00
|
|
|
hres = E_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
}
|
2012-09-17 13:16:42 +00:00
|
|
|
argv[i+1] = jsval_string(tmp_str);
|
2008-09-24 22:53:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(SUCCEEDED(hres)) {
|
2013-03-30 17:00:20 +00:00
|
|
|
argv[match->paren_count+1] = jsval_number(match->cp-str - match->match_len);
|
|
|
|
argv[match->paren_count+2] = jsval_string(jsstr);
|
2008-09-24 22:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(SUCCEEDED(hres))
|
2012-09-18 17:01:49 +00:00
|
|
|
hres = jsdisp_call_value(func, NULL, DISPATCH_METHOD, argc, argv, &val);
|
2008-09-24 22:53:29 +00:00
|
|
|
|
2013-02-19 09:12:27 +00:00
|
|
|
for(i=0; i <= match->paren_count; i++)
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(get_string(argv[i]));
|
2012-06-25 12:08:38 +00:00
|
|
|
heap_free(argv);
|
2008-09-24 22:53:29 +00:00
|
|
|
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-18 17:01:49 +00:00
|
|
|
hres = to_string(ctx, val, ret);
|
2012-09-17 13:16:20 +00:00
|
|
|
jsval_release(val);
|
2008-09-24 22:53:29 +00:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 15.5.4.11 */
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_replace(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2013-03-30 17:00:20 +00:00
|
|
|
const WCHAR *str, *match_str = NULL, *rep_str = NULL;
|
|
|
|
jsstr_t *rep_jsstr, *match_jsstr, *jsstr;
|
2010-09-06 14:11:49 +00:00
|
|
|
jsdisp_t *rep_func = NULL, *regexp = NULL;
|
2013-02-19 09:12:27 +00:00
|
|
|
match_state_t *match = NULL, last_match = {0};
|
2008-09-24 22:53:29 +00:00
|
|
|
strbuf_t ret = {NULL,0,0};
|
2013-02-19 09:12:27 +00:00
|
|
|
DWORD re_flags = REM_NO_CTX_UPDATE|REM_ALLOC_RESULT;
|
2013-03-30 17:00:20 +00:00
|
|
|
DWORD rep_len=0;
|
2008-09-24 22:53:29 +00:00
|
|
|
HRESULT hres = S_OK;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2013-03-30 17:00:20 +00:00
|
|
|
hres = get_string_flat_val(ctx, jsthis, &jsstr, &str);
|
2009-09-23 14:18:39 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2008-09-24 22:53:29 +00:00
|
|
|
|
2012-06-25 12:08:38 +00:00
|
|
|
if(!argc) {
|
2012-10-11 10:16:01 +00:00
|
|
|
if(r)
|
2013-03-30 17:00:20 +00:00
|
|
|
*r = jsval_string(jsstr);
|
2012-10-11 10:16:01 +00:00
|
|
|
else
|
2013-03-30 17:00:20 +00:00
|
|
|
jsstr_release(jsstr);
|
2008-09-24 22:53:29 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
if(is_object_instance(argv[0])) {
|
|
|
|
regexp = iface_to_jsdisp((IUnknown*)get_object(argv[0]));
|
|
|
|
if(regexp && !is_class(regexp, JSCLASS_REGEXP)) {
|
|
|
|
jsdisp_release(regexp);
|
|
|
|
regexp = NULL;
|
2008-09-24 22:53:29 +00:00
|
|
|
}
|
2012-09-17 13:16:42 +00:00
|
|
|
}
|
2008-09-24 22:53:29 +00:00
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
if(!regexp) {
|
2013-03-30 17:00:20 +00:00
|
|
|
hres = to_flat_string(ctx, argv[0], &match_jsstr, &match_str);
|
2009-07-12 17:51:28 +00:00
|
|
|
if(FAILED(hres)) {
|
2013-03-30 17:00:20 +00:00
|
|
|
jsstr_release(jsstr);
|
2008-09-24 22:53:29 +00:00
|
|
|
return hres;
|
2009-07-12 17:51:28 +00:00
|
|
|
}
|
2008-09-24 22:53:29 +00:00
|
|
|
}
|
|
|
|
|
2012-06-25 12:08:38 +00:00
|
|
|
if(argc >= 2) {
|
2012-09-17 13:16:42 +00:00
|
|
|
if(is_object_instance(argv[1])) {
|
|
|
|
rep_func = iface_to_jsdisp((IUnknown*)get_object(argv[1]));
|
|
|
|
if(rep_func && !is_class(rep_func, JSCLASS_FUNCTION)) {
|
|
|
|
jsdisp_release(rep_func);
|
|
|
|
rep_func = NULL;
|
2008-09-24 22:53:29 +00:00
|
|
|
}
|
2012-09-17 13:16:42 +00:00
|
|
|
}
|
2008-09-24 22:53:29 +00:00
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
if(!rep_func) {
|
2013-03-30 17:00:20 +00:00
|
|
|
hres = to_flat_string(ctx, argv[1], &rep_jsstr, &rep_str);
|
2013-02-19 09:12:27 +00:00
|
|
|
if(SUCCEEDED(hres))
|
2013-03-30 17:00:20 +00:00
|
|
|
rep_len = jsstr_length(rep_jsstr);
|
2008-09-24 22:53:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(SUCCEEDED(hres)) {
|
2013-03-30 17:00:20 +00:00
|
|
|
const WCHAR *ecp = str;
|
2008-09-24 22:53:29 +00:00
|
|
|
|
|
|
|
while(1) {
|
|
|
|
if(regexp) {
|
2013-03-30 17:00:20 +00:00
|
|
|
hres = regexp_match_next(ctx, regexp, re_flags, jsstr, &match);
|
2013-02-19 09:12:27 +00:00
|
|
|
re_flags = (re_flags | REM_CHECK_GLOBAL) & (~REM_ALLOC_RESULT);
|
2008-09-24 22:53:29 +00:00
|
|
|
|
|
|
|
if(hres == S_FALSE) {
|
|
|
|
hres = S_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
2012-04-18 11:50:19 +00:00
|
|
|
|
2013-02-19 09:12:27 +00:00
|
|
|
last_match.cp = match->cp;
|
|
|
|
last_match.match_len = match->match_len;
|
2008-09-24 22:53:29 +00:00
|
|
|
}else {
|
2013-02-19 09:12:27 +00:00
|
|
|
if(re_flags & REM_ALLOC_RESULT) {
|
|
|
|
re_flags &= ~REM_ALLOC_RESULT;
|
|
|
|
match = &last_match;
|
2013-03-30 17:00:20 +00:00
|
|
|
match->cp = str;
|
2013-02-19 09:12:27 +00:00
|
|
|
}
|
|
|
|
|
2013-03-30 17:00:20 +00:00
|
|
|
match->cp = strstrW(match->cp, match_str);
|
2013-02-19 09:12:27 +00:00
|
|
|
if(!match->cp)
|
2008-09-24 22:53:29 +00:00
|
|
|
break;
|
2013-03-30 17:00:20 +00:00
|
|
|
match->match_len = jsstr_length(match_jsstr);
|
2013-02-19 09:12:27 +00:00
|
|
|
match->cp += match->match_len;
|
2008-09-24 22:53:29 +00:00
|
|
|
}
|
|
|
|
|
2013-02-19 09:12:27 +00:00
|
|
|
hres = strbuf_append(&ret, ecp, match->cp-ecp-match->match_len);
|
|
|
|
ecp = match->cp;
|
2008-09-24 22:53:29 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if(rep_func) {
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_t *cstr;
|
2008-09-24 22:53:29 +00:00
|
|
|
|
2013-03-30 17:00:20 +00:00
|
|
|
hres = rep_call(ctx, rep_func, jsstr, str, match, &cstr);
|
2008-09-24 22:53:29 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
2013-03-30 17:00:20 +00:00
|
|
|
hres = strbuf_append_jsstr(&ret, cstr);
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(cstr);
|
2008-09-24 22:53:29 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
2009-08-11 12:06:52 +00:00
|
|
|
}else if(rep_str && regexp) {
|
2013-03-30 17:00:20 +00:00
|
|
|
const WCHAR *ptr = rep_str, *ptr2;
|
2009-08-11 12:06:52 +00:00
|
|
|
|
|
|
|
while((ptr2 = strchrW(ptr, '$'))) {
|
|
|
|
hres = strbuf_append(&ret, ptr, ptr2-ptr);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch(ptr2[1]) {
|
|
|
|
case '$':
|
|
|
|
hres = strbuf_append(&ret, ptr2, 1);
|
|
|
|
ptr = ptr2+2;
|
|
|
|
break;
|
|
|
|
case '&':
|
2013-02-19 09:12:27 +00:00
|
|
|
hres = strbuf_append(&ret, match->cp-match->match_len, match->match_len);
|
2009-08-11 12:06:52 +00:00
|
|
|
ptr = ptr2+2;
|
|
|
|
break;
|
|
|
|
case '`':
|
2013-03-30 17:00:20 +00:00
|
|
|
hres = strbuf_append(&ret, str, match->cp-str-match->match_len);
|
2009-08-11 12:06:52 +00:00
|
|
|
ptr = ptr2+2;
|
|
|
|
break;
|
|
|
|
case '\'':
|
2013-03-30 17:00:20 +00:00
|
|
|
hres = strbuf_append(&ret, ecp, (str+jsstr_length(jsstr))-ecp);
|
2009-08-11 12:06:52 +00:00
|
|
|
ptr = ptr2+2;
|
|
|
|
break;
|
|
|
|
default: {
|
|
|
|
DWORD idx;
|
|
|
|
|
|
|
|
if(!isdigitW(ptr2[1])) {
|
|
|
|
hres = strbuf_append(&ret, ptr2, 1);
|
|
|
|
ptr = ptr2+1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
idx = ptr2[1] - '0';
|
2013-02-19 09:12:27 +00:00
|
|
|
if(isdigitW(ptr2[2]) && idx*10 + (ptr2[2]-'0') <= match->paren_count) {
|
2009-08-11 12:06:52 +00:00
|
|
|
idx = idx*10 + (ptr[2]-'0');
|
|
|
|
ptr = ptr2+3;
|
2013-02-19 09:12:27 +00:00
|
|
|
}else if(idx && idx <= match->paren_count) {
|
2009-08-11 12:06:52 +00:00
|
|
|
ptr = ptr2+2;
|
|
|
|
}else {
|
|
|
|
hres = strbuf_append(&ret, ptr2, 1);
|
|
|
|
ptr = ptr2+1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-19 09:12:27 +00:00
|
|
|
if(match->parens[idx-1].index != -1)
|
2013-03-30 17:00:20 +00:00
|
|
|
hres = strbuf_append(&ret, str+match->parens[idx-1].index,
|
2013-02-19 09:12:27 +00:00
|
|
|
match->parens[idx-1].length);
|
2009-08-11 12:06:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(SUCCEEDED(hres))
|
2013-03-30 17:00:20 +00:00
|
|
|
hres = strbuf_append(&ret, ptr, (rep_str+rep_len)-ptr);
|
2009-08-11 12:06:52 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
2008-09-24 22:53:29 +00:00
|
|
|
}else if(rep_str) {
|
2013-03-30 17:00:20 +00:00
|
|
|
hres = strbuf_append(&ret, rep_str, rep_len);
|
2008-09-24 22:53:29 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
}else {
|
|
|
|
static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d'};
|
|
|
|
|
|
|
|
hres = strbuf_append(&ret, undefinedW, sizeof(undefinedW)/sizeof(WCHAR));
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
}
|
2012-04-09 12:02:35 +00:00
|
|
|
|
|
|
|
if(!regexp)
|
|
|
|
break;
|
2013-02-19 09:12:27 +00:00
|
|
|
else if(!match->match_len)
|
|
|
|
match->cp++;
|
2008-09-24 22:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(SUCCEEDED(hres))
|
2013-03-30 17:00:20 +00:00
|
|
|
hres = strbuf_append(&ret, ecp, str+jsstr_length(jsstr)-ecp);
|
2008-09-24 22:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(rep_func)
|
|
|
|
jsdisp_release(rep_func);
|
2012-10-11 10:16:01 +00:00
|
|
|
if(rep_str)
|
2013-03-30 17:00:20 +00:00
|
|
|
jsstr_release(rep_jsstr);
|
2012-10-11 10:16:01 +00:00
|
|
|
if(match_str)
|
2013-03-30 17:00:20 +00:00
|
|
|
jsstr_release(match_jsstr);
|
2013-02-19 09:12:27 +00:00
|
|
|
if(regexp)
|
|
|
|
heap_free(match);
|
2008-09-24 22:53:29 +00:00
|
|
|
|
2013-02-19 09:12:27 +00:00
|
|
|
if(SUCCEEDED(hres) && last_match.cp && regexp) {
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(ctx->last_match);
|
2013-03-30 17:00:20 +00:00
|
|
|
ctx->last_match = jsstr_addref(jsstr);
|
|
|
|
ctx->last_match_index = last_match.cp-str-last_match.match_len;
|
2013-02-19 09:12:27 +00:00
|
|
|
ctx->last_match_length = last_match.match_len;
|
2010-05-26 17:18:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(regexp)
|
|
|
|
jsdisp_release(regexp);
|
2013-03-30 17:00:20 +00:00
|
|
|
jsstr_release(jsstr);
|
2010-05-26 17:18:18 +00:00
|
|
|
|
2012-09-17 13:16:20 +00:00
|
|
|
if(SUCCEEDED(hres) && r) {
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_t *ret_str;
|
|
|
|
|
|
|
|
ret_str = jsstr_alloc_len(ret.buf, ret.len);
|
2008-09-24 22:53:29 +00:00
|
|
|
if(!ret_str)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
TRACE("= %s\n", debugstr_jsstr(ret_str));
|
2012-09-17 13:16:20 +00:00
|
|
|
*r = jsval_string(ret_str);
|
2008-09-24 22:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
heap_free(ret.buf);
|
|
|
|
return hres;
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_search(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2010-09-06 14:11:49 +00:00
|
|
|
jsdisp_t *regexp = NULL;
|
2013-03-30 17:00:20 +00:00
|
|
|
const WCHAR *str;
|
|
|
|
jsstr_t *jsstr;
|
2013-02-19 09:12:27 +00:00
|
|
|
match_state_t match, *match_ptr = &match;
|
2010-01-23 22:57:20 +00:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2013-03-30 17:00:20 +00:00
|
|
|
hres = get_string_flat_val(ctx, jsthis, &jsstr, &str);
|
2010-01-23 22:57:20 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-06-25 12:08:38 +00:00
|
|
|
if(!argc) {
|
2012-09-17 13:16:20 +00:00
|
|
|
if(r)
|
|
|
|
*r = jsval_null();
|
2013-03-30 17:00:20 +00:00
|
|
|
jsstr_release(jsstr);
|
2010-01-23 22:57:20 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
if(is_object_instance(argv[0])) {
|
|
|
|
regexp = iface_to_jsdisp((IUnknown*)get_object(argv[0]));
|
|
|
|
if(regexp && !is_class(regexp, JSCLASS_REGEXP)) {
|
|
|
|
jsdisp_release(regexp);
|
|
|
|
regexp = NULL;
|
2010-01-23 22:57:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!regexp) {
|
2012-09-17 13:16:42 +00:00
|
|
|
hres = create_regexp_var(ctx, argv[0], NULL, ®exp);
|
2010-01-23 22:57:20 +00:00
|
|
|
if(FAILED(hres)) {
|
2013-03-30 17:00:20 +00:00
|
|
|
jsstr_release(jsstr);
|
2010-01-23 22:57:20 +00:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-30 17:00:20 +00:00
|
|
|
match.cp = str;
|
|
|
|
hres = regexp_match_next(ctx, regexp, REM_RESET_INDEX|REM_NO_PARENS, jsstr, &match_ptr);
|
|
|
|
jsstr_release(jsstr);
|
2010-01-23 22:57:20 +00:00
|
|
|
jsdisp_release(regexp);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 13:16:20 +00:00
|
|
|
if(r)
|
2013-03-30 17:00:20 +00:00
|
|
|
*r = jsval_number(hres == S_OK ? match.cp-match.match_len-str : -1);
|
2010-01-23 22:57:20 +00:00
|
|
|
return S_OK;
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2008-09-21 13:42:05 +00:00
|
|
|
/* ECMA-262 3rd Edition 15.5.4.13 */
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_slice(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2012-10-11 10:16:01 +00:00
|
|
|
int start=0, end, length;
|
|
|
|
jsstr_t *str;
|
2012-05-03 08:41:10 +00:00
|
|
|
double d;
|
2008-09-21 13:42:05 +00:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
hres = get_string_val(ctx, jsthis, &str);
|
2009-09-23 14:18:39 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2008-09-21 13:42:05 +00:00
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
length = jsstr_length(str);
|
2012-06-25 12:08:38 +00:00
|
|
|
if(argc) {
|
2012-09-18 17:01:49 +00:00
|
|
|
hres = to_integer(ctx, argv[0], &d);
|
2009-07-12 17:51:36 +00:00
|
|
|
if(FAILED(hres)) {
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(str);
|
2008-09-21 13:42:05 +00:00
|
|
|
return hres;
|
2009-07-12 17:51:36 +00:00
|
|
|
}
|
2008-09-21 13:42:05 +00:00
|
|
|
|
2012-05-03 08:41:10 +00:00
|
|
|
if(is_int32(d)) {
|
|
|
|
start = d;
|
2008-09-21 13:42:05 +00:00
|
|
|
if(start < 0) {
|
|
|
|
start = length + start;
|
|
|
|
if(start < 0)
|
|
|
|
start = 0;
|
|
|
|
}else if(start > length) {
|
|
|
|
start = length;
|
|
|
|
}
|
2012-05-03 08:41:10 +00:00
|
|
|
}else if(d > 0) {
|
|
|
|
start = length;
|
2008-09-21 13:42:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-25 12:08:38 +00:00
|
|
|
if(argc >= 2) {
|
2012-09-18 17:01:49 +00:00
|
|
|
hres = to_integer(ctx, argv[1], &d);
|
2009-07-12 17:51:36 +00:00
|
|
|
if(FAILED(hres)) {
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(str);
|
2008-09-21 13:42:05 +00:00
|
|
|
return hres;
|
2009-07-12 17:51:36 +00:00
|
|
|
}
|
2008-09-21 13:42:05 +00:00
|
|
|
|
2012-05-03 08:41:10 +00:00
|
|
|
if(is_int32(d)) {
|
|
|
|
end = d;
|
2008-09-21 13:42:05 +00:00
|
|
|
if(end < 0) {
|
|
|
|
end = length + end;
|
|
|
|
if(end < 0)
|
|
|
|
end = 0;
|
|
|
|
}else if(end > length) {
|
|
|
|
end = length;
|
|
|
|
}
|
|
|
|
}else {
|
2012-05-03 08:41:10 +00:00
|
|
|
end = d < 0.0 ? 0 : length;
|
2008-09-21 13:42:05 +00:00
|
|
|
}
|
|
|
|
}else {
|
|
|
|
end = length;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(end < start)
|
|
|
|
end = start;
|
|
|
|
|
2012-09-17 13:16:20 +00:00
|
|
|
if(r) {
|
2013-03-04 09:57:14 +00:00
|
|
|
jsstr_t *retstr = jsstr_substr(str, start, end-start);
|
2009-07-12 17:51:36 +00:00
|
|
|
if(!retstr) {
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(str);
|
2008-09-21 13:42:05 +00:00
|
|
|
return E_OUTOFMEMORY;
|
2009-07-12 17:51:36 +00:00
|
|
|
}
|
2008-09-21 13:42:05 +00:00
|
|
|
|
2012-09-17 13:16:20 +00:00
|
|
|
*r = jsval_string(retstr);
|
2008-09-21 13:42:05 +00:00
|
|
|
}
|
2009-07-12 17:51:36 +00:00
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(str);
|
2008-09-21 13:42:05 +00:00
|
|
|
return S_OK;
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_small(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2008-11-30 12:40:37 +00:00
|
|
|
static const WCHAR smalltagW[] = {'S','M','A','L','L',0};
|
2012-09-18 17:01:49 +00:00
|
|
|
return do_attributeless_tag_format(ctx, jsthis, r, smalltagW);
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_split(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2013-02-19 09:12:27 +00:00
|
|
|
match_state_t match_result, *match_ptr = &match_result;
|
2012-09-24 13:41:53 +00:00
|
|
|
DWORD length, i, match_len = 0;
|
2013-03-30 17:00:20 +00:00
|
|
|
const WCHAR *ptr, *ptr2, *str, *match_str = NULL;
|
2015-05-14 08:15:14 +00:00
|
|
|
unsigned limit = ~0u;
|
2012-09-24 13:41:53 +00:00
|
|
|
jsdisp_t *array, *regexp = NULL;
|
2013-03-30 17:00:20 +00:00
|
|
|
jsstr_t *jsstr, *match_jsstr, *tmp_str;
|
2008-09-24 22:54:09 +00:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2012-09-24 13:41:34 +00:00
|
|
|
if(argc != 1 && argc != 2) {
|
|
|
|
FIXME("unsupported argc %u\n", argc);
|
2008-09-24 22:54:09 +00:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2013-03-30 17:00:20 +00:00
|
|
|
hres = get_string_flat_val(ctx, jsthis, &jsstr, &str);
|
2009-09-23 14:18:39 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2008-09-24 22:54:09 +00:00
|
|
|
|
2013-03-30 17:00:20 +00:00
|
|
|
length = jsstr_length(jsstr);
|
2012-10-11 10:16:01 +00:00
|
|
|
|
2012-09-24 13:41:34 +00:00
|
|
|
if(argc > 1 && !is_undefined(argv[1])) {
|
|
|
|
hres = to_uint32(ctx, argv[1], &limit);
|
|
|
|
if(FAILED(hres)) {
|
2013-03-30 17:00:20 +00:00
|
|
|
jsstr_release(jsstr);
|
2012-09-24 13:41:34 +00:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
if(is_object_instance(argv[0])) {
|
|
|
|
regexp = iface_to_jsdisp((IUnknown*)get_object(argv[0]));
|
2008-09-24 22:54:09 +00:00
|
|
|
if(regexp) {
|
2012-09-24 13:41:53 +00:00
|
|
|
if(!is_class(regexp, JSCLASS_REGEXP)) {
|
|
|
|
jsdisp_release(regexp);
|
|
|
|
regexp = NULL;
|
2012-09-17 13:16:42 +00:00
|
|
|
}
|
2008-09-24 22:54:09 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-17 13:16:42 +00:00
|
|
|
|
2012-09-24 13:41:53 +00:00
|
|
|
if(!regexp) {
|
2013-03-30 17:00:20 +00:00
|
|
|
hres = to_flat_string(ctx, argv[0], &match_jsstr, &match_str);
|
2009-07-12 17:51:47 +00:00
|
|
|
if(FAILED(hres)) {
|
2013-03-30 17:00:20 +00:00
|
|
|
jsstr_release(jsstr);
|
2008-10-07 17:03:02 +00:00
|
|
|
return hres;
|
2009-07-12 17:51:47 +00:00
|
|
|
}
|
2008-10-07 17:03:02 +00:00
|
|
|
|
2013-03-30 17:00:20 +00:00
|
|
|
match_len = jsstr_length(match_jsstr);
|
2008-10-07 17:03:02 +00:00
|
|
|
if(!match_len) {
|
2013-03-30 17:00:20 +00:00
|
|
|
jsstr_release(match_jsstr);
|
2008-10-07 17:03:02 +00:00
|
|
|
match_str = NULL;
|
|
|
|
}
|
2008-09-24 22:54:09 +00:00
|
|
|
}
|
|
|
|
|
2009-09-23 14:17:17 +00:00
|
|
|
hres = create_array(ctx, 0, &array);
|
2008-09-24 22:54:09 +00:00
|
|
|
|
|
|
|
if(SUCCEEDED(hres)) {
|
2013-03-30 17:00:20 +00:00
|
|
|
ptr = str;
|
|
|
|
match_result.cp = str;
|
2012-09-24 13:41:34 +00:00
|
|
|
for(i=0; i<limit; i++) {
|
2012-09-24 13:41:53 +00:00
|
|
|
if(regexp) {
|
2013-03-30 17:00:20 +00:00
|
|
|
hres = regexp_match_next(ctx, regexp, REM_NO_PARENS, jsstr, &match_ptr);
|
2012-09-24 13:41:53 +00:00
|
|
|
if(hres != S_OK)
|
2008-10-07 17:03:02 +00:00
|
|
|
break;
|
2013-02-19 09:12:27 +00:00
|
|
|
ptr2 = match_result.cp - match_result.match_len;
|
2008-10-07 17:03:02 +00:00
|
|
|
}else if(match_str) {
|
2013-03-30 17:00:20 +00:00
|
|
|
ptr2 = strstrW(ptr, match_str);
|
2008-10-07 17:03:02 +00:00
|
|
|
if(!ptr2)
|
|
|
|
break;
|
|
|
|
}else {
|
|
|
|
if(!*ptr)
|
|
|
|
break;
|
|
|
|
ptr2 = ptr+1;
|
|
|
|
}
|
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
tmp_str = jsstr_alloc_len(ptr, ptr2-ptr);
|
2012-09-17 13:16:42 +00:00
|
|
|
if(!tmp_str) {
|
2008-09-24 22:54:09 +00:00
|
|
|
hres = E_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-09-18 17:01:49 +00:00
|
|
|
hres = jsdisp_propput_idx(array, i, jsval_string(tmp_str));
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(tmp_str);
|
2008-09-24 22:54:09 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
2012-09-24 13:41:53 +00:00
|
|
|
if(regexp)
|
2013-02-19 09:12:27 +00:00
|
|
|
ptr = match_result.cp;
|
2008-10-07 17:03:02 +00:00
|
|
|
else if(match_str)
|
|
|
|
ptr = ptr2 + match_len;
|
|
|
|
else
|
|
|
|
ptr++;
|
2008-09-24 22:54:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-24 13:41:53 +00:00
|
|
|
if(SUCCEEDED(hres) && (match_str || regexp) && i<limit) {
|
2013-03-30 17:00:20 +00:00
|
|
|
DWORD len = (str+length) - ptr;
|
2008-09-24 22:54:09 +00:00
|
|
|
|
2008-10-07 17:03:02 +00:00
|
|
|
if(len || match_str) {
|
2012-10-11 10:16:01 +00:00
|
|
|
tmp_str = jsstr_alloc_len(ptr, len);
|
2008-09-24 22:54:09 +00:00
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
if(tmp_str) {
|
2012-09-18 17:01:49 +00:00
|
|
|
hres = jsdisp_propput_idx(array, i, jsval_string(tmp_str));
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(tmp_str);
|
2008-10-07 17:03:02 +00:00
|
|
|
}else {
|
|
|
|
hres = E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
}
|
2008-09-24 22:54:09 +00:00
|
|
|
}
|
|
|
|
|
2012-09-24 13:41:53 +00:00
|
|
|
if(regexp)
|
|
|
|
jsdisp_release(regexp);
|
2012-10-11 10:16:01 +00:00
|
|
|
if(match_str)
|
2013-03-30 17:00:20 +00:00
|
|
|
jsstr_release(match_jsstr);
|
|
|
|
jsstr_release(jsstr);
|
2008-09-24 22:54:09 +00:00
|
|
|
|
2012-09-17 13:16:20 +00:00
|
|
|
if(SUCCEEDED(hres) && r)
|
|
|
|
*r = jsval_obj(array);
|
2010-09-07 13:41:40 +00:00
|
|
|
else
|
2008-09-24 22:54:09 +00:00
|
|
|
jsdisp_release(array);
|
|
|
|
|
|
|
|
return hres;
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_strike(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2008-11-30 12:40:43 +00:00
|
|
|
static const WCHAR striketagW[] = {'S','T','R','I','K','E',0};
|
2012-09-18 17:01:49 +00:00
|
|
|
return do_attributeless_tag_format(ctx, jsthis, r, striketagW);
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_sub(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2008-12-10 09:07:35 +00:00
|
|
|
static const WCHAR subtagW[] = {'S','U','B',0};
|
2012-09-18 17:01:49 +00:00
|
|
|
return do_attributeless_tag_format(ctx, jsthis, r, subtagW);
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2008-09-21 13:41:02 +00:00
|
|
|
/* ECMA-262 3rd Edition 15.5.4.15 */
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_substring(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2012-10-11 10:16:01 +00:00
|
|
|
INT start=0, end, length;
|
|
|
|
jsstr_t *str;
|
2012-05-03 08:41:23 +00:00
|
|
|
double d;
|
2008-09-21 13:41:02 +00:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
hres = get_string_val(ctx, jsthis, &str);
|
2009-09-23 14:18:39 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2008-09-21 13:41:02 +00:00
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
length = jsstr_length(str);
|
2012-06-25 12:08:38 +00:00
|
|
|
if(argc >= 1) {
|
2012-09-18 17:01:49 +00:00
|
|
|
hres = to_integer(ctx, argv[0], &d);
|
2009-07-12 17:51:54 +00:00
|
|
|
if(FAILED(hres)) {
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(str);
|
2008-09-21 13:41:02 +00:00
|
|
|
return hres;
|
2009-07-12 17:51:54 +00:00
|
|
|
}
|
2008-09-21 13:41:02 +00:00
|
|
|
|
2012-05-03 08:41:23 +00:00
|
|
|
if(d >= 0)
|
2012-05-03 08:42:42 +00:00
|
|
|
start = is_int32(d) ? min(length, d) : length;
|
2008-09-21 13:41:02 +00:00
|
|
|
}
|
|
|
|
|
2012-06-25 12:08:38 +00:00
|
|
|
if(argc >= 2) {
|
2012-09-18 17:01:49 +00:00
|
|
|
hres = to_integer(ctx, argv[1], &d);
|
2009-07-12 17:51:54 +00:00
|
|
|
if(FAILED(hres)) {
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(str);
|
2008-09-21 13:41:02 +00:00
|
|
|
return hres;
|
2009-07-12 17:51:54 +00:00
|
|
|
}
|
2008-09-21 13:41:02 +00:00
|
|
|
|
2012-05-03 08:41:23 +00:00
|
|
|
if(d >= 0)
|
2012-05-03 08:42:42 +00:00
|
|
|
end = is_int32(d) ? min(length, d) : length;
|
2012-05-03 08:41:23 +00:00
|
|
|
else
|
|
|
|
end = 0;
|
2008-09-21 13:41:02 +00:00
|
|
|
}else {
|
|
|
|
end = length;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(start > end) {
|
|
|
|
INT tmp = start;
|
|
|
|
start = end;
|
|
|
|
end = tmp;
|
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:20 +00:00
|
|
|
if(r) {
|
2013-03-04 09:57:14 +00:00
|
|
|
jsstr_t *ret = jsstr_substr(str, start, end-start);
|
|
|
|
if(ret)
|
|
|
|
*r = jsval_string(ret);
|
|
|
|
else
|
|
|
|
hres = E_OUTOFMEMORY;
|
2008-09-21 13:41:02 +00:00
|
|
|
}
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(str);
|
2013-03-04 09:57:14 +00:00
|
|
|
return hres;
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2009-08-23 21:38:33 +00:00
|
|
|
/* ECMA-262 3rd Edition B.2.3 */
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_substr(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2012-10-11 10:16:01 +00:00
|
|
|
int start=0, len, length;
|
|
|
|
jsstr_t *str;
|
2012-05-03 08:41:36 +00:00
|
|
|
double d;
|
2009-08-23 21:38:33 +00:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
hres = get_string_val(ctx, jsthis, &str);
|
2009-09-23 14:18:39 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2009-08-23 21:38:33 +00:00
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
length = jsstr_length(str);
|
2012-06-25 12:08:38 +00:00
|
|
|
if(argc >= 1) {
|
2012-09-18 17:01:49 +00:00
|
|
|
hres = to_integer(ctx, argv[0], &d);
|
2009-08-23 21:38:33 +00:00
|
|
|
if(FAILED(hres)) {
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(str);
|
2009-08-23 21:38:33 +00:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2012-05-03 08:41:36 +00:00
|
|
|
if(d >= 0)
|
|
|
|
start = is_int32(d) ? min(length, d) : length;
|
2009-08-23 21:38:33 +00:00
|
|
|
}
|
|
|
|
|
2012-06-25 12:08:38 +00:00
|
|
|
if(argc >= 2) {
|
2012-09-18 17:01:49 +00:00
|
|
|
hres = to_integer(ctx, argv[1], &d);
|
2009-08-23 21:38:33 +00:00
|
|
|
if(FAILED(hres)) {
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(str);
|
2009-08-23 21:38:33 +00:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2012-05-03 08:41:36 +00:00
|
|
|
if(d >= 0.0)
|
|
|
|
len = is_int32(d) ? min(length-start, d) : length-start;
|
|
|
|
else
|
|
|
|
len = 0;
|
2009-08-23 21:38:33 +00:00
|
|
|
}else {
|
|
|
|
len = length-start;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = S_OK;
|
2012-09-17 13:16:20 +00:00
|
|
|
if(r) {
|
2013-03-04 09:57:14 +00:00
|
|
|
jsstr_t *ret = jsstr_substr(str, start, len);
|
2012-09-17 13:16:20 +00:00
|
|
|
if(ret)
|
|
|
|
*r = jsval_string(ret);
|
|
|
|
else
|
2009-08-23 21:38:33 +00:00
|
|
|
hres = E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(str);
|
2009-08-23 21:38:33 +00:00
|
|
|
return hres;
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_sup(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2008-12-10 09:07:46 +00:00
|
|
|
static const WCHAR suptagW[] = {'S','U','P',0};
|
2012-09-18 17:01:49 +00:00
|
|
|
return do_attributeless_tag_format(ctx, jsthis, r, suptagW);
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_toLowerCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_t *str;
|
2009-07-12 17:52:02 +00:00
|
|
|
HRESULT hres;
|
2008-11-23 22:35:40 +00:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
hres = get_string_val(ctx, jsthis, &str);
|
2009-09-23 14:18:39 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2008-11-23 22:35:40 +00:00
|
|
|
|
2012-09-17 13:16:20 +00:00
|
|
|
if(r) {
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_t *ret;
|
2013-03-25 11:28:38 +00:00
|
|
|
WCHAR *buf;
|
2012-10-11 10:16:01 +00:00
|
|
|
|
2013-03-25 11:28:38 +00:00
|
|
|
buf = jsstr_alloc_buf(jsstr_length(str), &ret);
|
|
|
|
if(!buf) {
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(str);
|
|
|
|
return E_OUTOFMEMORY;
|
2009-07-12 17:52:02 +00:00
|
|
|
}
|
2008-11-23 22:35:40 +00:00
|
|
|
|
2013-03-25 11:28:38 +00:00
|
|
|
jsstr_flush(str, buf);
|
|
|
|
strlwrW(buf);
|
2012-10-11 10:16:01 +00:00
|
|
|
*r = jsval_string(ret);
|
2008-11-23 22:35:40 +00:00
|
|
|
}
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(str);
|
2008-11-23 22:35:40 +00:00
|
|
|
return S_OK;
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_toUpperCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_t *str;
|
2009-07-12 17:52:10 +00:00
|
|
|
HRESULT hres;
|
2008-11-23 22:36:50 +00:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
hres = get_string_val(ctx, jsthis, &str);
|
2009-09-23 14:18:39 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2008-11-23 22:36:50 +00:00
|
|
|
|
2012-09-17 13:16:20 +00:00
|
|
|
if(r) {
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_t *ret;
|
2013-03-25 11:28:38 +00:00
|
|
|
WCHAR *buf;
|
2012-10-11 10:16:01 +00:00
|
|
|
|
2013-03-25 11:28:38 +00:00
|
|
|
buf = jsstr_alloc_buf(jsstr_length(str), &ret);
|
|
|
|
if(!buf) {
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(str);
|
|
|
|
return E_OUTOFMEMORY;
|
2009-07-12 17:52:10 +00:00
|
|
|
}
|
2008-11-23 22:36:50 +00:00
|
|
|
|
2013-03-25 11:28:38 +00:00
|
|
|
jsstr_flush(str, buf);
|
|
|
|
struprW(buf);
|
2012-10-11 10:16:01 +00:00
|
|
|
*r = jsval_string(ret);
|
2008-11-23 22:36:50 +00:00
|
|
|
}
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(str);
|
2008-11-23 22:36:50 +00:00
|
|
|
return S_OK;
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_toLocaleLowerCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
|
|
|
FIXME("\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_toLocaleUpperCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
|
|
|
FIXME("\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT String_localeCompare(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
|
|
|
FIXME("\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2015-02-06 11:09:40 +00:00
|
|
|
static HRESULT String_get_value(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2015-02-06 11:09:40 +00:00
|
|
|
StringInstance *This = (StringInstance*)jsthis;
|
2008-09-21 13:43:50 +00:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2015-02-05 13:49:01 +00:00
|
|
|
*r = jsval_string(jsstr_addref(This->str));
|
2008-09-21 13:43:50 +00:00
|
|
|
return S_OK;
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2010-09-06 14:11:49 +00:00
|
|
|
static void String_destructor(jsdisp_t *dispex)
|
2008-09-15 18:40:34 +00:00
|
|
|
{
|
|
|
|
StringInstance *This = (StringInstance*)dispex;
|
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(This->str);
|
2008-09-15 18:40:34 +00:00
|
|
|
heap_free(This);
|
|
|
|
}
|
|
|
|
|
2012-11-30 12:03:07 +00:00
|
|
|
static unsigned String_idx_length(jsdisp_t *jsdisp)
|
|
|
|
{
|
|
|
|
StringInstance *string = (StringInstance*)jsdisp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE: For invoke version < 2, indexed array is not implemented at all.
|
|
|
|
* Newer jscript.dll versions implement it on string type, not class,
|
|
|
|
* which is not how it should work according to spec. IE9 implements it
|
|
|
|
* properly, but it uses its own JavaScript engine inside MSHTML. We
|
|
|
|
* implement it here, but in the way IE9 and spec work.
|
|
|
|
*/
|
|
|
|
return string->dispex.ctx->version < 2 ? 0 : jsstr_length(string->str);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT String_idx_get(jsdisp_t *jsdisp, unsigned idx, jsval_t *r)
|
|
|
|
{
|
|
|
|
StringInstance *string = (StringInstance*)jsdisp;
|
|
|
|
jsstr_t *ret;
|
|
|
|
|
2013-03-04 09:57:14 +00:00
|
|
|
ret = jsstr_substr(string->str, idx, 1);
|
2012-11-30 12:03:07 +00:00
|
|
|
if(!ret)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2013-03-08 10:38:11 +00:00
|
|
|
TRACE("%p[%u] = %s\n", string, idx, debugstr_jsstr(ret));
|
|
|
|
|
2012-11-30 12:03:07 +00:00
|
|
|
*r = jsval_string(ret);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-09-10 00:33:37 +00:00
|
|
|
static const builtin_prop_t String_props[] = {
|
2009-08-17 10:12:25 +00:00
|
|
|
{anchorW, String_anchor, PROPF_METHOD|1},
|
2008-09-10 00:33:37 +00:00
|
|
|
{bigW, String_big, PROPF_METHOD},
|
|
|
|
{blinkW, String_blink, PROPF_METHOD},
|
|
|
|
{boldW, String_bold, PROPF_METHOD},
|
2009-08-17 10:12:25 +00:00
|
|
|
{charAtW, String_charAt, PROPF_METHOD|1},
|
|
|
|
{charCodeAtW, String_charCodeAt, PROPF_METHOD|1},
|
|
|
|
{concatW, String_concat, PROPF_METHOD|1},
|
2008-09-10 00:33:37 +00:00
|
|
|
{fixedW, String_fixed, PROPF_METHOD},
|
2009-08-17 10:12:25 +00:00
|
|
|
{fontcolorW, String_fontcolor, PROPF_METHOD|1},
|
|
|
|
{fontsizeW, String_fontsize, PROPF_METHOD|1},
|
|
|
|
{indexOfW, String_indexOf, PROPF_METHOD|2},
|
2008-09-10 00:33:37 +00:00
|
|
|
{italicsW, String_italics, PROPF_METHOD},
|
2009-08-17 10:12:25 +00:00
|
|
|
{lastIndexOfW, String_lastIndexOf, PROPF_METHOD|2},
|
2015-02-05 13:49:01 +00:00
|
|
|
{lengthW, NULL,0, String_get_length, String_set_length},
|
2009-08-17 10:12:25 +00:00
|
|
|
{linkW, String_link, PROPF_METHOD|1},
|
|
|
|
{localeCompareW, String_localeCompare, PROPF_METHOD|1},
|
|
|
|
{matchW, String_match, PROPF_METHOD|1},
|
|
|
|
{replaceW, String_replace, PROPF_METHOD|1},
|
2008-09-10 00:33:37 +00:00
|
|
|
{searchW, String_search, PROPF_METHOD},
|
|
|
|
{sliceW, String_slice, PROPF_METHOD},
|
|
|
|
{smallW, String_small, PROPF_METHOD},
|
2009-08-17 10:12:25 +00:00
|
|
|
{splitW, String_split, PROPF_METHOD|2},
|
2008-09-10 00:33:37 +00:00
|
|
|
{strikeW, String_strike, PROPF_METHOD},
|
|
|
|
{subW, String_sub, PROPF_METHOD},
|
2009-08-17 10:12:25 +00:00
|
|
|
{substrW, String_substr, PROPF_METHOD|2},
|
|
|
|
{substringW, String_substring, PROPF_METHOD|2},
|
2008-09-10 00:33:37 +00:00
|
|
|
{supW, String_sup, PROPF_METHOD},
|
|
|
|
{toLocaleLowerCaseW, String_toLocaleLowerCase, PROPF_METHOD},
|
|
|
|
{toLocaleUpperCaseW, String_toLocaleUpperCase, PROPF_METHOD},
|
|
|
|
{toLowerCaseW, String_toLowerCase, PROPF_METHOD},
|
|
|
|
{toStringW, String_toString, PROPF_METHOD},
|
|
|
|
{toUpperCaseW, String_toUpperCase, PROPF_METHOD},
|
|
|
|
{valueOfW, String_valueOf, PROPF_METHOD}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const builtin_info_t String_info = {
|
|
|
|
JSCLASS_STRING,
|
2015-02-05 13:49:01 +00:00
|
|
|
{NULL, NULL,0, String_get_value},
|
2008-09-10 00:33:37 +00:00
|
|
|
sizeof(String_props)/sizeof(*String_props),
|
|
|
|
String_props,
|
|
|
|
String_destructor,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2012-07-24 11:17:41 +00:00
|
|
|
static const builtin_prop_t StringInst_props[] = {
|
2015-02-05 13:49:01 +00:00
|
|
|
{lengthW, NULL,0, String_get_length, String_set_length}
|
2012-07-24 11:17:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const builtin_info_t StringInst_info = {
|
|
|
|
JSCLASS_STRING,
|
2015-02-05 13:49:01 +00:00
|
|
|
{NULL, NULL,0, String_get_value},
|
2012-07-24 11:17:41 +00:00
|
|
|
sizeof(StringInst_props)/sizeof(*StringInst_props),
|
|
|
|
StringInst_props,
|
|
|
|
String_destructor,
|
2012-11-30 12:03:07 +00:00
|
|
|
NULL,
|
|
|
|
String_idx_length,
|
|
|
|
String_idx_get
|
2012-07-24 11:17:41 +00:00
|
|
|
};
|
|
|
|
|
2009-07-13 23:36:58 +00:00
|
|
|
/* ECMA-262 3rd Edition 15.5.3.2 */
|
2009-09-23 14:18:39 +00:00
|
|
|
static HRESULT StringConstr_fromCharCode(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
|
2012-09-18 17:01:49 +00:00
|
|
|
unsigned argc, jsval_t *argv, jsval_t *r)
|
2009-07-13 23:36:58 +00:00
|
|
|
{
|
2013-03-25 11:28:38 +00:00
|
|
|
WCHAR *ret_str;
|
2009-07-13 23:36:58 +00:00
|
|
|
DWORD i, code;
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_t *ret;
|
2009-07-13 23:36:58 +00:00
|
|
|
HRESULT hres;
|
|
|
|
|
2012-09-17 13:16:20 +00:00
|
|
|
TRACE("\n");
|
|
|
|
|
2013-03-25 11:28:38 +00:00
|
|
|
ret_str = jsstr_alloc_buf(argc, &ret);
|
|
|
|
if(!ret_str)
|
2009-07-13 23:36:58 +00:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2012-06-25 12:08:38 +00:00
|
|
|
for(i=0; i<argc; i++) {
|
2012-09-18 17:01:49 +00:00
|
|
|
hres = to_uint32(ctx, argv[i], &code);
|
2009-07-13 23:36:58 +00:00
|
|
|
if(FAILED(hres)) {
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(ret);
|
2009-07-13 23:36:58 +00:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2013-03-25 11:28:38 +00:00
|
|
|
ret_str[i] = code;
|
2009-07-13 23:36:58 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:20 +00:00
|
|
|
if(r)
|
|
|
|
*r = jsval_string(ret);
|
|
|
|
else
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_release(ret);
|
2009-07-13 23:36:58 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:42 +00:00
|
|
|
static HRESULT StringConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 17:01:49 +00:00
|
|
|
jsval_t *r)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
2008-09-21 13:43:32 +00:00
|
|
|
HRESULT hres;
|
|
|
|
|
2008-09-21 13:44:29 +00:00
|
|
|
TRACE("\n");
|
|
|
|
|
2008-09-21 13:43:32 +00:00
|
|
|
switch(flags) {
|
2008-09-21 13:44:29 +00:00
|
|
|
case INVOKE_FUNC: {
|
2012-10-11 10:16:01 +00:00
|
|
|
jsstr_t *str;
|
2008-09-21 13:44:29 +00:00
|
|
|
|
2012-06-25 12:08:38 +00:00
|
|
|
if(argc) {
|
2012-09-18 17:01:49 +00:00
|
|
|
hres = to_string(ctx, argv[0], &str);
|
2008-09-21 13:44:29 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}else {
|
2012-10-11 10:16:01 +00:00
|
|
|
str = jsstr_empty();
|
2008-09-21 13:44:29 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 13:16:20 +00:00
|
|
|
*r = jsval_string(str);
|
2008-09-21 13:44:29 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-09-21 13:43:32 +00:00
|
|
|
case DISPATCH_CONSTRUCT: {
|
2013-10-21 14:26:35 +00:00
|
|
|
jsstr_t *str;
|
2010-09-06 14:11:49 +00:00
|
|
|
jsdisp_t *ret;
|
2008-09-21 13:43:32 +00:00
|
|
|
|
2012-06-25 12:08:38 +00:00
|
|
|
if(argc) {
|
2012-09-18 17:01:49 +00:00
|
|
|
hres = to_string(ctx, argv[0], &str);
|
2008-09-21 13:43:32 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}else {
|
2013-10-21 14:26:35 +00:00
|
|
|
str = jsstr_empty();
|
2008-09-21 13:43:32 +00:00
|
|
|
}
|
|
|
|
|
2013-10-21 14:26:35 +00:00
|
|
|
hres = create_string(ctx, str, &ret);
|
|
|
|
if (SUCCEEDED(hres)) *r = jsval_obj(ret);
|
|
|
|
jsstr_release(str);
|
|
|
|
return hres;
|
2008-09-21 13:43:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("unimplemented flags: %x\n", flags);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2008-09-10 00:33:37 +00:00
|
|
|
}
|
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
static HRESULT string_alloc(script_ctx_t *ctx, jsdisp_t *object_prototype, jsstr_t *str, StringInstance **ret)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
|
|
|
StringInstance *string;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
string = heap_alloc_zero(sizeof(StringInstance));
|
|
|
|
if(!string)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2009-08-12 10:47:53 +00:00
|
|
|
if(object_prototype)
|
|
|
|
hres = init_dispex(&string->dispex, ctx, &String_info, object_prototype);
|
2008-09-10 00:33:37 +00:00
|
|
|
else
|
2012-07-24 11:17:41 +00:00
|
|
|
hres = init_dispex_from_constr(&string->dispex, ctx, &StringInst_info, ctx->string_constr);
|
2008-09-10 00:33:37 +00:00
|
|
|
if(FAILED(hres)) {
|
|
|
|
heap_free(string);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
string->str = jsstr_addref(str);
|
2008-09-10 00:33:37 +00:00
|
|
|
*ret = string;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-07-13 23:36:58 +00:00
|
|
|
static const builtin_prop_t StringConstr_props[] = {
|
|
|
|
{fromCharCodeW, StringConstr_fromCharCode, PROPF_METHOD},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const builtin_info_t StringConstr_info = {
|
|
|
|
JSCLASS_FUNCTION,
|
2015-02-05 13:49:01 +00:00
|
|
|
DEFAULT_FUNCTION_VALUE,
|
2009-07-13 23:36:58 +00:00
|
|
|
sizeof(StringConstr_props)/sizeof(*StringConstr_props),
|
|
|
|
StringConstr_props,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2010-09-06 14:11:49 +00:00
|
|
|
HRESULT create_string_constr(script_ctx_t *ctx, jsdisp_t *object_prototype, jsdisp_t **ret)
|
2008-09-10 00:33:37 +00:00
|
|
|
{
|
|
|
|
StringInstance *string;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2009-09-16 23:04:44 +00:00
|
|
|
static const WCHAR StringW[] = {'S','t','r','i','n','g',0};
|
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
hres = string_alloc(ctx, object_prototype, jsstr_empty(), &string);
|
2008-09-10 00:33:37 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-07-16 13:31:10 +00:00
|
|
|
hres = create_builtin_constructor(ctx, StringConstr_value, StringW, &StringConstr_info,
|
2009-10-13 20:08:43 +00:00
|
|
|
PROPF_CONSTR|1, &string->dispex, ret);
|
2008-09-10 00:33:37 +00:00
|
|
|
|
|
|
|
jsdisp_release(&string->dispex);
|
|
|
|
return hres;
|
|
|
|
}
|
2008-09-15 18:40:34 +00:00
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
HRESULT create_string(script_ctx_t *ctx, jsstr_t *str, jsdisp_t **ret)
|
2008-09-15 18:40:34 +00:00
|
|
|
{
|
|
|
|
StringInstance *string;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2012-10-11 10:16:01 +00:00
|
|
|
hres = string_alloc(ctx, NULL, str, &string);
|
2008-09-15 18:40:34 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
*ret = &string->dispex;
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
}
|