[PATCH v11 10/10] jscript: Return the correct string for Object.toString(null) in ES5+ modes.

Jacek Caban jacek at codeweavers.com
Tue Nov 30 15:20:14 CST 2021


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.


Thanks,

Jacek




More information about the wine-devel mailing list