Closed Bug 121804 Opened 23 years ago Closed 23 years ago

JS Variables defined on external JS file cannot be used

Categories

(SeaMonkey :: General, defect)

x86
Windows 2000
defect
Not set
major

Tracking

(Not tracked)

VERIFIED INVALID

People

(Reporter: vicentesalvador, Assigned: asa)

Details

(Whiteboard: [js1.2])

Variables declared on an imported JS file; <script src='test.js'> </script> are undefined inside the main document. This is the test case: test.html <html> <head> <script src='test.js'> </script> </head> <body> hello, an alert with the a variable value should appear... <script> alert("m_attributes: " + a); </script> </body> </html> test.js a = "12"; The script throws an error because variable a is undefined !!!!
Openning directly the file test.js show me garbage... ▀*яPrttTр╢ФБJT╟UP24R╡ФJ+мK.илоSхHмиивпT╗VЮБ,J-)-йSP▀)$'ФД╓╕ХвZs
This is really a bad issue. After more investigation. I've seen that the sample code is functional. The problem is when opening a HTML page importing a lot of JS. Each JS files has relationships on others because on one file is defined some objects and on others are defined variables with this object definition. This complex sample works fine when executed from filesystem files but fails if executed from a HTTP server. It seems to be an JS synchonism issue. What can I do to give you more info???
This is not going to be a problem with the JS Engine itself, but how external JS files are loaded by the browser. Reassigning to Browser-General until we can get further information.
Assignee: rogerl → asa
Component: JavaScript Engine → Browser-General
QA Contact: pschwartau → doronr
Vicente, what URL is not working for you? Could you paste it in the URL field above? Thanks - Note: as Vicente says, the reduced testcase in the bug report above works fine in Mozilla. It's only in certain situations that we see this bug. I'm pretty sure this is a duplicate of bug 118404, "External JS files not loading; fixed by making new Profile". I will mark this as a duplicate and ask Vincente to verify. Vicente, could you could you try the URL with a new profile? To do this, launch Mozilla from the command line as follows: [(path to Mozilla)] ./mozilla.exe -profilemanager When the Profile Manager comes up, there's a button called "Create Profile". If that works, you can mark this bug "Verified" as a Duplicate. If it doesn't work, you can reopen it; thanks. Vicente: note, you will be cc'ed on bug 118404 so you can follow its progress - *** This bug has been marked as a duplicate of 118404 ***
Status: UNCONFIRMED → RESOLVED
Closed: 23 years ago
Resolution: --- → DUPLICATE
I've tested it with a new profile and the problem remains. I'm trying to create a testcase becasue the URL with the problem is user-password protected. I've isolated the page with a Page "Save As", putted it inside the Web Server and loaded and IT WORKS!!!. So, it seems to be a delay problem when the HTTP server send a external JS that is generated dinamically by the server. I'm going to Reopen the bug. If you contact me, I can give you a user-password to test. I cannot publish here this data for security reasons!!!
Status: RESOLVED → UNCONFIRMED
Resolution: DUPLICATE → ---
OK, I've got it!!! But it's still hard to reproduce. I can give some tips and request you some help. I've this command inside the html code: <script type="text/javascript" language="javascript1.2" src="/servlet/jrep_js?code=capuntes&lang=en&dbms=demo_sports1"></script> This is a dynamic generated javascript, but the server redirects this URL to /servlet/jrep_js?code=capuntes&lang=en&dbms=demo_sports1/user=vsc and the code sended by the server is not evaluated. This works fine on NS4 and IE. This is the WebServer Log: 192.168.10.181 - vsc [28/Jan/2002:10:56:30 1000] "GET /servlet/jrep_js?code=wic_jdic_lbldata&lang=en&dbms=wic_icon HTTP/1.1" 302 654 192.168.10.181 - vsc [28/Jan/2002:10:56:30 1000] "GET /servlet/jrep_js?code=wic_jdic_lbldata&lang=en&dbms=wic_icon&user=vsc HTTP/1.1" 200 215
Confirming bug by using private userid/password. The site loads fine in NN4.7, but in Mozilla we get a series of alertboxes like: WARNING: field attribute not found in setFieldNoentry('gcompedh.dtogen') From http://www.mydeister.com/coreutils/jscript/jsql.js: // ========================================================== // setFieldNoentry // // Cambia el estado NOENTRY de un campo // ========================================================== function setFieldNoentry(name, value) { var field = getFieldByName(name); if (field) { var attr = __getColumnAttribute(name); if (attr != null) attr.isNoentrySoft = value; else alert("WARNING: field attribute not found in setFieldNoentry('" + name + etc. } where we have: function __getColumnAttribute(name) { if (m_ColumnAttributes) { var attr = m_ColumnAttributes[name]; if (attr) { if (attr.isValid) return attr; } } // Not found ot not valid return null; } The problem is that in Mozilla, we are falling into the "Not found" case of this function. By looking at this in the Mozilla JS Debugger, (Tasks > Tools > JavaScript Debugger), I could see that the variable m_ColumnAttributes is of type Array, but it is evaluating in Mozilla to an empty array : [ ]. The logic check if (m_ColumnAttributes) is equivalent to if (m_ColumnAttributes.toString()) Since m_ColumnAttributes is an empty array, m_ColumnAttributes.toString() is the empty string, and so the if-condition evaluates to false. Hence __getColumnAttribute() returns null, hence the alertboxes...
Status: UNCONFIRMED → NEW
Ever confirmed: true
Notes: 1. After all the alertboxes, the site seems to look the same as in NN4.7, and I see no errors in the Mozilla JavaScript Console 2. In NN4.7, there ARE two errors in the JavaScript Console: Javascript Error: http://www.mydeister.com/servlet/jrep_js?code=gcompedh&lang=en&dbms=demo_sports1 Line 1: illegal character JavaScript Error: http://www.mydeister.com/coreutils/jscript/jsql.js line 1679: m_ColumnAttributes is not defined. 3. Vicente informs me that the array variable m_ColumnAttributes is set in the servlet: http://www.mydeister.com/servlet/jrep_js?code=gcompedh&lang=en&dbms=demo_sports1 &user=mozilla
I think I've figured this out. Here is the result of using javascript: URLS to debug the site, both in IE6 and Mozilla: IE6 MOZILLA javascript:alert(m_ColumnAttributes) (empty alertbox) (empty alertbox) javascript:alert(m_ColumnAttributes instanceof Array) true true javascript:alert(m_ColumnAttributes.length) 0 0 javascript:alert(m_ColumnAttributes.toString() === "") true true javascript:if (m_ColumnAttributes.length) {alert('TRUE')} else {alert('FALSE')}; FALSE FALSE javascript:if (m_ColumnAttributes.toString()) {alert('TRUE')} else {alert('FALSE')}; FALSE FALSE javascript:if (m_ColumnAttributes) {alert('TRUE')} else {alert('FALSE')}; TRUE FALSE or TRUE!!! We see that Mozilla and IE6 both recognize m_ColumnAttributes as an Array object, both agree that is is empty; i.e. has length 0, and both agree that m_ColumnAttributes.toString() is the empty string. However, there is a disagreement on evaluating | if (m_ColumnAttributes) | IE6 evaluates this as true; Mozilla evaluates it as false or true, depending on which version of JavaScript the developer is using!!! The behavior of this changed in versions of JavaScript later than 1.2. In comment # 7 above, when I said: The logic check if (m_ColumnAttributes) is equivalent to if (m_ColumnAttributes.toString()) is not generally correct. That is what happens in version 1.2 of the Mozilla/Netscape implementation of JavaScript. In all later versions, what I said is not correct, and an empty array will evaluate to true. So the website must be using, I think <SCRIPT language="JavaScript1.2"> or something similar. Thus I have to mark this bug as invalid. The site is very well-designed, but one should use <SCRIPT language="JavaScript"> to get the current implementation of the language.
Status: NEW → RESOLVED
Closed: 23 years ago23 years ago
Resolution: --- → INVALID
Marking Verified. Here is an example from the Mozilla standalone JS shell. You can make a similar HTML example by making a page with this code inside a tag <SCRIPT language="JavaScript1.2"> then inside a tag <SCRIPT language="JavaScript1.3">, etc. etc. // make an empty array js> var arr = []; // or do var arr = new Array(); js> version(120); // don't try this in the browser, use <SCRIPT> versioning 120 js> if (arr) {print('TRUE')} else {print('FALSE')} FALSE js> version(130); 130 js> if (arr) {print('TRUE')} else {print('FALSE')} TRUE js> version(140); 140 js> if (arr) {print('TRUE')} else {print('FALSE')} TRUE js> version(150); 150 js> if (arr) {print('TRUE')} else {print('FALSE')} TRUE
Status: RESOLVED → VERIFIED
Confirming my theory; from the site's HTML: <head> <title>PURCHASE ORDERS (demo_sports1)</title> etc. <script TYPE='text/javascript' LANGUAGE='javascript1.2' SRC='/coreutils/jscript/load.js'></SCRIPT> <script TYPE='text/javascript' LANGUAGE='javascript1.2'> setBrowserStatus('en', 9); </SCRIPT> <script TYPE='text/javascript' LANGUAGE='javascript1.2' SRC='/coreutils/jscript/userfunc.js'></SCRIPT> <script TYPE='text/javascript' LANGUAGE='javascript1.2' SRC='/coreutils/jscript/locale.js'></SCRIPT> <script TYPE='text/javascript' LANGUAGE='javascript1.2' SRC='/coreutils/jscript/jrep_messages.js'></SCRIPT> <script TYPE='text/javascript' LANGUAGE='javascript1.2' SRC='/coreutils/jscript/hide.js'></SCRIPT> <script TYPE='text/javascript' LANGUAGE='javascript1.2' SRC='/coreutils/jscript/form.js'></SCRIPT> <script TYPE='text/javascript' LANGUAGE='javascript1.2' SRC='/coreutils/jscript/head.js'></SCRIPT> <script TYPE='text/javascript' LANGUAGE='javascript1.2' SRC='/coreutils/jscript/head0.js'></SCRIPT> <script TYPE='text/javascript' LANGUAGE='javascript1.2' SRC='/coreutils/jscript/jsqlglo.js'></SCRIPT> <script TYPE='text/javascript' LANGUAGE='javascript1.2' SRC='/coreutils/jscript/jsql.js'></SCRIPT> <script TYPE='text/javascript' LANGUAGE='javascript1.2'>
Better explanation: the comment by me in Comment #7 is INCORRECT IN ALL VERSIONS of the Netscape/Mozilla implementation of JS: The logic check if (m_ColumnAttributes) is equivalent to if (m_ColumnAttributes.toString()) These are NOT equivalent in ANY version of JS. What changed between versions is the behavior of Boolean() on an empty array: In JS1.2, an empty array has a NON-empty toString(): [].toString() == "[]" In JS1.2, however, Boolean([]) == false In JS1.3++, an empty array has an EMPTY toString() : [].toString() == "" In JS1.3++, however, Boolean([]) == true Here is a sample from the standalone JS shell: js> version(120); 120 js> var arr1 = [ ]; js> var arr2 = new Array(); js> arr1.toString(); [ ] js> arr2.toString(); [ ] js> Boolean(arr1.toString()); true js> Boolean(arr1); false js> Boolean(arr2.toString()); true js> Boolean(arr2); false -------------------------------------------------------------------------- -------------------------------------------------------------------------- js> version(150); 150 js> var arr1 = [ ]; js> var arr2 = new Array(); js> arr1.toString(); <--- the empty string js> arr2.toString(); <--- the empty string js> Boolean(arr1.toString()); false js> Boolean(arr1); true js> Boolean(arr2.toString()); false js> Boolean(arr2); true
Whiteboard: [js1.2]
Product: Browser → Seamonkey
You need to log in before you can comment on or make changes to this bug.