[PATCH v11 10/10] jscript: Return the correct string for Object.toString(null) in ES5+ modes.
Gabriel Ivăncescu
gabrielopcode at gmail.com
Wed Dec 1 07:38:24 CST 2021
On 30/11/2021 23:20, Jacek Caban wrote:
> On 11/29/21 5:31 PM, Gabriel Ivăncescu wrote:
>> + else if(function->proc == Object_toString && ctx->version >=
>> SCRIPTLANGUAGEVERSION_ES5) {
>> + jsstr_t *ret;
>> + if(!r)
>> + return S_OK;
>> + ret = jsstr_alloc(L"[object Null]");
>> + if(!ret)
>> + return E_OUTOFMEMORY;
>> + *r = jsval_string(ret);
>> + return S_OK;
>> + }
>
>
> This is ugly. I think that what you observe is a change in how ES5
> treats 'this' argument in builtin functions. It allows 'this' to be of
> any type for builtin function. The conversion to object (or using a
> global object in place of null) happens only when we enter JS function,
> if I read it right. To support this properly, I'm afraid that we'd need
> to pass 'this' as jsval to builtin functions. We wouldn't need any
> special casing for toString() then.
>
Interesting, I did not realize builtin functions were special in regards
to the "this" context. I'll send this separately later then, but passing
jsval to builtin functions would also help with fixing the undefined
case (since toString reports [object Undefined] then), so it's on the
right track for sure.
More information about the wine-devel
mailing list