Skip to content
Browse files

Fixes seg fault when Zombie fails to compile a script.

  • Loading branch information...
1 parent 391d3ce commit a29425f2eaadd0efc378a2fac77b8f7bb7dab43d @assaf assaf committed Feb 21, 2011
Showing with 24 additions and 5 deletions.
  1. +8 −0 CHANGELOG.md
  2. +9 −1 spec/script-spec.coffee
  3. +7 −4 src/zombie/window_context.cc
View
8 CHANGELOG.md
@@ -1,6 +1,14 @@
zombie.js-changelog(7) -- Changelog
===================================
+### Version 0.9.3 2011-02-22
+
+Fixes seg fault when Zombie fails to compile a script.
+
+ 293 Tests
+ 3.3 sec to complete
+
+
### Version 0.9.2 2011-02-21
Fixes a couple of specs, plugs hole in array to prevent segfaults, and
View
10 spec/script-spec.coffee
@@ -12,6 +12,8 @@ brains.get "/script/context", (req, res)-> res.send """
brains.get "/script/window", (req, res)-> res.send "<script>document.title = [window == this, this == window.window].join(',')</script>"
+brains.get "/script/incomplete", (req, res)-> res.send "<script>1 +</script>"
+
brains.get "/script/error", (req, res)-> res.send "<script>foo.bar</script>"
brains.get "/script/order", (req, res)-> res.send """
@@ -136,11 +138,17 @@ vows.describe("Scripts").addBatch(
"should be the same as this and top": (browser)-> assert.equal browser.text("title"), "true,true"
###
+ "script incomplete":
+ topic: ->
+ browser = new zombie.Browser
+ browser.wants "http://localhost:3003/script/incomplete", (err, browser)=> @callback null, err
+ "should propagate error to window": (error)-> assert.equal error.message, "Unexpected end of input"
+
"script error":
topic: ->
browser = new zombie.Browser
browser.wants "http://localhost:3003/script/error", (err, browser)=> @callback null, err
- "should propagate error to window": (error)-> assert.deepEqual error.arguments, ["bar", undefined]
+ "should propagate error to window": (error)-> assert.equal error.message, "Cannot read property 'bar' of undefined"
"script order":
zombie.wants "http://localhost:3003/script/order"
View
11 src/zombie/window_context.cc
@@ -163,11 +163,14 @@ class WindowContext: ObjectWrap {
// Coerce argument into a string and execute that as a function.
Local<String> source = args[0]->ToString();
Local<String> filename = args[1]->ToString();
- Handle<Script> script = Script::New(source, filename);
- result = script->Run();
+ Handle<Script> script = Script::Compile(source, filename);
+ // Don't run script if it failed to compile, but go through cleanup
+ // before rethrowing exception.
+ if (!trycatch.HasCaught())
+ result = script->Run();
}
wc->context->Exit();
- if (result.IsEmpty())
+ if (trycatch.HasCaught())
trycatch.ReThrow();
return result;
}
@@ -229,7 +232,7 @@ SetPrimitive *WindowContext::primitives[] = {
new SetPrimitive("encodeURI"),
new SetPrimitive("encodeURIComponent"),
new SetPrimitive("escape"),
- new SetPrimitive("eval"),
+ //new SetPrimitive("eval"),
new SetPrimitive("isFinite"),
new SetPrimitive("isNaN"),
new SetPrimitive("parseFloat"),

0 comments on commit a29425f

Please sign in to comment.
Something went wrong with that request. Please try again.