[v8-embedding] - Exposing result-set as an array in javascript

88 views
Skip to first unread message

Abhishek Singh

unread,
Jun 28, 2016, 11:40:26 PM6/28/16
to v8-u...@googlegroups.com
I'm exposing C++ objects in javascript as a map using NamedPropertyHandlerConfiguration. So operations like below in javascript are intercepted by Getter/Setter/Deleter callbacks as defined in v8 binding code.

var obj = beer-sample["test_key2"]; // "beer-sample" is the keyword I'm exposing to JS from v8 binding code, it's encapsulating a C++ object
beer-sample["test_key1"] = "test_value1";
delete beer-sample["test_key3"];

Next step in this use-case I'm looking at is to enumerate result-set obtained. I've looked at GenericNamedPropertyEnumeratorCallback but that doesn't look to be helpful in this case. Signature looks like below:

void GenericNamedPropertyEnumeratorCallback(PropertyCallbackInfo<Array>& info);

It doesn't allow to pass Local<Name> property to it like Getter/Setter/Deleter callback and I understand Enumerator Callback's purpose is different by looking at the unit tests within V8 code.

===

Here is what I'm specifically after:

In javascript a user could write something like this:

```
var queryResult = queryObj["select * from `beer-sample`;"]

var resultLength = queryResult.length;

for (var i = 0; i < resultLength; i++) {
   //Do some computation and bookkeeping on each row 
   log(queryResult[i]);
}
```

So queryResult needs to of type PropertyCallbackInfo<Array> type and I'm not sure correct way to do this. What would be the recommended to achieve this?

Thanks,
Abhishek
--
Thanks,

Abhishek Singh

Jochen Eisinger

unread,
Jun 29, 2016, 2:12:27 AM6/29/16
to v8-u...@googlegroups.com

The enumerator callback returns what is used for eg Object.getOwnPropertyNames(queryObj)

If you want queryObj["foo"] to return an array, just create on in the getter callback and set it as return value. The getter takes a PropertyCallbackInfo<Value> and Array drives from Value

Best
Jochen


--
--
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