Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

nested if bug fix, try loop fix

  • Loading branch information...
commit 4708d19da2353585789b1c1a5c20a8ecea979f55 1 parent 501e97d
@hochang hochang authored
View
6 modules/app/package.json
@@ -1,7 +1,7 @@
{
"author": "ql.io",
"name": "ql.io-app",
- "version": "0.8.6",
+ "version": "0.8.7",
"repository": {
"type": "git",
"url": "https://github.com/ql-io/ql.io"
@@ -15,8 +15,8 @@
},
"dependencies": {
"commander": "1.0.0",
- "ql.io-console": "0.8.5",
- "ql.io-compiler": "0.8.2",
+ "ql.io-console": "0.8.6",
+ "ql.io-compiler": "0.8.3",
"winston": "0.6.2",
"express": "2.5.11",
"underscore": "1.3.3",
View
9 modules/compiler/lib/compiler.js
@@ -83,8 +83,8 @@ function plan(compiled) {
}
else if (line.type === 'try') {
//dependsOn are the lines in try clause
- divescope(line.dependsOn);
- _.each(line.catchClause, function(k, mycatch){
+ divescope(line.tryClause, line);
+ _.each(line.catchClause, function(mycatch, k){
divescope(mycatch.lines, line);
});
if(line.finallyClause) {
@@ -130,7 +130,7 @@ function plan(compiled) {
}
else if (line.type === 'try') {
//dependsOn are the lines in try clause
- divescope(line.dependsOn);
+ divescope(line.tryClause, line);
_.each(line.catchClause, function(mycatch, k){
divescope(mycatch.lines, line);
});
@@ -308,8 +308,7 @@ function walk(line, symbols) {
});
break;
case 'try':
- _.each(line.dependsOn, function(tryline){
- addListener(tryline, line);
+ _.each(line.tryClause, function(tryline){
walk(tryline, symbols);
});
_.each(line.catchClause, function(currentcatch){
View
7 modules/compiler/lib/peg/ql.js
@@ -781,9 +781,8 @@ module.exports = (function(){
id : id++,
line : line,
type : 'try',
- dependsOn : tryClause,
+ tryClause : tryClause,
catchClause : catchClause,
- exceptions : [],
finallyClause : finallyClause || undefined
}
})(pos0.offset, pos0.line, pos0.column, result0[4], result0[7], result0[8]);
@@ -1248,9 +1247,7 @@ module.exports = (function(){
}
if (result0 !== null) {
result0 = (function(offset, line, column, s1, sn) {
- if(sn){
- s1.fallback = sn;
- }
+ s1.fallback = sn;
return s1;
})(pos0.offset, pos0.line, pos0.column, result0[0], result0[2]);
}
View
2  modules/compiler/package.json
@@ -1,7 +1,7 @@
{
"author": "ql.io",
"name": "ql.io-compiler",
- "version": "0.8.2",
+ "version": "0.8.3",
"repository": {
"type": "git",
"url": "https://github.com/ql-io/ql.io"
View
2  modules/compiler/pegs/ql.peg
@@ -473,7 +473,7 @@ TryClause = 'try' insig '{' insig tryClause:TryCrlf+ insig '}' catchClause:Catch
id : id++,
line : line,
type : 'try',
- dependsOn : tryClause,
+ tryClause : tryClause,
catchClause : catchClause,
finallyClause : finallyClause || undefined
}
View
2  modules/compiler/test/scope-test.js
@@ -27,7 +27,7 @@ module.exports = {
}\n\
finally {select * from bbb}";
var statement = compiler.compile(q);
- test.equals(statement.rhs.dependsOn.length, 2);
+ test.equals(statement.rhs.tryClause.length, 2);
test.equals(statement.rhs.catchClause.length, 1);
test.equals(statement.rhs.catchClause[0].condition.values, 'asdf');
test.equals(statement.rhs.catchClause[0].condition.logic, 'normal');
View
6 modules/console/package.json
@@ -1,7 +1,7 @@
{
"author": "ql.io",
"name": "ql.io-console",
- "version": "0.8.5",
+ "version": "0.8.6",
"repository": {
"type": "git",
"url": "https://github.com/ql-io/ql.io"
@@ -15,9 +15,9 @@
"express": "2.5.11",
"ejs": "0.8.0",
"underscore": "1.3.3",
- "ql.io-engine": "0.8.4",
+ "ql.io-engine": "0.8.5",
"ql.io-mutable-uri": "0.8.0",
- "ql.io-compiler": "0.8.2",
+ "ql.io-compiler": "0.8.3",
"winston": "0.6.2",
"browserify": "1.14.2",
"uglify-js": "1.3.3",
View
103 modules/engine/lib/engine.js
@@ -306,7 +306,7 @@ Engine.prototype.execute = function() {
});
break;
case 'try':
- _.each(statement.dependsOn, function(line){
+ _.each(statement.tryClause, function(line){
init(line);
});
_.each(statement.catchClause, function(currentcatch){
@@ -346,46 +346,59 @@ Engine.prototype.execute = function() {
/* Skip assign statement. Make it undefined, and trigger listener
*/
- function skipVar(statement){
- if (execState[statement.id].state == eventTypes.STATEMENT_SUCCESS){
- return;
- }
- execState[statement.id].state = eventTypes.STATEMENT_SUCCESS;
- switch(statement.type){
- case 'try':
- _.each(statement.dependsOn, function(tryline){//these are just lines within try{}
- skipVar(tryline);
- });
- _.each(statement.catchClause, function(mycatch,k){
- _.each(mycatch.lines, function(catchline){
- skipVar(catchline);
+ function skipVarList(statements){
+ function skipVar(statement){
+ if (execState[statement.id].state == eventTypes.STATEMENT_SUCCESS){
+ return;
+ }
+ execState[statement.id].state = eventTypes.STATEMENT_SUCCESS;
+ switch(statement.type){
+ case 'try':
+ _.each(statement.tryClause, function(tryline){//these are just lines within try{}
+ skipVar(tryline);
});
- });
- _.each(statement.finallyClause, function(finallyline){
- skipVar(finallyline);
- });
- break;
- case 'if':
- _.each(statement.if, function(st) {
- skipVar(st);
- });
- _.each(statement.else, function(st) {
- skipVar(st);
- });
- break;
- default:
- if(!statement.assign){
- return;
- }
- context[statement.assign] = null;
- _.each(statement.listeners, function(listener) {
- execState[listener.id].count--;
- if (!(listener.fbhold)){
- sweep(listener);
+ _.each(statement.catchClause, function(mycatch,k){
+ _.each(mycatch.lines, function(catchline){
+ skipVar(catchline);
+ });
+ });
+ _.each(statement.finallyClause, function(finallyline){
+ skipVar(finallyline);
+ });
+ break;
+ case 'if':
+ _.each(statement.if, function(st) {
+ skipVar(st);
+ });
+ _.each(statement.else, function(st) {
+ skipVar(st);
+ });
+ break;
+ default:
+ if(!statement.assign){
+ return;
}
- });
- }
+ context[statement.assign] = null;
+ _.each(statement.listeners, function(listener) {
+ execState[listener.id].count--;
+ if (!(listener.fbhold)){
+ return listener;
+ }
+ });
+ }
+ }
+ var listeners = [];
+ _.each(statements, function(statement){
+ var tmp = skipVar(statement);
+ if(tmp){
+ listeners.push(tmp);
+ }
+ });
+ listeners = _.uniq(listeners);
+ _.each(listeners, function(listener){
+ sweep(listener);
+ });
}
// scope is complex to execute, handle separately
@@ -394,9 +407,7 @@ Engine.prototype.execute = function() {
case 'if' :
var toskip = arg.skip,
toexec = arg.exec;
- _.each(toskip, function(st) {
- skipVar(st);
- });
+ skipVarList(toskip);
_.each(toexec, function(st) {
sweep(st);
})
@@ -410,9 +421,7 @@ Engine.prototype.execute = function() {
sweep(line);
});
}else{
- _.each(mycatch[1].lines, function(line){
- skipVar(line);
- });
+ skipVarList(mycatch[1].lines);
}
});
break;
@@ -452,6 +461,12 @@ Engine.prototype.execute = function() {
execState[todo.id].count === 0 &&
scopeDone) {
execState[todo.id].state = eventTypes.STATEMENT_IN_FLIGHT;
+
+ if(todo.type === 'try'){
+ _.each(todo.tryClause, function(tryline){
+ sweep(tryline);
+ });
+ }
if (emitterID && !step1) {
// only used for debugger
unexecuted.push(statement);
View
4 modules/engine/package.json
@@ -1,7 +1,7 @@
{
"author": "ql.io",
"name": "ql.io-engine",
- "version": "0.8.4",
+ "version": "0.8.5",
"repository": {
"type": "git",
"url": "https://github.com/ql-io/ql.io"
@@ -14,7 +14,7 @@
"winston": "0.6.2",
"underscore": "1.3.3",
"xml2json": "https://github.com/ql-io/node-xml2json/tarball/master",
- "ql.io-compiler": "0.8.2",
+ "ql.io-compiler": "0.8.3",
"ql.io-mutable-uri": "0.8.0",
"ql.io-uri-template": "0.8.0",
"ql.io-str-template": "0.8.0",
View
43 modules/engine/test/scope-test.js
@@ -187,3 +187,46 @@ module.exports['trycatch-nested'] = function(test) {
}
}});
};
+
+module.exports['ifelse-nested'] = function(test) {
+ var context, q;
+ context = {
+ foo : {
+ 'hello' : 'Hello',
+ 'world' : 'World'
+ },
+ bar : {
+ 'chocolate' : 'Chocolate',
+ 'milk' : 'Milk'
+ },
+ empty : null,
+ cond : 1
+ };
+ q = 'if (x||y)\n\
+ {\n\
+ q= 12345\n\
+ if (!j )\n\
+ {\n\
+ g = "sad"\n\
+ }\n\
+ else\n\
+ {\n\
+ d= "sleepy"\n\
+ }\n\
+ }\n\
+ else\n\
+ {\n\
+ e = "enjoy"\n\
+ }\n\
+ return q||g|| d||e;';
+ engine.exec({script: q, context: context, cb: function(err, result) {
+ if(err) {
+ test.fail('got error: ' + err.stack);
+ test.done();
+ }
+ else {
+ test.equals(result.body, "enjoy");
+ test.done();
+ }
+ }});
+};
Please sign in to comment.
Something went wrong with that request. Please try again.