Comparing version 0.7.0 to 0.8.0
@@ -218,2 +218,8 @@ var fs = require('fs'); | ||
if (config.document) { | ||
options.referrer = config.document.referrer; | ||
options.cookie = config.document.cookie; | ||
options.cookieDomain = config.document.cookieDomain; | ||
} | ||
var window = exports.html(config.html, null, options).createWindow(); | ||
@@ -231,7 +237,2 @@ var features = JSON.parse(JSON.stringify(window.document.implementation._features)); | ||
if (config.document) { | ||
window.document._referrer = config.document.referrer; | ||
window.document._cookie = config.document.cookie; | ||
} | ||
window.document.implementation.addFeature('FetchExternalResources', ['script']); | ||
@@ -238,0 +239,0 @@ window.document.implementation.addFeature('ProcessExternalResources', ['script']); |
@@ -9,53 +9,8 @@ var http = require('http'), | ||
jsdom = require('../../jsdom'), | ||
Location = require('./Location'), | ||
NOT_IMPLEMENTED = require('./utils').NOT_IMPLEMENTED, | ||
CSSStyleDeclaration = require('cssstyle').CSSStyleDeclaration, | ||
toFileUrl = require('../utils').toFileUrl, | ||
Contextify = null; | ||
Contextify = require('contextify'); | ||
try { | ||
Contextify = require('contextify'); | ||
} catch (e) { | ||
// Shim for when the contextify compilation fails. | ||
// This is not quite as correct, but it gets the job done. | ||
Contextify = function(sandbox) { | ||
var vm = require('vm'); | ||
var context = vm.createContext(sandbox); | ||
var global = null; | ||
sandbox.run = function(code, filename) { | ||
return vm.runInContext(code, context, filename); | ||
}; | ||
sandbox.getGlobal = function() { | ||
if (!global) { | ||
global = vm.runInContext('this', context); | ||
} | ||
return global; | ||
}; | ||
sandbox.dispose = function() { | ||
global = null; | ||
sandbox.run = function () { | ||
throw new Error("Called run() after dispose()."); | ||
}; | ||
sandbox.getGlobal = function () { | ||
throw new Error("Called getGlobal() after dispose()."); | ||
}; | ||
sandbox.dispose = function () { | ||
throw new Error("Called dispose() after dispose()."); | ||
}; | ||
}; | ||
return sandbox; | ||
}; | ||
} | ||
function NOT_IMPLEMENTED(target, nameForErrorMessage) { | ||
return function() { | ||
if (!jsdom.debugMode) { | ||
var raise = target ? target.raise : this.raise; | ||
raise.call(this, 'error', 'NOT IMPLEMENTED' + (nameForErrorMessage ? ': ' + nameForErrorMessage : '')); | ||
} | ||
}; | ||
} | ||
function matchesDontThrow(el, selector) { | ||
@@ -143,123 +98,11 @@ try { | ||
function DOMWindow(options) { | ||
var _href = (options || {}).url || toFileUrl(__filename); | ||
var _location = URL.parse(_href); | ||
this.location = {}; | ||
this.location.reload = NOT_IMPLEMENTED(this, 'location.reload'); | ||
var url = (options || {}).url || toFileUrl(__filename); | ||
this.location = new Location(url, this); | ||
var window = this.console._window = this; | ||
this.console._window = this; | ||
this.location.__defineGetter__("protocol", function() { | ||
return _location.protocol; | ||
}); | ||
this.location.__defineGetter__("host", function() { | ||
return _location.host; | ||
}); | ||
this.location.__defineGetter__("auth", function() { | ||
return _location.auth; | ||
}); | ||
this.location.__defineGetter__("hostname", function() { | ||
return _location.hostname; | ||
}); | ||
this.location.__defineGetter__("port", function() { | ||
return _location.port; | ||
}); | ||
this.location.__defineGetter__("pathname", function() { | ||
return _location.pathname; | ||
}); | ||
this.location.__defineGetter__("href", function() { | ||
return _location.href; | ||
}); | ||
this.location.__defineSetter__("href", function(val) { | ||
var oldUrl = _location.href; | ||
var oldProtocol = _location.protocol; | ||
var oldHost = _location.host; | ||
var oldPathname = _location.pathname; | ||
var oldHash = _location.hash || ""; | ||
_location = URL.parse(URL.resolve(oldUrl, val)); | ||
var newUrl = _location.href; | ||
var newProtocol = _location.protocol; | ||
var newHost = _location.host; | ||
var newPathname = _location.pathname; | ||
var newHash = _location.hash || ""; | ||
if (oldProtocol === newProtocol && oldHost === newHost && oldPathname === newPathname) { | ||
if (oldHash !== newHash && options && options.document) { | ||
var ev = options.document.createEvent('HTMLEvents'); | ||
ev.initEvent('hashchange', false, false); | ||
ev.oldUrl = oldUrl; | ||
ev.newUrl = newUrl; | ||
process.nextTick(function () { | ||
window.dispatchEvent(ev); | ||
}); | ||
} | ||
} else { | ||
NOT_IMPLEMENTED(this, 'location.href (no reload)')(); | ||
} | ||
}); | ||
this.location.__defineGetter__("hash", function() { | ||
return _location.hash || ""; | ||
}); | ||
this.location.__defineSetter__("hash", function(val) { | ||
var oldUrl = _location.href; | ||
var oldHash = _location.hash || ""; | ||
if (val.lastIndexOf('#', 0) !== 0) { | ||
val = '#' + val; | ||
} | ||
_location = URL.parse(URL.resolve(oldUrl, val)); | ||
var newUrl = _location.href; | ||
var newHash = _location.hash || ""; | ||
if (oldHash !== newHash && options && options.document) { | ||
var ev = options.document.createEvent('HTMLEvents'); | ||
ev.initEvent('hashchange', false, false); | ||
ev.oldUrl = oldUrl; | ||
ev.newUrl = newUrl; | ||
process.nextTick(function () { | ||
window.dispatchEvent(ev); | ||
}); | ||
} | ||
}); | ||
this.location.__defineGetter__("search", function() { | ||
return _location.search || ""; | ||
}); | ||
this.location.__defineSetter__("search", function(val) { | ||
var oldUrl = _location.href; | ||
var oldHash = _location.hash || ""; | ||
if (val.length) { | ||
if (val.lastIndexOf('?', 0) !== 0) { | ||
val = '?' + val; | ||
} | ||
_location = URL.parse(URL.resolve(oldUrl, val + oldHash)); | ||
} else { | ||
_location = URL.parse(oldUrl.replace(/\?([^#]+)/, '')); | ||
} | ||
//XXX NOT_IMPLEMENTED(this, 'location.search (no reload)')(); | ||
}); | ||
this.location.replace = function(val) { | ||
window.location.href = val; | ||
}; | ||
this.location.toString = function() { | ||
return _location.href; | ||
}; | ||
if (options && options.document) { | ||
options.document.location = this.location; | ||
} | ||
this.addEventListener = function() { | ||
@@ -381,5 +224,31 @@ dom.Node.prototype.addEventListener.apply(window, arguments); | ||
platform: process.platform, | ||
appVersion: process.version | ||
appVersion: process.version, | ||
noUI: true | ||
}, | ||
XMLHttpRequest: function XMLHttpRequest() {}, | ||
XMLHttpRequest: function() { | ||
var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; | ||
var xhr = new XMLHttpRequest(); | ||
var lastUrl = ''; | ||
xhr._open = xhr.open; | ||
xhr.open = function(method, url, async, user, password) { | ||
url = URL.resolve(options.url, url); | ||
lastUrl = url; | ||
return xhr._open(method, url, async, user, password); | ||
}; | ||
xhr._send = xhr.send; | ||
xhr.send = function(data) { | ||
if (window.document.cookie) { | ||
var cookieDomain = window.document._cookieDomain; | ||
var url = URL.parse(lastUrl); | ||
var host = url.host.split(':')[0]; | ||
if (host.indexOf(cookieDomain, host.length - cookieDomain.length) !== -1) { | ||
xhr.setDisableHeaderCheck(true); | ||
xhr.setRequestHeader('cookie', window.document.cookie); | ||
xhr.setDisableHeaderCheck(false); | ||
} | ||
} | ||
return xhr._send(data); | ||
}; | ||
return xhr; | ||
}, | ||
@@ -386,0 +255,0 @@ name: 'nodejs', |
@@ -51,3 +51,3 @@ var core = require("./core").dom.level2.core, | ||
if (url.hostname) { | ||
this.download(url, this.baseUrl(element._ownerDocument), this.enqueue(element, callback, full)); | ||
this.download(url, element._ownerDocument._cookie, element._ownerDocument._cookieDomain, this.baseUrl(element._ownerDocument), this.enqueue(element, callback, full)); | ||
} | ||
@@ -115,3 +115,3 @@ else { | ||
}, | ||
download: function(url, referrer, callback) { | ||
download: function(url, cookie, cookieDomain, referrer, callback) { | ||
var path = url.pathname + (url.search || ''), | ||
@@ -132,2 +132,8 @@ options = {'method': 'GET', 'host': url.hostname, 'path': path}, | ||
} | ||
if (cookie) { | ||
var host = url.host.split(':')[0]; | ||
if (host.indexOf(cookieDomain, host.length - cookieDomain.length) !== -1) { | ||
request.setHeader('cookie', cookie); | ||
} | ||
} | ||
@@ -139,3 +145,3 @@ request.on('response', function (response) { | ||
var redirect = URL.resolve(url, response.headers["location"]); | ||
core.resourceLoader.download(URL.parse(redirect), referrer, callback); | ||
core.resourceLoader.download(URL.parse(redirect), cookie, cookieDomain, referrer, callback); | ||
} else { | ||
@@ -387,2 +393,3 @@ callback(null, data); | ||
this._cookie = options.cookie; | ||
this._cookieDomain = options.cookieDomain || '127.0.0.1'; | ||
this._URL = options.url || '/'; | ||
@@ -389,0 +396,0 @@ this._documentRoot = options.documentRoot || Path.dirname(this._URL); |
{ | ||
"name": "jsdom", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"description": "A JavaScript implementation of the W3C DOM", | ||
@@ -68,2 +68,3 @@ "keywords": ["dom", "w3c", "html"], | ||
"request": "2.x", | ||
"xmlhttprequest": ">=1.5.0", | ||
"cssom": "~0.2.5", | ||
@@ -70,0 +71,0 @@ "cssstyle": "~0.2.3", |
@@ -129,4 +129,5 @@ # jsdom | ||
- `config.document`: | ||
- `referer`: the new document will have this referer | ||
- `cookie`: manually set a cookie value, e.g. `'key=value; expires=Wed, Sep 21 2011 12:00:00 GMT; path=/'` | ||
- `referer`: the new document will have this referer. | ||
- `cookie`: manually set a cookie value, e.g. `'key=value; expires=Wed, Sep 21 2011 12:00:00 GMT; path=/'`. | ||
- `cookieDomain`: a cookie domain for the manually set cookie; defaults to `127.0.0.1`. | ||
- `config.features` : see `Flexibility` section below. **Note**: the default feature set for jsdom.env does _not_ include fetching remote JavaScript and executing it. This is something that you will need to **carefully** enable yourself. | ||
@@ -283,23 +284,23 @@ | ||
``` | ||
level1/core 535/535 100% | ||
level1/html 238/238 100% | ||
level1/svg 527/527 100% | ||
level2/core 283/283 100% | ||
level2/html 706/706 100% | ||
level2/style 15/15 100% | ||
level2/extra 4/4 100% | ||
level2/events 24/24 100% | ||
level3/xpath 93/93 100% | ||
window/index 7/7 100% | ||
window/script 10/10 100% | ||
window/frame 16/16 100% | ||
sizzle/index 14/14 100% | ||
jsdom/index 87/87 100% | ||
jsdom/parsing 8/8 100% | ||
jsdom/env 13/13 100% | ||
jsonp/jsonp 1/1 100% | ||
browser/contextifyReplacement 4/4 100% | ||
browser/index 34/34 100% | ||
------------------------------------------------------ | ||
TOTALS: 0/2619 failed; 100% success | ||
level1/core 535/535 100% | ||
level1/html 238/238 100% | ||
level1/svg 527/527 100% | ||
level2/core 283/283 100% | ||
level2/html 706/706 100% | ||
level2/style 15/15 100% | ||
level2/extra 4/4 100% | ||
level2/events 24/24 100% | ||
level3/xpath 93/93 100% | ||
window/index 7/7 100% | ||
window/script 10/10 100% | ||
window/console 2/2 100% | ||
window/frame 16/16 100% | ||
sizzle/index 14/14 100% | ||
jsdom/index 76/76 100% | ||
jsdom/parsing 8/8 100% | ||
jsdom/env 25/25 100% | ||
jsonp/jsonp 1/1 100% | ||
browser/index 34/34 100% | ||
--------------------------------------- | ||
TOTALS: 0/2618 failed; 100% success | ||
``` | ||
@@ -306,0 +307,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
26
344
4
352010
7
10198
+ Addedxmlhttprequest@>=1.5.0
+ Addedxmlhttprequest@1.8.0(transitive)