Skip to content

Commit

Permalink
log errors for primitives that do not properly pop the stack
Browse files Browse the repository at this point in the history
  • Loading branch information
codefrau committed Jan 6, 2021
1 parent d67f412 commit ca63f69
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 11 additions & 2 deletions vm.interpreter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,16 @@ Object.subclass('Squeak.Interpreter',
this.popNandPush(1, primIndex - 261); //return -1...2
return true;
}
var sp = this.sp;
var context = this.activeContext;
var success = this.primHandler.doPrimitive(primIndex, argCount, newMethod);
if (success
&& this.sp !== sp - argCount
&& context === this.activeContext
&& primIndex !== 117 // named prims are checked separately
&& !this.frozen) {
this.warnOnce("stack unbalanced after primitive " + primIndex, "error");
}
return success;
},
createActualMessage: function(selector, argCount, cls) {
Expand Down Expand Up @@ -1471,9 +1480,9 @@ Object.subclass('Squeak.Interpreter',
addMessage: function(message) {
return this.messages[message] ? ++this.messages[message] : this.messages[message] = 1;
},
warnOnce: function(message) {
warnOnce: function(message, what) {
if (this.addMessage(message) == 1)
console.warn(message);
console[what || "warn"](message);
},
printMethod: function(aMethod, optContext, optSel) {
// return a 'class>>selector' description for the method
Expand Down
4 changes: 4 additions & 0 deletions vm.primitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ Object.subclass('Squeak.Primitives',
this.loadedModules[modName] = mod;
}
var result = false;
var sp = this.vm.sp;
if (mod) {
this.interpreterProxy.argCount = argCount;
var primitive = mod[functionName];
Expand All @@ -441,6 +442,9 @@ Object.subclass('Squeak.Primitives',
} else {
this.vm.warnOnce("missing module: " + modName + " (" + functionName + ")");
}
if ((result === true || (result !== false && this.success)) && this.vm.sp !== sp - argCount && !this.vm.frozen) {
this.vm.warnOnce("stack unbalanced after primitive " + modName + "." + functionName, "error");
}
if (result === true || result === false) return result;
return this.success;
},
Expand Down

0 comments on commit ca63f69

Please sign in to comment.