0

Consider this code:

handler.toString = function() {
    return Reflect.get(original,'toString');
}
handler.apply = scope.exportFunctionWithName(function(target, thisArgs, args){
    try {
        return args.length?
            replacement.call(thisArgs, ...args):
            replacement.call(thisArgs);
    }
    catch (error){
        try {
            return original.apply(thisArgs, args);
        }
        catch (error){
            return target.apply(thisArgs, args);
        }
    }
}, window, "");
const proxy = new window.Proxy(original, handler);

if I invoke ApiObj.toString(), it works as expected.

Now if I want to invoke ApiObj.toString.caller, it errors out, with

get caller method called on incompatible proxy

How can I fix this ?

2
  • 1
    Please include the whole definition of handler, scope, original and ApiObj as a minimal reproducible example that we can run
    – Bergi
    Commented Nov 3, 2023 at 18:50
  • 2
    Do not use .caller, it is deprecated since ages.
    – Bergi
    Commented Nov 3, 2023 at 18:50

0

Browse other questions tagged or ask your own question.