mirror of
https://github.com/Mibew/design.git
synced 2024-11-15 17:34:12 +03:00
Fixed bugs in the JavaScript's MibewAPIInteraction class
This commit is contained in:
parent
2752ce5c25
commit
8a88f48d89
@ -13,9 +13,9 @@ MibewAPI.prototype.checkPackage=function(a){if("undefined"==typeof a.signature)t
|
||||
for(var b=0;b<a.requests.length;b++)this.checkRequest(a.requests[b])};MibewAPI.prototype.getResultFunction=function(a,b){"undefined"==typeof b&&(b=null);var c=null,d;for(d in a)if(a.hasOwnProperty(d)&&"result"==a[d]["function"]){if(null!==c)throw Error("Function 'result' already exists in functions list");c=a[d]}if(!0===b&&null===c)throw Error("There is no 'result' function in functions list");if(!1===b&&null!==c)throw Error("There is 'result' function in functions list");return c};
|
||||
MibewAPI.prototype.buildResult=function(a,b){var c=this.interaction.getObligatoryArgumentsDefaults("result"),d;for(d in c)c.hasOwnProperty(d)&&(a[d]=c[d]);return{token:b,functions:[{"function":"result",arguments:a}]}};MibewAPI.prototype.encodePackage=function(a){var b={signature:""};b.proto=this.protocolVersion;b.async=!0;b.requests=a;return encodeURIComponent(JSON.stringify(b)).replace(/\%20/gi,"+")};
|
||||
MibewAPI.prototype.decodePackage=function(a){a=JSON.parse(decodeURIComponent(a.replace(/\+/gi," ")));this.checkPackage(a);return a};function MibewAPIInteraction(){this.obligatoryArguments={};this.reservedFunctionNames=[]}
|
||||
MibewAPIInteraction.prototype.getObligatoryArguments=function(a){var b=[];if("object"==typeof this.obligatoryArguments["*"]&&this.obligatoryArguments["*"]instanceof Array)for(var c in this.obligatoryArguments["*"])this.obligatoryArguments["*"].hasOwnProperty(c)&&b.push(c);if("object"==typeof this.obligatoryArguments[a]&&this.obligatoryArguments[a]instanceof Array)for(c in this.obligatoryArguments[a])this.obligatoryArguments[a].hasOwnProperty(c)&&b.push(c);return b};
|
||||
MibewAPIInteraction.prototype.getObligatoryArgumentsDefaults=function(a){var b=[];if("object"==typeof this.obligatoryArguments["*"]&&this.obligatoryArguments["*"]instanceof Array)for(var c in this.obligatoryArguments["*"])this.obligatoryArguments["*"].hasOwnProperty(c)&&(b[c]=this.obligatoryArguments["*"][c]);if("object"==typeof this.obligatoryArguments[a]&&this.obligatoryArguments[a]instanceof Array)for(c in this.obligatoryArguments[a])this.obligatoryArguments[a].hasOwnProperty(c)&&(b[c]=this.obligatoryArguments[a][c]);
|
||||
return b};function MibewAPIWindowToCoreInteraction(){this.obligatoryArguments={"*":{"return":{},references:{}}};this.reservedFunctionNames=["result"]}MibewAPIWindowToCoreInteraction.prototype=new MibewAPIInteraction;function MibewAPIExecutionContext(){this.returnValues={};this.functionsResults=[]}
|
||||
MibewAPIInteraction.prototype.getObligatoryArguments=function(a){var b=[];if("object"==typeof this.obligatoryArguments["*"])for(var c in this.obligatoryArguments["*"])this.obligatoryArguments["*"].hasOwnProperty(c)&&b.push(c);if("object"==typeof this.obligatoryArguments[a])for(c in this.obligatoryArguments[a])this.obligatoryArguments[a].hasOwnProperty(c)&&b.push(c);return b};
|
||||
MibewAPIInteraction.prototype.getObligatoryArgumentsDefaults=function(a){var b={};if("object"==typeof this.obligatoryArguments["*"])for(var c in this.obligatoryArguments["*"])this.obligatoryArguments["*"].hasOwnProperty(c)&&(b[c]=this.obligatoryArguments["*"][c]);if("object"==typeof this.obligatoryArguments[a])for(c in this.obligatoryArguments[a])this.obligatoryArguments[a].hasOwnProperty(c)&&(b[c]=this.obligatoryArguments[a][c]);return b};
|
||||
function MibewAPIWindowToCoreInteraction(){this.obligatoryArguments={"*":{"return":{},references:{}}};this.reservedFunctionNames=["result"]}MibewAPIWindowToCoreInteraction.prototype=new MibewAPIInteraction;function MibewAPIExecutionContext(){this.returnValues={};this.functionsResults=[]}
|
||||
MibewAPIExecutionContext.prototype.getArgumentsList=function(a){var b=a.arguments,c=a.arguments.references,d,f,e;for(e in c)if(c.hasOwnProperty(e)){f=c[e];if("undefined"==typeof this.functionsResults[f-1])throw Error("Wrong reference in '"+a["function"]+"' function. Function #"+f+" does not call yet.");if("undefined"==typeof b[e]||""==b[e])throw Error("Wrong reference in '"+a["function"]+"' function. Empty '"+e+"' argument.");d=b[e];if("undefined"==typeof this.functionsResults[f-1][d])throw Error("Wrong reference in '"+
|
||||
a["function"]+"' function. There is no '"+d+"' argument in #"+f+" function results");b[e]=this.functionsResults[f-1][d]}return b};MibewAPIExecutionContext.prototype.getResults=function(){return this.returnValues};
|
||||
MibewAPIExecutionContext.prototype.storeFunctionResults=function(a,b){var c,d;for(d in a.arguments["return"])if(a.arguments["return"].hasOwnProperty(d)){c=a.arguments["return"][d];if("undefined"==typeof b[d])throw Error("Variable with name '"+d+"' is undefined in the results of the '"+a["function"]+"' function");this.returnValues[c]=b[d]}this.functionsResults.push(b)};
|
@ -324,8 +324,7 @@ function MibewAPIInteraction(){
|
||||
MibewAPIInteraction.prototype.getObligatoryArguments = function(functionName) {
|
||||
var obligatoryArguments = [];
|
||||
// Add obligatory for all functions arguments
|
||||
if (typeof this.obligatoryArguments['*'] == 'object' &&
|
||||
this.obligatoryArguments['*'] instanceof Array) {
|
||||
if (typeof this.obligatoryArguments['*'] == 'object') {
|
||||
for (var arg in this.obligatoryArguments['*']) {
|
||||
if (! this.obligatoryArguments['*'].hasOwnProperty(arg)) {
|
||||
continue;
|
||||
@ -334,8 +333,7 @@ MibewAPIInteraction.prototype.getObligatoryArguments = function(functionName) {
|
||||
}
|
||||
}
|
||||
// Add obligatory arguments for given function
|
||||
if (typeof this.obligatoryArguments[functionName] == 'object' &&
|
||||
this.obligatoryArguments[functionName] instanceof Array) {
|
||||
if (typeof this.obligatoryArguments[functionName] == 'object') {
|
||||
for (var arg in this.obligatoryArguments[functionName]) {
|
||||
if (! this.obligatoryArguments[functionName].hasOwnProperty(arg)) {
|
||||
continue;
|
||||
@ -354,10 +352,9 @@ MibewAPIInteraction.prototype.getObligatoryArguments = function(functionName) {
|
||||
* values are default values of them
|
||||
*/
|
||||
MibewAPIInteraction.prototype.getObligatoryArgumentsDefaults = function(functionName) {
|
||||
var obligatoryArguments = [];
|
||||
var obligatoryArguments = {};
|
||||
// Add obligatory for all functions arguments
|
||||
if (typeof this.obligatoryArguments['*'] == 'object' &&
|
||||
this.obligatoryArguments['*'] instanceof Array) {
|
||||
if (typeof this.obligatoryArguments['*'] == 'object') {
|
||||
for (var arg in this.obligatoryArguments['*']) {
|
||||
if (! this.obligatoryArguments['*'].hasOwnProperty(arg)) {
|
||||
continue;
|
||||
@ -366,8 +363,7 @@ MibewAPIInteraction.prototype.getObligatoryArgumentsDefaults = function(function
|
||||
}
|
||||
}
|
||||
// Add obligatory arguments for given function
|
||||
if (typeof this.obligatoryArguments[functionName] == 'object' &&
|
||||
this.obligatoryArguments[functionName] instanceof Array) {
|
||||
if (typeof this.obligatoryArguments[functionName] == 'object') {
|
||||
for (var arg in this.obligatoryArguments[functionName]) {
|
||||
if (! this.obligatoryArguments[functionName].hasOwnProperty(arg)) {
|
||||
continue;
|
||||
|
Loading…
Reference in New Issue
Block a user