-
-
Notifications
You must be signed in to change notification settings - Fork 325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Global variable declaration issue in IE7 #68
Comments
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++ // <script> ... + , SCRIPT_ENDING : S++ // <script> ... < +} + +sax.ENTITIES = +{ "apos" : "'" + , "quot" : "\"" + , "amp" : "&" + , "gt" : ">" + , "lt" : "<" +} + +for (var S in sax.STATE) sax.STATE[sax.STATE[S]] = S + +// shorthand +S = sax.STATE + + +// character classes and tokens +var whitespace = "\r\n\t " + // this really needs to be replaced with character classes. + // XML allows all manner of ridiculous numbers and digits. + , number = "0124356789" + , letter = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + // (Letter | "_" | ":") + , nameStart = letter+"_:" + , nameBody = nameStart+number+"-." + , quote = "'\"" + , entity = number+letter+"#" + , attribEnd = whitespace + ">" + , CDATA = "[CDATA[" + , DOCTYPE = "DOCTYPE" + , XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace" + , XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/" + , rootNS = { xml: XML_NAMESPACE, xmlns: XMLNS_NAMESPACE } + +// turn all the string character sets into character class objects. +whitespace = charClass(whitespace) +number = charClass(number) +letter = charClass(letter) +nameStart = charClass(nameStart) +nameBody = charClass(nameBody) +quote = charClass(quote) +entity = charClass(entity) +attribEnd = charClass(attribEnd) + +// SEAN: Declaration block end +///////////////////////////////////////// + function SAXParser (strict, opt) { if (!(this instanceof SAXParser)) return new SAXParser(strict, opt) @@ -223,34 +309,8 @@ -// character classes and tokens -var whitespace = "\r\n\t " - // this really needs to be replaced with character classes. - // XML allows all manner of ridiculous numbers and digits. - , number = "0124356789" - , letter = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" - // (Letter | "_" | ":") - , nameStart = letter+"_:" - , nameBody = nameStart+number+"-." - , quote = "'\"" - , entity = number+letter+"#" - , attribEnd = whitespace + ">" - , CDATA = "[CDATA[" - , DOCTYPE = "DOCTYPE" - , XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace" - , XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/" - , rootNS = { xml: XML_NAMESPACE, xmlns: XMLNS_NAMESPACE } -// turn all the string character sets into character class objects. -whitespace = charClass(whitespace) -number = charClass(number) -letter = charClass(letter) -nameStart = charClass(nameStart) -nameBody = charClass(nameBody) -quote = charClass(quote) -entity = charClass(entity) -attribEnd = charClass(attribEnd) - function charClass (str) { return str.split("").reduce(function (s, c) { s[c] = true @@ -266,58 +326,10 @@ return !charclass[c] } -var S = 0 -sax.STATE = -{ BEGIN : S++ -, TEXT : S++ // general stuff -, TEXT_ENTITY : S++ // & and such. -, OPEN_WAKA : S++ // < -, SGML_DECL : S++ // -, SCRIPT : S++ // <script> ... -, SCRIPT_ENDING : S++ // <script> ... < -} -sax.ENTITIES = -{ "apos" : "'" -, "quot" : "\"" -, "amp" : "&" -, "gt" : ">" -, "lt" : "<" -} - -for (var S in sax.STATE) sax.STATE[sax.STATE[S]] = S - -// shorthand -S = sax.STATE - function emit (parser, event, data) { parser[event] && parser[event](data) } |
You can |
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:
The patch should not have a block comment with your name. That's what commit history is for. We can always |
This does not occur in IE9, I have not tested others...
Instantiating the parser in IE7 causes the following Javascript error to occur:
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:
Again, the workaround is to move 'whitespace' above the constructor. Finally, IE7 does not support the Object.create function:
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.
The text was updated successfully, but these errors were encountered: