Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework the public API #4829

Merged
merged 1 commit into from
Dec 6, 2021
Merged

Conversation

dbatyai
Copy link
Member

@dbatyai dbatyai commented Nov 19, 2021

Related to #4186.

Some notable changes:

  • The term 'Error' now strictly refers to native Error objects defined in
    the ECMA standard, which are ordinary objects. All other uses of
    'error' or 'error reference' where the term refers to a thrown value is
    now called 'exception'.

  • Simplified the naming scheme of many String API functions. These functions
    will now also take an 'encoding' argument to specify the desired
    encoding in which to operate.

  • Removed the substring-copy-to-buffer functions. These functions
    behaved awkwardly, as they use character index to specify the
    start/end positions, and were mostly used incorrectly with byte
    offsets instead. The functionality can still be replicated with
    other functions if necessary.

  • String-to-buffer functions will no longer fail if the buffer is not
    sufficiently large, the string will instead be cropped.

  • Fixed the usage of the '_sz' prefix in many API functions. The term
    'sz' means zero-terminated string in hungarian notation, this was
    used incorrectly in many cases.

  • Renamed most of the public API functions to have shorter, more on-point
    names, rather than the often too long descriptive names. Functions are now
    also grouped by the type of value they operate on, where this makes
    sense.

@dbatyai dbatyai added the api Related to the public API label Nov 19, 2021
@dbatyai dbatyai force-pushed the api_rework branch 5 times, most recently from 781c973 to 77c0577 Compare November 23, 2021 15:01
docs/02.API-REFERENCE.md Outdated Show resolved Hide resolved
docs/02.API-REFERENCE.md Outdated Show resolved Hide resolved
docs/02.API-REFERENCE.md Outdated Show resolved Hide resolved
docs/02.API-REFERENCE.md Outdated Show resolved Hide resolved
docs/02.API-REFERENCE.md Outdated Show resolved Hide resolved
docs/02.API-REFERENCE.md Outdated Show resolved Hide resolved
docs/02.API-REFERENCE.md Show resolved Hide resolved
docs/02.API-REFERENCE.md Outdated Show resolved Hide resolved
docs/02.API-REFERENCE.md Outdated Show resolved Hide resolved
docs/02.API-REFERENCE.md Outdated Show resolved Hide resolved
@dbatyai dbatyai force-pushed the api_rework branch 7 times, most recently from 7dd0bfd to 861dbc8 Compare November 26, 2021 12:59
@dbatyai dbatyai marked this pull request as ready for review November 26, 2021 13:06
@dbatyai dbatyai force-pushed the api_rework branch 2 times, most recently from 58cd82f to 30cdafe Compare November 26, 2021 13:36
Copy link
Member

@rerobika rerobika left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

docs/02.API-REFERENCE.md Outdated Show resolved Hide resolved
@dbatyai dbatyai force-pushed the api_rework branch 9 times, most recently from 52ac604 to 7cc3db6 Compare December 2, 2021 15:11
@dbatyai dbatyai force-pushed the api_rework branch 2 times, most recently from 2ad4996 to 3b9c187 Compare December 3, 2021 16:12
Related to jerryscript-project#4186.

Some notable changes:
  - The term 'Error' now strictly refers to native Error objects defined in
    the ECMA standard, which are ordinary objects. All other uses of
    'error' or 'error reference' where the term refers to a thrown value is
    now called 'exception'.

  - Simplified the naming scheme of many String API functions. These functions
    will now also take an 'encoding' argument to specify the desired
    encoding in which to operate.

  - Removed the substring-copy-to-buffer functions. These functions
    behaved awkwardly, as they use character index to specify the
    start/end positions, and were mostly used incorrectly with byte
    offsets instead. The functionality can still be replicated with
    other functions if necessary.

  - String-to-buffer functions will no longer fail if the buffer is not
    sufficiently large, the string will instead be cropped.

  - Fixed the usage of the '_sz' prefix in many API functions. The term
    'sz' means zero-terminated string in hungarian notation, this was
    used incorrectly in many cases.

  - Renamed most of the public API functions to have shorter, more on-point
    names, rather than the often too long descriptive names. Functions are now
    also grouped by the type of value they operate on, where this makes
    sense.

JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai [email protected]
Copy link
Contributor

@galpeter galpeter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@rerobika rerobika merged commit 9860d66 into jerryscript-project:master Dec 6, 2021
@@ -328,7 +324,7 @@ Flags for [jerry_exec_snapshot](#jerry_exec_snapshot) functions:
- JERRY_SNAPSHOT_EXEC_COPY_DATA - copy snapshot data into memory (see below)
- JERRY_SNAPSHOT_EXEC_ALLOW_STATIC - allow executing static snapshots
- JERRY_SNAPSHOT_EXEC_LOAD_AS_FUNCTION - load snapshot as function instead of executing it
- JERRY_SNAPSHOT_EXEC_HAS_RESOURCE - `resource_name` field is valid
- JERRY_SNAPSHOT_EXEC_HAS_RESOURCE - `source_name` field is valid
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mayebe JERRY_SNAPSHOT_EXEC_HAS_SOURCE?

@lygstate
Copy link
Contributor

lygstate commented Dec 7, 2021

Suggest the in new public API
rename

void jerry_port_print_char (char c);

for more detailed message printing

void jerry_port_print_string (const char *s, size_t len); 

For example, for UTF8 string, jerry_port_print_char will not able to print a Unicode character
in a single function call.

By doing this we can also removed the global variable

static char debug_buffer[DEBUG_BUFFER_SIZE];
static int debug_buffer_index = 0;

So that multiple jerryscript engine would not sharing this variables and have no need of
thread local storage.

@dbatyai
Copy link
Member Author

dbatyai commented Dec 7, 2021

I wouldn't necessarily replace jerry_port_print_char, it has it's uses in it's current form. However, I agree that another port function could be added that can be used to print a string. I'm currently working on updating the port and ext API-s, so I can add this in the next PR.

As far as I can tell the debug_buffer array isn't strictly necessary at the moment either, it's only there to buffer the data over the debugger connection. In my opinion it could be removed regardless.

@lygstate
Copy link
Contributor

lygstate commented Dec 7, 2021

jerry_port_print_string can be implement with jerry_port_print_char,
I've already have the work that implement jerry_port_print_string across exist platforms.
Maybe I can do the work first.

@lygstate
Copy link
Contributor

lygstate commented Nov 25, 2024

what's the difference betwen jerry_length_t and jerry_size_t? can we merge them into jerry_size_t?
I do not see any difference between these, and there is mixed usage of them
for example

The decl is jerry_size_t but the impl is jerry_length_t in the following two files

jerry-core\include\jerryscript-core.h

jerry_value_t jerry_typedarray_buffer (const jerry_value_t value, jerry_size_t *byte_offset, jerry_size_t *byte_length);

jerry-core\api\jerryscript.c

/**
 * Get the underlying ArrayBuffer from a TypedArray.
 *
 * Additionally the byteLength and byteOffset properties are also returned
 * which were specified when the TypedArray was created.
 *
 * Note:
 *     the returned value must be freed with a jerry_value_free call
 *
 * @return ArrayBuffer of a TypedArray
 *         TypeError if the object is not a TypedArray.
 */
jerry_value_t
jerry_typedarray_buffer (const jerry_value_t value, /**< TypedArray to get the arraybuffer from */
                         jerry_length_t *byte_offset, /**< [out] byteOffset property */
                         jerry_length_t *byte_length) /**< [out] byteLength property */
{
  jerry_assert_api_enabled ();

#if JERRY_BUILTIN_TYPEDARRAY
  if (!ecma_is_typedarray (value))
  {
    return jerry_throw_sz (JERRY_ERROR_TYPE, ecma_get_error_msg (ECMA_ERR_OBJECT_IS_NOT_A_TYPEDARRAY));
  }

  ecma_object_t *array_p = ecma_get_object_from_value (value);
  uint8_t shift = ecma_typedarray_get_element_size_shift (array_p);

  if (byte_length != NULL)
  {
    *byte_length = (jerry_length_t) (ecma_typedarray_get_length (array_p) << shift);
  }

  if (byte_offset != NULL)
  {
    *byte_offset = (jerry_length_t) ecma_typedarray_get_offset (array_p);
  }

  ecma_object_t *arraybuffer_p = ecma_typedarray_get_arraybuffer (array_p);
  ecma_ref_object (arraybuffer_p);
  return jerry_return (ecma_make_object_value (arraybuffer_p));
#else /* !JERRY_BUILTIN_TYPEDARRAY */
  JERRY_UNUSED (value);
  JERRY_UNUSED (byte_length);
  JERRY_UNUSED (byte_offset);
  return jerry_throw_sz (JERRY_ERROR_TYPE, ecma_get_error_msg (ECMA_ERR_TYPED_ARRAY_NOT_SUPPORTED));
#endif /* JERRY_BUILTIN_TYPEDARRAY */
} /* jerry_typedarray_buffer */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Related to the public API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants