Skip to content

Commit

Permalink
Tweak to in-line script processing to fix a problem no one reported.
Browse files Browse the repository at this point in the history
  • Loading branch information
assaf committed May 25, 2012
1 parent e6d5bc1 commit e9e9c77
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,11 @@ zombie.js-changelog(7) -- Changelog
===================================


## Version 1.1.6 2012-05-24

Tweak to in-line script processing to fix a problem no one reported.


## Version 1.1.5 2012-05-24

The `wait` function (and its derivatives) now return most recent error in
Expand Down
21 changes: 10 additions & 11 deletions lib/zombie/scripts.coffee
Expand Up @@ -44,18 +44,17 @@ addInlineScriptSupport = (document)->
# listens on the script element itself, and someone the event it captures
# doesn't have any of the script contents.
document.addEventListener "DOMNodeInserted", (event)->
# Get the script tag from the event itself
node = event.relatedNode
node = event.target # Node being inserted
return unless node.tagName == "SCRIPT"
# Don't handle scripts with src URL, JSDOM takes care of these
return if node.src
code = node.text
return unless code
# Only process supported languages
language = HTML.languageProcessors[node.language]
return unless language
# Queue so inline scripts execute in order with external scripts
HTML.resourceLoader.enqueue(node, -> language(this, code, document.location.href))()
# Process scripts in order.
HTML.resourceLoader.enqueue(node, ->
code = node.text
# Only process supported languages
language = HTML.languageProcessors[node.language]
if code && language
# Queue so inline scripts execute in order with external scripts
language(this, code, document.location.href)
)()
return


Expand Down
3 changes: 2 additions & 1 deletion test/script_test.coffee
Expand Up @@ -179,7 +179,8 @@ describe "Scripts", ->
</head>
<body>
<script>
document.title = document.title + "Two";</script>
document.title = document.title + "Two";
</script>
</body>
</html>
"""
Expand Down

0 comments on commit e9e9c77

Please sign in to comment.