@@ -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;
@@ -844,26 +844,20 @@ ecma_op_function_call_simple (ecma_object_t *func_obj_p, /**< Function object */
844844 uint16_t status_flags = bytecode_data_p -> status_flags ;
845845
846846#if ENABLED (JERRY_ES2015 )
847- bool is_construct_call = JERRY_CONTEXT (current_new_target ) != NULL ;
848- if (JERRY_UNLIKELY (status_flags & (CBC_CODE_FLAGS_CLASS_CONSTRUCTOR | CBC_CODE_FLAGS_GENERATOR )))
849- {
850- if (!is_construct_call && (status_flags & CBC_CODE_FLAGS_CLASS_CONSTRUCTOR ))
851- {
852- return ecma_raise_type_error (ECMA_ERR_MSG ("Class constructor cannot be invoked without 'new'." ));
853- }
847+ uint16_t function_type = CBC_FUNCTION_GET_TYPE (status_flags );
854848
855- if (( status_flags & CBC_CODE_FLAGS_GENERATOR ) && is_construct_call )
856- {
857- return ecma_raise_type_error ( ECMA_ERR_MSG ( "Generator functions cannot be invoked with 'new'." ));
858- }
849+ if (JERRY_UNLIKELY ( function_type == CBC_FUNCTION_CONSTRUCTOR )
850+ && JERRY_CONTEXT ( current_new_target ) == NULL )
851+ {
852+ return ecma_raise_type_error ( ECMA_ERR_MSG ( "Class constructor cannot be invoked without 'new'." ));
859853 }
860854#endif /* ENABLED (JERRY_ES2015) */
861855
862856 /* 1. */
863857#if ENABLED (JERRY_ES2015 )
864858 ecma_object_t * old_function_object_p = JERRY_CONTEXT (current_function_obj_p );
865859
866- if (JERRY_UNLIKELY (status_flags & CBC_CODE_FLAGS_ARROW_FUNCTION ))
860+ if (JERRY_UNLIKELY (function_type == CBC_FUNCTION_ARROW ))
867861 {
868862 ecma_arrow_function_t * arrow_func_p = (ecma_arrow_function_t * ) func_obj_p ;
869863
@@ -921,7 +915,7 @@ ecma_op_function_call_simple (ecma_object_t *func_obj_p, /**< Function object */
921915 }
922916#if ENABLED (JERRY_ES2015 )
923917 // ECMAScript v6, 9.2.2.8
924- if (JERRY_UNLIKELY (status_flags & CBC_CODE_FLAGS_CLASS_CONSTRUCTOR ))
918+ if (JERRY_UNLIKELY (function_type == CBC_FUNCTION_CONSTRUCTOR ))
925919 {
926920 ecma_value_t lexical_this ;
927921 lexical_this = (ECMA_GET_THIRD_BIT_FROM_POINTER_TAG (ext_func_p -> u .function .scope_cp ) ? ECMA_VALUE_UNINITIALIZED
@@ -1279,20 +1273,39 @@ ecma_op_function_construct (ecma_object_t *func_obj_p, /**< Function object */
12791273
12801274 ecma_object_t * new_this_obj_p = NULL ;
12811275 ecma_value_t this_arg ;
1276+
1277+ #if ENABLED (JERRY_ES2015 )
12821278 ecma_extended_object_t * ext_func_obj_p = (ecma_extended_object_t * ) func_obj_p ;
12831279 const ecma_compiled_code_t * byte_code_p = ecma_op_function_get_compiled_code (ext_func_obj_p );
12841280
1285- if (byte_code_p -> status_flags & ( CBC_CODE_FLAGS_ARROW_FUNCTION | CBC_CODE_FLAGS_ACCESSOR ))
1281+ if (! CBC_FUNCTION_IS_CONSTRUCTABLE ( byte_code_p -> status_flags ))
12861282 {
1287- if (byte_code_p -> status_flags & CBC_CODE_FLAGS_ARROW_FUNCTION )
1283+ const char * message_p ;
1284+
1285+ switch (CBC_FUNCTION_GET_TYPE (byte_code_p -> status_flags ))
12881286 {
1289- return ecma_raise_type_error (ECMA_ERR_MSG ("Arrow functions have no constructor." ));
1287+ case CBC_FUNCTION_GENERATOR :
1288+ {
1289+ message_p = ECMA_ERR_MSG ("Generator functions cannot be invoked with 'new'." );
1290+ break ;
1291+ }
1292+ case CBC_FUNCTION_ARROW :
1293+ {
1294+ message_p = ECMA_ERR_MSG ("Arrow functions cannot be invoked with 'new'." );
1295+ break ;
1296+ }
1297+ default :
1298+ {
1299+ JERRY_ASSERT (CBC_FUNCTION_GET_TYPE (byte_code_p -> status_flags ) == CBC_FUNCTION_ACCESSOR );
1300+
1301+ message_p = ECMA_ERR_MSG ("Accessor functions cannot be invoked with 'new'." );
1302+ break ;
1303+ }
12901304 }
12911305
1292- return ecma_raise_type_error (ECMA_ERR_MSG ( "Expected a constructor." ) );
1306+ return ecma_raise_type_error (message_p );
12931307 }
12941308
1295- #if ENABLED (JERRY_ES2015 )
12961309 /* 6. */
12971310 ecma_object_t * old_new_target_p = JERRY_CONTEXT (current_new_target );
12981311 JERRY_CONTEXT (current_new_target ) = new_target_p ;
@@ -1367,17 +1380,18 @@ ecma_op_lazy_instantiate_prototype_object (ecma_object_t *object_p) /**< the fun
13671380 {
13681381 const ecma_compiled_code_t * byte_code_p = ecma_op_function_get_compiled_code ((ecma_extended_object_t * ) object_p );
13691382
1370- if (byte_code_p -> status_flags & CBC_CODE_FLAGS_GENERATOR )
1383+ if (!CBC_FUNCTION_HAS_PROTOTYPE (byte_code_p -> status_flags ))
1384+ {
1385+ return NULL ;
1386+ }
1387+
1388+ if (CBC_FUNCTION_GET_TYPE (byte_code_p -> status_flags ) == CBC_FUNCTION_GENERATOR )
13711389 {
13721390 proto_object_p = ecma_create_object (ecma_builtin_get (ECMA_BUILTIN_ID_GENERATOR_PROTOTYPE ),
13731391 0 ,
13741392 ECMA_OBJECT_TYPE_GENERAL );
13751393 init_constructor = false;
13761394 }
1377- else if (byte_code_p -> status_flags & (CBC_CODE_FLAGS_ARROW_FUNCTION | CBC_CODE_FLAGS_ACCESSOR ))
1378- {
1379- return NULL ;
1380- }
13811395 }
13821396#endif /* ENABLED (JERRY_ES2015) */
13831397
@@ -1475,7 +1489,7 @@ ecma_op_function_try_to_lazy_instantiate_property (ecma_object_t *object_p, /**<
14751489 ECMA_SET_SECOND_BIT_TO_POINTER_TAG (ext_func_p -> u .function .scope_cp );
14761490 const ecma_compiled_code_t * bytecode_data_p = ecma_op_function_get_compiled_code (ext_func_p );
14771491
1478- if (! (bytecode_data_p -> status_flags & CBC_CODE_FLAGS_CLASS_CONSTRUCTOR ) )
1492+ if (CBC_FUNCTION_GET_TYPE (bytecode_data_p -> status_flags ) != CBC_FUNCTION_CONSTRUCTOR )
14791493 {
14801494 ecma_value_t value = * ecma_compiled_code_resolve_function_name (bytecode_data_p );
14811495 if (value != ECMA_VALUE_EMPTY )
@@ -1695,7 +1709,7 @@ ecma_op_function_list_lazy_property_names (ecma_object_t *object_p, /**< functio
16951709 bytecode_data_p = ecma_op_function_get_compiled_code ((ecma_extended_object_t * ) object_p );
16961710
16971711#if ENABLED (JERRY_ES2015 )
1698- if (bytecode_data_p -> status_flags & ( CBC_CODE_FLAGS_ARROW_FUNCTION | CBC_CODE_FLAGS_ACCESSOR ))
1712+ if (! CBC_FUNCTION_HAS_PROTOTYPE ( bytecode_data_p -> status_flags ))
16991713 {
17001714 return ;
17011715 }
0 commit comments