Closed Bug 163810 Opened 23 years ago Closed 23 years ago

Option Object created, own properties added, but Mozilla "forgets" them after some time.

Categories

(Core :: DOM: Core & HTML, defect, P2)

defect

Tracking

()

RESOLVED FIXED
mozilla1.2beta

People

(Reporter: bugzilla, Assigned: peterv)

Details

(Keywords: testcase)

Attachments

(2 files, 1 obsolete file)

User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020529 Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020529 The included HTML and Javascript code (see "Steps to Reproduce") is an example for dynamically creating selectbox options. The code also adds the attribute "param" to each created option object. This "param" property is checked 1. after the body has loaded (body onload handler) 2. and again 2 seconds later On Netscape 4.x and IE both alert boxes show the correct attribut value (check the text after the "->" arrow), but Mozilla 1.0 fails: The second query results in an "undefined" value. Now comes the tricky part: If you remove the comment from the "dummy" variable this script will work in Mozilla, i.e. keeping a global reference to options[] will remedy the problem. Reproducible: Always Steps to Reproduce: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Mozilla Option Properties Bug</title> </head> <body onload="alert('body onload check:'+checkit()); setTimeout('alert(\'2 seconds later check:\'+checkit())',2000);"> <h2>Mozilla Selecbox Options Scripting Bug</h2> <form name="dkdk"> <select name="myparam" size=1 onchange="alert('this: '+this.options[this.selectedIndex].param);"> <option>Select . . . . . . . <option>Select . . . . . . . <option>Select . . . . . . . <option>Select . . . . . . . <option>Select . . . . . . . <option>Select . . . . . . . </select> </form> <script language="JavaScript"> // Activate line below to get correct results in Mozilla 1.0 // var dummy=document.dkdk.myparam.options; for (i=0;i<10;i++) { var nopt=new Option(); nopt.text="Test Option "+i; nopt.param="Parameter "+ i; // new property document.dkdk.myparam.options[i]=nopt; } // Query attribut "param" of selectbox option #1 function checkit() { return 'Select #1 -> '+document.dkdk.myparam.options[1].param; } </script> </body> </html> Actual Results: Two alert boxes pop up. The important result is the text after the "->" First alert box: "Parameter 1" Second:"undefined" Expected Results: First and second alert box: "Parameter 1"
This bug may relate to bug #138736. Indeed, if you use the script code provided there and replace "Image" by "Option", you get the same results, i.e. Option is not a constructor function any more.
Updating References: Bug #138736 is considered a duplicate of bug #146116 as of today. (2002-08-21 05:33 that is)
Peterv, was this the bug you were thinking about? :-) (on #mozilla) This should be fixed in nsHTMLOptionElement.cpp, when an option element is created we should get the node info manager from the document in the context where it's created, just like we do for new Image();. Easy fix, just copy what nsHTMLImageElement does. Over to peterv.
Assignee: jst → peterv
Status: UNCONFIRMED → NEW
Ever confirmed: true
Status: NEW → ASSIGNED
OS: Linux → All
Priority: -- → P2
Hardware: PC → All
Target Milestone: --- → mozilla1.2beta
Attached patch v1 (obsolete) — Splinter Review
Attachment #99038 - Flags: superreview+
Comment on attachment 99038 [details] [diff] [review] v1 - In nsContentUtils::GetDocumentFromCaller(): + if (cx) { ... + nsCOMPtr<nsIDOMWindowInternal> win(do_QueryInterface(sgo)); + if (!win) { + return; Sigh! 4-space indentation! :-) sr=jst
Comment on attachment 99038 [details] [diff] [review] v1 >+ /** >+ * Get the docshell through the JS context that's currently on the stack. >+ * If there's no JS context currently on the stack aDocShell will be null. >+ * >+ * @param aDocShell The docshell or null if no JS context >+ */ > static void GetDocShellFromCaller(nsIDocShell** aDocShell); >+ >+ /** >+ * Get the document through the JS context that's currently on the stack. >+ * If there's no JS context currently on the stack aDocument will be null. >+ * >+ * @param aDocument The document or null if no JS context >+ */ >+ static void GetDocumentFromCaller(nsIDOMDocument** aDocument); I'd prefer somewhat more distinguishing names for these functions as they do slightly different things (static vs. dynamic). A comment in the header would be ok too though with that, r=sicking
Attachment #99038 - Flags: review+
Actually, that's not needed. The functions do exactly the same thing, and this new function could (and actually should) use GetDynamicScriptGlobal() and not the static one (even though the script global you get in this case is the same one) since the dynamic version is potentially a bit faster. It doesn't really matter though, the point is that both these functions get the doc(shell) from the caller, that way one could even be based on the other. Peter, you could change the call to GetStaticScriptGlobal() to GetDynamicScriptGlobal() when you check in. sr=jst still applies.
Attached patch v2Splinter Review
Attachment #99038 - Attachment is obsolete: true
Attachment #99805 - Flags: superreview+
Checked in.
Status: ASSIGNED → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
added keywords
Component: DOM: Core → DOM: Core & HTML
QA Contact: stummala → general
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: