jscript: Support undefined separator in String.split implementation.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2018-11-30 16:20:35 +01:00 committed by Alexandre Julliard
parent 8780a4fa6d
commit 1fc9b2e934
3 changed files with 89 additions and 6 deletions

View File

@ -1140,17 +1140,32 @@ static HRESULT String_split(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
TRACE("\n"); TRACE("\n");
if(argc != 1 && argc != 2) {
FIXME("unsupported argc %u\n", argc);
return E_NOTIMPL;
}
hres = get_string_flat_val(ctx, jsthis, &jsstr, &str); hres = get_string_flat_val(ctx, jsthis, &jsstr, &str);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
length = jsstr_length(jsstr); length = jsstr_length(jsstr);
if(!argc || (is_undefined(argv[0]) && ctx->version >= SCRIPTLANGUAGEVERSION_ES5)) {
if(!r)
return S_OK;
hres = create_array(ctx, 0, &array);
if(FAILED(hres))
return hres;
/* NOTE: according to spec, we should respect limit argument here (if provided).
* We have a test showing that it's broken in native IE. */
hres = jsdisp_propput_idx(array, 0, jsval_string(jsstr));
if(FAILED(hres)) {
jsdisp_release(array);
return hres;
}
*r = jsval_obj(array);
return S_OK;
}
if(argc > 1 && !is_undefined(argv[1])) { if(argc > 1 && !is_undefined(argv[1])) {
hres = to_uint32(ctx, argv[1], &limit); hres = to_uint32(ctx, argv[1], &limit);
if(FAILED(hres)) { if(FAILED(hres)) {

View File

@ -618,6 +618,28 @@ ok(r[0] === "1", "r[0] = " + r[0]);
ok(r[1] === "2", "r[1] = " + r[1]); ok(r[1] === "2", "r[1] = " + r[1]);
ok(r[2] === "3", "r[1] = " + r[1]); ok(r[2] === "3", "r[1] = " + r[1]);
r = "1,2,3".split(undefined);
ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
ok(r.length === 1, "r.length = " + r.length);
ok(r[0] === "1,2,3", "r[0] = " + r[0]);
r = "1,undefined2undefined,3".split(undefined);
ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
ok(r.length === 3, "r.length = " + r.length);
ok(r[0] === "1,", "r[0] = " + r[0]);
ok(r[1] === "2", "r[1] = " + r[1]);
ok(r[2] === ",3", "r[2] = " + r[2]);
r = "1,undefined2undefined,3".split();
ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
ok(r.length === 1, "r.length = " + r.length);
ok(r[0] === "1,undefined2undefined,3", "r[0] = " + r[0]);
r = "".split();
ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
ok(r.length === 1, "r.length = " + r.length);
ok(r[0] === "", "r[0] = " + r[0]);
tmp = "abcd".indexOf("bc",0); tmp = "abcd".indexOf("bc",0);
ok(tmp === 1, "indexOf = " + tmp); ok(tmp === 1, "indexOf = " + tmp);
tmp = "abcd".indexOf("bc",1); tmp = "abcd".indexOf("bc",1);

View File

@ -460,6 +460,51 @@ function test_global_properties() {
next_test(); next_test();
} }
function test_string_split() {
var r;
/* IE9 got this wrong*/
if("1undefined2".split(undefined).length != 1) {
win_skip("detected broken String.prototype.split implementation");
next_test();
return;
}
r = "1,2,3".split(undefined);
ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
ok(r.length === 1, "r.length = " + r.length);
ok(r[0] === "1,2,3", "r[0] = " + r[0]);
r = "1,undefined2undefined,3".split(undefined);
ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
ok(r.length === 1, "r.length = " + r.length);
ok(r[0] === "1,undefined2undefined,3", "r[0] = " + r[0]);
r = "1,undefined2undefined,3".split();
ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
ok(r.length === 1, "r.length = " + r.length);
ok(r[0] === "1,undefined2undefined,3", "r[0] = " + r[0]);
/* note: spec violation, limit is ignored */
r = "1,undefined2undefined,3".split(undefined, 0);
ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
ok(r.length === 1, "r.length = " + r.length);
ok(r[0] === "1,undefined2undefined,3", "r[0] = " + r[0]);
r = "1,undefined2null,3".split(null);
ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
ok(r.length === 2, "r.length = " + r.length);
ok(r[0] === "1,undefined2", "r[0] = " + r[0]);
ok(r[1] === ",3", "r[1] = " + r[1]);
r = "".split();
ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
ok(r.length === 1, "r.length = " + r.length);
ok(r[0] === "", "r[0] = " + r[0]);
next_test();
}
var tests = [ var tests = [
test_date_now, test_date_now,
test_toISOString, test_toISOString,
@ -469,5 +514,6 @@ var tests = [
test_getOwnPropertyDescriptor, test_getOwnPropertyDescriptor,
test_defineProperty, test_defineProperty,
test_string_trim, test_string_trim,
test_global_properties test_global_properties,
test_string_split
]; ];