Jacek Caban : jscript: Added String.trim implementation.
Alexandre Julliard
julliard at winehq.org
Fri May 25 13:41:12 CDT 2018
Module: wine
Branch: master
Commit: 16ba7f444437d7d11600764a12ae143817e6f23c
URL: https://source.winehq.org/git/wine.git/?a=commit;h=16ba7f444437d7d11600764a12ae143817e6f23c
Author: Jacek Caban <jacek at codeweavers.com>
Date: Fri May 25 15:31:44 2018 +0200
jscript: Added String.trim implementation.
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/jscript/string.c | 37 +++++++++++++++++++++++++++++++++++++
dlls/mshtml/tests/documentmode.js | 2 ++
dlls/mshtml/tests/es5.js | 17 +++++++++++++++++
3 files changed, 56 insertions(+)
diff --git a/dlls/jscript/string.c b/dlls/jscript/string.c
index 737c878..e6e4997 100644
--- a/dlls/jscript/string.c
+++ b/dlls/jscript/string.c
@@ -63,6 +63,7 @@ static const WCHAR toLowerCaseW[] = {'t','o','L','o','w','e','r','C','a','s','e'
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 trimW[] = {'t','r','i','m',0};
static const WCHAR localeCompareW[] = {'l','o','c','a','l','e','C','o','m','p','a','r','e',0};
static const WCHAR fromCharCodeW[] = {'f','r','o','m','C','h','a','r','C','o','d','e',0};
@@ -1465,6 +1466,41 @@ static HRESULT String_toLocaleUpperCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD
return E_NOTIMPL;
}
+static HRESULT String_trim(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc,
+ jsval_t *argv, jsval_t *r)
+{
+ const WCHAR *str, *begin, *end;
+ jsstr_t *jsstr;
+ unsigned len;
+ HRESULT hres;
+
+ hres = to_flat_string(ctx, jsval_disp(jsthis->u.disp), &jsstr, &str);
+ if(FAILED(hres)) {
+ WARN("to_flat_string failed: %08x\n", hres);
+ return hres;
+ }
+ len = jsstr_length(jsstr);
+ TRACE("%s\n", debugstr_wn(str, len));
+
+ for(begin = str, end = str + len; begin < end && isspaceW(*begin); begin++);
+ while(end > begin + 1 && isspaceW(*(end-1))) end--;
+
+ if(r) {
+ jsstr_t *ret;
+
+ if(begin == str && end == str + len)
+ ret = jsstr_addref(jsstr);
+ else
+ ret = jsstr_alloc_len(begin, end - begin);
+ if(ret)
+ *r = jsval_string(ret);
+ else
+ hres = E_OUTOFMEMORY;
+ }
+ jsstr_release(jsstr);
+ return hres;
+}
+
static HRESULT String_localeCompare(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r)
{
@@ -1552,6 +1588,7 @@ static const builtin_prop_t String_props[] = {
{toLowerCaseW, String_toLowerCase, PROPF_METHOD},
{toStringW, String_toString, PROPF_METHOD},
{toUpperCaseW, String_toUpperCase, PROPF_METHOD},
+ {trimW, String_trim, PROPF_ES5|PROPF_METHOD},
{valueOfW, String_valueOf, PROPF_METHOD}
};
diff --git a/dlls/mshtml/tests/documentmode.js b/dlls/mshtml/tests/documentmode.js
index 12edb4b..663cce7 100644
--- a/dlls/mshtml/tests/documentmode.js
+++ b/dlls/mshtml/tests/documentmode.js
@@ -142,6 +142,8 @@ function test_javascript() {
test_exposed("toISOString", Date.prototype, v >= 9);
test_exposed("isArray", Array, v >= 9);
test_exposed("indexOf", Array.prototype, v >= 9);
+ test_exposed("trim", String.prototype, v >= 9);
+
/* FIXME: IE8 implements weird semi-functional property descriptors. */
if(v != 8) {
test_exposed("getOwnPropertyDescriptor", Object, v >= 8);
diff --git a/dlls/mshtml/tests/es5.js b/dlls/mshtml/tests/es5.js
index 62cf12a..e4b9557 100644
--- a/dlls/mshtml/tests/es5.js
+++ b/dlls/mshtml/tests/es5.js
@@ -427,6 +427,22 @@ function test_defineProperty() {
next_test();
}
+function test_string_trim() {
+ function test_trim(value, expected) {
+ var r = String.prototype.trim.call(value);
+ ok(r === expected, "trim(" + value + ") = " + r);
+ }
+
+ test_trim("test", "test");
+ test_trim(false, "false");
+ test_trim("\n \t\rte st\t\t\n", "te st");
+ test_trim({ toString: function() { return " test "; } }, "test");
+ test_trim("", "");
+ test_trim(" \t\n", "");
+
+ next_test();
+}
+
function test_global_properties() {
var o;
@@ -452,5 +468,6 @@ var tests = [
test_identifier_keywords,
test_getOwnPropertyDescriptor,
test_defineProperty,
+ test_string_trim,
test_global_properties
];
More information about the wine-cvs
mailing list