Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
5164f4a8
...
5164f4a883f33701e7f269d92facc986bce77e93
authored
2013-02-22 22:13:59 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
cleaner code, refactor of native phantomjs require() use
1 parent
165ed0a8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
29 deletions
bin/bootstrap.js
bin/bootstrap.js
View file @
5164f4a
...
...
@@ -69,30 +69,28 @@ if (typeof Function.prototype.bind !== "function") {
*/
function
patchRequire
(
require
)
{
"use strict"
;
require
=
require
||
window
.
require
;
if
(
require
.
patched
)
{
return
require
;
}
var
patchedRequire
=
function
_require
(
path
)
{
var
fs
=
require
(
'fs'
),
moduleFilePath
;
if
(
phantom
.
casperBuiltIns
.
indexOf
(
path
)
===
-
1
)
{
return
require
(
path
);
var
fs
=
require
(
'fs'
);
var
moduleFilePath
=
fs
.
pathJoin
(
phantom
.
casperPath
,
'modules'
,
path
+
'.js'
);
if
(
!
fs
.
exists
(
moduleFilePath
))
{
return
require
(
path
);
// native phantomjs' require() behavior
}
try
{
moduleFilePath
=
fs
.
pathJoin
(
phantom
.
casperModulesPath
,
path
+
'.js'
);
return
require
(
moduleFilePath
);
}
catch
(
e
)
{
if
(
moduleFilePath
)
{
var
error
=
new
window
.
CasperError
(
'__mod_error('
+
path
+
':'
+
e
.
line
+
'):: '
+
e
);
error
.
file
=
moduleFilePath
;
error
.
line
=
e
.
line
;
error
.
stack
=
e
.
stack
;
error
.
stackArray
=
JSON
.
parse
(
JSON
.
stringify
(
e
.
stackArray
));
if
(
error
.
stackArray
.
length
>
0
)
{
error
.
stackArray
[
0
].
sourceURL
=
moduleFilePath
;
}
throw
error
;
var
error
=
new
window
.
CasperError
(
'__mod_error('
+
path
+
':'
+
e
.
line
+
'):: '
+
e
);
error
.
file
=
moduleFilePath
;
error
.
line
=
e
.
line
;
error
.
stack
=
e
.
stack
;
error
.
stackArray
=
JSON
.
parse
(
JSON
.
stringify
(
e
.
stackArray
));
if
(
error
.
stackArray
.
length
>
0
)
{
error
.
stackArray
[
0
].
sourceURL
=
moduleFilePath
;
}
throw
e
;
throw
e
rror
;
}
};
patchedRequire
.
cache
=
require
.
cache
;
...
...
@@ -179,20 +177,6 @@ function bootstrap(global) {
// standard Error prototype inheritance
global
.
CasperError
.
prototype
=
Object
.
getPrototypeOf
(
new
Error
());
// path to standard casperjs modules directory
phantom
.
casperModulesPath
=
fs
.
pathJoin
(
phantom
.
casperPath
,
'modules'
);
// computing casperjs builtin modules list once for all
phantom
.
casperBuiltIns
=
(
function
getBuiltins
()
{
var
fs
=
require
(
'fs'
);
return
fs
.
list
(
phantom
.
casperModulesPath
).
filter
(
function
(
entry
)
{
var
absPath
=
fs
.
absolute
(
fs
.
pathJoin
(
phantom
.
casperModulesPath
,
entry
));
return
entry
!==
"."
&&
entry
!==
".."
&&
!
fs
.
isDirectory
(
absPath
);
}).
map
(
function
(
moduleFile
)
{
return
moduleFile
.
replace
(
/
\.
js$/
,
''
);
});
})();
// CasperJS version, extracted from package.json - see http://semver.org/
phantom
.
casperVersion
=
(
function
getVersion
(
path
)
{
var
parts
,
patchPart
,
pkg
,
pkgFile
;
...
...
Please
register
or
sign in
to post a comment