Global variable declaration issue in IE7 #68

seanhodges opened this Issue Apr 17, 2012 · 4 comments


None yet

3 participants


This does not occur in IE9, I have not tested others...

Instantiating the parser in IE7 causes the following Javascript error to occur:

"TypeError: 'S' is undefined"

Moving the declaration of 'S' further up the script (above the SAXParser constructor) fixes the problem, but then chokes during a parse on the 'whitespace' global variable:

"TypeError: 'whitespace' is undefined"

Again, the workaround is to move 'whitespace' above the constructor. Finally, IE7 does not support the Object.create function:

"TypeError: Object doesn't support this property or method"

I added Crockford's Object.create implementation in my own code to support this, however I believe you have a declaration in sax.js that might work by moving up the script as well.


I have attached below a dirty patch for my fix - sorry I don't have a lot of time to fork and patch upstream right now:

Index: lib/sax.js
--- lib/sax.js  (revision 32424)
+++ lib/sax.js  (revision 32425)
@@ -43,6 +43,92 @@
   , "closenamespace"
+// SEAN: Moved this declaration block here to support IE7...
+var S = 0
+sax.STATE =
+{ BEGIN                     : S++
+    , TEXT                      : S++ // general stuff
+    , TEXT_ENTITY               : S++ // & and such.
+    , OPEN_WAKA                 : S++ // <
+    , SGML_DECL                 : S++ // 
+    , SCRIPT                    : S++ // 

You can fork this project, applies the fixes, send a pull request. In the commit reference "Fixes #68" to close this issue


The above fix was a quick-and-dirty hack and has not been checked against the test suite. Once I get time I'll fork and test it properly; but in the meantime the patch above gives an opportunity for someone else to apply the same workaround or suggest a more elegant fix.


@seanhodges On the blob page on github, you can actually edit the file right there, and then it'll automatically make a pull req for you.

I am willing to accept contributions on this, but please send a patch via a pull request, or you can use the more oldschool method:

git clone git://
cd sax-js
# make your changes
git commit -m "Fix #68 Some reasonable short message goes here"
git format-patch HEAD^
# that creates a file like 0001-Fix-68-Some-reasonable-short-message-goes-here.patch
# get that file to me. is a common way to do that.  email works, too.

The patch should not have a block comment with your name. That's what commit history is for. We can always git blame to see where code came from much more effectively :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment