Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Script instead of eval for jQuery example
- Loading branch information
Jos Shepherd
committed
Jun 21, 2010
1 parent
d8ba99d
commit 40791ad
Showing
1 changed file
with
8 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
|
||
}); |