Rework the public API (#4829)
Related to #4186. Some notable changes: - The term 'Error' now strictly refers to native Error objects defined in the ECMA standard, which are ordinary objects. All other uses of 'error' or 'error reference' where the term refers to a thrown value is now called 'exception'. - Simplified the naming scheme of many String API functions. These functions will now also take an 'encoding' argument to specify the desired encoding in which to operate. - Removed the substring-copy-to-buffer functions. These functions behaved awkwardly, as they use character index to specify the start/end positions, and were mostly used incorrectly with byte offsets instead. The functionality can still be replicated with other functions if necessary. - String-to-buffer functions will no longer fail if the buffer is not sufficiently large, the string will instead be cropped. - Fixed the usage of the '_sz' prefix in many API functions. The term 'sz' means zero-terminated string in hungarian notation, this was used incorrectly in many cases. - Renamed most of the public API functions to have shorter, more on-point names, rather than the often too long descriptive names. Functions are now also grouped by the type of value they operate on, where this makes sense. JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
This commit is contained in:
@@ -19,75 +19,73 @@
|
||||
* Used in header/source files for wrappers, to declare the signature of the
|
||||
* registration function.
|
||||
*/
|
||||
#define DECLARE_JS_WRAPPER_REGISTRATION(NAME) \
|
||||
void jsmbed_wrap_registry_entry__ ## NAME (void)
|
||||
#define DECLARE_JS_WRAPPER_REGISTRATION(NAME) void jsmbed_wrap_registry_entry__##NAME (void)
|
||||
|
||||
//
|
||||
// 2. Wrapper function declaration/use macros
|
||||
//
|
||||
|
||||
// Global functions
|
||||
#define DECLARE_GLOBAL_FUNCTION(NAME) \
|
||||
jerry_value_t \
|
||||
NAME_FOR_GLOBAL_FUNCTION(NAME) (const jerry_call_info_t *call_info_p, \
|
||||
const jerry_value_t args[], \
|
||||
const jerry_length_t args_count)
|
||||
#define DECLARE_GLOBAL_FUNCTION(NAME) \
|
||||
jerry_value_t NAME_FOR_GLOBAL_FUNCTION ( \
|
||||
NAME) (const jerry_call_info_t* call_info_p, const jerry_value_t args[], const jerry_length_t args_count)
|
||||
|
||||
#define REGISTER_GLOBAL_FUNCTION(NAME) \
|
||||
jsmbed_wrap_register_global_function ( # NAME, NAME_FOR_GLOBAL_FUNCTION(NAME) )
|
||||
#define REGISTER_GLOBAL_FUNCTION(NAME) jsmbed_wrap_register_global_function (#NAME, NAME_FOR_GLOBAL_FUNCTION (NAME))
|
||||
|
||||
#define REGISTER_GLOBAL_FUNCTION_WITH_HANDLER(NAME, HANDLER) \
|
||||
jsmbed_wrap_register_global_function ( # NAME, HANDLER )
|
||||
#define REGISTER_GLOBAL_FUNCTION_WITH_HANDLER(NAME, HANDLER) jsmbed_wrap_register_global_function (#NAME, HANDLER)
|
||||
|
||||
// Class constructors
|
||||
#define DECLARE_CLASS_CONSTRUCTOR(CLASS) \
|
||||
jerry_value_t \
|
||||
NAME_FOR_CLASS_CONSTRUCTOR(CLASS) (const jerry_call_info_t *call_info_p, \
|
||||
const jerry_value_t args[], \
|
||||
const jerry_length_t args_count)
|
||||
#define DECLARE_CLASS_CONSTRUCTOR(CLASS) \
|
||||
jerry_value_t NAME_FOR_CLASS_CONSTRUCTOR ( \
|
||||
CLASS) (const jerry_call_info_t* call_info_p, const jerry_value_t args[], const jerry_length_t args_count)
|
||||
|
||||
#define REGISTER_CLASS_CONSTRUCTOR(CLASS) \
|
||||
jsmbed_wrap_register_class_constructor ( # CLASS, NAME_FOR_CLASS_CONSTRUCTOR(CLASS) )
|
||||
jsmbed_wrap_register_class_constructor (#CLASS, NAME_FOR_CLASS_CONSTRUCTOR (CLASS))
|
||||
|
||||
// Class functions
|
||||
#define DECLARE_CLASS_FUNCTION(CLASS, NAME) \
|
||||
jerry_value_t \
|
||||
NAME_FOR_CLASS_FUNCTION(CLASS, NAME) (const jerry_call_info_t *call_info_p, \
|
||||
const jerry_value_t args[], \
|
||||
const jerry_length_t args_count)
|
||||
#define DECLARE_CLASS_FUNCTION(CLASS, NAME) \
|
||||
jerry_value_t NAME_FOR_CLASS_FUNCTION (CLASS, NAME) (const jerry_call_info_t* call_info_p, \
|
||||
const jerry_value_t args[], \
|
||||
const jerry_length_t args_count)
|
||||
|
||||
#define ATTACH_CLASS_FUNCTION(OBJECT, CLASS, NAME) \
|
||||
jsmbed_wrap_register_class_function (OBJECT, # NAME, NAME_FOR_CLASS_FUNCTION(CLASS, NAME) )
|
||||
jsmbed_wrap_register_class_function (OBJECT, #NAME, NAME_FOR_CLASS_FUNCTION (CLASS, NAME))
|
||||
|
||||
//
|
||||
// 3. Argument checking macros
|
||||
//
|
||||
#define CHECK_ARGUMENT_COUNT(CLASS, NAME, EXPR) \
|
||||
if (!(EXPR)) { \
|
||||
const char* error_msg = "ERROR: wrong argument count for " # CLASS "." # NAME ", expected " # EXPR "."; \
|
||||
return jerry_create_error(JERRY_ERROR_TYPE, reinterpret_cast<const jerry_char_t*>(error_msg)); \
|
||||
}
|
||||
#define CHECK_ARGUMENT_COUNT(CLASS, NAME, EXPR) \
|
||||
if (!(EXPR)) \
|
||||
{ \
|
||||
const char* error_msg = "ERROR: wrong argument count for " #CLASS "." #NAME ", expected " #EXPR "."; \
|
||||
return jerry_throw_sz (JERRY_ERROR_TYPE, error_msg); \
|
||||
}
|
||||
|
||||
#define CHECK_ARGUMENT_TYPE_ALWAYS(CLASS, NAME, INDEX, TYPE) \
|
||||
if (!jerry_value_is_ ## TYPE (args[INDEX])) { \
|
||||
const char* error_msg = "ERROR: wrong argument type for " # CLASS "." # NAME ", expected argument " # INDEX " to be a " # TYPE ".\n"; \
|
||||
return jerry_create_error(JERRY_ERROR_TYPE, reinterpret_cast<const jerry_char_t*>(error_msg)); \
|
||||
}
|
||||
#define CHECK_ARGUMENT_TYPE_ALWAYS(CLASS, NAME, INDEX, TYPE) \
|
||||
if (!jerry_value_is_##TYPE (args[INDEX])) \
|
||||
{ \
|
||||
const char* error_msg = \
|
||||
"ERROR: wrong argument type for " #CLASS "." #NAME ", expected argument " #INDEX " to be a " #TYPE ".\n"; \
|
||||
return jerry_throw_sz (JERRY_ERROR_TYPE, error_msg); \
|
||||
}
|
||||
|
||||
#define CHECK_ARGUMENT_TYPE_ON_CONDITION(CLASS, NAME, INDEX, TYPE, EXPR) \
|
||||
if ((EXPR)) { \
|
||||
if (!jerry_value_is_ ## TYPE (args[INDEX])) { \
|
||||
const char* error_msg = "ERROR: wrong argument type for " # CLASS "." # NAME ", expected argument " # INDEX " to be a " # TYPE ".\n"; \
|
||||
return jerry_create_error(JERRY_ERROR_TYPE, reinterpret_cast<const jerry_char_t*>(error_msg)); \
|
||||
} \
|
||||
}
|
||||
#define CHECK_ARGUMENT_TYPE_ON_CONDITION(CLASS, NAME, INDEX, TYPE, EXPR) \
|
||||
if ((EXPR)) \
|
||||
{ \
|
||||
if (!jerry_value_is_##TYPE (args[INDEX])) \
|
||||
{ \
|
||||
const char* error_msg = \
|
||||
"ERROR: wrong argument type for " #CLASS "." #NAME ", expected argument " #INDEX " to be a " #TYPE ".\n"; \
|
||||
return jerry_throw_sz (JERRY_ERROR_TYPE, error_msg); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define NAME_FOR_GLOBAL_FUNCTION(NAME) __gen_jsmbed_global_func_ ## NAME
|
||||
#define NAME_FOR_CLASS_CONSTRUCTOR(CLASS) __gen_jsmbed_class_constructor_ ## CLASS
|
||||
#define NAME_FOR_CLASS_FUNCTION(CLASS, NAME) __gen_jsmbed_func_c_ ## CLASS ## _f_ ## NAME
|
||||
#define NAME_FOR_GLOBAL_FUNCTION(NAME) __gen_jsmbed_global_func_##NAME
|
||||
#define NAME_FOR_CLASS_CONSTRUCTOR(CLASS) __gen_jsmbed_class_constructor_##CLASS
|
||||
#define NAME_FOR_CLASS_FUNCTION(CLASS, NAME) __gen_jsmbed_func_c_##CLASS##_f_##NAME
|
||||
|
||||
#define NAME_FOR_CLASS_NATIVE_CONSTRUCTOR(CLASS, TYPELIST) __gen_native_jsmbed_ ## CLASS ## __Special_create_ ## TYPELIST
|
||||
#define NAME_FOR_CLASS_NATIVE_DESTRUCTOR(CLASS) __gen_native_jsmbed_ ## CLASS ## __Special_destroy
|
||||
#define NAME_FOR_CLASS_NATIVE_FUNCTION(CLASS, NAME) __gen_native_jsmbed_ ## CLASS ## _ ## NAME
|
||||
#define NAME_FOR_CLASS_NATIVE_CONSTRUCTOR(CLASS, TYPELIST) __gen_native_jsmbed_##CLASS##__Special_create_##TYPELIST
|
||||
#define NAME_FOR_CLASS_NATIVE_DESTRUCTOR(CLASS) __gen_native_jsmbed_##CLASS##__Special_destroy
|
||||
#define NAME_FOR_CLASS_NATIVE_FUNCTION(CLASS, NAME) __gen_native_jsmbed_##CLASS##_##NAME
|
||||
|
||||
#endif // _JERRYSCRIPT_MBED_UTIL_WRAPPERS_H
|
||||
#endif // _JERRYSCRIPT_MBED_UTIL_WRAPPERS_H
|
||||
|
||||
Reference in New Issue
Block a user