Fix empty string issue in ext/args (#1921)

Now the js string "" can be converted to C array by jerryx_arg_string

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
This commit is contained in:
Zidong Jiang
2017-07-14 23:41:02 +08:00
committed by Akos Kiss
parent 00f93bc287
commit 8c9b0d4086
2 changed files with 12 additions and 3 deletions
+2 -2
View File
@@ -259,10 +259,10 @@ jerryx_arg_string_common_routine (jerry_value_t js_arg, /**< JS arg */
target_p, target_p,
target_buf_size); target_buf_size);
if (size == 0 || size == target_buf_size) if ((size == target_buf_size) || (size == 0 && jerry_get_string_length (js_arg) != 0))
{ {
return jerry_create_error (JERRY_ERROR_TYPE, return jerry_create_error (JERRY_ERROR_TYPE,
(jerry_char_t *) "The size of the buffer is not large enough."); (jerry_char_t *) "Buffer size is not large enough.");
} }
target_p[size] = '\0'; target_p[size] = '\0';
+10 -1
View File
@@ -33,6 +33,7 @@ const char *test_source = (
"arg1 = new Boolean(true);" "arg1 = new Boolean(true);"
"arg3 = new String('abc');" "arg3 = new String('abc');"
"test_validator1(arg1, arg2, arg3);" "test_validator1(arg1, arg2, arg3);"
"test_validator1(arg1, arg2, '');"
"arg2 = new Number(10.5);" "arg2 = new Number(10.5);"
"test_validator1(arg1, arg2, arg3);" "test_validator1(arg1, arg2, arg3);"
"test_validator1(arg1, 10.5, 'abcdef');" "test_validator1(arg1, 10.5, 'abcdef');"
@@ -141,6 +142,14 @@ test_validator1_handler (const jerry_value_t func_obj_val __attribute__((unused)
TEST_ASSERT (strcmp (arg3, "abc") == 0); TEST_ASSERT (strcmp (arg3, "abc") == 0);
TEST_ASSERT (jerry_value_is_undefined (arg4)); TEST_ASSERT (jerry_value_is_undefined (arg4));
} }
else if (validator1_count == 2)
{
TEST_ASSERT (!jerry_value_has_error_flag (is_ok));
TEST_ASSERT (arg1);
TEST_ASSERT (arg2 == 10.5);
TEST_ASSERT (strcmp (arg3, "") == 0);
TEST_ASSERT (jerry_value_is_undefined (arg4));
}
else else
{ {
TEST_ASSERT (jerry_value_has_error_flag (is_ok)); TEST_ASSERT (jerry_value_has_error_flag (is_ok));
@@ -520,7 +529,7 @@ main (void)
jerry_value_t res = jerry_run (parsed_code_val); jerry_value_t res = jerry_run (parsed_code_val);
TEST_ASSERT (!jerry_value_has_error_flag (res)); TEST_ASSERT (!jerry_value_has_error_flag (res));
TEST_ASSERT (validator1_count == 4); TEST_ASSERT (validator1_count == 5);
TEST_ASSERT (validator2_count == 3); TEST_ASSERT (validator2_count == 3);
TEST_ASSERT (validator_prop_count == 4); TEST_ASSERT (validator_prop_count == 4);
TEST_ASSERT (validator_int_count == 2); TEST_ASSERT (validator_int_count == 2);