From d9fac3459609a807be6506fb3441b5da4b154d14 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 4 Dec 2021 09:58:17 +0100 Subject: [PATCH] Ensure that the `shadow` helper function is passed a valid property (PR 14152 follow-up) Trying to shadow a non-existent property is always an implementation mistake, since it leads to the `shadow`-call not having any effect. In PR 14152 I overlooked the fact that it's fairly easy to enforce this during development/testing, since that can help catch e.g. simple spelling bugs. --- src/shared/util.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/shared/util.js b/src/shared/util.js index 1af94158d..7211254dd 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -488,6 +488,15 @@ function createValidAbsoluteUrl(url, baseUrl = null, options = null) { } function shadow(obj, prop, value) { + if ( + typeof PDFJSDev === "undefined" || + PDFJSDev.test("!PRODUCTION || TESTING") + ) { + assert( + prop in obj, + `shadow: Property "${prop && prop.toString()}" not found in object.` + ); + } Object.defineProperty(obj, prop, { value, enumerable: true,