]> git.parisson.com Git - pdf.js.git/commitdiff
Add eofObj and helper for converting Obj->JS value
authorChris Jones <jones.chris.g@gmail.com>
Wed, 4 May 2011 22:15:26 +0000 (17:15 -0500)
committerChris Jones <jones.chris.g@gmail.com>
Wed, 4 May 2011 22:15:26 +0000 (17:15 -0500)
pdf.js

diff --git a/pdf.js b/pdf.js
index 3d48bbf0d993b097b8410f03f1b20f1e66ba9f22..5b93f8567d4f23d624d530cd721b914f1a7b5e17 100644 (file)
--- 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); }