question on the sample file process.cc

32 views
Skip to first unread message

wxz

unread,
Jun 29, 2017, 4:07:43 PM6/29/17
to v8-users
hi all,

there are two maps used in this example, one for 'options', one for 'output'. My question is, why is that in the script, the brackets [] works for 'output', but not for 'options'?

For example, if change the line:
options.verbose  ===> options[verbose]
it returns error: verbose is not defined

However, 'output[request.host]' is perfectly fine.

The two maps are installed with the same code, the wrap/unwrap are the same, what's the difference?

I guess my confusion is what exactly does bracket mean here? Does it invoke the named property interceptor?

Jakob Kummerow

unread,
Jun 29, 2017, 5:07:20 PM6/29/17
to v8-users
The equivalent of options.verbose is options["verbose"] (note the quotes). Does that help?

--
--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

wxz

unread,
Jun 29, 2017, 8:34:48 PM6/29/17
to v8-users
YES!  Thanks.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.

wxz

unread,
Jun 30, 2017, 9:31:32 AM6/30/17
to v8-users
a follow up question, in the script, the 'output' map is used as map<string, int>:

output[request.host] = 1;
output[request.host]++

however, it's a map<string, string> in c++ side, which part of the c++ code handles such conversion?


On Thursday, June 29, 2017 at 5:07:20 PM UTC-4, Jakob Kummerow wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.

Jakob Kummerow

unread,
Jun 30, 2017, 11:21:11 AM6/30/17
to v8-users
There are no conversions happening. In the script, "output" is a regular JavaScript object, with all the behavior you would expect.

On the C++ side, "output" is a map<string, string>, but "output_obj" is a JavaScript object created from that map (via the WrapMap(output) call), and that's what's exposed to the script.


To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscribe@googlegroups.com.

wxz

unread,
Jun 30, 2017, 4:38:42 PM6/30/17
to v8-users
Thanks for the explanation, but it's still blur to me.  I'm trying to wrap those two maps into an interceptor class.  Please see the attached.  It works for lines such as:  
if (option.verbose)

but it fails on lines:
output[request.host] = 1;

The script runs, but the final output is:

Instead, the correct result should be:
map_interceptor.cpp
map_interceptor.h

Jakob Kummerow

unread,
Jul 2, 2017, 9:03:26 AM7/2/17
to v8-users
If you look at the source of gin::V8ToString, you will see that it only handles string arguments. Try output[request.host] = "1", or consider using a map<std::string, int>, or change your implementation to perform number-to-string conversions as needed.
Reply all
Reply to author
Forward
0 new messages