From bbab24da2ecf819a180d85e05c22c52789043225 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Wed, 4 May 2011 17:15:26 -0500 Subject: [PATCH] Add eofObj and helper for converting Obj->JS value --- pdf.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pdf.js b/pdf.js index 3d48bbf0d..5b93f8567 100644 --- a/pdf.js +++ b/pdf.js @@ -92,11 +92,24 @@ var Obj = (function() { return this.value.get(key); } } + constructor.prototype.lowerToJS = function() { + if (this.isInt() || this.isReal() || this.isString() + || this.isName() || this.isBool() || this.isNone()) { + return this.value; + } else if (this.isNull()) { + return null; + } else if (this.isArray()) { + return this.value.map(function (e) e.lowerToJS()); + } else { + return undefined; + } + } constructor.trueObj = new constructor(constructor.Bool, true); constructor.falseObj = new constructor(constructor.Bool, false); constructor.nullObj = new constructor(constructor.Null); constructor.errorObj = new constructor(constructor.Error); + constructor.eofObj = new constructor(constructor.EOF); return constructor; })(); @@ -662,7 +675,8 @@ var Interpreter = (function() { dispatch: function(cmdObj, args) { var fnName = this.getAndCheckCmd(cmdObj, args); - this.gfx[fnName].apply(this.gfx, args.map(function(o) o.value)); + this.gfx[fnName].apply(this.gfx, + args.map(function(o) o.lowerToJS())); }, getAndCheckCmd: function(cmdObj, args) { const CMD_TABLE = { @@ -941,7 +955,7 @@ function runEchoTests() { function name(n) { return new Obj(Obj.Name, n); } function int(i) { return new Obj(Obj.Int, i); } function string(s) { return new Obj(Obj.String, s); } - function eof() { return new Obj(Obj.EOF); } + function eof() { return Obj.eofObj; } function array(a) { return new Obj(Obj.Array, a); } function real(r) { return new Obj(Obj.Real, r); }