[v8-users] Re: Property Interceptors - anything similar for functions?

2009-07-17 Thread Ravi


Thanks Stephen!

On Jul 16, 4:30 pm, Stephan Beal sgb...@googlemail.com wrote:
 On Thu, Jul 16, 2009 at 9:56 PM, Ravi chinn...@yahoo.com wrote:

  Using Interceptors, is there anyway to figure out the arguments 'arg1'
  and 'arg2' on 'method1', or will I have to add a function callback
  after knowing (in the interceptor) that it's trying to invoke a method
  called 'method1'.

 The interceptors never see the arguments. The call:

 obj.method(arg1,arg2)

 is logically a few different parts:

 a) call interceptor for obj['method']. This part you can intercept in client
 code.
 b) Ensure that the property is-a callable type. If not, throw an error.
 c) Evaluate the arguments (in an unspecified order, AFAIK) and push them
 onto an arguments list.
 d) call the result of (a), passing it the arguments list.

 To intercept part (d) you have to (re)implement the function pointed to by
 obj.method.

 --
 - stephan bealhttp://wanderinghorse.net/home/stephan/
--~--~-~--~~~---~--~~
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
-~--~~~~--~~--~--~---



[v8-users] Re: Property Interceptors - anything similar for functions?

2009-07-16 Thread Matthias Ernst

A method is nothing but a property with a function as value.

So you can do:
object_template-Set(
  f, FunctionTemplate::New(callback)-GetFunction());

or with a property accessor:

HandleValue return_data(LocalString property, const AccessorInfo info) {
  return info.Data();
}

object_template-SetAccessor(
  String::New(f),
  return_data, NULL,
  FunctionTemplate::New(callback)-GetFunction());


Matthias

On Thu, Jul 16, 2009 at 5:06 PM, Ravichinn...@yahoo.com wrote:

 Hi,

 The property interceptors provide a way to handle any object property
 with a callback. I was wondering if there is something similar to
 handle any object method.

 Thank you,
 Ravi

 


--~--~-~--~~~---~--~~
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
-~--~~~~--~~--~--~---



[v8-users] Re: Property Interceptors - anything similar for functions?

2009-07-16 Thread Ravi


Thanks Stephan. Interceptors do seem to handle functions, but, I
couldn't figure out a way to access the function arguments. I wish
there were an example for such a scenario.

On Jul 16, 11:22 am, Stephan Beal sgb...@googlemail.com wrote:
 On Thu, Jul 16, 2009 at 5:06 PM, Ravi chinn...@yahoo.com wrote:
  The property interceptors provide a way to handle any object property
  with a callback. I was wondering if there is something similar to
  handle any object method.

 In theory, since a method is-a property, methods can also be handled via
 interceptors. i haven't tried it, but since JS does not syntactically
 differentiate between (a.b = c) based on the types of a.b and c, then
 interceptors should work on methods in the same way they work on
 non-method members.

 In theory, of course.

 --
 - stephan bealhttp://wanderinghorse.net/home/stephan/
--~--~-~--~~~---~--~~
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
-~--~~~~--~~--~--~---



[v8-users] Re: Property Interceptors - anything similar for functions?

2009-07-16 Thread Dean McNamee

The interceptor just returns the function, you aren't calling the
function.  The arguments come in when you call the function.

On Thu, Jul 16, 2009 at 5:39 PM, Ravichinn...@yahoo.com wrote:


 Thanks Stephan. Interceptors do seem to handle functions, but, I
 couldn't figure out a way to access the function arguments. I wish
 there were an example for such a scenario.

 On Jul 16, 11:22 am, Stephan Beal sgb...@googlemail.com wrote:
 On Thu, Jul 16, 2009 at 5:06 PM, Ravi chinn...@yahoo.com wrote:
  The property interceptors provide a way to handle any object property
  with a callback. I was wondering if there is something similar to
  handle any object method.

 In theory, since a method is-a property, methods can also be handled via
 interceptors. i haven't tried it, but since JS does not syntactically
 differentiate between (a.b = c) based on the types of a.b and c, then
 interceptors should work on methods in the same way they work on
 non-method members.

 In theory, of course.

 --
 - stephan bealhttp://wanderinghorse.net/home/stephan/
 


--~--~-~--~~~---~--~~
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
-~--~~~~--~~--~--~---



[v8-users] Re: Property Interceptors - anything similar for functions?

2009-07-16 Thread Ravi


Thanks Dean.

The scenario I'm working on is: having a generic handler to capture
all the property and method calls on an object. For example, let's say
an object Obj is being used in javaScript, I'd like to capture and
record any operation on that Obj, like
var a = Obj.A
document.write(a)
Obj.method1(arg1, arg2);
Obj.b = 2;
.

Here, I do not know the names of Obj's properties/methods ahead. I'd
simply like to know that the script accessed Obj property 'A', invoked
'method1' on Obj with arguments 'arg1' and 'arg2', and set the
property 'b'.

Using Interceptors, is there anyway to figure out the arguments 'arg1'
and 'arg2' on 'method1', or will I have to add a function callback
after knowing (in the interceptor) that it's trying to invoke a method
called 'method1'.

Thank you.



On Jul 16, 11:49 am, Dean McNamee de...@chromium.org wrote:
 The interceptor just returns the function, you aren't calling the
 function.  The arguments come in when you call the function.



 On Thu, Jul 16, 2009 at 5:39 PM, Ravichinn...@yahoo.com wrote:

  Thanks Stephan. Interceptors do seem to handle functions, but, I
  couldn't figure out a way to access the function arguments. I wish
  there were an example for such a scenario.

  On Jul 16, 11:22 am, Stephan Beal sgb...@googlemail.com wrote:
  On Thu, Jul 16, 2009 at 5:06 PM, Ravi chinn...@yahoo.com wrote:
   The property interceptors provide a way to handle any object property
   with a callback. I was wondering if there is something similar to
   handle any object method.

  In theory, since a method is-a property, methods can also be handled via
  interceptors. i haven't tried it, but since JS does not syntactically
  differentiate between (a.b = c) based on the types of a.b and c, then
  interceptors should work on methods in the same way they work on
  non-method members.

  In theory, of course.

  --
  - stephan bealhttp://wanderinghorse.net/home/stephan/- Hide quoted 
  text -

 - Show quoted text -
--~--~-~--~~~---~--~~
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
-~--~~~~--~~--~--~---