我使用Remote debugging protocol为Google Chrome编写自定义调试程序。我的调试器工作正常,除了它无法访问功能范围。我监听Debugger.paused
事件,监听器得到CallFrame
的数组。我从每个帧获得closure
范围,因此我可以获得所有绑定变量及其属性。这些变量中有一些功能。我将带有其中一个功能ID的Runtime.getProperties
发布到Chrome并获取其属性。以下是我的回应:
{
"result":[
{
"configurable":false, "enumerable":false,
"isOwn":true, "name":"length",
"value":{
"description":"0",
"type":"number",
"value":0
},
"writable":false
}, {
"configurable":false, "enumerable":false,
"isOwn":true, "name":"name",
"value":{
"type":"string",
"value":""
},
"writable":false
}, {
"configurable":false, "enumerable":false,
"get":{
"className":"Function",
"description":"function ThrowTypeError() { [native code] }",
"objectId":"{\"injectedScriptId\":3,\"id\":34}",
"type":"function"
},
"isOwn":true,"name":"arguments",
"set":{
"className":"Function",
"description":"function ThrowTypeError() { [native code] }",
"objectId":"{\"injectedScriptId\":3,\"id\":35}",
"type":"function"
}
}, {
"configurable":false, "enumerable":false,
"get":{
"className":"Function",
"description":"function ThrowTypeError() { [native code] }",
"objectId":"{\"injectedScriptId\":3,\"id\":36}",
"type":"function"
},
"isOwn":true, "name":"caller",
"set":{
"className":"Function",
"description":"function ThrowTypeError() { [native code] }",
"objectId":"{\"injectedScriptId\":3,\"id\":37}",
"type":"function"
}
}, {
"configurable":false, "enumerable":false,
"isOwn":true, "name":"prototype",
"value":{
"className":"Object",
"description":"Object",
"objectId":"{\"injectedScriptId\":3,\"id\":38}",
"type":"object"
},
"writable":true
}, {
"configurable":true, "enumerable":false,
"isOwn":true, "name":"__proto__",
"value":{
"className":"Function",
"description":"function Empty() {}",
"objectId":"{\"injectedScriptId\":3,\"id\":39}",
"type":"function"
},
"writable":true
}
]
}
如您所见,没有<function scope>
属性。但是,当我调试相同的代码并停在同一位置时,我可以打开Closure
- &gt; $return
- &gt; <function scope>
。我真的需要这个,因为$ return是在其范围内包含绑定变量的回调,所以通过回调闭包链我可以重建堆栈跟踪。