Defining Accessor on FunctionTemplate causes crash when debugging

150 views
Skip to first unread message

J Decker

unread,
Aug 28, 2024, 8:05:35 PM8/28/24
to v8-users
Although this is something I'm doing for Node, there's really nothing Node specific about the following (other than the steps I use to produce it)

The example JS could would be something like

class TestAccessor {
    #a = 123;
    get f() { return this.#a } // throws exception in debugger because this isn't a 'TestAccessor'
}

the above JS version of this shows example0-a.png
Thich clicking on the (...) is an error of course...  (not so fatal of an error as the DebugBreak() that node generates which pops up with a debugger dialog on systems with a development environment installed)
example0.png


So, when defining a FunctionTemplate... 

void ComObject::Init( Local<Object> exports ) {
Isolate* isolate = Isolate::GetCurrent();
Local<Context> context = isolate->GetCurrentContext();
Local<FunctionTemplate> comTemplate;

comTemplate = FunctionTemplate::New( isolate, New );
comTemplate->SetClassName( String::NewFromUtf8Literal( isolate, "sack.ComPort" ) );
comTemplate->InstanceTemplate()->SetInternalFieldCount( 1 ); // 1 required for wrap

comTemplate->PrototypeTemplate()->SetAccessorProperty( String::NewFromUtf8Literal( isolate, "rts" )
, FunctionTemplate::New( isolate, ComObject::getRTS )
, FunctionTemplate::New( isolate, ComObject::setRTS )
);
}

where ComObject::getRTS and setRTS are 

void ComObject::getRTS( const FunctionCallbackInfo<Value>& args ) {}


When debugging the Node process, if I mouse over the object containing the function with the above accessor, the getter is called, but it's not passed a valid object, so an breakpoint is generated when (node term; unwrapping) the object.
example.png

I tried to change to SetNativeDataProperty instead...   comTemplate->PrototypeTemplate()->SetNativeDataProperty( String::NewFromUtf8Literal( isolate, "rts" )
, ComObject::getRTS2
, nullptr //Local<Function>()
, Local<Value>()
, PropertyAttribute::None
, SideEffectType::kHasNoSideEffect
, SideEffectType::kHasSideEffect
);

Which then gives me (...) option call the getter.... 
example2.png

Which gives me (...) instead the above just shows the value directly without the getter expanded value... doesn't immediately cause a debugbreak, but will if I click on the (...)  which IMO shouldn't be called ever, since it cannot be given a valid object as 'this'.

I was just testing this, and thought it was something I was doing with my direct V8 Interface, but my JS test was initially missing 'f' after 'get' as in 'get f()', which does end up showing similar behavior... that the prototype getter shouldn't be called.  I can make this a cr-bug if noone else wants to ?  
Reply all
Reply to author
Forward
0 new messages