Result is the same. It tries to execute NamedGetter first. Thanks for your advice, but I still need another solution. I can't remove NamedPropertyHandler in my case. I just need to make NamedPropertyHandler process functions correctly as well or ignore them in any way.
вторник, 11 сентября 2018 г., 16:39:10 UTC+3 пользователь J Decker написал: > > I found it esaier to work with > SetAccessorProperty > > https://v8docs.nodesource.com/node-0.12/db/df7/classv8_1_1_template.html#a25856e3bf1b8b0d3ee7865687a8e6d97 > > example > https://github.com/d3x0r/sack.vfs/blob/master/src/gui/sack_image_module.cc#L134 > defines some get/set methods on an image class; that works with the > prototype template, but it's part of Template should also be availble on an > ObjectTemplate > > the setter has a default of 0 (NULL) > > but like imageTemplate->PrototypeTemplate()->SetAccessorProperty( > String::NewFromUtf8( isolate, "jpgQuality" ) > , FunctionTemplate::New( isolate, ImageObject::getJpegQuality ) > , FunctionTemplate::New( isolate, ImageObject::setJpegQuality ), > DontDelete ); > > But they just take 'regular' function definitions > > void ImageObject::getJpegQuality( const FunctionCallbackInfo<Value>& args > ) { } > void ImageObject::setJpegQuality( const FunctionCallbackInfo<Value>& > args ) {} > > Now, what happens if you also define a function of the same name I don't > know. > > > On Tue, Sep 11, 2018 at 6:24 AM Andrei Vinogradov <anri...@gmail.com > <javascript:>> wrote: > >> Hello. >> I'm trying to create new template that should match required behaviour >> but now i'm stuck with NamedPropertyHandler. >> What I need to achieve: >> 1. All property access calls should be processed by unified handlers >> (getter/setter for indexed access and getter/setter for named access). >> (This part is working). >> 2. Template also should have a set of predefined functions with different >> handlers for each. (This part is not working). >> >> What I am doing. Assume that we have code like following: >> >> void NamedGetter(Local<Name> name, const PropertyCallbackInfo<Value> & >> info) { ... } >> void NamedSetter(Local<Name> name, Local<Value> value, const >> PropertyCallbackInfo<Value> &info) { ... } >> void IndexedGetter(uint32_t index, const PropertyCallbackInfo<Value> & >> info) { ... } >> void IndexedSetter(uint32_t index, Local<Value> value, const >> PropertyCallbackInfo<Value> &info) { ... } >> void FunctionAHandler(const FunctionCallbackInfo<Value> &info) { ... } >> >> //Lets skip initialization code... >> >> Local<String> funcName = String::NewFromUtf8(isolate, "FunctionA", v8:: >> NewStringType::kNormal).ToLocalChecked(); >> >> Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); >> templ->Set(funcName, FunctionTemplate::New(isolate, FunctionAHandler, >> funcName)); >> templ->SetHandler(NamedPropertyHandlerConfiguration(NamedGetter, >> NamedSetter)); >> templ->SetHandler(IndexedPropertyHandlerConfiguration(IndexedGetter, >> IndexedSetter)); >> >> //Creating instance of template in current context with name >> my_instance... >> >> Then, when i'm executing JS like "my_instance.FunctionA();" this is >> proccessed by V8 like i'm accessing property with name "FunctionA". I mean >> it's starting to execute NamedGetter function. >> And after that it fails with error: >> >> <unknown>:10: Uncaught TypeError: my_instance.FunctionA is not a function >> >> If I'm not adding NamedPropertyHandler to template - FunctionAHandler is >> invoked like expected. >> So my question is - how to avoid executing NamedGetter when function with >> such name is defined on template? Or maybe i't possible to proccess >> function calls inside NamedGetter and avoid creating handlers for each >> function I need in template? >> I would appreciate any help with this. >> >> -- >> -- >> v8-users mailing list >> v8-u...@googlegroups.com <javascript:> >> 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 <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > -- -- v8-users mailing list v8-users@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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.