run_loop 0.1.0.pre1 → 0.1.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
data/scripts/run_loop.js CHANGED
@@ -246,15 +246,62 @@ UIATarget.onAlert = function (alert) {
246
246
  return true;
247
247
  };
248
248
 
249
+ /*
250
+ (defn sanitize
251
+ "Removes elements not serializable to preferences"
252
+ [x]
253
+
254
+ (cond
255
+ (nil? x) ":nil"
256
+ (string? x) x
257
+ (keyword? x) (name x)
258
+ (map? x) (into {}
259
+ (map (fn [[k v]]
260
+ [k (sanitize v)])
261
+ x))
262
+ (coll? x) (map sanitize x)
263
+ (instance? js/UIAElement x) (.toString x)
264
+ :else x))
265
+
266
+ */
249
267
 
250
268
  var target = null,
251
269
  preferences = null,
252
270
  __calabashRequest = "__calabashRequest",
253
271
  __calabashResponse = "__calabashResponse",
272
+ _sanitize = function(val) {
273
+ if (typeof val === 'undefined' || val === null || val instanceof UIAElementNil) {
274
+ return ":nil";
275
+ }
276
+ if (typeof val === 'string' || val instanceof String) {
277
+ return val;
278
+ }
279
+ var arrVal = null, i, N;
280
+ if (val instanceof Array || val instanceof UIAElementArray) {
281
+ arrVal = [];
282
+ for (i=0,N=val.length;i<N;i++) {
283
+ arrVal[i] = _sanitize(val[i]);
284
+ }
285
+ return arrVal;
286
+ }
287
+ if (val instanceof UIAElement) {
288
+ return val.toString();
289
+ }
290
+ var objVal = null, p;
291
+ if (typeof val == 'object') {
292
+ objVal = {};
293
+ for (p in val) {
294
+ objVal[p] = _sanitize(val[p]);
295
+ }
296
+ return objVal;
297
+ }
298
+ return val;
299
+ },
254
300
  _response = function(response) {
255
- target.frontMostApp().setPreferencesValueForKey(response, __calabashResponse);
301
+ target.frontMostApp().setPreferencesValueForKey(_sanitize(response), __calabashResponse);
256
302
  },
257
303
  _success = function(result,index) {
304
+
258
305
  _response({"status":'success', "value":result, "index": index});
259
306
 
260
307
  },
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: run_loop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre1
4
+ version: 0.1.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karl Krukow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-20 00:00:00.000000000 Z
11
+ date: 2013-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor