@@ -27,6 +27,7 @@ var Module;
2727var Perl = {
2828 trace : false , // user may enable this
2929 endAfterMain : false , // user may enable this (before Perl.init)
30+ Util : { } ,
3031 // internal variables:
3132 initStepsLeft : 2 , // Must match number of Perl.initStepFinished() calls!
3233 state : "Uninitialized" ,
@@ -179,18 +180,21 @@ var getScriptURL = (function() { // with thanks to https://stackoverflow.com/a/2
179180 return function ( ) { return myScript . src ; } ;
180181} ) ( ) ;
181182
183+ Perl . Util . baseurl = function ( urlstr ) {
184+ var url = new URL ( urlstr ) ;
185+ if ( url . protocol == 'file:' )
186+ return url . href . substring ( 0 , url . href . lastIndexOf ( '/' ) ) ;
187+ else
188+ return url . origin + url . pathname . substring ( 0 , url . pathname . lastIndexOf ( '/' ) ) ;
189+ } ;
190+
182191Perl . init = function ( readyCallback ) {
183192 if ( Perl . state != "Uninitialized" )
184193 throw "Perl: can't call init in state " + Perl . state ;
185194 Perl . changeState ( "Initializing" ) ;
186- var baseurl = new URL ( getScriptURL ( ) ) ;
187- if ( baseurl . protocol == 'file:' )
188- // Note that a lot of things still won't work for file:// URLs
189- // because of the Same-Origin Policy.
190- // see e.g. https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSRequestNotHttp
191- baseurl = baseurl . href . substring ( 0 , baseurl . href . lastIndexOf ( '/' ) ) ;
192- else
193- baseurl = baseurl . origin + baseurl . pathname . substring ( 0 , baseurl . pathname . lastIndexOf ( '/' ) ) ;
195+ // Note that a lot of things still won't work for file:// URLs because of the Same-Origin Policy.
196+ // see e.g. https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSRequestNotHttp
197+ var baseurl = Perl . Util . baseurl ( getScriptURL ( ) ) ;
194198 Perl . readyCallback = readyCallback ;
195199 Module = {
196200 noInitialRun : true ,
0 commit comments