NS_ERROR_FAILURE return code when getting value or type of element's selectionStart property




DOM: Core & HTML
9 years ago
6 years ago


(Reporter: Clay Compton, Unassigned)



Firefox Tracking Flags

(Not tracked)



(2 attachments, 1 obsolete attachment)



9 years ago
User-Agent:       Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; InfoPath.2; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; OfficeLiveConnector.1.3; OfficeLivePatch.0.0)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1b2) Gecko/20081201 Firefox/3.1b2

Javascript fails to execute on this browser after performing either of a couple possible actions on a property called selectionStart.  A javascript error reports an exception with the return code NS_ERROR_FAILURE.  This is a regression from Firefox 3.0.4.

Reproducible: Always

Steps to Reproduce:
1.  Copy and paste the following into a file and save it as an HTML document:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <title>Test Page</title>
    <script type="text/javascript">
        function DoTest() {
            var test = document.getElementById("Button1");
            var results = document.getElementById("resultsParagraph");

            results.innerHTML += test["selectionStart"] + "<br />";
            results.innerHTML += typeof (test["selectionStart"]);             
<body onload="DoTest();">
<p id="testParagraph">
    <input type="button" id="Button1" name="Button1" value="Generic Button" />
<p id="resultsParagraph"></p>

Note that the above document performs a pair of actions related to the selectionStart property of a button on the page (i.e. getting the property value and retrieving its type), either of which are capable of generating the error described in the summary.
2.  Navigate to the page using Firefox 3.1 beta 2.
3.  Open the error console and observe the error.
Actual Results:  
Error: uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMNSHTMLInputElement.selectionStart]"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"  location: "JS frame :: http://localhost/TestSite/TestPage.htm :: DoTest :: line 13"  data: no]

Expected Results:  
Both of the operations in the HTML document using this property should be valid, just as they are with other properties on the element that can be enumerated using a for-in loop.

Comment 1

9 years ago
I can confirm this behavior using Minefield and Firefox as shipped with Ubuntu 8.10.

Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2a1pre) Gecko/20090121 Minefield/3.2a1pre and Mozilla/5.0 (X11; U; Linux i686; pt-BR; rv: Gecko/2008121622 Ubuntu/8.10 (intrepid) Firefox/3.0.5

It is not related to innerHTML. The exception happens just by evaluating test["selectionStart"].
Created attachment 358548 [details]
Reporter's testcase
(In reply to comment #0)
> This is a regression from Firefox 3.0.4.

No, I can reproduce it in 3.0.4 and 3.0 and Firefox 2 too.


In this case we have a nsGfxButtonControlFrame there, it doesn't implement
Keywords: testcase
OS: Windows Server 2003 → All
Hardware: x86 → All

Comment 4

9 years ago
The following patch will return NS_OK if the element does not have a textControlFrame.

Comment 5

9 years ago
Created attachment 358667 [details] [diff] [review]
Returns NS_OK if the element does not have a textControlFrame.

Comment 6

9 years ago
I get an uncaught exception in Firefox 2 but just a total stop on javascript processing in firefox 3 when trying to access the selectionStart attribute of a form checkbox element.
Not that I am trying to access that, but I am doing a for loop on the form object attributes.  When it gets to selectionStart it just stops.  No error or nothing.

Some script to reproduce...how is this not confirmed?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
<HTML LANG="en">
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<SCRIPT TYPE="text/javascript">
function init()
   var element = document.aform.toggle;
   var msgElement = document.getElementById("msg");
   var msg = "";
   for (var i in element)
      msg += i + " ";
      msgElement.innerHTML = msg;
      msg += "<b>" + typeof(element[i]) + "</b><BR>";
   msgElement.innerHTML = msg;
<DIV ID="msg"></DIV>
This is a mass search for bugs which are in the Firefox General component, are
UNCO, have not been changed for 500 days and have an unspecified version. 

Reporter, can you please update to Firefox 3.6.10 or later, create a fresh profile, http://support.mozilla.com/en-US/kb/managing+profiles, and test again. If you still see the issue, please update this bug. If the issue is gone, please set the status to RESOLVED > WORKSFORME.
Whiteboard: [CLOSEME 2010-11-01]
Still reproducible with the testcase in a recent trunk build.
Component: General → DOM: Core & HTML
Product: Firefox → Core
QA Contact: general → general
Whiteboard: [CLOSEME 2010-11-01]


7 years ago
Attachment #358667 - Flags: review?(Olli.Pettay)

Comment 9

7 years ago
Comment on attachment 358667 [details] [diff] [review]
Returns NS_OK if the element does not have a textControlFrame.

Could you please upload a patch created using -U 8 -p. Especially
without -p this kind of patch is quite difficult to review.
Attachment #358667 - Flags: review?(Olli.Pettay)
And also, this needs a mochitest.
Created attachment 491247 [details] [diff] [review]
With -pU8

I'll write a test.
Attachment #358667 - Attachment is obsolete: true
Attachment #491247 - Flags: review?(Olli.Pettay)
Comment on attachment 491247 [details] [diff] [review]
With -pU8

Sorry for the delay.

So why do we want to throw when there is no formControlFrame?
HTML5 draft isn't quite clear what should happen.


7 years ago
Attachment #491247 - Flags: review?(Olli.Pettay)
Actually, we should throw, as selectionStart doesn't apply: <http://www.whatwg.org/html/#submit-button-state>
Last Resolved: 7 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 366663

Comment 14

6 years ago
@Ms2ger: Shouldn't a property that's not there simply be "undefined"? How do you test for existence of a property then when you cannot use "if(element.selectionStart != undefined)"?
if("selectionStart" in element) {}
You need to log in before you can comment on or make changes to this bug.