isNum and operator argument type checking
This commit is contained in:
parent
229043c15d
commit
9969a937ce
12
pdf.js
12
pdf.js
@ -82,6 +82,9 @@ var Obj = (function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constructor.prototype.isNum = function(value) {
|
||||||
|
return this.isInt(value) || this.isReal(value);
|
||||||
|
}
|
||||||
constructor.prototype.lookup = function(key) {
|
constructor.prototype.lookup = function(key) {
|
||||||
function lookup(key) {
|
function lookup(key) {
|
||||||
if (!(this.value.contains(key)))
|
if (!(this.value.contains(key)))
|
||||||
@ -718,13 +721,18 @@ var Interpreter = (function() {
|
|||||||
var cmd = CMD_TABLE[cmdName];
|
var cmd = CMD_TABLE[cmdName];
|
||||||
if (!cmd) {
|
if (!cmd) {
|
||||||
this.error("Unknown command '"+ cmdName +"'");
|
this.error("Unknown command '"+ cmdName +"'");
|
||||||
} else if (!this.typeCheck(cmd, args)) {
|
} else if (!this.typeCheck(cmd.params, args)) {
|
||||||
this.error("Wrong arguments for command '"+ cmdName +"'");
|
this.error("Wrong arguments for command '"+ cmdName +"'");
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd.fn;
|
return cmd.fn;
|
||||||
},
|
},
|
||||||
typeCheck: function(cmd, args) {
|
typeCheck: function(params, args) {
|
||||||
|
if (params.length != args.length)
|
||||||
|
return false;
|
||||||
|
for (var i = 0; i < params.length; ++i)
|
||||||
|
if (!args[i]["is"+ params[i]]())
|
||||||
|
return false;
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
error: function(what) {
|
error: function(what) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user