Skip to content

Commit

Permalink
wsh lookup implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dmi3y committed Apr 20, 2014
1 parent a224fc8 commit 1548f1e
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/cli/wsh.js
Expand Up @@ -12,6 +12,9 @@ var wshapi = (function(){
var shell = WScript.CreateObject("WScript.Shell");
var finalArgs = [], i, args = WScript.Arguments;

var WshShell = new ActiveXObject("WScript.Shell");
var userhome = WshShell.ExpandEnvironmentStrings("%USERPROFILE%");

if (typeof Array.prototype.forEach !== "function") {
Array.prototype.forEach = function(f,m) {
for (var i=0, L=this.length; i<L; ++i) {
Expand Down Expand Up @@ -72,6 +75,39 @@ var wshapi = (function(){
};
}

//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
if (!Array.prototype.map)
{
Array.prototype.map = function(fun /*, thisArg */ ) {
"use strict";

if (this === void 0 || this === null) {
throw new TypeError();
}

var t = Object(this);
var len = t.length >>> 0;
if (typeof fun !== "function") {
throw new TypeError();
}

var res = new Array(len);
var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
for (var i = 0; i < len; i++) {
// NOTE: Absolute correctness would demand Object.defineProperty
// be used. But this method is fairly new, and failure is
// possible only if Object.prototype or Array.prototype
// has a property |i| (very unlikely), so use a less-correct
// but more portable alternative.
if (i in t) {
res[i] = fun.call(thisArg, t[i], i, t);
}
}

return res;
};
}

function traverseDir(files, path) {
var filename, folder = fso.GetFolder(path),
subFlds, fc = new Enumerator(folder.files);
Expand Down Expand Up @@ -100,6 +136,7 @@ var wshapi = (function(){
args: finalArgs,
print: function(s) { WScript.Echo(s);},
quit: function (v) { WScript.Quit(v);},
userhome: userhome,

isDirectory: function(name){
return fso.FolderExists(name);
Expand Down

0 comments on commit 1548f1e

Please sign in to comment.