@@ -46,61 +46,37 @@ function MockWindow(options) {
46
46
} ) ;
47
47
} ;
48
48
49
- this . location = {
50
- replace : function ( url ) {
51
- locationHref = url ;
49
+ //IE8 hack. defineProperty doesn't work with POJS, just with certain DOM elements
50
+ this . location = document . createElement ( 'div' ) ;
51
+ this . location . href = { } ;
52
+ this . location . hash = { } ;
53
+ this . location . replace = function ( url ) {
54
+ locationHref = url ;
55
+ mockWindow . history . state = null ;
56
+ } ;
57
+ Object . defineProperty ( this . location , 'href' , {
58
+ enumerable : false ,
59
+ configurable : true ,
60
+ set : function ( value ) {
61
+ locationHref = value ;
52
62
mockWindow . history . state = null ;
63
+ historyEntriesLength ++ ;
64
+ } ,
65
+ get : function ( ) {
66
+ return locationHref ;
53
67
}
54
- } ;
55
- dump ( msie ) ;
56
- if ( ! msie || msie > 8 ) {
57
- eval ( [
58
- "this.location = {" ,
59
- "get href() {" ,
60
- "return locationHref;" ,
61
- "}," ,
62
- "set href(value) {" ,
63
- "locationHref = value;" ,
64
- "mockWindow.history.state = null;" ,
65
- "historyEntriesLength++;" ,
66
- "}," ,
67
- "get hash() {" ,
68
- "return getHash(locationHref);" ,
69
- "}," ,
70
- "set hash(value) {" ,
71
- "locationHref = stripHash(locationHref) + '#' + value;" ,
72
- "}," ,
73
- "replace: function(url) {" ,
74
- "locationHref = url;" ,
75
- "mockWindow.history.state = null;" ,
76
- "}" ,
77
- "};"
78
- ] . join ( '\n' ) ) ;
79
- }
80
- else {
81
- eval ( [
82
- "this.location={" ,
83
- "replace: function(url) {" ,
84
- "locationHref = url;" ,
85
- "mockWindow.history.state = null;" ,
86
- "}" ,
87
- "};" ,
88
- "this.location.__defineGetter__('href', function getHref() {" ,
89
- "return locationHref;" ,
90
- "});" ,
91
- "this.location.__defineSetter__('href', function setHref(value) {" ,
92
- "locationHref = value;" ,
93
- "mockWindow.history.state = null;" ,
94
- "historyEntriesLength++;" ,
95
- "});" ,
96
- "this.location.__defineGetter__('hash', function getHash() {" ,
97
- "return getHash(locationHref);" ,
98
- "});" ,
99
- "this.location.__defineSetter__('hash', function setHash(value) {" ,
100
- "locationHref = stripHash(locationHref) + '#' + value;" ,
101
- "});"
102
- ] . join ( '\n' ) ) ;
103
- }
68
+ } ) ;
69
+
70
+ Object . defineProperty ( this . location , 'hash' , {
71
+ enumerable : false ,
72
+ configurable : true ,
73
+ set : function ( value ) {
74
+ locationHref = stripHash ( locationHref ) + '#' + value ;
75
+ } ,
76
+ get : function ( ) {
77
+ return getHash ( locationHref ) ;
78
+ }
79
+ } ) ;
104
80
105
81
this . history = {
106
82
replaceState : noop ,
@@ -151,7 +127,6 @@ describe('browser', function() {
151
127
warn : function ( ) { logs . warn . push ( slice . call ( arguments ) ) ; } ,
152
128
info : function ( ) { logs . info . push ( slice . call ( arguments ) ) ; } ,
153
129
error : function ( ) { logs . error . push ( slice . call ( arguments ) ) ; } } ;
154
-
155
130
browser = new Browser ( fakeWindow , fakeDocument , fakeLog , sniffer ) ;
156
131
} ) ;
157
132
0 commit comments