mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 18:36:36 +00:00
zjsunit: Simplify zjquery patching.
This makes it so that we can bypass the Proxy object in zjquery with less code in namespace.js.
This commit is contained in:
committed by
Steve Howell
parent
306bf930f5
commit
d74266ac75
@@ -197,17 +197,10 @@ exports.with_overrides = function (test_function) {
|
||||
|
||||
unused_funcs.get(obj).set(func_name, true);
|
||||
|
||||
let old_f =
|
||||
const old_f =
|
||||
"__esModule" in obj && "__Rewire__" in obj && !(func_name in obj)
|
||||
? obj.__GetDependency__(func_name)
|
||||
: obj[func_name];
|
||||
if (old_f === undefined) {
|
||||
// Create a dummy function so that we can
|
||||
// attach _patched_with_override to it.
|
||||
old_f = () => {
|
||||
throw new Error(`There is no ${func_name}() field for this object.`);
|
||||
};
|
||||
}
|
||||
|
||||
const new_f = function (...args) {
|
||||
unused_funcs.get(obj).delete(func_name);
|
||||
@@ -227,9 +220,7 @@ exports.with_overrides = function (test_function) {
|
||||
} else {
|
||||
obj[func_name] = new_f;
|
||||
restore_callbacks.push(() => {
|
||||
old_f._patched_with_override = true;
|
||||
obj[func_name] = old_f;
|
||||
delete old_f._patched_with_override;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -608,6 +608,11 @@ function make_zjquery() {
|
||||
|
||||
const $ = new Proxy(make_zjquery(), {
|
||||
set(obj, prop, value) {
|
||||
if (obj[prop] && obj[prop]._patched_with_override) {
|
||||
obj[prop] = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (value._patched_with_override) {
|
||||
obj[prop] = value;
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user