From 75557d27d156bac9c03417a79d12c349be478593 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 28 Sep 2015 14:18:11 +0200 Subject: [PATCH] Add `getArray` method to `Dict` This method extend `get`, and will fetch all indirect objects (i.e. `Ref`s) when the result is an `Array`. --- src/core/obj.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/core/obj.js b/src/core/obj.js index 161e8ca29..be62eab55 100644 --- a/src/core/obj.js +++ b/src/core/obj.js @@ -135,6 +135,22 @@ var Dict = (function DictClosure() { return Promise.resolve(value); }, + // Same as get(), but dereferences all elements if the result is an Array. + getArray: function Dict_getArray(key1, key2, key3) { + var value = this.get(key1, key2, key3); + if (!isArray(value)) { + return value; + } + value = value.slice(); // Ensure that we don't modify the Dict data. + for (var i = 0, ii = value.length; i < ii; i++) { + if (!isRef(value[i])) { + continue; + } + value[i] = this.xref.fetch(value[i]); + } + return value; + }, + // no dereferencing getRaw: function Dict_getRaw(key) { return this.map[key];