W3C home > Mailing lists > Public > public-html@w3.org > June 2009

Re: typeof document.all

From: Thomas Broyer <t.broyer@ltgt.net>
Date: Fri, 19 Jun 2009 10:27:29 +0200
Message-ID: <a9699fd20906190127t1533cfeucbcbfb79c044a14@mail.gmail.com>
To: HTML WG <public-html@w3.org>
On Fri, Jun 19, 2009 at 9:38 AM, Maciej Stachowiak wrote:
> Here are the special behaviors WebKit ensures
> for document.all:
> - document.all is false when tested in a boolean comparison, so if
> (document.all) checks fail
> - the following expression evaluates to true: document.all == undefined
> - the following expression evaluates to true: document.all == null
> - the following expression evaluates to false: document.all != undefined
> - the following expression evaluates to false: document.all != null
> - the expression "typeof document.all" returns the string "undefined"
> - the expression !document.all evaluates to true
> Note that these are all impossible for a normal JavaScript object following
> the ECMAScript spec. However, the ECMAScript spec allows host objects to do
> essentially anything.
> One thing we do not do is affect the behavior of === and !== (the strict
> equality and strict inequality operators).
> I am not sure exactly which of these rules are needed for Web compatibility.

Doing some additional tests:
 - Opera (9.64), FF (3.0.11) and Safari (4) all report document.all as
[object HTMLCollection] in their JS console; Chrome (3) on the other
hand reports it as undefined; however, all four browsers agree that
document.all.toString() is "[object HTMLCollection]", it might just be
how the JS console is implemented?
 - All four browsers return true for ("all" in document), I would have
expect a false here (this is explicitly allowed by ECMAScript, ยง8.6.2:
"Host objects may implement these methods in any manner unless
specified otherwise; for
example, one possibility is that [[Get]] and [[Put]] for a particular
host object indeed fetch and store property values but [[HasProperty]]
always generates false.")
 - Opera and FF return false for document.hasOwnProperty("all"); this
is inconsistent with the above, given that document.prototype is null
(the property exists according to [[HasProperty]], it cannot be in the
prototype chain as there is not prototype, but it doesn't exist on the
object, so where is it?!) Chrome and Safari return true.

Thomas Broyer
Received on Friday, 19 June 2009 08:28:07 UTC

This archive was generated by hypermail 2.4.0 : Saturday, 9 October 2021 18:44:49 UTC