Search code examples
c++v8

What are the AccessorGetter and AccessorSetter typedefs for in v8?


I am viewing v8 header file, and got a problem again.

https://github.com/joyent/node/blob/master/deps/v8/include/v8.h#L1408-1414

typedef Handle<Value> (*AccessorGetter)(Local<String> property,
                                    const AccessorInfo& info);


typedef void (*AccessorSetter)(Local<String> property,
                           Local<Value> value,
                           const AccessorInfo& info);

I don't know what this typedef use for?


Solution

  • The two type definitions create simple names for pointers to functions matching a given signature.

    typedef Handle<Value> (*AccessorGetter)
        (Local<String> property,
         const AccessorInfo& info);
    

    This defines a new type AccessorGetter that can be used to create variables that contain the address of a function with the signature

    Handle<Value> SampleAccessorGetter
        (Local<String> property,
         const AccessorInfo& info)
    {
        // ...
    }
    

    And it can be used in code such as:

    int main ()
    {
        // two variables that contain the address of `SampleAccessorGetter`.
        AccessorGetter f = &SampleAccessorGetter;
        AccessorGetter g = &SampleAccessorGetter;
    
        // these variables can be used to call the pointee function:
        f(...);
        g(...);
    }