/usr/lib/nodejs/jsdom/utils.js is in node-jsdom 0.8.10+dfsg1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | var path = require('path');
/**
* Intercepts a method by replacing the prototype's implementation
* with a wrapper that invokes the given interceptor instead.
*
* utils.intercept(core.Element, 'inserBefore',
* function(_super, args, newChild, refChild) {
* console.log('insertBefore', newChild, refChild);
* return _super.apply(this, args);
* }
* );
*/
exports.intercept = function(clazz, method, interceptor) {
var proto = clazz.prototype,
_super = proto[method],
unwrapArgs = interceptor.length > 2;
proto[method] = function() {
if (unwrapArgs) {
var args = Array.prototype.slice.call(arguments);
args.unshift(_super, arguments);
return interceptor.apply(this, args);
}
else {
return interceptor.call(this, _super, arguments);
}
};
};
exports.toFileUrl = function (fileName) {
// Beyond just the `path.resolve`, this is mostly for the benefit of Windows,
// where we need to convert '\' to '/' and add an extra '/' prefix before the
// drive letter.
var pathname = path.resolve(process.cwd(), fileName).replace(/\\/g, '/');
if (pathname[0] !== '/') {
pathname = '/' + pathname;
}
return 'file://' + pathname;
};
|