w3c / webdriver

Remote control interface that enables introspection and control of user agents.
https://w3c.github.io/webdriver/
Other
679 stars 194 forks source link

Call of toJSON in the internal JSON clone algorithm #1730

Open nechaev-chromium opened 1 year ago

nechaev-chromium commented 1 year ago

According to the internal JSON clone algorithm:

(if the serialized object) has an own property named "toJSON" that is a Function (...) return success with the value returned by Function.[[Call]](toJSON) with value as the this value.

The standard does not mention what to do with inherited property toJSON of the serialized object. Would it make sense to handle toJSON uniformly for both own and inherited toJSON property?

Use case: According to the ECMAScript standard toJSON is an inherited property of Date object defined in Date.prototype. As it is not an own property we have to serialize Date as an object instead of calling Date.prototype.toJSON

Implementations: ChromeDriver

GeckoDriver It looks like it also calls Date.prototype.toJSON as the serialization result is a string of the form YYYY-MM-DDTHH:mm:ss.sssZ (ISO8601)