4
new Proxy(function() {}, {})

Creating a proxy to watch a function does not work on Chrome. Instead it throws an error:

Uncaught illegal access

I want to watch a function and create a proxy handler for when its properties are accessed. Seems fine in Firefox. Any way to get around this?

northamerican
  • 2,185
  • 1
  • 20
  • 31

2 Answers2

5

This is a problem with the Chrome devtools console trying to show the result, not the Proxy constructor itself. What version of Chrome are you using?

In the Chrome 50 console, I see this:

> let p = new Proxy(function(){return 6},{})
< undefined
> p
< #<Function>
Uncaught illegal access
  DebuggerScript.getFunctionScopes @ (program):4
> p()
< 6

So the function proxy works just fine, but the console barfs displaying it. Should be fixed in the latest Chrome versions. For now, you can just ignore the error.

Andreas Rossberg
  • 34,518
  • 3
  • 61
  • 72
0

Indeed as @AndreasRossberg answered a Chrome limitation. If you use same code in Firefox it works correctly and outputs as expected:

> let p = new Proxy(function(){return 6},{})
< undefined
> p
< function ()
> p()
< 6
Wilt
  • 41,477
  • 12
  • 152
  • 203