Skip to content
Browse files

[#37] Ugly but works.

  • Loading branch information...
1 parent a7f093e commit e652bb76b9737d9404d3f6e1115fdf60135ae385 @assaf committed Feb 15, 2011
Showing with 33 additions and 4 deletions.
  1. +29 −1 src/zombie/browser.coffee
  2. +4 −3 src/zombie/windowcontext.cc
View
30 src/zombie/browser.coffee
@@ -95,7 +95,35 @@ class Browser extends require("events").EventEmitter
newWindow = jsdom.createWindow(html)
newWindow._evalContext = new WindowContext(newWindow)
- newWindow._evaluate = (code, filename)-> window._evalContext.evaluate(code, filename)
+ global = newWindow._evalContext.global
+ global.decodeURI = decodeURI
+ global.decodeURIComponent = decodeURIComponent
+ global.encodeURI = encodeURI
+ global.encodeURIComponent = encodeURIComponent
+ global.escape = escape
+ global.eval = eval
+ global.isFinite = isFinite
+ global.isNaN = isNaN
+ global.parseFloat = parseFloat
+ global.parseInt = parseInt
+ global.unescape = unescape
+ global.Array = [].constructor
+ global.Boolean = Boolean
+ global.Date = Date
+ global.Error = Error
+ global.Function = Function
+ global.Math = Math
+ global.Number = Number
+ global.Object = {}.constructor
+ global.RegExp = //.constructor
+ global.String = newWindow._evalContext.evaluate("''.constructor")
+
+ newWindow._evaluate = (code, filename)->
+ try
+ newWindow._evalContext.evaluate(code, filename)
+ catch ex
+ console.log ex.message[0..500]
+ console.log ex.stack
# Switch to the newly created window if it's interactive.
# Examples of non-interactive windows are frames.
View
7 src/zombie/windowcontext.cc
@@ -22,8 +22,9 @@ class WindowContext: ObjectWrap {
s_ct->InstanceTemplate()->SetInternalFieldCount(1);
s_ct->SetClassName(String::NewSymbol("WindowContext"));
+ Local<ObjectTemplate> instance_t = t->InstanceTemplate();
+ instance_t->SetAccessor(String::New("global"), GetGlobal);
NODE_SET_PROTOTYPE_METHOD(s_ct, "evaluate", Evaluate);
- NODE_SET_PROTOTYPE_METHOD(s_ct, "global", GetGlobal);
target->Set(String::NewSymbol("WindowContext"), s_ct->GetFunction());
}
@@ -49,8 +50,8 @@ class WindowContext: ObjectWrap {
}
// Returns the global object.
- static Handle<Value> GetGlobal(const Arguments& args) {
- WindowContext* wc = ObjectWrap::Unwrap<WindowContext>(args.This());
+ static Handle<Value> GetGlobal(Local<String> name, const AccessorInfo& info) {
+ WindowContext* wc = ObjectWrap::Unwrap<WindowContext>(info.This());
return wc->global;
}

0 comments on commit e652bb7

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