Not able to get child objects methods in proxy object handler



2 years ago
2 years ago


(Reporter: shimpiatul, Unassigned)



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



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

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) + ')');
                    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.
Last Resolved: 2 years ago
Resolution: --- → INVALID

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);
Component: Untriaged → General
Product: Firefox → Invalid Bugs

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.