test-server/calabash-js/src/calabash.js in calabash-android-0.5.1 vs test-server/calabash-js/src/calabash.js in calabash-android-0.5.2.pre1
- old
+ new
@@ -96,12 +96,44 @@
res = object;
}
return res;
}
+ function applyMethods(object, arguments) {
+ var length = arguments.length;
+
+ for(var i = 0; i < length; i++) {
+ var argument = arguments[i];
+
+ if (typeof argument === 'string') {
+ argument = {method_name: argument, arguments: []}
+ }
+
+ var methodName = argument.method_name;
+ var methodArguments = argument.arguments;
+
+ if (typeof object[methodName] === 'undefined') {
+ var type = Object.prototype.toString.call(object);
+
+ object =
+ {
+ error: "No such method '" + methodName + "'",
+ methodName: methodName,
+ receiverString: object.constructor.name,
+ receiverClass: type
+ };
+
+ break;
+ } else {
+ object = object[methodName].apply(object, methodArguments);
+ }
+ }
+ }
+
var exp = '%@'/* dynamic */,
- queryType = '%@',
+ queryType = '%@' /* dynamic */,
+ arguments = '%@' /* dynamic */,
nodes = null,
res = [],
i,N;
try
{
@@ -120,7 +152,16 @@
}
catch (e)
{
return JSON.stringify({error:'Exception while running query: '+exp, details:e.toString()})
}
+
+ if (arguments !== '%@') {
+ var length = res.length;
+
+ for (var i = 0; i < length; i++) {
+ res[i] = applyMethods(res[i], arguments);
+ }
+ }
+
return JSON.stringify(toJSON(res));
})();