W3C home > Mailing lists > Public > public-web-perf@w3.org > September 2013

Re: [ResourcePriorities] Error in example

From: Ivan Kotenkov <kotenkov@yandex-team.ru>
Date: Thu, 12 Sep 2013 12:15:25 +0400
Cc: public-web-perf@w3.org
Message-Id: <995AEEFA-BE5D-4F8C-88C5-2328345D0FBD@yandex-team.ru>
To: Boris Zbarsky <bzbarsky@MIT.EDU>
I'm afraid, I cannot agree with you.

At first let's look at the spec: http://www.w3.org/TR/WebIDL/#dfn-read-only .
"The attribute is read only if the readonly keyword is used before the attribute keyword. An object that implements the interface on which a read only attribute is defined will not allow assignment to that attribute. It is language binding specific whether assignment is simply disallowed by the language, ignored or an exception is thrown."
I think, using setAttribute is a direct assignment, so it cannot be used on a readonly attribute.

Next let's look at an example. As a developer of chromium-based browser I'll use chromium code as an example.
interface HTMLInputElement is defined in HTMLInputElement.idl. Among other attributes it has 
    readonly attribute boolean willValidate;

Now let's create a simple webpage that will try to change the attribute:
<html>
<script>
function changeInput() {
  input = document.getElementById('inp');
  alert(input.willValidate);
  input.setAttribute('willValidate', false);
  alert(input.willValidate);
}
</script>
</html>
<body onload='changeInput()'>
<input type="text" id="inp" />
</body>
</html>

In latest chromium both alerts produces 'true'.

Also, grepping the *.idl files for 'readonly' gives us attributes that obviously should not be change by using setters, for example:
HTMLFormElement.idl:    readonly attribute HTMLCollection elements;
HTMLFormElement.idl:    readonly attribute long length;

--
Regards,
Ivan Kotenkov




12.09.2013, Χ 0:39, Boris Zbarsky <bzbarsky@MIT.EDU> ΞΑΠΙΣΑΜ(Α):

> On 9/11/13 4:32 PM, Ivan Kotenkov wrote:
>> Please correct me if I'm wrong:
>> As I understand, readonly keyword means that the attribute cannot be
>> assigned directly from the webpage(via html or js)
> 
> That's incorrect.  It just means the JS property has no setter. setAttribute will still work fine.
> 
> -Boris


Received on Thursday, 12 September 2013 08:15:53 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:01:21 UTC