Do all interceptor function need to be static?

25 views
Skip to first unread message

Abhishek Singh

unread,
Jul 8, 2016, 1:56:17 AM7/8/16
to v8-u...@googlegroups.com
Is it a requirement that all interceptor functions passed to "NamedPropertyHandlerConfiguration" need to be static? Looking at couple of examples, it looks pretty restrictive.

This is how I've designed my application around v8.

class Database {
  public:
    Database(Worker* w);
    ~Database();
    ...
    ...
    static DB::Client* DB_conn_obj;

  private:
    bool InstallMaps(map<string, string>* bucket);

    static Local<ObjectTemplate> MakeDBMapTemplate(Isolate* isolate);

    static void DBGet(Local<Name> name,
                          const PropertyCallbackInfo<Value>& info);
    static void DBSet(Local<Name> name, Local<Value> value,
                          const PropertyCallbackInfo<Value>& info);
    static void DBDelete(Local<Name> name,
                             const PropertyCallbackInfo<Boolean>& info);

   ...
};

Interceptors functions like DBGet/DBSet/DBDelete need to use a DB::Client connection handle and I had to make it static for things to work. But in this model, I can't connect to multiple databases because each DB needs a unique connection handle - so Ideally I would require non-static, object specific connection handle.

Any suggestion on how to overcome this limitation?

--
Thanks,

Abhishek Singh

Ben Noordhuis

unread,
Jul 8, 2016, 3:16:15 AM7/8/16
to v8-users
NamedPropertyHandlerConfiguration() takes a Local<Value> as its
second-to-last argument that is passed to your callbacks. You can
wrap a pointer with v8::External::New() and unwrap it in your
callbacks. HTH.

Abhishek Singh

unread,
Jul 8, 2016, 4:41:48 AM7/8/16
to v8-u...@googlegroups.com
Thanks again Ben, this looks promising - will give it a shot.

-- 
-- 
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages