2016-10-01 4 views
2

私は何をしたいですか?それを動作させるには?TypeError:プロキシの 'ownKeys':トラップ結果に 'arguments'が含まれていません

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)) 

それはエラーを出力しますが、それはいけない:

[email protected]:~/tst$ node --version 
v6.2.2 
[email protected]:~/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 

は、これはバグですか?もしそうなら、私はそれを提出することができますか?

+1

を私はあなたが不変壊していると考えている - すべての機能が必要に'.arguments'プロパティを持っていますが、あなたのものはありません。 'getOwnPropertyNames'を呼び出すと、なぜこれが現れますか?知りません。 – Bergi

答えて

2

これはバグではありません。この動作はownKeys、ステップ17aのproxy specによって定義されます。平易な英語では、実際のtargetのいずれかの非設定可能なプロパティは、そう、具体的argumentsはあなたの例では欠けている、ownKeysによって返されたプロパティのリストで発生する必要があります。

> Object.getOwnPropertyDescriptor(target, "arguments") 
Object {value: null, writable: false, enumerable: false, configurable: false} 
+0

これは、 'arguments'、' caller'、 'prototype'という名前の設定可能なプロパティを持つ関数のプロキシを作成できないことを意味します。これらの名前は設定不可能なものとしてハードコードされているからです。これは正しいです? – user619271

+1

はい、プロキシトラップの結果リストでそれらを省略することはできません。 – jmrk

関連する問題