NamedPropertyHandlers on Function object

67 views
Skip to first unread message

Charles Lowell

unread,
Jun 21, 2010, 10:01:59 AM6/21/10
to v8-users
Hi there,

What, if any, is the best way to intercept property lookups on a
Function object? I'm reflecting ruby classes into javascript as
constructor functions, but the ruby classes themselves have
potentially dynamic properties just like any other object, and so I'd
like to be able to reuse the same named property handlers from my
normal ruby objects. I just can't figure out where to put them.

cheers,
Charles

Duncan Tebbs

unread,
Jul 11, 2012, 2:19:39 AM7/11/12
to v8-u...@googlegroups.com

I've come across this same problem trying to replace JavaScriptCore with v8.  Did you ever find a solution?

It would be great to have FunctionTemplate::SetNamedPropertyHandler, as we have with ObjectTemplate, to intercept property accesses on the Function created by the template.  Does anyone know how this could be achieved, or is it just missing API?

Thanks,
Duncan

Michael Schwartz

unread,
Jul 11, 2012, 9:53:16 AM7/11/12
to v8-u...@googlegroups.com

Duncan Tebbs

unread,
Jul 12, 2012, 1:58:15 AM7/12/12
to v8-u...@googlegroups.com
Thanks for pointing that out. I'll look into that as there doesn't seem
to be a solution via the C++ API.

Duncan
>> v8-u...@googlegroups.com <mailto:v8-u...@googlegroups.com>
>> http://groups.google.com/group/v8-users

Michael Schwartz

unread,
Jul 12, 2012, 2:27:21 PM7/12/12
to v8-u...@googlegroups.com
What would really rock is if you could proxy for the global object.

Andreas Rossberg

unread,
Jul 13, 2012, 4:34:43 AM7/13/12
to v8-u...@googlegroups.com
On 12 July 2012 20:27, Michael Schwartz <myk...@gmail.com> wrote:
What would really rock is if you could proxy for the global object.

*shudder*  I fear that this will, in fact, be possible at some point, and I already cringe at just thinking of the perverted ways programmers will sure find to abuse that feature. ;)

/Andreas

mschwartz

unread,
Jul 13, 2012, 10:36:30 AM7/13/12
to v8-u...@googlegroups.com
Heh.

The possibilities I see for its use are to protect the global object from extraneous modification and tracking changes to the global object.

Server-side implementations can have some interesting issues when arbitrary user code is allowed to execute.  I'm thinking of an MVC situation where the templates are written by users and contain JavaScript.  Tools like JSLint and JSHint are great for us developers, but a production/creative person may not see the benefit from those sorts of tools.  

Another issue that comes up on this list from time to time is the ability to "reset" the global object between requests in a server-side HTTP scenario.  If you can track changes made during one request, you can undo them between requests.

You can also enforce certain policies, like "only approved frameworks can store to the global object."

Or you can implement monitoring tools to discover global usage patterns while an application is running.

But I'm sure there are horrible things that people can do as well.

Stephan Beal

unread,
Jul 13, 2012, 10:55:47 AM7/13/12
to v8-u...@googlegroups.com
On Fri, Jul 13, 2012 at 4:36 PM, mschwartz <myk...@gmail.com> wrote:
The possibilities I see for its use are to protect the global object from extraneous modification and tracking changes to the global object.

Would that not be applicable for the recent thread about how to "reset" the global object for re-use?
 
Another issue that comes up on this list from time to time is the ability to "reset" the global object between requests in a server-side HTTP scenario.  If you can track changes made during one request, you can undo them between requests.

That's what i get for not reading ahead before asking questions :/. Undo might not always be feasible because changes could have side-effects which the global object does not directly see. For example:

var foo = {}; // in global scope. Global knows about foo, but...

// in client code:

foo.bar = ...;

the global observer probably could not catch that and therefore not generically revert it.

--
----- stephan beal
http://wanderinghorse.net/home/stephan/
Reply all
Reply to author
Forward
0 new messages