From 9758e3800acee4031b09f605de4561982b51e9e6 Mon Sep 17 00:00:00 2001 From: Toad06 Date: Mon, 10 Jun 2024 11:05:30 +0200 Subject: [PATCH] Detect ref, null and unknown types in `YYTypeof` --- scripts/functions/Function_Maths.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/scripts/functions/Function_Maths.js b/scripts/functions/Function_Maths.js index 01ba7577..79f5e1a0 100644 --- a/scripts/functions/Function_Maths.js +++ b/scripts/functions/Function_Maths.js @@ -1349,12 +1349,23 @@ function YYInstanceof(_x) { function YYTypeof(_x) { var ret = typeof(_x); switch (ret) { - case "boolean": return "bool"; - case "function": return "method"; + case "number": + case "string": + case "undefined": + return ret; + case "boolean": + return "bool"; + case "function": + return "method"; case "object": - // JS objects that aren't arrays count as pointers - return (_x instanceof Array) ? "array" : (_x instanceof ArrayBuffer) ? "ptr" : (_x instanceof Long) ? "int64" : "struct"; - default: return ret; + if (_x === null) return "null"; // `typeof null` is "object" in JS + if (_x instanceof Array) return "array"; + if (_x instanceof ArrayBuffer) return "ptr"; + if (_x instanceof Long) return "int64"; + if (_x instanceof YYRef) return "ref"; + return "struct"; + default: + return "unknown"; // this would be a "symbol" or a "bigint" which are not supported types in GameMaker } }