@@ -23,7 +23,7 @@ export default function Location(self: any, doc: Boolean = true) {
2323
2424 const ancestor : DOMStringList | Array < string > = self . location . ancestorOrigins || [ ] ;
2525
26- const descriptors : Array < Window & { prototype : object | any } | Location & { prototype : object | any } | Document & { prototype : object | any } > = [
26+ const descriptors : Array < Window & { prototype : object | any } | Location & { prototype : object | any } | Document & { prototype : object | any } > = [
2727 self . Window ,
2828 self . Location ,
2929 self . WorkerLocation ,
@@ -36,12 +36,12 @@ export default function Location(self: any, doc: Boolean = true) {
3636
3737 const descriptor : PropertyDescriptor = {
3838 get ( ) {
39- return self . __dynamic . location ;
39+ return self . __dynamic . location ;
4040 } ,
4141 set ( value : Location | string ) {
42- if ( value instanceof self . Location ) return self . __dynamic . location = value ;
42+ if ( value instanceof self . Location ) return self . __dynamic . location = value ;
4343
44- self . __dynamic . location . href = value ;
44+ self . __dynamic . location . href = value ;
4545 } ,
4646 configurable : true ,
4747 } ;
@@ -66,48 +66,54 @@ export default function Location(self: any, doc: Boolean = true) {
6666 ] ;
6767
6868 try {
69- var property : URL = new URL ( self . __dynamic$url || self . __dynamic . url . decode ( self . location . pathname + self . location . search + self . location . hash ) ) ;
69+ var property : URL = new URL ( self . __dynamic$url || self . __dynamic . url . decode ( self . location . pathname + self . location . search + self . location . hash ) ) ;
7070 } catch {
71- self . __dynamic$url = 'about:blank'
72- var property : URL = new URL ( 'about:blank' ) ;
71+ self . __dynamic$url = 'about:blank'
72+ var property : URL = new URL ( 'about:blank' ) ;
7373 }
7474
7575 self . __dynamic . property = property ;
7676 self . __dynamic . meta . load ( property as URL ) ;
7777 self . __dynamic . location = self . __dynamic . util . clone ( self . location ) as Location
7878
7979 props . forEach ( prop => {
80- self . __dynamic . define ( self . __dynamic . location , prop , {
81- get : ( ) =>
82- ( prop == 'search' && ( self . location [ prop ] + ( self . location . search ? property . search . replace ( '?' , '&' ) : property . search ) ) ) || ( prop == 'hash' ? location [ prop ] : ( property as any ) [ prop ] as string ) ,
83- set : ( e :any ) =>
84- ( self . location [ prop ] = self . __dynamic . url . encode ( self . __dynamic . meta . href . replace ( ( property as any ) [ prop ] , e ) , property ) ) as string
85- } ) ;
80+ self . __dynamic . define ( self . __dynamic . location , prop , {
81+ get : ( ) =>
82+ ( prop == 'search' && ( self . location [ prop ] + ( self . location . search ? property . search . replace ( '?' , '&' ) : property . search ) ) ) || ( prop == 'hash' ? location [ prop ] : ( property as any ) [ prop ] as string ) ,
83+ set : ( e : any ) => {
84+ if ( prop === "href" ) {
85+ ( self . location [ prop ] = self . __dynamic . url . encode ( self . __dynamic . meta . href . replace ( ( property as any ) [ prop ] , e ) , property ) ) as string
86+ }
87+ else {
88+ self . location [ prop ] = e . toString ( ) ;
89+ }
90+ }
91+ } ) ;
8692 } ) ;
8793
8894 self . __dynamic . define ( self . Object . prototype , '__dynamic$location' , {
8995 get ( ) {
90- if ( this === self || this === self . __dynamic$window || this === self . document || this === self . __dynamic$document ) return this . __dynamic ?. location ;
96+ if ( this === self || this === self . __dynamic$window || this === self . document || this === self . __dynamic$document ) return this . __dynamic ?. location ;
9197
92- return this . location ;
98+ return this . location ;
9399 } ,
94100 set ( value : string ) {
95- if ( this === self || this === self . __dynamic$window || this === self . document || this === self . __dynamic$document ) return this . __dynamic . location . href = value ;
101+ if ( this === self || this === self . __dynamic$window || this === self . document || this === self . __dynamic$document ) return this . __dynamic . location . href = value ;
96102
97- return this . location = value ;
103+ return this . location = value ;
98104 } ,
99105 configurable : true
100- } )
106+ } )
101107
102108 funcs . forEach ( func => {
103- self . __dynamic . define ( self . __dynamic . location , func , {
104- get : ( ) => {
105- if ( func == 'toString' ) return ( ) => property [ 'href' ] as string ;
109+ self . __dynamic . define ( self . __dynamic . location , func , {
110+ get : ( ) => {
111+ if ( func == 'toString' ) return ( ) => property [ 'href' ] as string ;
106112
107- return new self . __dynamic . Function ( "arg" , `return window.location.${ func } (arg?${ "reload" !== func && "toString" !== func ? "(self.__dynamic).url.encode(arg, new URL('" + property . href + "'))" : "arg" } :null)` ) as Function ;
108- } ,
109- set : ( ) => null
110- } ) ;
113+ return new self . __dynamic . Function ( "arg" , `return window.location.${ func } (arg?${ "reload" !== func && "toString" !== func ? "(self.__dynamic).url.encode(arg, new URL('" + property . href + "'))" : "arg" } :null)` ) as Function ;
114+ } ,
115+ set : ( ) => null
116+ } ) ;
111117 } ) ;
112118
113119 if ( ancestor . length ) {
@@ -121,11 +127,11 @@ export default function Location(self: any, doc: Boolean = true) {
121127 self . __dynamic . define ( object . prototype , '__dynamic$location' , descriptor ) ;
122128 } ) ;
123129
124- if ( ! self . __dynamic . hashchange ) self . __dynamic . hashchange = ( self . addEventListener ( "hashchange" , ( event : HashChangeEvent ) => {
130+ if ( ! self . __dynamic . hashchange ) self . __dynamic . hashchange = ( self . addEventListener ( "hashchange" , ( event : HashChangeEvent ) => {
125131 //property["hash"] = "#" + (event.newURL.split("#")[1] || "");
126132
127133 //self.history.pushState(null, null, self.__dynamic.location.href);
128134 } ) , true ) ;
129135
130136 return self . __dynamic . location ;
131- } ;
137+ } ;
0 commit comments