Permalink
Browse files

Added try/catch to WindowContext, to make sure we clear the context.

  • Loading branch information...
assaf committed Feb 21, 2011
1 parent cffd7ac commit 9dd2f1b31a5873c5f37e582d52b2ec8465125f06
Showing with 15 additions and 4 deletions.
  1. +8 −0 spec/script-spec.coffee
  2. +1 −1 src/zombie/browser.coffee
  3. +4 −1 src/zombie/{windowcontext.cc → window_context.cc}
  4. +2 −2 wscript
View
@@ -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/error", (req, res)-> res.send "<script>foo.bar</script>"
+
brains.get "/script/order", (req, res)-> res.send """
<html>
<head>
@@ -134,6 +136,12 @@ vows.describe("Scripts").addBatch(
"should be the same as this and top": (browser)-> assert.equal browser.text("title"), "true,true"
###
+ "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]
+
"script order":
zombie.wants "http://localhost:3003/script/order"
"should run scripts in order regardless of source": (browser)-> assert.equal browser.text("title"), "ZeroOneTwo"
@@ -7,7 +7,7 @@ require "./xpath"
History = require("./history").History
EventLoop = require("./eventloop").EventLoop
require.paths.push "../../build/default"
-WindowContext = require("../../build/default/windowcontext").WindowContext
+WindowContext = require("../../build/default/window_context").WindowContext
# Use the browser to open up new windows and load documents.
@@ -153,6 +153,7 @@ class WindowContext: ObjectWrap {
static Handle<Value> Evaluate(const Arguments& args) {
WindowContext* wc = ObjectWrap::Unwrap<WindowContext>(args.This());
Handle<Value> result;
+ TryCatch trycatch;
wc->context->Enter();
if (args[0]->IsFunction()) {
// Execute function in the global scope.
@@ -166,6 +167,8 @@ class WindowContext: ObjectWrap {
result = script->Run();
}
wc->context->Exit();
+ if (result.IsEmpty())
+ trycatch.ReThrow();
return result;
}
@@ -239,5 +242,5 @@ extern "C" {
static void init(Handle<Object> target) {
WindowContext::Init(target);
}
- NODE_MODULE(windowcontext, init);
+ NODE_MODULE(window_context, init);
}
View
@@ -7,5 +7,5 @@ def configure(conf):
def build(bld):
obj = bld.new_task_gen("cxx", "shlib", "node_addon")
- obj.target = "windowcontext"
- obj.source = "src/zombie/windowcontext.cc"
+ obj.target = "window_context"
+ obj.source = "src/zombie/window_context.cc"

0 comments on commit 9dd2f1b

Please sign in to comment.