From 3c15d0ef0b98cfb4080ceabb7f5b1de8707182aa Mon Sep 17 00:00:00 2001 From: jaknapper Date: Thu, 5 Jun 2025 11:50:43 +0100 Subject: [PATCH] Custom at() function in webapp for backwards compatibility --- .../labThingsComponents/actionButton.vue | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/webapp/src/components/labThingsComponents/actionButton.vue b/webapp/src/components/labThingsComponents/actionButton.vue index 7efbbbc9..4033f133 100644 --- a/webapp/src/components/labThingsComponents/actionButton.vue +++ b/webapp/src/components/labThingsComponents/actionButton.vue @@ -171,6 +171,25 @@ export default { }, mounted() { + //Define .at() as a custom function, for backwards compatibility with Connect + function at(n) { + // ToInteger() abstract op + n = Math.trunc(n) || 0; + // Allow negative indexing from the end + if (n < 0) n += this.length; + // OOB access is guaranteed to return undefined + if (n < 0 || n >= this.length) return undefined; + // Otherwise, this is just normal property access + return this[n]; + } + const TypedArray = Reflect.getPrototypeOf(Int8Array); + for (const C of [Array, String, TypedArray]) { + Object.defineProperty(C.prototype, "at", + { value: at, + writable: true, + enumerable: false, + configurable: true }); + } // Check for already running tasks if (this.taskStarted != true) { this.checkExistingTasks();