@@ -602,9 +602,9 @@ ecma_op_function_is_generator (ecma_object_t *obj_p) /**< object */
602602 && !ecma_get_object_is_builtin (obj_p ))
603603 {
604604 ecma_extended_object_t * ext_func_obj_p = (ecma_extended_object_t * ) obj_p ;
605- const ecma_compiled_code_t * bytecode_data_p = ecma_op_function_get_compiled_code (ext_func_obj_p );
605+ const ecma_compiled_code_t * byte_code_p = ecma_op_function_get_compiled_code (ext_func_obj_p );
606606
607- return ( bytecode_data_p -> status_flags & CBC_CODE_FLAGS_GENERATOR ) != 0 ;
607+ return CBC_FUNCTION_GET_TYPE ( byte_code_p -> status_flags ) == CBC_FUNCTION_GENERATOR ;
608608 }
609609
610610 return false;
@@ -843,26 +843,20 @@ ecma_op_function_call_simple (ecma_object_t *func_obj_p, /**< Function object */
843843 uint16_t status_flags = bytecode_data_p -> status_flags ;
844844
845845#if ENABLED (JERRY_ES2015 )
846- bool is_construct_call = JERRY_CONTEXT (current_new_target ) != NULL ;
847- if (JERRY_UNLIKELY (status_flags & (CBC_CODE_FLAGS_CLASS_CONSTRUCTOR | CBC_CODE_FLAGS_GENERATOR )))
848- {
849- if (!is_construct_call && (status_flags & CBC_CODE_FLAGS_CLASS_CONSTRUCTOR ))
850- {
851- return ecma_raise_type_error (ECMA_ERR_MSG ("Class constructor cannot be invoked without 'new'." ));
852- }
846+ uint16_t function_type = CBC_FUNCTION_GET_TYPE (status_flags );
853847
854- if (( status_flags & CBC_CODE_FLAGS_GENERATOR ) && is_construct_call )
855- {
856- return ecma_raise_type_error ( ECMA_ERR_MSG ( "Generator functions cannot be invoked with 'new'." ));
857- }
848+ if (JERRY_UNLIKELY ( function_type == CBC_FUNCTION_CONSTRUCTOR )
849+ && JERRY_CONTEXT ( current_new_target ) == NULL )
850+ {
851+ return ecma_raise_type_error ( ECMA_ERR_MSG ( "Class constructor cannot be invoked without 'new'." ));
858852 }
859853#endif /* ENABLED (JERRY_ES2015) */
860854
861855 /* 1. */
862856#if ENABLED (JERRY_ES2015 )
863857 ecma_object_t * old_function_object_p = JERRY_CONTEXT (current_function_obj_p );
864858
865- if (JERRY_UNLIKELY (status_flags & CBC_CODE_FLAGS_ARROW_FUNCTION ))
859+ if (JERRY_UNLIKELY (function_type == CBC_FUNCTION_ARROW ))
866860 {
867861 ecma_arrow_function_t * arrow_func_p = (ecma_arrow_function_t * ) func_obj_p ;
868862
@@ -920,7 +914,7 @@ ecma_op_function_call_simple (ecma_object_t *func_obj_p, /**< Function object */
920914 }
921915#if ENABLED (JERRY_ES2015 )
922916 // ECMAScript v6, 9.2.2.8
923- if (JERRY_UNLIKELY (status_flags & CBC_CODE_FLAGS_CLASS_CONSTRUCTOR ))
917+ if (JERRY_UNLIKELY (function_type == CBC_FUNCTION_CONSTRUCTOR ))
924918 {
925919 ecma_value_t lexical_this ;
926920 lexical_this = (ECMA_GET_THIRD_BIT_FROM_POINTER_TAG (ext_func_p -> u .function .scope_cp ) ? ECMA_VALUE_UNINITIALIZED
@@ -1278,20 +1272,39 @@ ecma_op_function_construct (ecma_object_t *func_obj_p, /**< Function object */
12781272
12791273 ecma_object_t * new_this_obj_p = NULL ;
12801274 ecma_value_t this_arg ;
1275+
1276+ #if ENABLED (JERRY_ES2015 )
12811277 ecma_extended_object_t * ext_func_obj_p = (ecma_extended_object_t * ) func_obj_p ;
12821278 const ecma_compiled_code_t * byte_code_p = ecma_op_function_get_compiled_code (ext_func_obj_p );
12831279
1284- if (byte_code_p -> status_flags & ( CBC_CODE_FLAGS_ARROW_FUNCTION | CBC_CODE_FLAGS_ACCESSOR ))
1280+ if (! CBC_FUNCTION_IS_CONSTRUCTABLE ( byte_code_p -> status_flags ))
12851281 {
1286- if (byte_code_p -> status_flags & CBC_CODE_FLAGS_ARROW_FUNCTION )
1282+ const char * message_p ;
1283+
1284+ switch (CBC_FUNCTION_GET_TYPE (byte_code_p -> status_flags ))
12871285 {
1288- return ecma_raise_type_error (ECMA_ERR_MSG ("Arrow functions have no constructor." ));
1286+ case CBC_FUNCTION_GENERATOR :
1287+ {
1288+ message_p = ECMA_ERR_MSG ("Generator functions cannot be invoked with 'new'." );
1289+ break ;
1290+ }
1291+ case CBC_FUNCTION_ARROW :
1292+ {
1293+ message_p = ECMA_ERR_MSG ("Arrow functions cannot be invoked with 'new'." );
1294+ break ;
1295+ }
1296+ default :
1297+ {
1298+ JERRY_ASSERT (CBC_FUNCTION_GET_TYPE (byte_code_p -> status_flags ) == CBC_FUNCTION_ACCESSOR );
1299+
1300+ message_p = ECMA_ERR_MSG ("Accessor functions cannot be invoked with 'new'." );
1301+ break ;
1302+ }
12891303 }
12901304
1291- return ecma_raise_type_error (ECMA_ERR_MSG ( "Expected a constructor." ) );
1305+ return ecma_raise_type_error (message_p );
12921306 }
12931307
1294- #if ENABLED (JERRY_ES2015 )
12951308 /* 6. */
12961309 ecma_object_t * old_new_target_p = JERRY_CONTEXT (current_new_target );
12971310 JERRY_CONTEXT (current_new_target ) = new_target_p ;
@@ -1366,17 +1379,18 @@ ecma_op_lazy_instantiate_prototype_object (ecma_object_t *object_p) /**< the fun
13661379 {
13671380 const ecma_compiled_code_t * byte_code_p = ecma_op_function_get_compiled_code ((ecma_extended_object_t * ) object_p );
13681381
1369- if (byte_code_p -> status_flags & CBC_CODE_FLAGS_GENERATOR )
1382+ if (!CBC_FUNCTION_HAS_PROTOTYPE (byte_code_p -> status_flags ))
1383+ {
1384+ return NULL ;
1385+ }
1386+
1387+ if (CBC_FUNCTION_GET_TYPE (byte_code_p -> status_flags ) == CBC_FUNCTION_GENERATOR )
13701388 {
13711389 proto_object_p = ecma_create_object (ecma_builtin_get (ECMA_BUILTIN_ID_GENERATOR_PROTOTYPE ),
13721390 0 ,
13731391 ECMA_OBJECT_TYPE_GENERAL );
13741392 init_constructor = false;
13751393 }
1376- else if (byte_code_p -> status_flags & (CBC_CODE_FLAGS_ARROW_FUNCTION | CBC_CODE_FLAGS_ACCESSOR ))
1377- {
1378- return NULL ;
1379- }
13801394 }
13811395#endif /* ENABLED (JERRY_ES2015) */
13821396
@@ -1474,7 +1488,7 @@ ecma_op_function_try_to_lazy_instantiate_property (ecma_object_t *object_p, /**<
14741488 ECMA_SET_SECOND_BIT_TO_POINTER_TAG (ext_func_p -> u .function .scope_cp );
14751489 const ecma_compiled_code_t * bytecode_data_p = ecma_op_function_get_compiled_code (ext_func_p );
14761490
1477- if (! (bytecode_data_p -> status_flags & CBC_CODE_FLAGS_CLASS_CONSTRUCTOR ) )
1491+ if (CBC_FUNCTION_GET_TYPE (bytecode_data_p -> status_flags ) != CBC_FUNCTION_CONSTRUCTOR )
14781492 {
14791493 ecma_value_t value = * ecma_compiled_code_resolve_function_name (bytecode_data_p );
14801494 if (value != ECMA_VALUE_EMPTY )
@@ -1694,7 +1708,7 @@ ecma_op_function_list_lazy_property_names (ecma_object_t *object_p, /**< functio
16941708 bytecode_data_p = ecma_op_function_get_compiled_code ((ecma_extended_object_t * ) object_p );
16951709
16961710#if ENABLED (JERRY_ES2015 )
1697- if (bytecode_data_p -> status_flags & ( CBC_CODE_FLAGS_ARROW_FUNCTION | CBC_CODE_FLAGS_ACCESSOR ))
1711+ if (! CBC_FUNCTION_HAS_PROTOTYPE ( bytecode_data_p -> status_flags ))
16981712 {
16991713 return ;
17001714 }
0 commit comments