jerryscript: UTF-8 variable name error

When using UTF-8 variable name, the “jerry_parse” function will returns a value “1073429487”, wondering how to get it fixed?

var 测试 = "您好";

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (8 by maintainers)

Commits related to this issue

Most upvoted comments

@akosthekiss Thank you so much, your minial example works like a champ now… Hope the UTF-8 variable name issue would be fixed very soon too…

@weixiongmei The following minimal example works for me:

#include <stdio.h>

#include "jerryscript.h"

static void
print_exception (jerry_value_t error_value) /**< error value */
{

  jerry_value_t err_str_val = jerry_value_to_string (error_value);
  jerry_size_t err_str_size = jerry_get_string_size (err_str_val);
  jerry_char_t err_str_buf[err_str_size + 1];

  jerry_size_t string_end = jerry_string_to_char_buffer (err_str_val, err_str_buf, err_str_size);
  err_str_buf[string_end] = 0;

  printf ("Error: %s\n", err_str_buf);
  jerry_release_value (err_str_val);
} /* print_exception */

int main (void)
{
  jerry_init (JERRY_INIT_EMPTY);

  const jerry_char_t bugous_src[] = "{";

  jerry_value_t ret_value = jerry_create_undefined ();
  ret_value = jerry_parse (NULL, 0,
                           bugous_src, sizeof (bugous_src) - 1,
                           JERRY_PARSE_NO_OPTS);

  if (jerry_value_is_error (ret_value))
  {
    ret_value = jerry_get_value_from_error (ret_value, true);
    print_exception (ret_value);
  }

  jerry_release_value (ret_value);

  return 1;
} /* main */

Its output is Error: SyntaxError: Primary expression expected. [line: 1, column: 2].

The ret_value = jerry_get_value_from_error (ret_value, true); line is an important difference compared to old code. The API around errors have changed somewhat (around #2350). See http://jerryscript.net/api-reference/#jerry_get_value_from_error . That may also affect your experience with print_unhandled_exception.

Do take a look at main-unix.c. It is always a good starting example.