lottie/expressions: minor size down expressions engine.

- disable unused builtin realm functions.
- disable global this
- disable regexp (potential)
- disable unicode case conversion (potential)

Some features are marked with (potential)
since we are not certain these are used practically.

until now, total binary size diff by expressions: +287kb
This commit is contained in:
Hermet Park 2024-05-06 22:46:11 +09:00 committed by Hermet Park
parent 18b9e8141d
commit c8551d4856
9 changed files with 16 additions and 153 deletions

View file

@ -423,22 +423,6 @@ jerry_string (const jerry_char_t *buffer_p, /**< pointer to buffer */
return ecma_make_string_value (ecma_str_p);
} /* jerry_string */
/**
* Creates a new realm (global object).
*
* @return new realm object
*/
jerry_value_t
jerry_realm (void)
{
#if JERRY_BUILTIN_REALMS
ecma_global_object_t *global_object_p = ecma_builtin_create_global_object ();
return ecma_make_object_value ((ecma_object_t *) global_object_p);
#else /* !JERRY_BUILTIN_REALMS */
return jerry_throw_sz (JERRY_ERROR_TYPE, ecma_get_error_msg (ECMA_ERR_REALMS_ARE_DISABLED));
#endif /* JERRY_BUILTIN_REALMS */
} /* jerry_realm */
/**
* Get length of a string value
*
@ -632,117 +616,6 @@ jerry_object_set_native_ptr (jerry_value_t object, /**< object to set native poi
}
} /* jerry_object_set_native_ptr */
/**
* Replaces the currently active realm with another realm.
*
* The replacement should be temporary, and the original realm must be
* restored after the tasks are completed. During the replacement, the
* realm must be referenced by the application (i.e. the gc must not
* reclaim it). This is also true to the returned previously active
* realm, so there is no need to free the value after the restoration.
*
* @return previous realm value - if the passed value is a realm
* exception - otherwise
*/
jerry_value_t
jerry_set_realm (jerry_value_t realm_value) /**< jerry api value */
{
#if JERRY_BUILTIN_REALMS
if (ecma_is_value_object (realm_value))
{
ecma_object_t *object_p = ecma_get_object_from_value (realm_value);
if (ecma_builtin_is_global (object_p))
{
ecma_global_object_t *previous_global_object_p = JERRY_CONTEXT (global_object_p);
JERRY_CONTEXT (global_object_p) = (ecma_global_object_t *) object_p;
return ecma_make_object_value ((ecma_object_t *) previous_global_object_p);
}
}
return jerry_undefined();
#else /* !JERRY_BUILTIN_REALMS */
JERRY_UNUSED (realm_value);
return jerry_undefined();
#endif /* JERRY_BUILTIN_REALMS */
} /* jerry_set_realm */
/**
* Gets the 'this' binding of a realm
*
* @return type error - if realm_value is not a realm
* this value - otherwise
*/
jerry_value_t
jerry_realm_this (jerry_value_t realm) /**< realm value */
{
#if JERRY_BUILTIN_REALMS
if (ecma_is_value_object (realm))
{
ecma_object_t *object_p = ecma_get_object_from_value (realm);
if (ecma_builtin_is_global (object_p))
{
ecma_global_object_t *global_object_p = (ecma_global_object_t *) object_p;
ecma_ref_object (ecma_get_object_from_value (global_object_p->this_binding));
return global_object_p->this_binding;
}
}
#else /* !JERRY_BUILTIN_REALMS */
ecma_object_t *global_object_p = ecma_builtin_get_global ();
if (realm == ecma_make_object_value (global_object_p))
{
ecma_ref_object (global_object_p);
return realm;
}
#endif /* JERRY_BUILTIN_REALMS */
return jerry_undefined();
} /* jerry_realm_this */
/**
* Sets the 'this' binding of a realm
*
* This function must be called before executing any script on the realm.
* Otherwise the operation is undefined.
*
* @return type error - if realm_value is not a realm or this_value is not object
* true - otherwise
*/
jerry_value_t
jerry_realm_set_this (jerry_value_t realm, /**< realm value */
jerry_value_t this_value) /**< this value */
{
#if JERRY_BUILTIN_REALMS
if (ecma_is_value_object (realm))
{
ecma_object_t *object_p = ecma_get_object_from_value (realm);
if (ecma_builtin_is_global (object_p))
{
ecma_global_object_t *global_object_p = (ecma_global_object_t *) object_p;
global_object_p->this_binding = this_value;
ecma_object_t *global_lex_env_p = ecma_create_object_lex_env (NULL, ecma_get_object_from_value (this_value));
ECMA_SET_NON_NULL_POINTER (global_object_p->global_env_cp, global_lex_env_p);
global_object_p->global_scope_cp = global_object_p->global_env_cp;
ecma_deref_object (global_lex_env_p);
return ECMA_VALUE_TRUE;
}
}
return jerry_undefined();
#else /* !JERRY_BUILTIN_REALMS */
JERRY_UNUSED (realm);
JERRY_UNUSED (this_value);
return jerry_undefined();
#endif /* JERRY_BUILTIN_REALMS */
} /* jerry_realm_set_this */
/**
* @}

View file

@ -49,6 +49,7 @@
* @return iterator result object, if success
* error - otherwise
*/
#ifdef JERRY_BUILTIN_REGEXP
static ecma_value_t
ecma_builtin_regexp_string_iterator_prototype_object_next (ecma_value_t this_val) /**< this argument */
{
@ -176,6 +177,7 @@ free_variables:
return result;
} /* ecma_builtin_regexp_string_iterator_prototype_object_next */
#endif
/**
* @}

View file

@ -19,6 +19,8 @@
#include "ecma-builtin-helpers-macro-defines.inc.h"
#ifdef JERRY_BUILTIN_REGEXP
STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
LIT_MAGIC_STRING_REGEXP_STRING_ITERATOR_UL,
ECMA_PROPERTY_FLAG_CONFIGURABLE)
@ -27,4 +29,6 @@ STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
ROUTINE (LIT_MAGIC_STRING_NEXT, ecma_builtin_regexp_string_iterator_prototype_object_next, 0, 0)
#endif
#include "ecma-builtin-helpers-macro-undefs.inc.h"

View file

@ -1013,7 +1013,6 @@ ecma_op_function_call_constructor (vm_frame_ctx_shared_args_t *shared_args_p, /*
shared_args_p->header.status_flags |= VM_FRAME_CTX_SHARED_NON_ARROW_FUNC;
ecma_value_t ret_value;
ecma_global_object_t *saved_global_object_p;
ecma_extended_object_t *ext_func_p;
if (JERRY_CONTEXT (current_new_target_p) == NULL)
@ -1031,7 +1030,7 @@ ecma_op_function_call_constructor (vm_frame_ctx_shared_args_t *shared_args_p, /*
ecma_op_create_environment_record (scope_p, this_binding, shared_args_p->header.function_object_p);
#if JERRY_BUILTIN_REALMS
saved_global_object_p = JERRY_CONTEXT (global_object_p);
ecma_global_object_t *saved_global_object_p = JERRY_CONTEXT (global_object_p);
JERRY_CONTEXT (global_object_p) = ecma_op_function_get_realm (shared_args_p->header.bytecode_header_p);
#endif /* JERRY_BUILTIN_REALMS */

View file

@ -132,7 +132,9 @@ ecma_op_create_iterator_object (ecma_value_t iterated_value, /**< value from cre
/* 1. */
JERRY_ASSERT (iterator_type == ECMA_OBJECT_CLASS_ARRAY_ITERATOR || iterator_type == ECMA_OBJECT_CLASS_SET_ITERATOR
|| iterator_type == ECMA_OBJECT_CLASS_MAP_ITERATOR
#ifdef JERRY_BUILTIN_REGEXP
|| iterator_type == ECMA_OBJECT_CLASS_REGEXP_STRING_ITERATOR
#endif
|| iterator_type == ECMA_OBJECT_CLASS_STRING_ITERATOR);
JERRY_ASSERT (kind < ECMA_ITERATOR__COUNT);

View file

@ -2978,6 +2978,7 @@ ecma_op_is_concat_spreadable (ecma_value_t arg) /**< argument */
ecma_value_t
ecma_op_is_regexp (ecma_value_t arg) /**< argument */
{
#if JERRY_BUILTIN_REGEXP
if (!ecma_is_value_object (arg))
{
return ECMA_VALUE_FALSE;
@ -2998,6 +2999,9 @@ ecma_op_is_regexp (ecma_value_t arg) /**< argument */
}
return ecma_make_boolean_value (ecma_object_is_regexp_object (arg));
#else
return ECMA_VALUE_FALSE;
#endif
} /* ecma_op_is_regexp */
/**

View file

@ -48,10 +48,6 @@
#define JERRY_BUILTIN_NUMBER JERRY_BUILTINS
#endif /* !defined (JERRY_BUILTIN_NUMBER) */
#ifndef JERRY_BUILTIN_REGEXP
#define JERRY_BUILTIN_REGEXP JERRY_BUILTINS
#endif /* !defined (JERRY_BUILTIN_REGEXP) */
#ifndef JERRY_BUILTIN_STRING
#define JERRY_BUILTIN_STRING JERRY_BUILTINS
#endif /* !defined (JERRY_BUILTIN_STRING) */
@ -60,14 +56,6 @@
#define JERRY_BUILTIN_CONTAINER JERRY_BUILTINS
#endif /* !defined (JERRY_BUILTIN_CONTAINER) */
#ifndef JERRY_BUILTIN_GLOBAL_THIS
#define JERRY_BUILTIN_GLOBAL_THIS JERRY_BUILTINS
#endif /* !defined (JERRY_BUILTIN_GLOBAL_THIS) */
#ifndef JERRY_BUILTIN_REALMS
#define JERRY_BUILTIN_REALMS JERRY_BUILTINS
#endif /* !defined (JERRY_BUILTIN_REALMS) */
#ifndef JERRY_BUILTIN_TYPEDARRAY
#define JERRY_BUILTIN_TYPEDARRAY JERRY_BUILTINS
#endif /* !defined (JERRY_BUILTIN_TYPEDARRAY) */
@ -354,7 +342,7 @@
* By default Unicode case conversion is enabled.
*/
#ifndef JERRY_UNICODE_CASE_CONVERSION
#define JERRY_UNICODE_CASE_CONVERSION 1
#define JERRY_UNICODE_CASE_CONVERSION 0
#endif /* !defined (JERRY_UNICODE_CASE_CONVERSION) */
/**

View file

@ -58,9 +58,6 @@ jerry_value_t jerry_object_get_sz (const jerry_value_t object, const char *key_p
jerry_value_t jerry_object_get_index (const jerry_value_t object, uint32_t index);
void *jerry_object_get_native_ptr (const jerry_value_t object, const jerry_object_native_info_t *native_info_p);
jerry_value_t jerry_function_external (jerry_external_handler_t handler);
jerry_value_t jerry_realm (void);
jerry_value_t jerry_realm_this (jerry_value_t realm);
jerry_value_t jerry_realm_set_this (jerry_value_t realm, jerry_value_t this_value);
void jerry_value_free (jerry_value_t value);
JERRY_C_API_END

View file

@ -2245,12 +2245,6 @@ opfunc_lexical_scope_has_restricted_binding (vm_frame_ctx_t *frame_ctx_p, /**< f
{
JERRY_ASSERT (ecma_get_lex_env_type (frame_ctx_p->lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE);
#if JERRY_BUILTIN_REALMS
JERRY_ASSERT (frame_ctx_p->this_binding == JERRY_CONTEXT (global_object_p)->this_binding);
#else /* !JERRY_BUILTIN_REALMS */
JERRY_ASSERT (frame_ctx_p->this_binding == ecma_builtin_get_global ());
#endif /* JERRY_BUILTIN_REALMS */
ecma_object_t *lex_env_p = frame_ctx_p->lex_env_p;
ecma_property_t *binding_p = ecma_find_named_property (lex_env_p, name_p);
@ -2259,6 +2253,8 @@ opfunc_lexical_scope_has_restricted_binding (vm_frame_ctx_t *frame_ctx_p, /**< f
return ECMA_VALUE_TRUE;
}
ecma_object_t *global_obj_p = ecma_get_object_from_value (frame_ctx_p->this_binding);
#if JERRY_BUILTIN_REALMS
ecma_object_t *const global_scope_p = ecma_get_global_scope ((ecma_object_t *) JERRY_CONTEXT (global_object_p));
#else /* !JERRY_BUILTIN_REALMS */
@ -2270,8 +2266,6 @@ opfunc_lexical_scope_has_restricted_binding (vm_frame_ctx_t *frame_ctx_p, /**< f
return ECMA_VALUE_FALSE;
}
ecma_object_t *global_obj_p = ecma_get_object_from_value (frame_ctx_p->this_binding);
#if JERRY_BUILTIN_PROXY
if (ECMA_OBJECT_IS_PROXY (global_obj_p))
{