SetTimout does not input.select NS_ERROR_XPC_BAD_OP_ON_WN_PROTO

RESOLVED INVALID

Status

()

Core
DOM
RESOLVED INVALID
9 years ago
7 years ago

People

(Reporter: leolite1, Unassigned)

Tracking

({testcase})

Trunk
testcase
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

9 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.1) Gecko/20090715 Firefox/3.5.1 (.NET CLR 3.5.30729)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.1) Gecko/20090715 Firefox/3.5.1 (.NET CLR 3.5.30729)

When using setTimeout to select an input field the call fails unless there is a extra "()" which doesn't make sense since the () indicate the execution of the function right away. 

function handler(){document.getElementById("field1").select();}

setTimeout(handler, 200);    //works	   
setTimeout(document.getElementById("field1").select, 200);      //doesn't work
setTimeout('document.getElementById("field1").select()', 200);  //works

The failed case gives the NS_ERROR_XPC_BAD_OP_ON_WN_PROTO exception


Reproducible: Always

Steps to Reproduce:
See Details
Actual Results:  
Error: uncaught exception: [Exception... "Illegal operation on WrappedNative prototype object"  nsresult: "0x8057000c (NS_ERROR_XPC_BAD_OP_ON_WN_PROTO)"  location: "<unknown>"  data: no]

Expected Results:  
The callback should be triggered as defined in the Mozilla setTimeout documentation.
(Reporter)

Updated

9 years ago
Version: unspecified → 3.5 Branch
(Reporter)

Comment 1

9 years ago
This is my sample test page

<!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">
<head>
    <title>setTimeout</title>
    <script type="text/javascript">        
		function handler(){	document.getElementById("field1").select();	}        
        function process()
        {
            //setTimeout('document.getElementById("field1").select()', 200);  //works
            //setTimeout(Core.handler, 200);    //works		   
            setTimeout(document.getElementById("field1").select, 200);      //doesn't work
        }
    </script>
</head>
<body>
    <button type="submit" onclick="process();">setTimeout</button>
    <input id="field1" type="text" value="text" />
</body>
</html>
Created attachment 502375 [details]
Test case
On first sight, looks like this happens with all native methods.
Assignee: nobody → general
Severity: major → normal
Status: UNCONFIRMED → NEW
Component: General → JavaScript Engine
Ever confirmed: true
Keywords: testcase
OS: Windows Vista → All
Product: Firefox → Core
QA Contact: general → general
Hardware: x86 → All
Version: 3.5 Branch → Trunk
This is the right behavior.  setTimeout runs its first argument with the |this| object set to the window.  So you're trying to do, basically:

  document.getElementById("field1").select.call(window);

The |select| method has no idea what to do with a |this| that's a Window; it only knows what to do with an HTMLInputElement |this|.  So it throws.  What were you expecting this code to do, exactly?  If the idea was to select the field after a timeout, then your "handler" approach is the right way to do that.
Status: NEW → RESOLVED
Last Resolved: 7 years ago
Resolution: --- → INVALID
And another note: NONE of this involves the JS engine.  This is all DOM/XPConnect stuff.
Assignee: general → nobody
Component: JavaScript Engine → DOM
QA Contact: general → general
You need to log in before you can comment on or make changes to this bug.