Permalink
Browse files

Use Script instead of eval for jQuery example

  • Loading branch information...
1 parent d8ba99d commit 40791ada7fdba155a6d202fef093cbdb6039c407 Jos Shepherd committed Jun 21, 2010
Showing with 8 additions and 13 deletions.
  1. +8 −13 example/jquery/run.js
View
@@ -1,22 +1,17 @@
-var sys = require("sys"), fs = require("fs");
+var sys = require("sys"), fs = require("fs");
var dom = require("../../lib/jsdom/level1/core").dom.level1.core;
var window = require("../../lib/jsdom/browser").windowAugmentation(dom).window;
-var document = window.document;
-var location = window.location;
-var navigator = window.navigator;
+var Script = process.binding('evals').Script;
fs.readFile(__dirname + "/jquery.js", function(err, data) {
-
+
try {
- eval(data.toString());
- } catch (e) {
- sys.puts(sys.inspect(e.stack, true));
+ Script.runInNewContext(data.toString(), {window: window, location: window.location, navigator: window.navigator});
+ } catch(e){
+ sys.puts(sys.inspect(e));
}
-
- // Doing this requires you setup a parser, easiest way is to put node-htmlparser.js into
- // ~/.node_libraries/
-
- window.jQuery(document.body).append("<div class='testing'>Hello World, It works!</div>");
+ window.jQuery('body').append("<div class='testing'>Hello World, It works!</div>");
sys.puts(window.jQuery(".testing").text());
+
});

0 comments on commit 40791ad

Please sign in to comment.