Skip to content

Commit 8152d43

Browse files
SailorMaxXhmikosR
authored andcommitted
Fix WSH.
WSH does not support `String.trim()`, `Object.create()` and `Object.getPrototypeOf()`. Closes #627.
1 parent 6beedfd commit 8152d43

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/cli/wsh.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,27 @@ var wshapi = (function() {
1414
var shell = WScript.CreateObject("WScript.Shell");
1515
var finalArgs = [], i, args = WScript.Arguments;
1616

17+
if (typeof Object.getPrototypeOf !== "function") {
18+
Object.getPrototypeOf = function(obj) {
19+
var deprecatedProto = "__proto__"; // anti warning solution
20+
return obj[deprecatedProto];
21+
};
22+
}
23+
24+
if (typeof Object.create !== "function") {
25+
Object.create = function(proto) {
26+
var Foo = function(){};
27+
Foo.prototype = proto;
28+
return new Foo();
29+
};
30+
}
31+
32+
if (typeof String.prototype.trim !== "function") {
33+
String.prototype.trim = function() {
34+
return this.replace(/^\s+|\s+$/g, "");
35+
};
36+
}
37+
1738
if (typeof Array.prototype.forEach !== "function") {
1839
Array.prototype.forEach = function(f, m) {
1940
for (var i=0, L=this.length; i<L; ++i) {

0 commit comments

Comments
 (0)