bugzilla.mozilla.org has resumed normal operation. Attachments prior to 2014 will be unavailable for a few days. This is tracked in Bug 1475801.
Please report any other irregularities here.

Not able to get child objects methods in proxy object handler

RESOLVED INVALID

Status

Invalid Bugs
General
RESOLVED INVALID
2 years ago
2 years ago

People

(Reporter: shimpiatul, Unassigned)

Tracking

Details

(Whiteboard: [specification][type:bug])

(Reporter)

Description

2 years ago
What did you do?
================
I have javascript object such as var Countries = {};

I create proxy on this object to trap all method calls.

When i call a function like this Countries.Cities.getAll(),
i want to trap cities and getAll().

What happened?
==============
Trap is getting only Cities. 

What should have happened?
==========================
Trap should get Cities.getAll()

Is there anything else we should know?
======================================
Can you provide a standalone testcase?
Component: API → Untriaged
Flags: needinfo?(shimpiatul)
Product: Mozilla Developer Network → Firefox
(Reporter)

Comment 2

2 years ago
My code in app.js
var apiMall = function(){
 
};
 
obj  = new Proxy({},
        { get : function(target, method, receiver)
            {
                console.log("type : " + target);
                if(target[method] === undefined)
                    return function()  {                                                                         
                        //console.log('Method : ' +  method + '(' + JSON.stringify(arguments) + ')');
                    };
                else
                    return target[method];
            },                  
});

included this file in html page using the script tag.

Then called the function obj.Cities.getAll() from one of the button handler.
On console its printing "type : " Cities when i clcked the button.
Actual its should print Cities.getAll().
I want to trap the object also.
Flags: needinfo?(shimpiatul)
In your code, object returned from get handler is not a Proxy.
If you want to trap get on the property, you need to return Proxy for the property access, 

anyway, not a browser's bug.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 2 years ago
Resolution: --- → INVALID
(Reporter)

Comment 4

2 years ago
Can u give me example.

It may not be a bug. But i want to achieve that functionality.

Basically what i want is that,if object.childObject1.childObject2.anyMethod() is called, i want to trap
childObject1, childObject1 and anyMethod. I want list of all the objects.
function f() {
  return new Proxy(function(){}, {
    get: function(target, name) {
      console.log("get", name);
      return f();
    },
    apply: function(target, thisArg, args) {
      console.log("apply", args);
    }
  });
}

var object = f();
object.childObject1.childObject2.anyMethod(1, 2, 3);

Updated

2 years ago
Component: Untriaged → General
Product: Firefox → Invalid Bugs
(Reporter)

Comment 6

2 years ago
Wow. Thanks I am almost closer.
Can u tell me how can i get childObject1, childObject2 and anyMethod() in one shot.
Means for every method call, i want to detect childObjec1, childObject2 and create a function.
You need to log in before you can comment on or make changes to this bug.