From c12ec35b2d20d50d18bf009b633eccf8505a06b2 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Fri, 20 Feb 2015 20:27:06 +0300 Subject: [PATCH] Extension API: description of structures used for describing extension object; jerry_extend_with - stub for extension interface routine. --- jerry-core/CMakeLists.txt | 2 + jerry-core/config.h | 5 ++ jerry-core/jerry-extension.cpp | 44 ++++++++++++++ jerry-core/jerry-extension.h | 104 +++++++++++++++++++++++++++++++++ jerry-core/jerry.h | 2 + 5 files changed, 157 insertions(+) create mode 100644 jerry-core/jerry-extension.cpp create mode 100644 jerry-core/jerry-extension.h diff --git a/jerry-core/CMakeLists.txt b/jerry-core/CMakeLists.txt index 3504efd3e..70d8a120f 100644 --- a/jerry-core/CMakeLists.txt +++ b/jerry-core/CMakeLists.txt @@ -96,6 +96,7 @@ project (JerryCore CXX C ASM) # Sources # Jerry core + file(GLOB SOURCE_CORE_API *.cpp) file(GLOB SOURCE_CORE_MEM mem/*.cpp) file(GLOB SOURCE_CORE_VM vm/*.cpp) file(GLOB SOURCE_CORE_ECMA_BUILTINS ecma/builtin-objects/*.cpp) @@ -107,6 +108,7 @@ project (JerryCore CXX C ASM) set(SOURCE_CORE jerry.cpp + ${SOURCE_CORE_API} ${SOURCE_CORE_MEM} ${SOURCE_CORE_VM} ${SOURCE_CORE_ECMA_BUILTINS} diff --git a/jerry-core/config.h b/jerry-core/config.h index 1a6965544..9810b4a1c 100644 --- a/jerry-core/config.h +++ b/jerry-core/config.h @@ -150,4 +150,9 @@ // #define CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN #endif /* CONFIG_ECMA_COMPACT_PROFILE */ +/** + * Size of character buffer used to exchange character data between core and extensions' routine + */ +#define CONFIG_EXTENSION_CHAR_BUFFER_SIZE 2048 + #endif /* !CONFIG_H */ diff --git a/jerry-core/jerry-extension.cpp b/jerry-core/jerry-extension.cpp new file mode 100644 index 000000000..c12848707 --- /dev/null +++ b/jerry-core/jerry-extension.cpp @@ -0,0 +1,44 @@ +/* Copyright 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "config.h" +#include "jerry-extension.h" +#include "jrt.h" + +/** \addtogroup jerry Jerry engine extension interface + * @{ + */ + +/** + * Buffer of character data (used for exchange between core and extensions' routines) + */ +char jerry_extension_characters_buffer [CONFIG_EXTENSION_CHAR_BUFFER_SIZE]; + +/** + * Extend Global scope with specified extension object + * + * After extension the object is accessible through non-configurable property + * with name equal to builtin_object_name converted to ecma chars. + */ +void +jerry_extend_with (const char *builtin_object_name, /**< name of the extension object */ + const jerry_extension_descriptor_t *desc_p) /**< description of the extension object */ +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS (builtin_object_name, desc_p); +} /* jerry_extend_with */ + +/** + * @} + */ diff --git a/jerry-core/jerry-extension.h b/jerry-core/jerry-extension.h new file mode 100644 index 000000000..cdfc83b06 --- /dev/null +++ b/jerry-core/jerry-extension.h @@ -0,0 +1,104 @@ +/* Copyright 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef JERRY_EXTENSION_H +#define JERRY_EXTENSION_H + +#include +#include + +/** \addtogroup jerry Jerry engine extension interface + * @{ + */ + +/** + * Jerry's extension-related data types + */ +typedef enum +{ + JERRY_EXTENSION_FIELD_TYPE_BOOLEAN, /**< bool */ + JERRY_EXTENSION_FIELD_TYPE_FLOAT, /**< float */ + JERRY_EXTENSION_FIELD_TYPE_STRING /**< chars buffer */ +} jerry_extension_data_type_t; + +/** + * Description of an extension object's fields + */ +typedef struct +{ + jerry_extension_data_type_t type; /**< field data type */ + + /** + * Value description + */ + union + { + bool v_boolean; /**< boolean */ + float v_float; /**< number */ + const char* v_string; /**< string */ + }; +} jerry_extension_field_t; + +typedef struct +{ + jerry_extension_data_type_t type; /**< argument data type */ + + union + { + bool v_bool; /**< boolean */ + + float v_float; /**< number converted to float */ + + /** String copied to external characters buffer (not zero-terminated) */ + struct + { + char* chars_p; /**< pointer to the string's chars in characters buffer */ + size_t length; /**< number of characters */ + } v_string; + }; +} jerry_extension_function_arg_t; + +/** + * Description of an extension object's function + */ +typedef struct +{ + const char* function_name_p; /**< name of function */ + + jerry_extension_function_arg_t *args_p; /**< arrays of the function's arguments */ + uint32_t args_number; /**< number of arguments */ +} jerry_extension_function_t; + +/** + * Description of an extention object + */ +typedef struct +{ + uint32_t fields_count; /**< number of fields */ + uint32_t functions_count; /**< number of functions */ + + const jerry_extension_field_t *fields_p; /**< array of field descriptor */ + const jerry_extension_function_t *functions_p; /**< array of function descriptors */ +} jerry_extension_descriptor_t; + +extern void +jerry_extend_with (const char *builtin_object_name, + const jerry_extension_descriptor_t *desc_p); + +/** + * @} + */ + +#endif /* !JERRY_EXTENSION_H */ diff --git a/jerry-core/jerry.h b/jerry-core/jerry.h index e4e612e7e..b3fd24833 100644 --- a/jerry-core/jerry.h +++ b/jerry-core/jerry.h @@ -23,6 +23,8 @@ * @{ */ +#include "jerry-extension.h" + /** * Jerry flags */