Replace vera++ with clang-format (#4518)

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik robert.fancsik@h-lab.eu
This commit is contained in:
Robert Fancsik
2021-11-05 14:15:47 +01:00
committed by GitHub
parent bc091e1742
commit badfdf4dba
564 changed files with 10195 additions and 15090 deletions
+50 -70
View File
@@ -16,8 +16,9 @@
#include <string.h>
#include "jerryscript.h"
#include "test-common.h"
#include "jerryscript-ext/module.h"
#include "test-common.h"
/* Load a module. */
const char eval_string1[] = "require ('my_custom_module');";
@@ -26,64 +27,58 @@ const char eval_string1[] = "require ('my_custom_module');";
const char eval_string2[] = "require ('differently-handled-module');";
/* Load a broken module using the built-in resolver. */
const char eval_string3[] =
"(function() {"
" var theError;"
" try {"
" require ('my_broken_module');"
" } catch (anError) {"
" theError = anError;"
" }"
" return (((theError.message === 'Module on_resolve () must not be NULL') &&"
" (theError.moduleName === 'my_broken_module') &&"
" (theError instanceof TypeError)) ? 1 : 0);"
"}) ();";
const char eval_string3[] = "(function() {"
" var theError;"
" try {"
" require ('my_broken_module');"
" } catch (anError) {"
" theError = anError;"
" }"
" return (((theError.message === 'Module on_resolve () must not be NULL') &&"
" (theError.moduleName === 'my_broken_module') &&"
" (theError instanceof TypeError)) ? 1 : 0);"
"}) ();";
/* Load a non-existent module. */
const char eval_string4[] =
"(function() {"
" var theError;"
" try {"
" require ('some_missing_module_xyzzy');"
" } catch (anError) {"
" theError = anError;"
" }"
" return (((theError.message === 'Module not found') &&"
" (theError.moduleName === 'some_missing_module_xyzzy')) ? 1 : 0);"
"}) ();";
const char eval_string4[] = "(function() {"
" var theError;"
" try {"
" require ('some_missing_module_xyzzy');"
" } catch (anError) {"
" theError = anError;"
" }"
" return (((theError.message === 'Module not found') &&"
" (theError.moduleName === 'some_missing_module_xyzzy')) ? 1 : 0);"
"}) ();";
/* Make sure the result of a module load is cached. */
const char eval_string5[] =
"(function() {"
" var x = require('cache-check');"
" var y = require('cache-check');"
" return x === y ? 1 : 0;"
"}) ();";
const char eval_string5[] = "(function() {"
" var x = require('cache-check');"
" var y = require('cache-check');"
" return x === y ? 1 : 0;"
"}) ();";
/* Make sure the result of a module load is removed from the cache. */
const char eval_string6[] =
"(function() {"
" var x = require('cache-check');"
" clear_require_cache('cache-check');"
" var y = require('cache-check');"
" return x !== y ? 1 : 0;"
"}) ();";
const char eval_string6[] = "(function() {"
" var x = require('cache-check');"
" clear_require_cache('cache-check');"
" var y = require('cache-check');"
" return x !== y ? 1 : 0;"
"}) ();";
/* Make sure the entire cache is cleared. */
const char eval_string7[] =
"(function() {"
" var x = require('cache-check');"
" clear_require_cache(undefined);"
" var y = require('cache-check');"
" return x !== y ? 1 : 0;"
"}) ();";
const char eval_string7[] = "(function() {"
" var x = require('cache-check');"
" clear_require_cache(undefined);"
" var y = require('cache-check');"
" return x !== y ? 1 : 0;"
"}) ();";
/*
* Define a resolver for a module named "differently-handled-module" to check that custom resolvers work.
*/
static bool
resolve_differently_handled_module (const jerry_value_t name,
jerry_value_t *result)
resolve_differently_handled_module (const jerry_value_t name, jerry_value_t *result)
{
jerry_size_t name_size = jerry_get_utf8_string_size (name);
JERRY_VLA (jerry_char_t, name_string, name_size);
@@ -97,11 +92,7 @@ resolve_differently_handled_module (const jerry_value_t name,
return false;
} /* resolve_differently_handled_module */
static jerryx_module_resolver_t differently_handled_module_resolver =
{
NULL,
resolve_differently_handled_module
};
static jerryx_module_resolver_t differently_handled_module_resolver = { NULL, resolve_differently_handled_module };
/*
* Define module "cache-check" via its own resolver as an empty object. Since objects are accessible only via references
@@ -109,8 +100,7 @@ static jerryx_module_resolver_t differently_handled_module_resolver =
* on the first attempt and establish that the two are in fact the same object - which in turn shows that caching works.
*/
static bool
cache_check (const jerry_value_t name,
jerry_value_t *result)
cache_check (const jerry_value_t name, jerry_value_t *result)
{
jerry_size_t name_size = jerry_get_utf8_string_size (name);
JERRY_VLA (jerry_char_t, name_string, name_size);
@@ -124,18 +114,11 @@ cache_check (const jerry_value_t name,
return false;
} /* cache_check */
static jerryx_module_resolver_t cache_check_resolver =
{
NULL,
cache_check
};
static jerryx_module_resolver_t cache_check_resolver = { NULL, cache_check };
static const jerryx_module_resolver_t *resolvers[3] =
{
&jerryx_module_native_resolver,
&differently_handled_module_resolver,
&cache_check_resolver
};
static const jerryx_module_resolver_t *resolvers[3] = { &jerryx_module_native_resolver,
&differently_handled_module_resolver,
&cache_check_resolver };
static jerry_value_t
handle_clear_require_cache (const jerry_call_info_t *call_info_p,
@@ -152,9 +135,7 @@ handle_clear_require_cache (const jerry_call_info_t *call_info_p,
} /* handle_clear_require_cache */
static jerry_value_t
handle_require (const jerry_call_info_t *call_info_p,
const jerry_value_t args_p[],
const jerry_length_t args_count)
handle_require (const jerry_call_info_t *call_info_p, const jerry_value_t args_p[], const jerry_length_t args_count)
{
(void) call_info_p;
(void) args_count;
@@ -177,9 +158,8 @@ assert_number (jerry_value_t js_value, double expected_result)
static void
eval_one (const char *the_string, double expected_result)
{
jerry_value_t js_eval_result = jerry_eval ((const jerry_char_t *) the_string,
strlen (the_string),
JERRY_PARSE_STRICT_MODE);
jerry_value_t js_eval_result =
jerry_eval ((const jerry_char_t *) the_string, strlen (the_string), JERRY_PARSE_STRICT_MODE);
assert_number (js_eval_result, expected_result);
jerry_release_value (js_eval_result);
} /* eval_one */
+1
View File
@@ -14,6 +14,7 @@
*/
#include "jerryscript.h"
#include "jerryscript-ext/module.h"
#define MODULE_NAME my_broken_module
+1
View File
@@ -14,6 +14,7 @@
*/
#include "jerryscript.h"
#include "jerryscript-ext/module.h"
#define MODULE_NAME my_custom_module
+12 -12
View File
@@ -22,19 +22,19 @@
#define JERRY_UNUSED(x) ((void) (x))
#define TEST_ASSERT(x) \
do \
{ \
if (!(x)) \
{ \
jerry_port_log (JERRY_LOG_LEVEL_ERROR, \
#define TEST_ASSERT(x) \
do \
{ \
if (!(x)) \
{ \
jerry_port_log (JERRY_LOG_LEVEL_ERROR, \
"TEST: Assertion '%s' failed at %s(%s):%lu.\n", \
#x, \
__FILE__, \
__func__, \
(unsigned long) __LINE__); \
jerry_port_fatal (ERR_FAILED_INTERNAL_ASSERTION); \
} \
#x, \
__FILE__, \
__func__, \
(unsigned long) __LINE__); \
jerry_port_fatal (ERR_FAILED_INTERNAL_ASSERTION); \
} \
} while (0)
#define TEST_STRING_LITERAL(x) x
+109 -168
View File
@@ -18,62 +18,61 @@
*/
#include <string.h>
#include "jerryscript.h"
#include "jerryscript-ext/arg.h"
#include "test-common.h"
static const jerry_char_t test_source[] = TEST_STRING_LITERAL (
"var arg1 = true;"
"var arg2 = 10.5;"
"var arg3 = 'abc';"
"var arg4 = function foo() {};"
"test_validator1(arg1, arg2, arg3, arg4);"
"arg1 = new Boolean(true);"
"arg3 = new String('abc');"
"test_validator1(arg1, arg2, arg3);"
"test_validator1(arg1, arg2, '');"
"arg2 = new Number(10.5);"
"test_validator1(arg1, arg2, arg3);"
"test_validator1(arg1, 10.5, 'abcdef');"
"test_validator3(arg1, arg1);"
"test_validator3(arg1);"
"test_validator3();"
"test_validator3(undefined, undefined);"
"var obj_a = new MyObjectA();"
"var obj_b = new MyObjectB();"
"test_validator2.call(obj_a, 5);"
"test_validator2.call(obj_b, 5);"
"test_validator2.call(obj_a, 1);"
"var obj1 = {prop1:true, prop2:'1.5'};"
"test_validator_prop1(obj1);"
"test_validator_prop2(obj1);"
"test_validator_prop2();"
"var obj2 = {prop1:true};"
"Object.defineProperty(obj2, 'prop2', {"
" get: function() { throw new TypeError('prop2 error') }"
"});"
"test_validator_prop3(obj2);"
"test_validator_int1(-1000, 1000, 128, -1000, 1000, -127,"
" -1000, 4294967297, 65536, -2200000000, 4294967297, -2147483647);"
"test_validator_int2(-1.5, -1.5, -1.5, 1.5, 1.5, 1.5, Infinity, -Infinity, 300.5, 300.5);"
"test_validator_int3(NaN);"
"var arr = [1, 2];"
"test_validator_array1(arr);"
"test_validator_array1();"
"test_validator_array2(arr);"
"test_validator_restore(false, 3.0);"
"test_validator_restore(3.0, false);"
);
static const jerry_char_t test_source[] =
TEST_STRING_LITERAL ("var arg1 = true;"
"var arg2 = 10.5;"
"var arg3 = 'abc';"
"var arg4 = function foo() {};"
"test_validator1(arg1, arg2, arg3, arg4);"
"arg1 = new Boolean(true);"
"arg3 = new String('abc');"
"test_validator1(arg1, arg2, arg3);"
"test_validator1(arg1, arg2, '');"
"arg2 = new Number(10.5);"
"test_validator1(arg1, arg2, arg3);"
"test_validator1(arg1, 10.5, 'abcdef');"
"test_validator3(arg1, arg1);"
"test_validator3(arg1);"
"test_validator3();"
"test_validator3(undefined, undefined);"
"var obj_a = new MyObjectA();"
"var obj_b = new MyObjectB();"
"test_validator2.call(obj_a, 5);"
"test_validator2.call(obj_b, 5);"
"test_validator2.call(obj_a, 1);"
"var obj1 = {prop1:true, prop2:'1.5'};"
"test_validator_prop1(obj1);"
"test_validator_prop2(obj1);"
"test_validator_prop2();"
"var obj2 = {prop1:true};"
"Object.defineProperty(obj2, 'prop2', {"
" get: function() { throw new TypeError('prop2 error') }"
"});"
"test_validator_prop3(obj2);"
"test_validator_int1(-1000, 1000, 128, -1000, 1000, -127,"
" -1000, 4294967297, 65536, -2200000000, 4294967297, -2147483647);"
"test_validator_int2(-1.5, -1.5, -1.5, 1.5, 1.5, 1.5, Infinity, -Infinity, 300.5, 300.5);"
"test_validator_int3(NaN);"
"var arr = [1, 2];"
"test_validator_array1(arr);"
"test_validator_array1();"
"test_validator_array2(arr);"
"test_validator_restore(false, 3.0);"
"test_validator_restore(3.0, false);");
static const jerry_object_native_info_t thing_a_info =
{
static const jerry_object_native_info_t thing_a_info = {
.free_cb = NULL,
.number_of_references = 0,
.offset_of_references = 0,
};
static const jerry_object_native_info_t thing_b_info =
{
static const jerry_object_native_info_t thing_b_info = {
.free_cb = NULL,
.number_of_references = 0,
.offset_of_references = 0,
@@ -119,25 +118,20 @@ test_validator1_handler (const jerry_call_info_t *call_info_p, /**< call informa
char arg3[5] = "1234";
jerry_value_t arg4 = jerry_create_undefined ();
jerryx_arg_t mapping[] =
{
/* ignore this */
jerryx_arg_ignore (),
/* 1st argument should be boolean */
jerryx_arg_boolean (&arg1, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
/* 2nd argument should be strict number */
jerryx_arg_number (&arg2, JERRYX_ARG_NO_COERCE, JERRYX_ARG_REQUIRED),
/* 3th argument should be string */
jerryx_arg_string (arg3, 5, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
/* 4th argument should be function, and it is optional */
jerryx_arg_function (&arg4, JERRYX_ARG_OPTIONAL)
jerryx_arg_t mapping[] = { /* ignore this */
jerryx_arg_ignore (),
/* 1st argument should be boolean */
jerryx_arg_boolean (&arg1, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
/* 2nd argument should be strict number */
jerryx_arg_number (&arg2, JERRYX_ARG_NO_COERCE, JERRYX_ARG_REQUIRED),
/* 3th argument should be string */
jerryx_arg_string (arg3, 5, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
/* 4th argument should be function, and it is optional */
jerryx_arg_function (&arg4, JERRYX_ARG_OPTIONAL)
};
jerry_value_t is_ok = jerryx_arg_transform_this_and_args (call_info_p->this_value,
args_p,
args_cnt,
mapping,
ARRAY_SIZE (mapping));
jerry_value_t is_ok =
jerryx_arg_transform_this_and_args (call_info_p->this_value, args_p, args_cnt, mapping, ARRAY_SIZE (mapping));
if (validator1_count == 0)
{
@@ -189,8 +183,7 @@ my_custom_transform (jerryx_arg_js_iterator_t *js_arg_iter_p, /**< available JS
{
jerry_release_value (to_number);
return jerry_create_error (JERRY_ERROR_TYPE,
(jerry_char_t *) "It can not be converted to a number.");
return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "It can not be converted to a number.");
}
int expected_num = (int) c_arg_p->extra_info;
@@ -198,8 +191,7 @@ my_custom_transform (jerryx_arg_js_iterator_t *js_arg_iter_p, /**< available JS
if (get_num != expected_num)
{
return jerry_create_error (JERRY_ERROR_TYPE,
(jerry_char_t *) "Number value is not expected.");
return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "Number value is not expected.");
}
return jerry_create_undefined ();
@@ -217,19 +209,14 @@ test_validator2_handler (const jerry_call_info_t *call_info_p, /**< call informa
{
my_type_a_t *thing_p;
jerryx_arg_t mapping[] =
{
/* this should has native pointer, whose type is thing_a_info */
jerryx_arg_native_pointer ((void **) &thing_p, &thing_a_info, JERRYX_ARG_REQUIRED),
/* custom tranform function */
jerryx_arg_custom (NULL, 5, my_custom_transform)
jerryx_arg_t mapping[] = { /* this should has native pointer, whose type is thing_a_info */
jerryx_arg_native_pointer ((void **) &thing_p, &thing_a_info, JERRYX_ARG_REQUIRED),
/* custom tranform function */
jerryx_arg_custom (NULL, 5, my_custom_transform)
};
jerry_value_t is_ok = jerryx_arg_transform_this_and_args (call_info_p->this_value,
args_p,
args_cnt,
mapping,
ARRAY_SIZE (mapping));
jerry_value_t is_ok =
jerryx_arg_transform_this_and_args (call_info_p->this_value, args_p, args_cnt, mapping, ARRAY_SIZE (mapping));
if (validator2_count == 0)
{
@@ -261,8 +248,7 @@ test_validator3_handler (const jerry_call_info_t *call_info_p, /**< call informa
bool arg1 = false;
bool arg2 = false;
jerryx_arg_t mapping[] =
{
jerryx_arg_t mapping[] = {
/* ignore this */
jerryx_arg_ignore (),
/* 1th argument should be boolean, and it is optional */
@@ -271,11 +257,8 @@ test_validator3_handler (const jerry_call_info_t *call_info_p, /**< call informa
jerryx_arg_boolean (&arg2, JERRYX_ARG_COERCE, JERRYX_ARG_OPTIONAL),
};
jerry_value_t is_ok = jerryx_arg_transform_this_and_args (call_info_p->this_value,
args_p,
args_cnt,
mapping,
ARRAY_SIZE (mapping));
jerry_value_t is_ok =
jerryx_arg_transform_this_and_args (call_info_p->this_value, args_p, args_cnt, mapping, ARRAY_SIZE (mapping));
if (validator3_count == 0)
{
@@ -328,14 +311,11 @@ test_validator_prop1_handler (const jerry_call_info_t *call_info_p, /**< call in
double native2 = 0;
double native3 = 3;
const char *name_p[] = {"prop1", "prop2", "prop3"};
const char *name_p[] = { "prop1", "prop2", "prop3" };
jerryx_arg_t mapping[] =
{
jerryx_arg_boolean (&native1, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_number (&native2, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_number (&native3, JERRYX_ARG_COERCE, JERRYX_ARG_OPTIONAL)
};
jerryx_arg_t mapping[] = { jerryx_arg_boolean (&native1, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_number (&native2, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_number (&native3, JERRYX_ARG_COERCE, JERRYX_ARG_OPTIONAL) };
jerry_value_t is_ok = jerryx_arg_transform_object_properties (args_p[0],
(const jerry_char_t **) name_p,
@@ -372,20 +352,16 @@ test_validator_prop2_handler (const jerry_call_info_t *call_info_p, /**< call in
const char *name_p[] = { "prop1", "prop2", "prop3" };
jerryx_arg_t prop_mapping[] =
{
jerryx_arg_boolean (&native1, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_number (&native2, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_number (&native3, JERRYX_ARG_COERCE, JERRYX_ARG_OPTIONAL)
};
jerryx_arg_t prop_mapping[] = { jerryx_arg_boolean (&native1, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_number (&native2, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_number (&native3, JERRYX_ARG_COERCE, JERRYX_ARG_OPTIONAL) };
prop_info.name_p = (const jerry_char_t **) name_p;
prop_info.name_cnt = 3;
prop_info.c_arg_p = prop_mapping;
prop_info.c_arg_cnt = 3;
jerryx_arg_t mapping[] =
{
jerryx_arg_t mapping[] = {
jerryx_arg_object_properties (&prop_info, JERRYX_ARG_OPTIONAL),
};
@@ -418,8 +394,7 @@ test_validator_prop3_handler (const jerry_call_info_t *call_info_p, /**< call in
const char *name_p[] = { "prop1", "prop2" };
jerryx_arg_t mapping[] =
{
jerryx_arg_t mapping[] = {
jerryx_arg_boolean (&native1, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_boolean (&native2, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
};
@@ -455,8 +430,7 @@ test_validator_int1_handler (const jerry_call_info_t *call_info_p, /**< call inf
uint32_t num6, num7, num8;
int32_t num9, num10, num11;
jerryx_arg_t mapping[] =
{
jerryx_arg_t mapping[] = {
jerryx_arg_uint8 (&num0, JERRYX_ARG_ROUND, JERRYX_ARG_CLAMP, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_uint8 (&num1, JERRYX_ARG_ROUND, JERRYX_ARG_CLAMP, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_uint8 (&num2, JERRYX_ARG_ROUND, JERRYX_ARG_CLAMP, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
@@ -471,10 +445,7 @@ test_validator_int1_handler (const jerry_call_info_t *call_info_p, /**< call inf
jerryx_arg_int32 (&num11, JERRYX_ARG_ROUND, JERRYX_ARG_CLAMP, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED)
};
jerry_value_t is_ok = jerryx_arg_transform_args (args_p,
args_cnt,
mapping,
ARRAY_SIZE (mapping));
jerry_value_t is_ok = jerryx_arg_transform_args (args_p, args_cnt, mapping, ARRAY_SIZE (mapping));
TEST_ASSERT (!jerry_value_is_error (is_ok));
TEST_ASSERT (num0 == 0);
@@ -507,8 +478,7 @@ test_validator_int2_handler (const jerry_call_info_t *call_info_p, /**< call inf
num8 = 123;
num9 = 123;
jerryx_arg_t mapping[] =
{
jerryx_arg_t mapping[] = {
jerryx_arg_int8 (&num0, JERRYX_ARG_ROUND, JERRYX_ARG_CLAMP, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_int8 (&num1, JERRYX_ARG_FLOOR, JERRYX_ARG_CLAMP, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_int8 (&num2, JERRYX_ARG_CEIL, JERRYX_ARG_CLAMP, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
@@ -521,10 +491,7 @@ test_validator_int2_handler (const jerry_call_info_t *call_info_p, /**< call inf
jerryx_arg_int8 (&num9, JERRYX_ARG_ROUND, JERRYX_ARG_NO_CLAMP, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
};
jerry_value_t is_ok = jerryx_arg_transform_args (args_p,
args_cnt,
mapping,
ARRAY_SIZE (mapping));
jerry_value_t is_ok = jerryx_arg_transform_args (args_p, args_cnt, mapping, ARRAY_SIZE (mapping));
TEST_ASSERT (jerry_value_is_error (is_ok));
TEST_ASSERT (num0 == -2);
@@ -553,15 +520,11 @@ test_validator_int3_handler (const jerry_call_info_t *call_info_p, /**< call inf
int8_t num0;
jerryx_arg_t mapping[] =
{
jerryx_arg_t mapping[] = {
jerryx_arg_int8 (&num0, JERRYX_ARG_ROUND, JERRYX_ARG_CLAMP, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
};
jerry_value_t is_ok = jerryx_arg_transform_args (args_p,
args_cnt,
mapping,
ARRAY_SIZE (mapping));
jerry_value_t is_ok = jerryx_arg_transform_args (args_p, args_cnt, mapping, ARRAY_SIZE (mapping));
TEST_ASSERT (jerry_value_is_error (is_ok));
@@ -584,18 +547,14 @@ test_validator_array1_handler (const jerry_call_info_t *call_info_p, /**< call i
jerryx_arg_array_items_t arr_info;
jerryx_arg_t item_mapping[] =
{
jerryx_arg_number (&native1, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_number (&native2, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_number (&native3, JERRYX_ARG_COERCE, JERRYX_ARG_OPTIONAL)
};
jerryx_arg_t item_mapping[] = { jerryx_arg_number (&native1, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_number (&native2, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_number (&native3, JERRYX_ARG_COERCE, JERRYX_ARG_OPTIONAL) };
arr_info.c_arg_p = item_mapping;
arr_info.c_arg_cnt = 3;
jerryx_arg_t mapping[] =
{
jerryx_arg_t mapping[] = {
jerryx_arg_array (&arr_info, JERRYX_ARG_OPTIONAL),
};
@@ -626,11 +585,8 @@ test_validator_array2_handler (const jerry_call_info_t *call_info_p, /**< call i
double native1 = 0;
bool native2 = false;
jerryx_arg_t item_mapping[] =
{
jerryx_arg_number (&native1, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_boolean (&native2, JERRYX_ARG_NO_COERCE, JERRYX_ARG_REQUIRED)
};
jerryx_arg_t item_mapping[] = { jerryx_arg_number (&native1, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
jerryx_arg_boolean (&native2, JERRYX_ARG_NO_COERCE, JERRYX_ARG_REQUIRED) };
jerry_value_t is_ok = jerryx_arg_transform_array (args_p[0], item_mapping, ARRAY_SIZE (item_mapping));
@@ -654,10 +610,10 @@ test_validator_array2_handler (const jerry_call_info_t *call_info_p, /**< call i
* against backing up too far, when the check for the double fails,
* we'll "restore" the stack three times; this shouldn't break
* anything.
*/
*/
/*
* This enumeration type specifies the kind of thing held in the union.
*/
*/
typedef enum
{
DOUBLE_VALUE,
@@ -667,7 +623,7 @@ typedef enum
/*
* This struct holds either a boolean or double in a union and has a
* second field that describes the type held in the union.
*/
*/
typedef struct
{
union_type_t type_of_value;
@@ -682,21 +638,20 @@ typedef struct
* This creates a jerryx_arg_t that can be used like any
* of the installed functions, like jerryx_arg_bool().
*/
#define jerryx_arg_double_or_bool_t(value_ptr, coerce_or_not, optional_or_not, last_parameter) \
jerryx_arg_custom (value_ptr, \
(uintptr_t)&((uintptr_t []){(uintptr_t)coerce_or_not, \
(uintptr_t)optional_or_not, \
(uintptr_t)last_parameter}), \
jerry_arg_to_double_or_bool_t)
#define jerryx_arg_double_or_bool_t(value_ptr, coerce_or_not, optional_or_not, last_parameter) \
jerryx_arg_custom ( \
value_ptr, \
(uintptr_t) \
& ((uintptr_t[]){ (uintptr_t) coerce_or_not, (uintptr_t) optional_or_not, (uintptr_t) last_parameter }), \
jerry_arg_to_double_or_bool_t)
/*
* This function is the argument validator used in the above macro called
* jerryx_arg_double_or_bool. It calls jerryx_arg_js_iterator_restore()
* more times than it should to ensure that calling that function too
* often doesn't cause an error.
*/
*/
static jerry_value_t
jerry_arg_to_double_or_bool_t (jerryx_arg_js_iterator_t *js_arg_iter_p,
const jerryx_arg_t *c_arg_p)
jerry_arg_to_double_or_bool_t (jerryx_arg_js_iterator_t *js_arg_iter_p, const jerryx_arg_t *c_arg_p)
{
/* c_arg_p has two fields: dest, which is a pointer to the data that
* gets filled in, and extra_info, which contains the flags used to
@@ -763,14 +718,13 @@ jerry_arg_to_double_or_bool_t (jerryx_arg_js_iterator_t *js_arg_iter_p,
/* Fall through indicates that whatever they gave us, it wasn't
* one of the types we were expecting... */
jerry_release_value (conversion_result);
return jerry_create_error (JERRY_ERROR_TYPE,
(const jerry_char_t *) "double_or_bool-type error.");
return jerry_create_error (JERRY_ERROR_TYPE, (const jerry_char_t *) "double_or_bool-type error.");
} /* jerry_arg_to_double_or_bool_t */
/**
* This validator expects two parameters, one a bool and one a double -- the
* order doesn't matter (so we'll call it twice with the orders reversed).
*/
*/
static jerry_value_t
test_validator_restore_handler (const jerry_call_info_t *call_info_p, /**< call information */
const jerry_value_t args_p[], /**< arguments list */
@@ -781,11 +735,8 @@ test_validator_restore_handler (const jerry_call_info_t *call_info_p, /**< call
double_or_bool_t arg1;
double_or_bool_t arg2;
jerryx_arg_t item_mapping[] =
{
jerryx_arg_double_or_bool_t (&arg1, JERRYX_ARG_NO_COERCE, JERRYX_ARG_REQUIRED, 0),
jerryx_arg_double_or_bool_t (&arg2, JERRYX_ARG_NO_COERCE, JERRYX_ARG_REQUIRED, 1)
};
jerryx_arg_t item_mapping[] = { jerryx_arg_double_or_bool_t (&arg1, JERRYX_ARG_NO_COERCE, JERRYX_ARG_REQUIRED, 0),
jerryx_arg_double_or_bool_t (&arg2, JERRYX_ARG_NO_COERCE, JERRYX_ARG_REQUIRED, 1) };
jerry_value_t is_ok = jerryx_arg_transform_args (args_p, args_cnt, item_mapping, ARRAY_SIZE (item_mapping));
@@ -812,15 +763,11 @@ test_utf8_string (void)
size_t buf_len = sizeof (expect_utf8_buf) - 1;
JERRY_VLA (char, buf, buf_len + 1);
jerryx_arg_t mapping[] =
{
jerryx_arg_t mapping[] = {
jerryx_arg_utf8_string (buf, (uint32_t) buf_len + 1, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
};
jerry_value_t is_ok = jerryx_arg_transform_args (&str,
1,
mapping,
ARRAY_SIZE (mapping));
jerry_value_t is_ok = jerryx_arg_transform_args (&str, 1, mapping, ARRAY_SIZE (mapping));
TEST_ASSERT (!jerry_value_is_error (is_ok));
TEST_ASSERT (!strcmp (buf, expect_utf8_buf));
@@ -839,9 +786,7 @@ create_object_a_handler (const jerry_call_info_t *call_info_p, /**< call informa
TEST_ASSERT (jerry_value_is_object (call_info_p->this_value));
my_thing_a.x = 1;
jerry_set_object_native_pointer (call_info_p->this_value,
&my_thing_a,
&thing_a_info);
jerry_set_object_native_pointer (call_info_p->this_value, &my_thing_a, &thing_a_info);
return jerry_create_boolean (true);
} /* create_object_a_handler */
@@ -857,9 +802,7 @@ create_object_b_handler (const jerry_call_info_t *call_info_p, /**< call informa
TEST_ASSERT (jerry_value_is_object (call_info_p->this_value));
my_thing_b.x = false;
jerry_set_object_native_pointer (call_info_p->this_value,
&my_thing_b,
&thing_b_info);
jerry_set_object_native_pointer (call_info_p->this_value, &my_thing_b, &thing_b_info);
return jerry_create_boolean (true);
} /* create_object_b_handler */
@@ -906,9 +849,7 @@ main (void)
register_js_function ("test_validator_array2", test_validator_array2_handler);
register_js_function ("test_validator_restore", test_validator_restore_handler);
jerry_value_t parsed_code_val = jerry_parse (test_source,
sizeof (test_source) - 1,
NULL);
jerry_value_t parsed_code_val = jerry_parse (test_source, sizeof (test_source) - 1, NULL);
TEST_ASSERT (!jerry_value_is_error (parsed_code_val));
jerry_value_t res = jerry_run (parsed_code_val);
+2 -2
View File
@@ -18,6 +18,7 @@
*/
#include "jerryscript.h"
#include "jerryscript-ext/autorelease.h"
#include "test-common.h"
@@ -32,8 +33,7 @@ native_free_cb (void *native_p, /**< native pointer */
++native_free_cb_call_count;
} /* native_free_cb */
static const jerry_object_native_info_t native_info =
{
static const jerry_object_native_info_t native_info = {
.free_cb = native_free_cb,
.number_of_references = 0,
.offset_of_references = 0,
@@ -18,6 +18,7 @@
*/
#include "jerryscript.h"
#include "jerryscript-ext/handle-scope.h"
#include "test-common.h"
@@ -32,8 +33,7 @@ native_free_cb (void *native_p, /**< native pointer */
++native_free_cb_call_count;
} /* native_free_cb */
static const jerry_object_native_info_t native_info =
{
static const jerry_object_native_info_t native_info = {
.free_cb = native_free_cb,
.number_of_references = 0,
.offset_of_references = 0,
@@ -20,6 +20,7 @@
*/
#include "jerryscript.h"
#include "jerryscript-ext/handle-scope.h"
#include "test-common.h"
@@ -35,8 +36,7 @@ native_free_cb (void *native_p, /**< native pointer */
++native_free_cb_call_count;
} /* native_free_cb */
static const jerry_object_native_info_t native_info =
{
static const jerry_object_native_info_t native_info = {
.free_cb = native_free_cb,
.number_of_references = 0,
.offset_of_references = 0,
@@ -49,7 +49,7 @@ create_object (void)
jerryx_open_escapable_handle_scope (&scope);
jerry_value_t obj;
for (size_t idx = 0; idx < handle_count; idx ++)
for (size_t idx = 0; idx < handle_count; idx++)
{
obj = jerryx_create_handle (jerry_create_object ());
jerry_set_object_native_pointer (obj, NULL, &native_info);
@@ -73,7 +73,7 @@ test_handle_scope_val (void)
(void) obj;
jerry_gc (JERRY_GC_PRESSURE_LOW);
TEST_ASSERT (native_free_cb_call_count == (handle_count -1));
TEST_ASSERT (native_free_cb_call_count == (handle_count - 1));
jerryx_close_handle_scope (scope);
} /* test_handle_scope_val */
@@ -20,6 +20,7 @@
*/
#include "jerryscript.h"
#include "jerryscript-ext/handle-scope.h"
#include "test-common.h"
@@ -35,8 +36,7 @@ native_free_cb (void *native_p, /**< native pointer */
++native_free_cb_call_count;
} /* native_free_cb */
static const jerry_object_native_info_t native_info =
{
static const jerry_object_native_info_t native_info = {
.free_cb = native_free_cb,
.number_of_references = 0,
.offset_of_references = 0,
@@ -49,7 +49,7 @@ create_object (void)
jerryx_open_escapable_handle_scope (&scope);
jerry_value_t obj;
for (size_t idx = 0; idx < handle_count; idx ++)
for (size_t idx = 0; idx < handle_count; idx++)
{
obj = jerryx_create_handle (jerry_create_object ());
jerry_set_object_native_pointer (obj, NULL, &native_info);
@@ -73,7 +73,7 @@ test_handle_scope_val (void)
(void) obj;
jerry_gc (JERRY_GC_PRESSURE_LOW);
TEST_ASSERT (native_free_cb_call_count == (handle_count -1));
TEST_ASSERT (native_free_cb_call_count == (handle_count - 1));
jerryx_close_handle_scope (scope);
} /* test_handle_scope_val */
@@ -21,6 +21,7 @@
*/
#include "jerryscript.h"
#include "jerryscript-ext/handle-scope.h"
#include "test-common.h"
@@ -35,8 +36,7 @@ native_free_cb (void *native_p, /**< native pointer */
++native_free_cb_call_count;
} /* native_free_cb */
static const jerry_object_native_info_t native_info =
{
static const jerry_object_native_info_t native_info = {
.free_cb = native_free_cb,
.number_of_references = 0,
.offset_of_references = 0,
@@ -18,6 +18,7 @@
*/
#include "jerryscript.h"
#include "jerryscript-ext/handle-scope.h"
#include "test-common.h"
@@ -32,8 +33,7 @@ native_free_cb (void *native_p, /**< native pointer */
++native_free_cb_call_count;
} /* native_free_cb */
static const jerry_object_native_info_t native_info =
{
static const jerry_object_native_info_t native_info = {
.free_cb = native_free_cb,
.number_of_references = 0,
.offset_of_references = 0,
+2 -2
View File
@@ -18,6 +18,7 @@
*/
#include "jerryscript.h"
#include "jerryscript-ext/handle-scope.h"
#include "test-common.h"
@@ -33,8 +34,7 @@ native_free_cb (void *native_p, /**< native pointer */
++native_free_cb_call_count;
} /* native_free_cb */
static const jerry_object_native_info_t native_info =
{
static const jerry_object_native_info_t native_info = {
.free_cb = native_free_cb,
.number_of_references = 0,
.offset_of_references = 0,
+2 -2
View File
@@ -18,6 +18,7 @@
*/
#include "jerryscript.h"
#include "jerryscript-ext/handle-scope.h"
#include "test-common.h"
@@ -32,8 +33,7 @@ native_free_cb (void *native_p, /**< native pointer */
++native_free_cb_call_count;
} /* native_free_cb */
static const jerry_object_native_info_t native_info =
{
static const jerry_object_native_info_t native_info = {
.free_cb = native_free_cb,
.number_of_references = 0,
.offset_of_references = 0,
+12 -22
View File
@@ -17,12 +17,13 @@
* Unit test for jerry-ext/handler property registration
*/
#include <string.h>
#include "jerryscript.h"
#include "jerryscript-ext/handler.h"
#include "test-common.h"
#include <string.h>
static jerry_value_t
method_hello (const jerry_call_info_t *call_info_p, /**< call information */
const jerry_value_t jargv[], /**< arguments */
@@ -64,16 +65,11 @@ test_simple_registration (void)
jerry_value_t target_object = jerry_create_object ();
// Test simple registration
jerryx_property_entry methods[] =
{
JERRYX_PROPERTY_FUNCTION ("hello", method_hello),
JERRYX_PROPERTY_NUMBER ("my_number", 42.5),
JERRYX_PROPERTY_STRING ("my_str", "super_str"),
JERRYX_PROPERTY_STRING_SZ ("my_str_sz", "super_str", 6),
JERRYX_PROPERTY_BOOLEAN ("my_bool", true),
JERRYX_PROPERTY_BOOLEAN ("my_bool_false", false),
JERRYX_PROPERTY_UNDEFINED ("my_non_value"),
JERRYX_PROPERTY_LIST_END (),
jerryx_property_entry methods[] = {
JERRYX_PROPERTY_FUNCTION ("hello", method_hello), JERRYX_PROPERTY_NUMBER ("my_number", 42.5),
JERRYX_PROPERTY_STRING ("my_str", "super_str"), JERRYX_PROPERTY_STRING_SZ ("my_str_sz", "super_str", 6),
JERRYX_PROPERTY_BOOLEAN ("my_bool", true), JERRYX_PROPERTY_BOOLEAN ("my_bool_false", false),
JERRYX_PROPERTY_UNDEFINED ("my_non_value"), JERRYX_PROPERTY_LIST_END (),
};
jerryx_register_result register_result = jerryx_set_properties (target_object, methods);
@@ -196,8 +192,7 @@ test_error_single_function (void)
jerry_value_t target_object = jerry_create_object ();
freeze_property (target_object, target_prop);
jerryx_property_entry methods[] =
{
jerryx_property_entry methods[] = {
JERRYX_PROPERTY_FUNCTION (target_prop, method_hello), // This registration should fail
JERRYX_PROPERTY_LIST_END (),
};
@@ -228,8 +223,7 @@ test_error_multiple_functions (void)
jerry_value_t target_object = jerry_create_object ();
freeze_property (target_object, prop_err);
jerryx_property_entry methods[] =
{
jerryx_property_entry methods[] = {
JERRYX_PROPERTY_FUNCTION (prop_ok, method_hello), // This registration is ok
JERRYX_PROPERTY_FUNCTION (prop_err, method_hello), // This registration should fail
JERRYX_PROPERTY_FUNCTION (prop_not, method_hello), // This registration is not done
@@ -254,16 +248,12 @@ test_error_multiple_functions (void)
// Try calling the method
jerry_value_t prop_ok_func = jerry_get_property (target_object, prop_ok_val);
TEST_ASSERT (jerry_value_is_function (prop_ok_func) == true);
jerry_value_t args[2] =
{
jerry_value_t args[2] = {
jerry_create_number (22),
jerry_create_number (-3),
};
jerry_size_t args_cnt = sizeof (args) / sizeof (jerry_value_t);
jerry_value_t func_result = jerry_call_function (prop_ok_func,
jerry_create_undefined (),
args,
args_cnt);
jerry_value_t func_result = jerry_call_function (prop_ok_func, jerry_create_undefined (), args, args_cnt);
TEST_ASSERT (jerry_value_is_number (func_result) == true);
TEST_ASSERT ((uint32_t) jerry_get_number_value (func_result) == 2u);
jerry_release_value (func_result);
+5 -7
View File
@@ -16,11 +16,12 @@
#include <string.h>
#include "jerryscript.h"
#include "test-common.h"
#include "jerryscript-ext/module.h"
#include "test-common.h"
#define ACTUAL_NAME "alice"
#define ALIAS_NAME "bob"
#define ALIAS_NAME "bob"
static jerry_value_t
get_canonical_name (const jerry_value_t name)
@@ -60,11 +61,8 @@ resolve (const jerry_value_t canonical_name, jerry_value_t *result)
return false;
} /* resolve */
static const jerryx_module_resolver_t canonical_test =
{
.get_canonical_name_p = get_canonical_name,
.resolve_p = resolve
};
static const jerryx_module_resolver_t canonical_test = { .get_canonical_name_p = get_canonical_name,
.resolve_p = resolve };
#define TEST_VALUE 95.0
+2 -1
View File
@@ -16,8 +16,9 @@
#include <string.h>
#include "jerryscript.h"
#include "test-common.h"
#include "jerryscript-ext/module.h"
#include "test-common.h"
int
main (int argc, char **argv)