Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 957ec1f

Browse files
committed
WIP: single getter/setter definition for IE8 and modern browsers
1 parent 4b1446a commit 957ec1f

File tree

1 file changed

+29
-54
lines changed

1 file changed

+29
-54
lines changed

test/ng/browserSpecs.js

+29-54
Original file line numberDiff line numberDiff line change
@@ -46,61 +46,37 @@ function MockWindow(options) {
4646
});
4747
};
4848

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;
5262
mockWindow.history.state = null;
63+
historyEntriesLength++;
64+
},
65+
get: function() {
66+
return locationHref;
5367
}
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+
});
10480

10581
this.history = {
10682
replaceState: noop,
@@ -151,7 +127,6 @@ describe('browser', function() {
151127
warn: function() { logs.warn.push(slice.call(arguments)); },
152128
info: function() { logs.info.push(slice.call(arguments)); },
153129
error: function() { logs.error.push(slice.call(arguments)); }};
154-
155130
browser = new Browser(fakeWindow, fakeDocument, fakeLog, sniffer);
156131
});
157132

0 commit comments

Comments
 (0)