From 1ee45d084ac4c5908237f6d432e480c9319f7a7d Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Fri, 9 Dec 2016 12:30:58 -0800 Subject: [PATCH] Fixes #203 - Running "ios-sim showdevicetypes" throws error "Cannot read property 'replace' of undefined" --- src/lib.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/lib.js b/src/lib.js index c7fcba2..8358aea 100644 --- a/src/lib.js +++ b/src/lib.js @@ -277,9 +277,15 @@ var lib = { }); list = []; - var remove = function(runtime) { + var remove = function(devicename, runtime) { // remove "iOS" prefix in runtime, remove prefix "com.apple.CoreSimulator.SimDeviceType." in id - list.push(util.format('%s, %s', name_id_map[ deviceName ].replace(/^com.apple.CoreSimulator.SimDeviceType./, ''), runtime.replace(/^iOS /, ''))); + list.push(util.format('%s, %s', name_id_map[ devicename ].replace(/^com.apple.CoreSimulator.SimDeviceType./, ''), runtime.replace(/^iOS /, ''))); + }; + + var cur = function(devicename) { + return function(runtime) { + remove(devicename, runtime); + }; }; for (var deviceName in druntimes) { @@ -289,7 +295,8 @@ var lib = { if (!(dname in name_id_map)) { continue; } - runtimes.forEach(remove); + + runtimes.forEach(cur(dname)); } return list; },