aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Jones <brian.j.jones@intel.com>2017-12-07 14:27:44 -0800
committerGeoff Gustafson <geoff@linux.intel.com>2017-12-07 14:27:44 -0800
commit808cbc16b1bf0c4d9b5b888fff886cb098c5abc1 (patch)
tree325a64fd735e6855e5a178c3444e2af4150de5cf
parent9731e725aef4b4f9ac657a2a83df4230c9c208ea (diff)
[modules] Fix to allow linux to load JS modules (#1691)
Linux requires the module object be returned to work Signed-off-by: Brian J Jones <brian.j.jones@intel.com>
-rwxr-xr-xscripts/trlite4
-rw-r--r--src/main.c2
-rw-r--r--src/zjs_modules.c25
-rw-r--r--src/zjs_script.c9
-rw-r--r--src/zjs_script.h2
-rw-r--r--tools/snapshot.c3
6 files changed, 18 insertions, 27 deletions
diff --git a/scripts/trlite b/scripts/trlite
index e56cd6e..292687c 100755
--- a/scripts/trlite
+++ b/scripts/trlite
@@ -243,9 +243,7 @@ function try_test()
echo "******************************************************************************"
echo Error: Test incomplete in $LABEL subtest \#$TESTNUM with code $CODE \(rerun with: trlite $VMNUM $TESTNUM\)!
echo "******************************************************************************"
- # FIXME: Should exit here but we'll soft fail until we fix things
- # The callbacks, event, gpio, promise, and timers tests all fail ATM
- # and were broken by PR #1542 (commit a36b2c9)
+ exit 1
else
echo Success: $LABEL
fi
diff --git a/src/main.c b/src/main.c
index 97b3029..7670087 100644
--- a/src/main.c
+++ b/src/main.c
@@ -291,7 +291,7 @@ if (start_debug_server) {
#endif
#ifdef ZJS_LINUX_BUILD
- zjs_free_script(script);
+ zjs_free(script);
#endif
#ifdef ZJS_SNAPSHOT_BUILD
diff --git a/src/zjs_modules.c b/src/zjs_modules.c
index 6d3a413..a0de246 100644
--- a/src/zjs_modules.c
+++ b/src/zjs_modules.c
@@ -92,32 +92,30 @@ static bool load_js_module_fs(const jerry_value_t module_name, jerry_value_t *re
DBG_PRINT("Parser disabled, can't check FS for module\n");
return false;
#endif
-
jerry_size_t module_size = jerry_get_utf8_string_size(module_name) + 1;
char module[module_size];
zjs_copy_jstring(module_name, module, &module_size);
-
jerry_size_t size = MAX_MODULE_STR_LEN;
char full_path[size + 9];
- char *str;
+ char *str = NULL;
u32_t len;
bool ret = false;
sprintf(full_path, "modules/%s", module);
full_path[size + 8] = '\0';
if (zjs_read_script(full_path, &str, &len)) {
- ret = false;
+ return false;
}
- ZVAL code_eval = jerry_parse((jerry_char_t *)str, len, false);
- if (jerry_value_has_error_flag(code_eval)) {
+
+ (*result) = jerry_eval((jerry_char_t *)str, len, false);
+ if (jerry_value_has_error_flag(*result)) {
+ ERR_PRINT("failed to evaluate JS\n");
ret = false;
}
- ZVAL res = jerry_run(code_eval);
- if (!jerry_value_has_error_flag(res)) {
+ else {
ret = true;
}
-
- zjs_free_script(str);
+ zjs_free(str);
return ret;
}
#endif // !ZJS_LINUX_BUILD
@@ -189,13 +187,18 @@ static ZJS_DECL_FUNC(native_require_handler)
// Get the module name
jerry_size_t module_size = jerry_get_utf8_string_size(argv[0]) + 1;
+ if (module_size > MAX_MODULE_STR_LEN) {
+ return RANGE_ERROR("module name too long");
+ }
+
char module[module_size];
zjs_copy_jstring(argv[0], module, &module_size);
// Try each of the resolvers to see if we can find the requested module
jerry_value_t result = jerryx_module_resolve(argv[0], resolvers, 3);
if (jerry_value_has_error_flag(result)) {
- ERR_PRINT("Couldn't load module %s\n", module);
+ DBG_PRINT("Couldn't load module %s\n", module);
+ return NOTSUPPORTED_ERROR("Module not found");
}
else {
DBG_PRINT("Module %s loaded\n", module);
diff --git a/src/zjs_script.c b/src/zjs_script.c
index 519211b..a95e4ad 100644
--- a/src/zjs_script.c
+++ b/src/zjs_script.c
@@ -56,13 +56,4 @@ uint8_t zjs_read_script(char *name, char **script, uint32_t *length)
return 0;
}
-
-void zjs_free_script(char *script)
-{
- if (script) {
- free(script);
- }
- return;
-}
-
#endif
diff --git a/src/zjs_script.h b/src/zjs_script.h
index a18dc18..fa3e909 100644
--- a/src/zjs_script.h
+++ b/src/zjs_script.h
@@ -8,6 +8,4 @@
uint8_t zjs_read_script(char *name, char **script, uint32_t *length);
-void zjs_free_script(char *script);
-
#endif /* ZJS_SCRIPT_H_ */
diff --git a/tools/snapshot.c b/tools/snapshot.c
index 55ee307..f6f7f0e 100644
--- a/tools/snapshot.c
+++ b/tools/snapshot.c
@@ -46,7 +46,8 @@ int main(int argc, char *argv[])
snapshot_buf,
sizeof(snapshot_buf));
- zjs_free_script(script);
+ if (script != NULL)
+ free(script);
if (size == 0) {
fprintf(stderr, "JerryScript: failed to parse JS and create snapshot\n");