mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
This extension provides the following facilities: - registering modules, - module resolvers, and - an API for retrieving a module instance given its name. A module is defined as a global static structure containing a pointer to a string which is the name of the module, and a pointer to a function which will be called when an instance of the module is needed. A module resolver is a function that accepts a string holding the name of the module and returns a `jerry_value_t` in an out-parameter and `true` if the module was found, or `false` if it was not. If it returns `true` and the out-parameter has the error flag set then the API will pass it through without caching. This extension provides a built-in module resolver which attempts to load modules that follow the above module definition. The API provided by this extension invokes all module resolvers it receives in sequence to attempt to resolve the name of a single module. After one resolver returns `true` and a `jerry_value_t` that represents the module the API stops iterating over the remaining resolvers and caches the value if its error flag is not set. It then returns the `jerry_value_t`. The API will return a `jerry_value_t` containing an error indicating that the module was not found if it reaches the end of the list of resolvers. The error it returns has an extra property `"moduleName"` the value of which is a string containing the name of the module that the API was asked to resolve. JerryScript-DCO-1.0-Signed-off-by: Gabriel Schulhof gabriel.schulhof@intel.com
57 lines
2.1 KiB
C
57 lines
2.1 KiB
C
/* Copyright JS Foundation and other contributors, http://js.foundation
|
|
*
|
|
* 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 JERRYX_SECTION_IMPL_H
|
|
#define JERRYX_SECTION_IMPL_H
|
|
|
|
/**
|
|
* Define the name of a section
|
|
*
|
|
* @param name the name of the section without quotes
|
|
*/
|
|
#ifdef __MACH__
|
|
#define JERRYX_SECTION_NAME(name) "__DATA," #name
|
|
#else /* !__MACH__ */
|
|
#define JERRYX_SECTION_NAME(name) #name
|
|
#endif /* __MACH__ */
|
|
|
|
/**
|
|
* Expands to the proper __attribute__(()) qualifier for appending a variable to a section.
|
|
*/
|
|
#define JERRYX_SECTION_ATTRIBUTE(name) \
|
|
__attribute__ ((used, section (JERRYX_SECTION_NAME (name)), aligned (sizeof (void *))))
|
|
|
|
/**
|
|
* Declare references to a section that contains an array of items.
|
|
*
|
|
* @param name the name of the section (without quotes)
|
|
* @param type the type of the elements stored in the array
|
|
*
|
|
* This macro declares two extern const variables such that their type is an array of @p type and their names are
|
|
* constructed by prefixing @p name with "__start_" and "__stop_". They evaluate to the starting and ending address
|
|
* of the section @p name.
|
|
*/
|
|
#ifdef __MACH__
|
|
#define JERRYX_SECTION_DECLARE(name, type) \
|
|
extern const type __start_ ## name[] __asm("section$start$__DATA$" #name); \
|
|
extern const type __stop_ ## name[] __asm("section$end$__DATA$" #name);
|
|
#else /* !__MACH__ */
|
|
#define JERRYX_SECTION_DECLARE(name, type) \
|
|
extern const type __start_ ## name[] __attribute__((weak)); \
|
|
extern const type __stop_ ## name[] __attribute__((weak));
|
|
#endif /* __MACH__ */
|
|
|
|
#endif /* !JERRYX_SECTION_IMPL_H */
|