Open Bug 352471 Opened 18 years ago Updated 2 years ago

JavaScript exception is not thrown when the script tag is appended to a container instead of document.

Categories

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

1.8 Branch
defect

Tracking

()

UNCONFIRMED

People

(Reporter: kem, Unassigned)

Details

User-Agent:       Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6
Build Identifier: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6

Hi Folks,

I am getting an expected exception when I append a scritp with incorrect source to the document object. But I am not getting any exceptions when I am appending the script to a container (div).

please take a look at my prototype.

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Exception Handling Bug Demo in WebKit</title>
<script type="text/javascript" language="javascript">

/**
 * This method is used to load 3rd party scripts.
 *
 * @author Kem Apak
 * @param uri The URI of the script file.
 */
function loadThirdPartyScript(uri) {
	
	var scriptElement = document.createElement('script');	
	
	scriptElement.type = 'text/javascript';
	scriptElement.language = 'javascript';
		
	try {
		scriptElement.src = uri;
		
		// Throws exception.
		//document.appendChild(scriptElement);
		
		// Throws no exception.		 
		document.getElementById('thirdPartyScriptContainer').appendChild(scriptElement);
		
	} catch(exception) {
		
		alert('exception :' + exception);
	} 
}
</script>
</head>
<body>

<div id="thirdPartyScriptContainer"></div>
<script type="text/javascript" language="javascript">
	loadThirdPartyScript('nonexistantScript.js');
</script>
</body>
</html>

Reproducible: Always

Steps to Reproduce:
1.please save the code above into as html file
2.load the page into firefox
3.no exceptions thrown 



Expected Results:  
An exception should be thrown and the code should go into the catch block.

Please let me know if you have questions. Thank you very much for your help.
Assignee: nobody → general
Component: General → DOM
Product: Firefox → Core
QA Contact: general → ian
Version: unspecified → 1.8 Branch
The document can itself have only one element appended to it, especially in XML.  That's why attaching it to the document directly is throwing an exception.

You're expecting an error to be thrown because the script doesn't exist, right?
Yes, I am expecting an exception because of a non existant script. Thanks for looking into the issue.
Assignee: general → nobody
QA Contact: ian → general
https://bugzilla.mozilla.org/show_bug.cgi?id=1472046

Move all DOM bugs that haven't been updated in more than 3 years and has no one currently assigned to P5.

If you have questions, please contact :mdaly.
Priority: -- → P5
Component: DOM → DOM: Core & HTML
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.