Commit f608e3cb f608e3cb019758b5188ce85757604149fa0e4c73 by Nicolas Perriault

closes #97 - De-anonymize all functions (bootstrap.js)

1 parent a19f2978
...@@ -28,28 +28,28 @@ ...@@ -28,28 +28,28 @@
28 * 28 *
29 */ 29 */
30 30
31 phantom.loadCasper = function() { 31 phantom.loadCasper = function loadCasper() {
32 // Patching fs 32 // Patching fs
33 // TODO: watch for these methods being implemented in official fs module 33 // TODO: watch for these methods being implemented in official fs module
34 var fs = (function(fs) { 34 var fs = (function _fs(fs) {
35 if (!fs.hasOwnProperty('basename')) { 35 if (!fs.hasOwnProperty('basename')) {
36 fs.basename = function(path) { 36 fs.basename = function basename(path) {
37 return path.replace(/.*\//, ''); 37 return path.replace(/.*\//, '');
38 }; 38 };
39 } 39 }
40 if (!fs.hasOwnProperty('dirname')) { 40 if (!fs.hasOwnProperty('dirname')) {
41 fs.dirname = function(path) { 41 fs.dirname = function dirname(path) {
42 return path.replace(/\\/g, '/').replace(/\/[^\/]*$/, ''); 42 return path.replace(/\\/g, '/').replace(/\/[^\/]*$/, '');
43 }; 43 };
44 } 44 }
45 if (!fs.hasOwnProperty('isWindows')) { 45 if (!fs.hasOwnProperty('isWindows')) {
46 fs.isWindows = function() { 46 fs.isWindows = function isWindows() {
47 var testPath = arguments[0] || this.workingDirectory; 47 var testPath = arguments[0] || this.workingDirectory;
48 return (/^[a-z]{1,2}:/i).test(testPath) || testPath.indexOf("\\\\") === 0; 48 return (/^[a-z]{1,2}:/i).test(testPath) || testPath.indexOf("\\\\") === 0;
49 }; 49 };
50 } 50 }
51 if (!fs.hasOwnProperty('pathJoin')) { 51 if (!fs.hasOwnProperty('pathJoin')) {
52 fs.pathJoin = function() { 52 fs.pathJoin = function pathJoin() {
53 return Array.prototype.join.call(arguments, this.separator); 53 return Array.prototype.join.call(arguments, this.separator);
54 }; 54 };
55 } 55 }
...@@ -59,12 +59,12 @@ phantom.loadCasper = function() { ...@@ -59,12 +59,12 @@ phantom.loadCasper = function() {
59 // casper root path 59 // casper root path
60 if (!phantom.casperPath) { 60 if (!phantom.casperPath) {
61 try { 61 try {
62 phantom.casperPath = phantom.args.map(function(i) { 62 phantom.casperPath = phantom.args.map(function _map(i) {
63 var match = i.match(/^--casper-path=(.*)/); 63 var match = i.match(/^--casper-path=(.*)/);
64 if (match) { 64 if (match) {
65 return fs.absolute(match[1]); 65 return fs.absolute(match[1]);
66 } 66 }
67 }).filter(function(path) { 67 }).filter(function _filter(path) {
68 return fs.isDirectory(path); 68 return fs.isDirectory(path);
69 }).pop(); 69 }).pop();
70 } catch (e) {} 70 } catch (e) {}
...@@ -82,7 +82,7 @@ phantom.loadCasper = function() { ...@@ -82,7 +82,7 @@ phantom.loadCasper = function() {
82 phantom.sourceIds = {}; 82 phantom.sourceIds = {};
83 83
84 // custom global CasperError 84 // custom global CasperError
85 window.CasperError = function(msg) { 85 window.CasperError = function CasperError(msg) {
86 Error.call(this); 86 Error.call(this);
87 try { 87 try {
88 // let's get where this error has been thrown from, if we can 88 // let's get where this error has been thrown from, if we can
...@@ -98,7 +98,7 @@ phantom.loadCasper = function() { ...@@ -98,7 +98,7 @@ phantom.loadCasper = function() {
98 window.CasperError.prototype = Object.getPrototypeOf(new Error()); 98 window.CasperError.prototype = Object.getPrototypeOf(new Error());
99 99
100 // Stack formatting 100 // Stack formatting
101 window.CasperError.prototype.formatStack = function() { 101 window.CasperError.prototype.formatStack = function formatStack() {
102 var location = this.fileName || phantom.sourceIds[this.sourceId] || "unknown"; 102 var location = this.fileName || phantom.sourceIds[this.sourceId] || "unknown";
103 location += ':' + (this.line ? this.line : 0); 103 location += ':' + (this.line ? this.line : 0);
104 return this.toString() + '\n ' + (this._from || "anonymous") + '() at ' + location; 104 return this.toString() + '\n ' + (this._from || "anonymous") + '() at ' + location;
...@@ -111,10 +111,10 @@ phantom.loadCasper = function() { ...@@ -111,10 +111,10 @@ phantom.loadCasper = function() {
111 */ 111 */
112 if (!new CasperError().hasOwnProperty('stack')) { 112 if (!new CasperError().hasOwnProperty('stack')) {
113 Object.defineProperty(CasperError.prototype, 'stack', { 113 Object.defineProperty(CasperError.prototype, 'stack', {
114 set: function(string) { 114 set: function set(string) {
115 this._stack = string; 115 this._stack = string;
116 }, 116 },
117 get: function() { 117 get: function get() {
118 if (this._stack) { 118 if (this._stack) {
119 return this._stack; 119 return this._stack;
120 } 120 }
...@@ -148,7 +148,7 @@ phantom.loadCasper = function() { ...@@ -148,7 +148,7 @@ phantom.loadCasper = function() {
148 minor: ~~parts[1] || 0, 148 minor: ~~parts[1] || 0,
149 patch: ~~patchPart[0] || 0, 149 patch: ~~patchPart[0] || 0,
150 ident: patchPart[1] || "", 150 ident: patchPart[1] || "",
151 toString: function() { 151 toString: function toString() {
152 var version = [this.major, this.minor, this.patch].join('.'); 152 var version = [this.major, this.minor, this.patch].join('.');
153 if (this.ident) { 153 if (this.ident) {
154 version = [version, this.ident].join('-'); 154 version = [version, this.ident].join('-');
...@@ -164,7 +164,7 @@ phantom.loadCasper = function() { ...@@ -164,7 +164,7 @@ phantom.loadCasper = function() {
164 * @param String file The path to the file 164 * @param String file The path to the file
165 * @param Function|null onError An error callback (optional) 165 * @param Function|null onError An error callback (optional)
166 */ 166 */
167 phantom.getScriptCode = function(file, onError) { 167 phantom.getScriptCode = function getScriptCode(file, onError) {
168 var scriptCode = fs.read(file); 168 var scriptCode = fs.read(file);
169 if (/\.coffee$/i.test(file)) { 169 if (/\.coffee$/i.test(file)) {
170 try { 170 try {
...@@ -191,7 +191,7 @@ phantom.loadCasper = function() { ...@@ -191,7 +191,7 @@ phantom.loadCasper = function() {
191 * @param String file A file path to associate to this error 191 * @param String file A file path to associate to this error
192 * @param Function callback An optional callback 192 * @param Function callback An optional callback
193 */ 193 */
194 phantom.processScriptError = function(error, file, callback) { 194 phantom.processScriptError = function processScriptError(error, file, callback) {
195 if (!this.sourceIds.hasOwnProperty(error.sourceId)) { 195 if (!this.sourceIds.hasOwnProperty(error.sourceId)) {
196 this.sourceIds[error.sourceId] = file; 196 this.sourceIds[error.sourceId] = file;
197 } 197 }
...@@ -212,11 +212,11 @@ phantom.loadCasper = function() { ...@@ -212,11 +212,11 @@ phantom.loadCasper = function() {
212 * Inspired by phantomjs-nodify: https://github.com/jgonera/phantomjs-nodify/ 212 * Inspired by phantomjs-nodify: https://github.com/jgonera/phantomjs-nodify/
213 * TODO: remove when PhantomJS has full module support 213 * TODO: remove when PhantomJS has full module support
214 */ 214 */
215 require = (function(require, requireDir) { 215 require = (function _require(require, requireDir) {
216 var phantomBuiltins = ['fs', 'webpage', 'webserver']; 216 var phantomBuiltins = ['fs', 'webpage', 'webserver'];
217 var phantomRequire = phantom.__orig__require = require; 217 var phantomRequire = phantom.__orig__require = require;
218 var requireCache = {}; 218 var requireCache = {};
219 return function(path) { 219 return function _require(path) {
220 var i, dir, paths = [], 220 var i, dir, paths = [],
221 fileGuesses = [], 221 fileGuesses = [],
222 file, 222 file,
...@@ -243,7 +243,7 @@ phantom.loadCasper = function() { ...@@ -243,7 +243,7 @@ phantom.loadCasper = function() {
243 paths.push(fs.pathJoin(requireDir, 'lib', path)); 243 paths.push(fs.pathJoin(requireDir, 'lib', path));
244 paths.push(fs.pathJoin(requireDir, 'modules', path)); 244 paths.push(fs.pathJoin(requireDir, 'modules', path));
245 } 245 }
246 paths.forEach(function(testPath) { 246 paths.forEach(function _forEach(testPath) {
247 fileGuesses.push.apply(fileGuesses, [ 247 fileGuesses.push.apply(fileGuesses, [
248 testPath, 248 testPath,
249 testPath + '.js', 249 testPath + '.js',
...@@ -287,7 +287,7 @@ phantom.loadCasper = function() { ...@@ -287,7 +287,7 @@ phantom.loadCasper = function() {
287 phantom.casperLoaded = true; 287 phantom.casperLoaded = true;
288 }; 288 };
289 289
290 phantom.initCasperCli = function() { 290 phantom.initCasperCli = function initCasperCli() {
291 var fs = require("fs"); 291 var fs = require("fs");
292 292
293 if (!!phantom.casperArgs.options.version) { 293 if (!!phantom.casperArgs.options.version) {
......