Commit 0e5933f7 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Added support for indexed string access.

parent 956cb343
......@@ -1396,6 +1396,35 @@ static void String_destructor(jsdisp_t *dispex)
heap_free(This);
}
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;
TRACE("%p[%u] = %s\n", string, idx, debugstr_wn(string->str->str+idx, 1));
ret = jsstr_alloc_len(string->str->str+idx, 1);
if(!ret)
return E_OUTOFMEMORY;
*r = jsval_string(ret);
return S_OK;
}
static const builtin_prop_t String_props[] = {
{anchorW, String_anchor, PROPF_METHOD|1},
{bigW, String_big, PROPF_METHOD},
......@@ -1451,7 +1480,9 @@ static const builtin_info_t StringInst_info = {
sizeof(StringInst_props)/sizeof(*StringInst_props),
StringInst_props,
String_destructor,
NULL
NULL,
String_idx_length,
String_idx_get
};
/* ECMA-262 3rd Edition 15.5.3.2 */
......
......@@ -1785,6 +1785,9 @@ function callTest(argc) {
ok(arguments.length === argc+1, "arguments.length = " + arguments.length + " expected " + (argc+1));
for(var i=1; i <= argc; i++)
ok(arguments[i] === i, "arguments[i] = " + arguments[i]);
var a = arguments;
for(var i=1; i <= argc; i++)
ok(a[i] === i, "a[i] = " + a[i]);
}
callTest.call(tmp, 1, 1);
......
......@@ -1199,6 +1199,20 @@ try {
}catch(e) {}
ok(!("prop" in obj), "prop in obj");
if(invokeVersion >= 2) {
ok("test"[0] === "t", '"test"[0] = ' + test[0]);
ok("test"[5] === undefined, '"test"[0] = ' + test[0]);
tmp = "test";
ok(tmp[1] === "e", "tmp[1] = " + tmp[1]);
tmp[1] = "x";
ok(tmp[1] === "e", "tmp[1] = " + tmp[1]);
ok(tmp["1"] === "e", "tmp['1'] = " + tmp["1"]);
ok(tmp["0x1"] === undefined, "tmp['0x1'] = " + tmp["0x1"]);
}else {
ok("test"[0] === undefined, '"test"[0] = ' + test[0]);
}
ok(isNaN(NaN) === true, "isNaN(NaN) !== true");
ok(isNaN(0.5) === false, "isNaN(0.5) !== false");
ok(isNaN(Infinity) === false, "isNaN(Infinity) !== false");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment