diff --git a/docs/02.API-REFERENCE.md b/docs/02.API-REFERENCE.md index 708bde012..d46c28fbe 100644 --- a/docs/02.API-REFERENCE.md +++ b/docs/02.API-REFERENCE.md @@ -22,6 +22,18 @@ Possible types of an error: - JERRY_ERROR_TYPE - type error - JERRY_ERROR_URI - URI error +## jerry_feature_t + +Possible compile time enabled feature types: + + - JERRY_FEATURE_ERROR_MESSAGES - error messages + - JERRY_FEATURE_CPOINTER_32_BIT - 32 bit compressed pointers + - JERRY_FEATURE_MEM_STATS - memory statistics + - JERRY_FEATURE_PARSER_DUMP - parser byte-code dumps + - JERRY_FEATURE_REGEXP_DUMP - regexp byte-code dumps + - JERRY_FEATURE_SNAPSHOT_SAVE - saving snapshot files + - JERRY_FEATURE_SNAPSHOT_EXEC - executing snapshot files + ## jerry_char_t **Summary** @@ -917,6 +929,38 @@ jerry_value_is_undefined (const jerry_value_t value) - [jerry_release_value](#jerry_release_value) +## jerry_is_feature_enabled + +**Summary** + +Returns whether the specified compile time feature is enabled. + +**Prototype** + +```c +bool +jerry_is_feature_enabled (const jerry_feature_t feature); +``` + +- `feature` - jerry feature +- return value + - true, if the given `jerry_feature_t` is enabled + - false, otherwise + +**Example** + +```c +{ + ... + jerry_feature_t feature = JERRY_FEATURE_SNAPSHOT_SAVE; + + if (jerry_is_feature_enabled (feature)) + { + ... + } + +} +``` # Error flag manipulation functions diff --git a/jerry-core/jerry-api.h b/jerry-core/jerry-api.h index fa9dabaf4..be9dd08a1 100644 --- a/jerry-core/jerry-api.h +++ b/jerry-core/jerry-api.h @@ -68,6 +68,18 @@ typedef enum JERRY_ERROR_URI /**< URIError */ } jerry_error_t; +typedef enum +{ + JERRY_FEATURE_ERROR_MESSAGES, /**< error messages */ + JERRY_FEATURE_CPOINTER_32_BIT, /**< 32 bit compressed pointers */ + JERRY_FEATURE_MEM_STATS, /**< memory statistics */ + JERRY_FEATURE_PARSER_DUMP, /**< parser byte-code dumps */ + JERRY_FEATURE_REGEXP_DUMP, /**< regexp byte-code dumps */ + JERRY_FEATURE_SNAPSHOT_SAVE, /**< saving snapshot files */ + JERRY_FEATURE_SNAPSHOT_EXEC, /**< executing snapshot files */ + JERRY_FEATURE__COUNT /**< number of features. NOTE: must be at the end of the list */ +} jerry_feature_t; + /** * Jerry's char value */ @@ -191,6 +203,11 @@ bool jerry_value_is_object (const jerry_value_t); bool jerry_value_is_string (const jerry_value_t); bool jerry_value_is_undefined (const jerry_value_t); +/** + * Checker function of whether the specified compile feature is enabled + */ +bool jerry_is_feature_enabled (const jerry_feature_t); + /** * Error flag manipulation functions */ diff --git a/jerry-core/jerry.c b/jerry-core/jerry.c index 0f29a9e89..d46019a8c 100644 --- a/jerry-core/jerry.c +++ b/jerry-core/jerry.c @@ -518,6 +518,41 @@ jerry_value_is_undefined (const jerry_value_t value) /**< api value */ return ecma_is_value_undefined (value); } /* jerry_value_is_undefined */ +/** + * Check if the specified feature is enabled. + * + * @return true - if the specified feature is enabled, + * false - otherwise. + */ +bool jerry_is_feature_enabled (const jerry_feature_t feature) +{ + JERRY_ASSERT (feature < JERRY_FEATURE__COUNT); + + return (false +#ifdef JERRY_ENABLE_ERROR_MESSAGES + || feature == JERRY_FEATURE_ERROR_MESSAGES +#endif /* JERRY_ENABLE_ERROR_MESSAGES */ +#ifdef JERRY_CPOINTER_32_BIT + || feature == JERRY_FEATURE_CPOINTER_32_BIT +#endif /* JERRY_CPOINTER_32_BIT */ +#ifdef JMEM_STATS + || feature == JERRY_FEATURE_MEM_STATS +#endif /* JMEM_STATS */ +#ifdef PARSER_DUMP_BYTE_CODE + || feature == JERRY_FEATURE_PARSER_DUMP +#endif /* PARSER_DUMP_BYTE_CODE */ +#ifdef REGEXP_DUMP_BYTE_CODE + || feature == JERRY_FEATURE_REGEXP_DUMP +#endif /* REGEXP_DUMP_BYTE_CODE */ +#ifdef JERRY_ENABLE_SNAPSHOT_SAVE + || feature == JERRY_FEATURE_SNAPSHOT_SAVE +#endif /* JERRY_ENABLE_SNAPSHOT_SAVE */ +#ifdef JERRY_ENABLE_SNAPSHOT_EXEC + || feature == JERRY_FEATURE_SNAPSHOT_EXEC +#endif /* JERRY_ENABLE_SNAPSHOT_EXEC */ + ); +} /* jerry_is_feature_enabled */ + /** * Check if the specified value is an error value. *