Commit de0a8751 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

jscript: Added Global.escape() implementation.

parent be910d97
......@@ -296,8 +296,72 @@ static HRESULT JSGlobal_Enumerator(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
static HRESULT JSGlobal_escape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
FIXME("\n");
return E_NOTIMPL;
BSTR ret, str;
const WCHAR *ptr;
DWORD len = 0, i, size;
char buf[4];
HRESULT hres;
TRACE("\n");
if(!arg_cnt(dp)) {
if(retv) {
ret = SysAllocString(undefinedW);
if(!ret)
return E_OUTOFMEMORY;
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
}
return S_OK;
}
hres = to_string(ctx, get_arg(dp, 0), ei, &str);
if(FAILED(hres))
return hres;
for(ptr=str; *ptr; ptr++) {
if(isalnumW(*ptr) || *ptr=='*' || *ptr=='@' || *ptr=='-' || *ptr=='_'
|| *ptr=='+' || *ptr=='.' || *ptr=='/')
len++;
else {
size = WideCharToMultiByte(CP_UTF8, 0, ptr, 1, NULL, 0, NULL, NULL)*3;
if(!size) {
FIXME("throw Error\n");
return E_FAIL;
}
len += size;
}
}
ret = SysAllocStringLen(NULL, len);
if(!ret)
return E_OUTOFMEMORY;
len = 0;
for(ptr=str; *ptr; ptr++) {
if(isalnumW(*ptr) || *ptr=='*' || *ptr=='@' || *ptr=='-' || *ptr=='_'
|| *ptr=='+' || *ptr=='.' || *ptr=='/')
ret[len++] = *ptr;
else {
size = WideCharToMultiByte(CP_UTF8, 0, ptr, 1, buf, sizeof(buf), NULL, NULL);
for(i=0; i<size; i++) {
ret[len++] = '%';
ret[len++] = int_to_char(buf[i] >> 4);
ret[len++] = int_to_char(buf[i] & 0xf);
}
}
}
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
}
else
SysFreeString(ret);
return S_OK;
}
/* ECMA-262 3rd Edition 15.1.2.1 */
......
......@@ -58,6 +58,15 @@ ok(tmp === "undefined", "encodeURI() = " + tmp);
tmp = encodeURI("abc", "test");
ok(tmp === "abc", "encodeURI('abc') = " + tmp);
tmp = escape("abc");
ok(tmp === "abc", "escape('abc') = " + tmp);
tmp = escape("");
ok(tmp === "", "escape('') = " + tmp);
tmp = escape("a1b c!d+e@*-_+./,");
ok(tmp === "a1b%20c%21d+e@*-_+./%2C", "escape('a1b c!d+e@*-_+./,') = " + tmp);
tmp = escape();
ok(tmp === "undefined", "escape() = " + tmp);
tmp = unescape("abc");
ok(tmp === "abc", "unescape('abc') = " + tmp);
tmp = unescape("");
......@@ -69,6 +78,10 @@ ok(tmp === "undefined", "unescape() = " + tmp);
tmp = unescape("%54%65s%u0074");
ok(tmp === "Test", "unescape('%54%65s%u0074') = " + tmp);
tmp = "aA1~`!@#$%^&*()_+=-][{}';:/.,<>?\|";
ok(escape(tmp) === "aA1%7E%60%21@%23%24%25%5E%26*%28%29_+%3D-%5D%5B%7B%7D%27%3B%3A/.%2C%3C%3E%3F%7C", "escape('" + tmp + "') = " + escape(tmp));
ok(unescape(escape(tmp)) === tmp, "unescape(escape('" + tmp + "')) = " + unescape(escape(tmp)));
tmp = "" + new Object();
ok(tmp === "[object Object]", "'' + new Object() = " + tmp);
(tmp = new Array).f = Object.prototype.toString;
......
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