On Thu, Nov 22, 2018 at 8:37 AM Gautham B A <gautham.bangal...@gmail.com> wrote: > Hi all, > > I'm trying to create a CustomError class by inheriting from the JavaScript > Error class. So, I have a FunctionTemplate for CustomError > > auto custom_err_template = v8::FunctionTemplate::New(isolate); > > In the v8 docs on FunctionTemplate - > https://v8docs.nodesource.com/node-7.10/d8/d83/classv8_1_1_function_template.html#ac54d88e6fdc00872babe5c91515b9dce > , it is mentioned that I can call Inherit(<parent_function_template>) . I'm > trying to achieve the same by attempting to get the FunctionTemplate of the > Error class, but in vain. > > auto context = isolate->GetCurrentContext(); > auto global = context->Global(); > auto error_function = global->Get(v8::String::NewFromUtf8(isolate, > "Error")).As<v8::Function>(); > // How do I get the FunctionTemplate of error_function ? Is it possible to do > so? > > // I can then call the following to setup the inheritance Error as the parent > of CustomError > custom_err_template->Inherit(<function_template_of_Error>); > > Since Error is a builtin class, I get it from the global object. But I'm not > sure how to get the FunctionTemplate from the v8::Local<v8::Function> > instance. > > Could anyone please help me? > > Thanks, > --Gautham
I don't think that's currently possible, inheriting from Error through a FunctionTemplate. As a workaround, you could mutate the prototype after creating an instance of your class (NewInstance() + SetPrototype().) -- -- 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.