5

What do it wants from me? How to make it work?

var proxy_handler = 
{
    ownKeys: function(target)
    {
        return Object.keys(target.data)
    },
}

var proxxxy = function(initial_data)
{
    var return_value = "Goodbye world"
    var target = function() { return return_value }
    if(typeof initial_data == "undefined")
    {
        target.data = {}
    }
    else
    {
        target.data = initial_data
    }
    return new Proxy(target, proxy_handler)
}

var p = proxxxy({q:"aaa",w:"bbb",f:"ccc"})
console.log(p())
console.log(Object.getOwnPropertyNames(p))

It prints an error but it shouldn't:

me@me:~/tst$ node --version
v6.2.2
me@me:~/tst$ node test3.js 
Goodbye world
/home/me/tst/test3.js:26
    console.log(Object.getOwnPropertyNames(p))
                       ^

TypeError: 'ownKeys' on proxy: trap result did not include 'arguments'
    at Object.<anonymous> (/home/me/tst/test3.js:26:24)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.runMain (module.js:575:10)
    at run (node.js:348:7)
    at startup (node.js:140:9)
    at node.js:463:3

Is this a bug? If so - where I can submit it?

user619271
  • 4,766
  • 5
  • 30
  • 35
  • 1
    I believe you are breaking an invariant - every function must have an `.arguments` property but yours doesn't. Why this surfaces when you call `getOwnPropertyNames`? I don't know. – Bergi Oct 01 '16 at 21:19

2 Answers2

3

This is not a bug; this behavior is defined by the proxy spec for ownKeys, step 17a. In plain English, any non-configurable property of the actual target must occur in the list of properties returned by ownKeys, so specifically arguments is missing in your example:

> Object.getOwnPropertyDescriptor(target, "arguments")
Object {value: null, writable: false, enumerable: false, configurable: false}
jmrk
  • 34,271
  • 7
  • 59
  • 74
  • So that means I cannot create a proxy of a function with configurable properties named `arguments`, `caller` and `prototype` because these names are hard-coded as non-configurable. Is this correct? – user619271 Mar 19 '17 at 18:19
  • 1
    Yes, and you can't omit them either in the proxy trap's result list. – jmrk Mar 19 '17 at 23:50
0

Use getOwnPropertyNames instead of Object.keys

  ownKeys (targert) {
    return Object.getOwnPropertyNames(targert)
  }
clarkttfu
  • 577
  • 6
  • 11