Samsung / escargot

Escargot is a lightweight JavaScript engine designed specifically for resource-constrained environments.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Debugger crashes when the class have a default constructor and field initializers

zherczeg opened this issue · comments

Example:

class C {
  a = 1
}
new C

Problem is, the byte code of the class initializers are generated after the parsing is done.

When a class has no constructor, the code->m_codeBlock is NULL here:
https://github.com/Samsung/escargot/blob/master/src/interpreter/ByteCodeInterpreter.cpp#L2783

If the debugger is enabled, the createFunctionSourceFromScriptSource crashes, because lazy compilation is detected.

The byte code of a non-default class constructor is generated here:
https://github.com/Samsung/escargot/blob/master/src/parser/ast/ClassDeclarationNode.h#L83

Somehow the class initializers (arrow functions) are also compiled in this case, so no issues with the debugger.

Would it be possible to generate the default class constructor here or this issue should be fixed in some other way?

IMO debugger could not support dynamically created functions like below,
because these functions are created during the execution and do not have static source code.
So, users cannot add any breakpoints into it.

var func = new Function('a', 'b', 'return a + b'); // dynamically created function

Similar to the above, default constructor of class is also invisible too.
Escargot just creates dynamic functions for this.

I think that we don't need to support these dynamic functions in debugger.
My question is that, is it possible to make debugger ignore these dynamic functions?

Probably these can be ignored, but the main problem is the not dynamic part:

class C {
  a = 1
}
new C

Maybe some people wants to put a breakpoint to a=1

On your example code,
a = 1 statement is belong to class initializer, not default constructor.
A virtual arrow function is created for this initializer and this function is eagerly compiled together when bytecode of class C is generated as follow.

m_class.classBody()->generateClassInitializer(codeBlock, context, classIndex);

IMHO, If we could ignore default constructor in debugger, there is no issue with lazy compilation on class.
Or maybe I misunderstood your comments.
Would you please elaborate a bit more about the trouble case?

Fixed by #958