/** * @param {Object} [prefix] * @param {String} method * @param {Function} patch */ function autociv_patchApplyN() { if (arguments.length < 2) { let error = new Error("Insufficient arguments to patch: " + arguments[0]); warn(error.message) warn(error.stack) return; } let prefix, method, patch; if (arguments.length == 2) { prefix = global; method = arguments[0]; patch = arguments[1]; } else { prefix = arguments[0]; method = arguments[1]; patch = arguments[2]; } if (!(method in prefix)) { let error = new Error("Function not defined: " + method); warn(error.message) warn(error.stack) return; } prefix[method] = new Proxy(prefix[method], { apply: patch }); } Engine.RegisterGlobal("autociv_patchApplyN",autociv_patchApplyN) if (!("autociv_profile_defined" in global)) global.autociv_profile_defined = new Set() for (let key in global) if (typeof global[key] == "function" && "prototype" in global[key]) { const proto = global[key].prototype if (autociv_profile_defined.has(key)) { // warn(`tried to repeat proxy to ${key}`) continue } autociv_profile_defined.add(key) for (let pkey in proto) if (typeof proto[pkey] == "function") { autociv_patchApplyN(proto, pkey, function (target, that, args) { Engine.ProfileStart(`S::${key}.${pkey}`) const res = target.apply(that, args) Engine.ProfileStop() return res }) } }