module: Re-implement using library constructors/destructors (#2018)
By using constructors/destructors we unify the case of static linking with that of dynamic linking, and we reuse the build flag FEATURE_INIT_FINI. Using constructors/destructors also allows us to cover the case where library constructor/destructor functionality is unavailable, because we can expose the module registration/unregistration functions as global symbols, to be called explicitly from within the application. Fixes https://github.com/jerryscript-project/jerryscript/issues/1952 JerryScript-DCO-1.0-Signed-off-by: Gabriel Schulhof gabriel.schulhof@intel.com
This commit is contained in:
committed by
Zoltan Herczeg
parent
8d916a44f1
commit
81952f3cd0
@@ -19,8 +19,6 @@
|
||||
#include "test-common.h"
|
||||
#include "jerryscript-ext/module.h"
|
||||
|
||||
#ifdef JERRYX_NATIVE_MODULES_SUPPORTED
|
||||
|
||||
/* Load a module. */
|
||||
const char eval_string1[] = "require ('my_custom_module');";
|
||||
|
||||
@@ -138,6 +136,11 @@ eval_one (const char *the_string, double expected_result)
|
||||
jerry_release_value (js_eval_result);
|
||||
} /* eval_one */
|
||||
|
||||
#ifndef ENABLE_INIT_FINI
|
||||
extern void my_broken_module_register (void);
|
||||
extern void my_custom_module_register (void);
|
||||
#endif /* !ENABLE_INIT_FINI */
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
@@ -145,6 +148,11 @@ main (int argc, char **argv)
|
||||
(void) argv;
|
||||
jerry_value_t js_global = 0, js_function = 0, js_property_name = 0;
|
||||
|
||||
#ifndef ENABLE_INIT_FINI
|
||||
my_broken_module_register ();
|
||||
my_custom_module_register ();
|
||||
#endif /* !ENABLE_INIT_FINI */
|
||||
|
||||
jerry_init (JERRY_INIT_EMPTY);
|
||||
|
||||
js_global = jerry_get_global_object ();
|
||||
@@ -164,5 +172,3 @@ main (int argc, char **argv)
|
||||
|
||||
jerry_cleanup ();
|
||||
} /* main */
|
||||
|
||||
#endif /* JERRYX_NATIVE_MODULES_SUPPORTED */
|
||||
|
||||
Reference in New Issue
Block a user