Please find standalone code simulating your suggestion - https://gist.github.com/abhi-bit/d3a2910ec54a47ce8294c2cc0c4bef93 <https://gist.github.com/abhi-bit/d3a2910ec54a47ce8294c2cc0c4bef93> (In the comment pasted output in my case). Will appreciate if you could guide using this test script.
> On 28-Jul-2016, at 4:05 PM, Abhishek Singh <[email protected]> > wrote: > > I believe this is the change you wanted me to do: > > Local<Object> HTTPBody::WrapHTTPBodyMap() { > EscapableHandleScope handle_scope(GetIsolate()); > > Local<FunctionTemplate> body_map_template = > FunctionTemplate::New(GetIsolate()); > body_map_template->InstanceTemplate()->SetHandler( > NamedPropertyHandlerConfiguration(NULL, HTTPBodySet)); > body_map_template->InstanceTemplate()->SetInternalFieldCount(1); > Local<Object> result = body_map_template->GetFunction()->NewInstance(); > > Local<External> map_ptr = External::New(GetIsolate(), &http_body); > > result->SetInternalField(0, map_ptr); > > return handle_scope.Escape(result); > } > > This didn’t help. I’ll share a standalone program that simulates problem I > see, maybe that would help you to see what the problem could be? Would be > some bit of effort for me, but will do given it will be very useful to have > nested c++ maps exposed to JS. > >> On 28-Jul-2016, at 12:54 PM, Jochen Eisinger <[email protected] >> <mailto:[email protected]>> wrote: >> >> I guess you should use function templates here. >> >> Local<FunctionTemplate> body_map_template = FunctionTemplate::New(isolate); >> body_map_template->InstanceTemplate()->SetHandler(...) >> body_map_template->InstanceTemplate()->SetInternalFieldCount(1); >> result = body_map_template->GetFunction()->NewInstance(); >> >> On Wed, Jul 27, 2016 at 4:27 PM Abhishek Singh <[email protected] >> <mailto:[email protected]>> wrote: >> Hi Jochen, >> >> Full code of relevant file available - http://pastebin.com/fZJENvSi >> <http://pastebin.com/fZJENvSi> >> >> Snippet of relevant portions for WrapHTTPBodyMap: >> >> Local<ObjectTemplate> HTTPBody::MakeHTTPBodyMapTemplate( >> Isolate* isolate) { >> EscapableHandleScope handle_scope(isolate); >> >> Local<ObjectTemplate> result = ObjectTemplate::New(isolate); >> result->SetInternalFieldCount(1); >> result->SetHandler(NamedPropertyHandlerConfiguration(NULL, >> HTTPBodySet)); >> >> return handle_scope.Escape(result); >> } >> >> Local<Object> HTTPBody::WrapHTTPBodyMap() { >> EscapableHandleScope handle_scope(GetIsolate()); >> >> if (http_body_map_template_.IsEmpty()) { >> Local<ObjectTemplate> raw_template = >> MakeHTTPBodyMapTemplate(GetIsolate()); >> http_body_map_template_.Reset(GetIsolate(), raw_template); >> } >> Local<ObjectTemplate> templ = >> Local<ObjectTemplate>::New(GetIsolate(), http_body_map_template_); >> >> Local<Object> result = >> templ->NewInstance(GetIsolate()->GetCurrentContext()).ToLocalChecked(); >> >> Local<External> map_ptr = External::New(GetIsolate(), &http_body); >> >> result->SetInternalField(0, map_ptr); >> >> return handle_scope.Escape(result); >> } >> >> >>> On 27-Jul-2016, at 7:47 PM, Jochen Eisinger <[email protected] >>> <mailto:[email protected]>> wrote: >>> >>> Can you provide a complete example? I suspect that WrapHTTPBodyMap doesn't >>> do what you expect it does >>> >>> On Tue, Jul 26, 2016 at 1:04 PM Abhishek Singh <[email protected] >>> <mailto:[email protected]>> wrote: >>> Would you mind guiding me a bit here? For now just trying to expose nested >>> “body” map i.e. to allow something like “response.body.result = >>> dbQueryResult" >>> >>> First is the Set interceptor for “response” (C++ object) and here I’m >>> setting up “body” (C++ object for “body”) & setting return value to “body” >>> object. Second one is Set interceptor for “body” >>> >>> void HTTPResponse::HTTPResponseSet(Local<Name> name, Local<Value> value_obj, >>> const PropertyCallbackInfo<Value>& info) >>> { >>> if (name->IsSymbol()) return; >>> >>> V8Handle* w = UnwrapV8HandleInstance(info.Holder()); >>> HTTPBody* body = new HTTPBody(w); >>> >>> Local<Object> body_map = body->WrapHTTPBodyMap(); >>> info.GetReturnValue().Set(body_map); >>> } >>> >>> >>> void HTTPBody::HTTPBodySet(Local<Name> name, Local<Value> value_obj, >>> const PropertyCallbackInfo<Value>& info) { >>> if (name->IsSymbol()) return; >>> >>> string key = ObjectToString(Local<String>::Cast(name)); >>> string value = ToString(info.GetIsolate(), value_obj); >>> >>> map<string, string>* body = UnwrapMap(info.Holder()); >>> (*body)[key] = value; >>> >>> cout << "body field " << value << endl; >>> } >>> >>> >>> Currently I’m not hitting Set interceptor of “body” object, I suppose I’m >>> doing something wrong here. >>> >>> >>>> On 25-Jul-2016, at 10:00 PM, Jochen Eisinger <[email protected] >>>> <mailto:[email protected]>> wrote: >>>> >>> >>>> To create dynamic nested maps from C++, the outter object (response) would >>>> have to return another intercepted object (e.g. body) that then returns >>>> the actual values on access. >>>> >>>> On Fri, Jul 22, 2016 at 8:12 AM Abhishek Singh >>>> <[email protected] <mailto:[email protected]>> wrote: >>>> Hi, >>>> >>>> I’m wondering if there is a way to expose map<string, map<string, string> >>>> > into JS world from C++? Exposing map<string, string> looks >>>> straightforward and I’m doing for some C++ objects using >>>> NamedPropertyConfigurationHandler. I’ll just show sample JS code that I >>>> would like to have and where C++ map<string, map<string, string> > will >>>> come into picture: >>>> >>>> function OnHTTPGet(request, response) { >>>> >>>> var city = “BLR”; >>>> var limit = “10”; >>>> >>>> var queryResult = dbCal(“select * from users where city=${city} >>>> limit ${limit}”); >>>> >>>> // This works for me presently >>>> /* response.data = queryResult; >>>> response.status_code = 200; */ >>>> >>>> // What I would like to have >>>> response.body.data = queryResult; >>>> response.header.status_code = 200; >>>> } >>>> >>>> “request” - native HTTP request JSON passed from C++ V8 binding as args to >>>> JS function >>>> “response” - C++ based HTTP object exposed with Setter callback set using >>>> NamedPropertyConfigHandler and this what I write back to user who made the >>>> “request" >>>> >>>> I basically want to set HTTP response body and header transparently, which >>>> would require me to expose C++ HTTP object probably as a map<string, >>>> map<string, string> >. Hope my question is clear, please let me know if >>>> there a way to do this? >>>> >>>> Thanks, >>>> Abhishek >>>> >>>> -- >>>> -- >>>> v8-users mailing list >>>> [email protected] <mailto:[email protected]> >>>> http://groups.google.com/group/v8-users >>>> <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 [email protected] >>>> <mailto:v8-users%[email protected]>. >>>> For more options, visit https://groups.google.com/d/optout >>>> <https://groups.google.com/d/optout>. >>>> >>>> -- >>>> -- >>>> v8-users mailing list >>>> [email protected] <mailto:[email protected]> >>>> http://groups.google.com/group/v8-users >>>> <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 [email protected] >>>> <mailto:[email protected]>. >>>> For more options, visit https://groups.google.com/d/optout >>>> <https://groups.google.com/d/optout>. >>> >>> >>> -- >>> -- >>> v8-users mailing list >>> [email protected] <mailto:[email protected]> >>> http://groups.google.com/group/v8-users >>> <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 [email protected] >>> <mailto:[email protected]>. >>> For more options, visit https://groups.google.com/d/optout >>> <https://groups.google.com/d/optout>. >>> >>> -- >>> -- >>> v8-users mailing list >>> [email protected] <mailto:[email protected]> >>> http://groups.google.com/group/v8-users >>> <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 [email protected] >>> <mailto:[email protected]>. >>> For more options, visit https://groups.google.com/d/optout >>> <https://groups.google.com/d/optout>. >> >> >> -- >> -- >> v8-users mailing list >> [email protected] <mailto:[email protected]> >> http://groups.google.com/group/v8-users >> <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 [email protected] >> <mailto:[email protected]>. >> For more options, visit https://groups.google.com/d/optout >> <https://groups.google.com/d/optout>. >> >> -- >> -- >> v8-users mailing list >> [email protected] <mailto:[email protected]> >> http://groups.google.com/group/v8-users >> <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 [email protected] >> <mailto:[email protected]>. >> For more options, visit https://groups.google.com/d/optout >> <https://groups.google.com/d/optout>. > -- -- v8-users mailing list [email protected] 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
