On Sun, Jun 26, 2011 at 10:59 PM, Marcel Laverdet <[email protected]>wrote:

On Sun, Jun 26, 2011 at 10:59 PM, Marcel Laverdet <[email protected]>
 wrote:

> The first param is the FunctionTemplate of your "this" object. If it's a
> method, you would put your ctor's FunctionTemplate there. Then just set argc
> to the number of arguments the function is supposed to have followed by an
> array of FunctionTemplates for each parameter type.
>

If you're pasting that from official docs, i'd love to know the source! If
you just wrote it, i would ask that you please get them added to the API
docs :).

There is a simple usage example in my node-fibers project:
> https://github.com/laverdet/node-fibers/blob/master/src/fibers.cc
>

It seems to me that the internal overhead of using a signature is more
costly than using one additional internal field, seeing as the signatures
hold more information that that.

signature into that and v8 will guarantee your arguments are as expected per
> the Signature. I don't think it's possible to specify optional arguments,
> multiple types, etc. I saw you were doing some method overloading stuff so
> maybe this is the wrong solution.
>

Yes, the approach i'm now developing/using uses functors which examine the
Arguments object, so they can perform logic based on count, types, and
potentially other app-related state (but i can't imagine that being all that
useful except to maybe perform some one-time initialization of related code
the first time it is called from JS. e.g. initializing lt_dlinit() or the
ncurses screen state). The functors can be combined using templates so that
we can literally create trees of logic. There's a brief demonstration here:

http://code.google.com/p/v8-juice/source/browse/convert/ConvertDemo.cpp#170

Another feature it provides which Signatures doen't is the runtime
determination of whether a JS number is compatible with int8_t, int16_t
and/or int32_t (v8 doesn't support 64-bit ints). We could use that same
technique to enforce numeric range validation on converted types, throwing a
JS error if a numeric arg is not in a specific range (i.e. can't be legally
converted to the type expected by the native).

-- 
----- stephan beal
http://wanderinghorse.net/home/stephan/

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to