Add testing support for nuttx-stm32f4 target
Provide the 'assert' and 'gc' implementation for the engine.
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka
@@ -113,6 +113,70 @@ read_file (const char *file_name, /**< source code */
return (const uint8_t *) buffer;
} /* read_file */
+/**
+ * Provide the 'assert' implementation for the engine.
+ *
+ * @return true - if only one argument was passed and the argument is a boolean true.
+ */
+static jerry_value_t
+assert_handler (const jerry_value_t func_obj_val __attribute__((unused)), /**< function object */
+ const jerry_value_t this_p __attribute__((unused)), /**< this arg */
+ const jerry_value_t args_p[], /**< function arguments */
+ const jerry_length_t args_cnt) /**< number of function arguments */
+{
+ if (args_cnt == 1
+ && jerry_value_is_boolean (args_p[0])
+ && jerry_get_boolean_value (args_p[0]))
+ {
+ return jerry_create_boolean (true);
+ }
+ else
+ {
+ jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Script Error: assertion failed\n");
+ exit (JERRY_STANDALONE_EXIT_CODE_FAIL);
+ }
+} /* assert_handler */
+
+/**
+ * Provide the 'gc' implementation for the engine.
+ *
+ * @return undefined.
+ */
+static jerry_value_t
+gc_handler (const jerry_value_t func_obj_val __attribute__((unused)), /**< function object */
+ const jerry_value_t this_p __attribute__((unused)), /**< this arg */
+ const jerry_value_t args_p[] __attribute__((unused)), /**< function arguments */
+ const jerry_length_t args_cnt __attribute__((unused))) /**< number of function arguments */
+{
+ jerry_gc ();
+ return jerry_create_undefined ();
+} /* gc_handler */
+
+/**
+ * Register a JavaScript function in the global object.
+ */
+static void
+register_js_function (const char *name_p, /**< name of the function */
+ jerry_external_handler_t handler_p) /**< function callback */
+{
+ jerry_value_t global_obj_val = jerry_get_global_object ();
+
+ jerry_value_t function_val = jerry_create_external_function (handler_p);
+ jerry_value_t function_name_val = jerry_create_string ((const jerry_char_t *) name_p);
+ jerry_value_t result_val = jerry_set_property (global_obj_val, function_name_val, function_val);
+
+ jerry_release_value (function_name_val);
+ jerry_release_value (function_val);
+ jerry_release_value (global_obj_val);
+
+ if (jerry_value_has_error_flag (result_val))
+ {
+ jerry_port_log (JERRY_LOG_LEVEL_WARNING, "Warning: failed to register '%s' method.", name_p);
+ }
+
+ jerry_release_value (result_val);
+} /* register_js_function */
+
/**
* JerryScript log level
*/
@@ -195,6 +259,10 @@ int jerry_main (int argc, char *argv[])
}
jerry_init (flags);
+
+ register_js_function ("assert", assert_handler);
+ register_js_function ("gc", gc_handler);
+
jerry_value_t ret_value = jerry_create_undefined ();
for (i = 0; i < files_counter; i++)
