Module: wine Branch: master Commit: 1fc9b2e93435ec336ba1f921ed2614de224cdbe3 URL: https://source.winehq.org/git/wine.git/?a=commit;h=1fc9b2e93435ec336ba1f921e...
Author: Jacek Caban jacek@codeweavers.com Date: Fri Nov 30 16:20:35 2018 +0100
jscript: Support undefined separator in String.split implementation.
Signed-off-by: Jacek Caban jacek@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/jscript/string.c | 25 +++++++++++++++++++----- dlls/jscript/tests/api.js | 22 ++++++++++++++++++++++ dlls/mshtml/tests/es5.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 89 insertions(+), 6 deletions(-)
diff --git a/dlls/jscript/string.c b/dlls/jscript/string.c index 7a6133d..79d7884 100644 --- a/dlls/jscript/string.c +++ b/dlls/jscript/string.c @@ -1140,17 +1140,32 @@ static HRESULT String_split(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
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); if(FAILED(hres)) return hres;
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])) { hres = to_uint32(ctx, argv[1], &limit); if(FAILED(hres)) { diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js index f9178a9..ff6a6b7 100644 --- a/dlls/jscript/tests/api.js +++ b/dlls/jscript/tests/api.js @@ -618,6 +618,28 @@ ok(r[0] === "1", "r[0] = " + r[0]); ok(r[1] === "2", "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); ok(tmp === 1, "indexOf = " + tmp); tmp = "abcd".indexOf("bc",1); diff --git a/dlls/mshtml/tests/es5.js b/dlls/mshtml/tests/es5.js index e4b9557..6097f4c 100644 --- a/dlls/mshtml/tests/es5.js +++ b/dlls/mshtml/tests/es5.js @@ -460,6 +460,51 @@ function test_global_properties() { 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 = [ test_date_now, test_toISOString, @@ -469,5 +514,6 @@ var tests = [ test_getOwnPropertyDescriptor, test_defineProperty, test_string_trim, - test_global_properties + test_global_properties, + test_string_split ];