Skip to content

Bug calling _iter metametoth after creating Array or Object #361

@jespa007

Description

@jespa007

This causes a segmentation fault

class A{
	constructor(){
		this.iter=[]._iter();
	}
}

(new A())

The output code is the following,

ScriptFunction: '@MainFunction'                                             
 Stack code: 2                                                    
 Stack local vars: 0                                         
 Total stack required: 2                                     
 Scopes: 1                                                   

 NUM |RS|AS|               BYTE CODE                        
-----+--+--+--------------------------------------------------
[0000| 1|01]    NEW_OBJECT_BY_TYPE      A
[0001| 1|02]    LOAD_CONSTRUCTOR_FUNCT  constructor
[0002|-1|00]    CALL_CONSTRUCTOR        arg:0 ret:0 [RST]

______________________________________________________________

 ScriptFunction: 'A::constructor'                                             
 Stack code: 3                                                    
 Stack local vars: 0                                         
 Total stack required: 3                                     
 Scopes: 0                                                   

 NUM |RS|AS|               BYTE CODE                        
-----+--+--+--------------------------------------------------
[0000| 1|01]    NEW_ARRAY
[0001| 1|02]    LOAD_OBJ@ITEM           _iter [CALL]
[0002| 0|02]    MEMBER_CALL             arg:0 ret:1 
[0003| 1|03]    PUSH_STK_THIS@VAR       this.iter [SLOT]
[0004|-1|00]    STORE                   n:1 [RST]

Segmentation fault (core dumped)

As a solution could be do not call _iter just after creation (i.e NEW_ARRAY or NEW_OBJECT instruction)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions