Skip to content

Commit 59c0c4a

Browse files
committed
fallback when Object.defineProperty is not available
1 parent d4573e5 commit 59c0c4a

File tree

1 file changed

+46
-36
lines changed

1 file changed

+46
-36
lines changed

lib/HotModuleReplacement.runtime.js

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,47 +29,57 @@ module.exports = function() {
2929
};
3030
for(var name in $require$) {
3131
if(Object.prototype.hasOwnProperty.call($require$, name)) {
32-
Object.defineProperty(fn, name, (function(name) {
33-
return {
34-
configurable: true,
35-
enumerable: true,
36-
get: function() {
37-
return $require$[name];
38-
},
39-
set: function(value) {
40-
$require$[name] = value;
41-
}
42-
};
43-
}(name)));
32+
if(Object.defineProperty) {
33+
Object.defineProperty(fn, name, (function(name) {
34+
return {
35+
configurable: true,
36+
enumerable: true,
37+
get: function() {
38+
return $require$[name];
39+
},
40+
set: function(value) {
41+
$require$[name] = value;
42+
}
43+
};
44+
}(name)));
45+
} else {
46+
fn[name] = $require$[name];
47+
}
4448
}
4549
}
46-
Object.defineProperty(fn, "e", {
47-
enumerable: true,
48-
value: function(chunkId, callback) {
49-
if(hotStatus === "ready")
50-
hotSetStatus("prepare");
51-
hotChunksLoading++;
52-
$require$.e(chunkId, function() {
53-
try {
54-
callback.call(null, fn);
55-
} finally {
56-
finishChunkLoading();
57-
}
5850

59-
function finishChunkLoading() {
60-
hotChunksLoading--;
61-
if(hotStatus === "prepare") {
62-
if(!hotWaitingFilesMap[chunkId]) {
63-
hotEnsureUpdateChunk(chunkId);
64-
}
65-
if(hotChunksLoading === 0 && hotWaitingFiles === 0) {
66-
hotUpdateDownloaded();
67-
}
51+
function ensure(chunkId, callback) {
52+
if(hotStatus === "ready")
53+
hotSetStatus("prepare");
54+
hotChunksLoading++;
55+
$require$.e(chunkId, function() {
56+
try {
57+
callback.call(null, fn);
58+
} finally {
59+
finishChunkLoading();
60+
}
61+
62+
function finishChunkLoading() {
63+
hotChunksLoading--;
64+
if(hotStatus === "prepare") {
65+
if(!hotWaitingFilesMap[chunkId]) {
66+
hotEnsureUpdateChunk(chunkId);
67+
}
68+
if(hotChunksLoading === 0 && hotWaitingFiles === 0) {
69+
hotUpdateDownloaded();
6870
}
6971
}
70-
});
71-
}
72-
});
72+
}
73+
});
74+
}
75+
if(Object.defineProperty) {
76+
Object.defineProperty(fn, "e", {
77+
enumerable: true,
78+
value: ensure
79+
});
80+
} else {
81+
fn.e = ensure;
82+
}
7383
return fn;
7484
}
7585

0 commit comments

Comments
 (0)