Rename resource_name to source_name (#4846)

JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo luoyonggang@gmail.com
This commit is contained in:
Yonggang Luo 2021-12-07 21:05:04 +08:00 committed by GitHub
parent 51da15516e
commit f8faf574b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 171 additions and 170 deletions

View File

@ -324,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 - `source_name` field is valid
- JERRY_SNAPSHOT_EXEC_HAS_SOURCE_NAME - `source_name` field is valid
in [jerry_exec_snapshot_option_values_t](#jerry_exec_snapshot_option_values_t)
- JERRY_SNAPSHOT_EXEC_HAS_USER_VALUE - `user_value` field is valid
in [jerry_exec_snapshot_option_values_t](#jerry_exec_snapshot_option_values_t)
@ -560,7 +560,7 @@ typedef struct
uint32_t options; /**< combination of jerry_parse_option_enable_feature_t values */
jerry_value_t argument_list; /**< function argument list if JERRY_PARSE_HAS_ARGUMENT_LIST is set in options
* Note: must be string value */
jerry_value_t source_name; /**< resource name string (usually a file name)
jerry_value_t source_name; /**< source name string (usually a file name)
* if JERRY_PARSE_HAS_SOURCE_NAME is set in options
* Note: must be string value */
uint32_t start_line; /**< start line of the source code if JERRY_PARSE_HAS_START is set in options */
@ -626,7 +626,7 @@ Source code location data retrieved by
```c
typedef struct
{
jerry_value_t source_name; /**< resource name */
jerry_value_t source_name; /**< source name */
jerry_size_t line; /**< line index */
jerry_size_t column; /**< column index */
} jerry_frame_location_t;
@ -1398,8 +1398,8 @@ Various configuration options for [jerry_exec_snapshot](#jerry_exec_snapshot)
```c
typedef struct
{
jerry_value_t source_name; /**< resource name string (usually a file name)
* if JERRY_SNAPSHOT_EXEC_HAS_RESOURCE is set in exec_snapshot_opts
jerry_value_t source_name; /**< source name string (usually a file name)
* if JERRY_SNAPSHOT_EXEC_HAS_SOURCE_NAME is set in exec_snapshot_opts
* Note: non-string values are ignored */
jerry_value_t user_value; /**< user value assigned to all functions created by this script including
* eval calls executed by the script if JERRY_SNAPSHOT_EXEC_HAS_USER_VALUE
@ -11575,7 +11575,7 @@ main (void)
**Summary**
Get the resource name (usually a file name) of the currently executed script or the given function object.
Get the source name (usually a file name) of the currently executed script or the given function object.
This function is typically called from native callbacks.
@ -11592,17 +11592,17 @@ is no longer needed.
jerry_value_t
jerry_source_name (jerry_value_t value);
```
- `value` - api value to obtain the resource name from
- `value` - api value to obtain the source name from
- return string value constructed from
- the currently executed function object's resource name, if the given value is undefined
- resource name of the function object, if the given value is a function object
- the currently executed function object's source name, if the given value is undefined
- source name of the function object, if the given value is a function object
- "<anonymous>", otherwise
*New in version 2.2*.
**Example**
[doctest]: # (name="02.API-REFERENCE-jsresourcename.c")
[doctest]: # (name="02.API-REFERENCE-jssourcename.c")
```c
#include <stdio.h>
@ -11628,10 +11628,10 @@ main (void)
jerry_value_t global = jerry_current_realm ();
/* Register the "resourceName" method. */
/* Register the sourceName" method. */
{
jerry_value_t func = jerry_function_external (source_name_handler);
jerry_value_t name = jerry_string_sz ("resourceName");
jerry_value_t name = jerry_string_sz ("sourceName");
jerry_value_t result = jerry_object_set (global, name, func);
jerry_value_free (result);
jerry_value_free (name);
@ -11640,7 +11640,7 @@ main (void)
jerry_value_free (global);
const jerry_char_t source[] = "function myFunction() { return resourceName() }; myFunction()";
const jerry_char_t source[] = "function myFunction() { return sourceName() }; myFunction()";
jerry_parse_options_t parse_options;
parse_options.options = JERRY_PARSE_HAS_SOURCE_NAME;

View File

@ -74,8 +74,8 @@ Currently, `jerryx_debugger_rp_create ()` for raw packet transport layer and
`jerryx_debugger_serial_create (const char* config)` for serial protocol
are also available.)
The resource name provided to `jerry_parse ()` is used by the client
to identify the resource name of the source code. This resource name
The source name provided to `jerry_parse ()` is used by the client
to identify the source name of the source code. This source name
is usually a file name.
## JerryScript debugger C-API interface
@ -103,8 +103,8 @@ typedef jerry_value_t
size_t source_size, void *user_p);
```
- `source_name_p` - resource (usually a file) name of the source code
- `source_name_size` - size of resource name
- `source_name_p` - source (usually a file) name of the source code
- `source_name_size` - size of source name
- `source_p` - source code character data
- `source_size` - size of source code
- `user_p` - custom pointer passed to [jerry_debugger_wait_for_client_source](#jerry_debugger_wait_for_client_source)
@ -306,8 +306,8 @@ jerry_debugger_wait_for_client_source (jerry_debugger_wait_for_source_callback_t
* Runs the source code received by jerry_debugger_wait_for_client_source.
*/
static jerry_value_t
wait_for_source_callback (const jerry_char_t *source_name_p, /**< resource name */
size_t source_name_size, /**< size of resource name */
wait_for_source_callback (const jerry_char_t *source_name_p, /**< source name */
size_t source_name_size, /**< size of source name */
const jerry_char_t *source_p, /**< source code */
size_t source_size, /**< source code size */
void *user_p /**< user pointer */)

View File

@ -643,10 +643,10 @@ snapshot_load_compiled_code (const uint8_t *base_addr_p, /**< base address of th
}
#endif /* JERRY_ESNEXT */
#if JERRY_RESOURCE_NAME
/* resource name */
#if JERRY_SOURCE_NAME
/* source name */
extra_bytes += (uint32_t) sizeof (ecma_value_t);
#endif /* JERRY_RESOURCE_NAME */
#endif /* JERRY_SOURCE_NAME */
new_code_size = JERRY_ALIGNUP (new_code_size + extra_bytes, JMEM_ALIGNMENT);
@ -880,7 +880,7 @@ jerry_exec_snapshot (const uint32_t *snapshot_p, /**< snapshot */
uint32_t allowed_opts =
(JERRY_SNAPSHOT_EXEC_COPY_DATA | JERRY_SNAPSHOT_EXEC_ALLOW_STATIC | JERRY_SNAPSHOT_EXEC_LOAD_AS_FUNCTION
| JERRY_SNAPSHOT_EXEC_HAS_RESOURCE | JERRY_SNAPSHOT_EXEC_HAS_USER_VALUE);
| JERRY_SNAPSHOT_EXEC_HAS_SOURCE_NAME | JERRY_SNAPSHOT_EXEC_HAS_USER_VALUE);
if ((exec_snapshot_opts & ~(allowed_opts)) != 0)
{
@ -955,10 +955,10 @@ jerry_exec_snapshot (const uint32_t *snapshot_p, /**< snapshot */
script_p->realm_p = (ecma_object_t *) JERRY_CONTEXT (global_object_p);
#endif /* JERRY_BUILTIN_REALMS */
#if JERRY_RESOURCE_NAME
ecma_value_t source_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
#if JERRY_SOURCE_NAME
ecma_value_t source_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_SOURCE_NAME_ANON);
if ((exec_snapshot_opts & JERRY_SNAPSHOT_EXEC_HAS_RESOURCE) && option_values_p != NULL
if ((exec_snapshot_opts & JERRY_SNAPSHOT_EXEC_HAS_SOURCE_NAME) && option_values_p != NULL
&& ecma_is_value_string (option_values_p->source_name) > 0)
{
ecma_ref_ecma_string (ecma_get_string_from_value (option_values_p->source_name));
@ -966,7 +966,7 @@ jerry_exec_snapshot (const uint32_t *snapshot_p, /**< snapshot */
}
script_p->source_name = source_name;
#endif /* JERRY_RESOURCE_NAME */
#endif /* JERRY_SOURCE_NAME */
#if JERRY_FUNCTION_TO_STRING
script_p->source_code = ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY);

View File

@ -5364,19 +5364,19 @@ jerry_frame_is_strict (jerry_frame_t *frame_p) /**< frame pointer */
} /* jerry_frame_is_strict */
/**
* Get the resource name (usually a file name) of the currently executed script or the given function object
* Get the source name (usually a file name) of the currently executed script or the given function object
*
* Note: returned value must be freed with jerry_value_free, when it is no longer needed
*
* @return JS string constructed from
* - the currently executed function object's resource name, if the given value is undefined
* - resource name of the function object, if the given value is a function object
* - the currently executed function object's source name, if the given value is undefined
* - source name of the function object, if the given value is a function object
* - "<anonymous>", otherwise
*/
jerry_value_t
jerry_source_name (const jerry_value_t value) /**< jerry api value */
{
#if JERRY_RESOURCE_NAME
#if JERRY_SOURCE_NAME
if (ecma_is_value_undefined (value) && JERRY_CONTEXT (vm_top_context_p) != NULL)
{
return ecma_copy_value (ecma_get_source_name (JERRY_CONTEXT (vm_top_context_p)->shared_p->bytecode_header_p));
@ -5386,16 +5386,16 @@ jerry_source_name (const jerry_value_t value) /**< jerry api value */
if (script_value == JMEM_CP_NULL)
{
return ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
return ecma_make_magic_string_value (LIT_MAGIC_STRING_SOURCE_NAME_ANON);
}
const cbc_script_t *script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value);
return ecma_copy_value (script_p->source_name);
#else /* !JERRY_RESOURCE_NAME */
#else /* !JERRY_SOURCE_NAME */
JERRY_UNUSED (value);
return ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
#endif /* JERRY_RESOURCE_NAME */
return ecma_make_magic_string_value (LIT_MAGIC_STRING_SOURCE_NAME_ANON);
#endif /* JERRY_SOURCE_NAME */
} /* jerry_source_name */
/**

View File

@ -716,12 +716,12 @@
#endif /* JERRY_PROMISE_CALLBACK && !JERRY_ESNEXT */
/**
* Resource name related types into a single guard
* Source name related types into a single guard
*/
#if JERRY_LINE_INFO || JERRY_ERROR_MESSAGES || JERRY_MODULE_SYSTEM
#define JERRY_RESOURCE_NAME 1
#define JERRY_SOURCE_NAME 1
#else /* !(JERRY_LINE_INFO || JERRY_ERROR_MESSAGES || JERRY_MODULE_SYSTEM) */
#define JERRY_RESOURCE_NAME 0
#define JERRY_SOURCE_NAME 0
#endif /* JERRY_LINE_INFO || JERRY_ERROR_MESSAGES || JERRY_MODULE_SYSTEM */
#endif /* !JERRYSCRIPT_CONFIG_H */

View File

@ -1433,9 +1433,9 @@ ecma_script_deref (ecma_value_t script_value) /**< script value */
}
}
#if JERRY_RESOURCE_NAME
#if JERRY_SOURCE_NAME
ecma_deref_ecma_string (ecma_get_string_from_value (script_p->source_name));
#endif /* JERRY_RESOURCE_NAME */
#endif /* JERRY_SOURCE_NAME */
#if JERRY_MODULE_SYSTEM
if (type & CBC_SCRIPT_HAS_IMPORT_META)
@ -1773,27 +1773,27 @@ ecma_compiled_code_get_line_info (const ecma_compiled_code_t *bytecode_header_p)
#endif /* JERRY_LINE_INFO */
/**
* Get the resource name of a compiled code.
* Get the source name of a compiled code.
*
* @return resource name value
* @return source name value
*/
ecma_value_t
ecma_get_source_name (const ecma_compiled_code_t *bytecode_p) /**< compiled code */
{
#if JERRY_RESOURCE_NAME
#if JERRY_SOURCE_NAME
#if JERRY_SNAPSHOT_EXEC
if (JERRY_UNLIKELY (bytecode_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION))
{
return ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
return ecma_make_magic_string_value (LIT_MAGIC_STRING_SOURCE_NAME_ANON);
}
#endif /* JERRY_SNAPSHOT_EXEC */
ecma_value_t script_value = ((cbc_uint8_arguments_t *) bytecode_p)->script_value;
return ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value)->source_name;
#else /* !JERRY_RESOURCE_NAME */
#else /* !JERRY_SOURCE_NAME */
JERRY_UNUSED (bytecode_p);
return ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
#endif /* !JERRY_RESOURCE_NAME */
return ecma_make_magic_string_value (LIT_MAGIC_STRING_SOURCE_NAME_ANON);
#endif /* !JERRY_SOURCE_NAME */
} /* ecma_get_source_name */
#if (JERRY_STACK_LIMIT != 0)

View File

@ -47,7 +47,7 @@
*
* See also: ECMAScript v6, 9.2.1.1
*
* @return resource name as ecma-string
* @return source name as ecma-string
*/
ecma_value_t
ecma_op_function_form_name (ecma_string_t *prop_name_p, /**< property name */

View File

@ -43,7 +43,7 @@ typedef enum
/**
* Callback for jerry_debugger_wait_and_run_client_source
*
* The callback receives the resource name, source code and a user pointer.
* The callback receives the source name, source code and a user pointer.
*
* @return this value is passed back by jerry_debugger_wait_and_run_client_source
*/

View File

@ -45,8 +45,8 @@ typedef enum
JERRY_SNAPSHOT_EXEC_COPY_DATA = (1u << 0), /**< copy snashot data */
JERRY_SNAPSHOT_EXEC_ALLOW_STATIC = (1u << 1), /**< static snapshots allowed */
JERRY_SNAPSHOT_EXEC_LOAD_AS_FUNCTION = (1u << 2), /**< load snapshot as function instead of executing it */
JERRY_SNAPSHOT_EXEC_HAS_RESOURCE = (1u << 3), /**< source_name field is valid
* in jerry_exec_snapshot_option_values_t */
JERRY_SNAPSHOT_EXEC_HAS_SOURCE_NAME = (1u << 3), /**< source_name field is valid
* in jerry_exec_snapshot_option_values_t */
JERRY_SNAPSHOT_EXEC_HAS_USER_VALUE = (1u << 4), /**< user_value field is valid
* in jerry_exec_snapshot_option_values_t */
} jerry_exec_snapshot_opts_t;
@ -56,8 +56,8 @@ typedef enum
*/
typedef struct
{
jerry_value_t source_name; /**< resource name string (usually a file name)
* if JERRY_SNAPSHOT_EXEC_HAS_RESOURCE is set in exec_snapshot_opts
jerry_value_t source_name; /**< source name string (usually a file name)
* if JERRY_SNAPSHOT_EXEC_HAS_SOURCE_NAME is set in exec_snapshot_opts
* Note: non-string values are ignored */
jerry_value_t user_value; /**< user value assigned to all functions created by this script including
* eval calls executed by the script if JERRY_SNAPSHOT_EXEC_HAS_USER_VALUE

View File

@ -441,7 +441,7 @@ typedef enum
*/
typedef struct
{
jerry_value_t source_name; /**< resource name */
jerry_value_t source_name; /**< source name */
jerry_size_t line; /**< line index */
jerry_size_t column; /**< column index */
} jerry_frame_location_t;

View File

@ -340,9 +340,9 @@ LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_THROW, "throw")
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TRUNC, "trunc")
#endif /* JERRY_BUILTIN_MATH && JERRY_ESNEXT */
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_VALUE, "value")
#if JERRY_PARSER && JERRY_RESOURCE_NAME
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_RESOURCE_EVAL, "<eval>")
#endif /* JERRY_PARSER && JERRY_RESOURCE_NAME */
#if JERRY_PARSER && JERRY_SOURCE_NAME
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SOURCE_NAME_EVAL, "<eval>")
#endif /* JERRY_PARSER && JERRY_SOURCE_NAME */
#if JERRY_BUILTIN_BIGINT
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_BIGINT_UL, "BigInt")
#endif /* JERRY_BUILTIN_BIGINT */
@ -807,7 +807,7 @@ LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_UTC_DATE_UL, "setUTCDate")
#if JERRY_BUILTIN_STRING && JERRY_ESNEXT
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_STARTS_WITH, "startsWith")
#endif /* JERRY_BUILTIN_STRING && JERRY_ESNEXT */
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_RESOURCE_ANON, "<anonymous>")
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SOURCE_NAME_ANON, "<anonymous>")
#if JERRY_BUILTIN_TYPEDARRAY
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ARRAY_BUFFER_UL, "ArrayBuffer")
#endif /* JERRY_BUILTIN_TYPEDARRAY */
@ -1127,8 +1127,8 @@ LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (4, LIT_MAGIC_STRING_LN10_U)
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (4, LIT_MAGIC_STRING_NULL_UL)
#endif /* JERRY_BUILTIN_MATH */
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (5, LIT_MAGIC_STRING_ARRAY_UL)
#if JERRY_PARSER && JERRY_RESOURCE_NAME
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (6, LIT_MAGIC_STRING_RESOURCE_EVAL)
#if JERRY_PARSER && JERRY_SOURCE_NAME
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (6, LIT_MAGIC_STRING_SOURCE_NAME_EVAL)
#elif JERRY_BUILTIN_BIGINT
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (6, LIT_MAGIC_STRING_BIGINT_UL)
#elif JERRY_BUILTIN_MATH
@ -1170,7 +1170,7 @@ LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (10, LIT_MAGIC_STRING_COPY_WITHIN)
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (10, LIT_MAGIC_STRING_ENUMERABLE)
#endif /* JERRY_BUILTIN_TYPEDARRAY \
|| JERRY_ESNEXT */
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (11, LIT_MAGIC_STRING_RESOURCE_ANON)
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (11, LIT_MAGIC_STRING_SOURCE_NAME_ANON)
#if JERRY_BUILTIN_TYPEDARRAY
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (12, LIT_MAGIC_STRING_FLOAT32_ARRAY_UL)
#elif JERRY_BUILTIN_TYPEDARRAY && JERRY_NUMBER_TYPE_FLOAT64

View File

@ -143,7 +143,7 @@ LIT_MAGIC_STRING_ATOMICS_STORE = "store"
LIT_MAGIC_STRING_THROW = "throw"
LIT_MAGIC_STRING_TRUNC = "trunc"
LIT_MAGIC_STRING_VALUE = "value"
LIT_MAGIC_STRING_RESOURCE_EVAL = "<eval>"
LIT_MAGIC_STRING_SOURCE_NAME_EVAL = "<eval>"
LIT_MAGIC_STRING_BIGINT_UL = "BigInt"
LIT_MAGIC_STRING_ERRORS_UL = "errors"
LIT_MAGIC_STRING_LOG10E_U = "LOG10E"
@ -323,7 +323,7 @@ LIT_MAGIC_STRING_SET_MINUTES_UL = "setMinutes"
LIT_MAGIC_STRING_SET_SECONDS_UL = "setSeconds"
LIT_MAGIC_STRING_SET_UTC_DATE_UL = "setUTCDate"
LIT_MAGIC_STRING_STARTS_WITH = "startsWith"
LIT_MAGIC_STRING_RESOURCE_ANON = "<anonymous>"
LIT_MAGIC_STRING_SOURCE_NAME_ANON = "<anonymous>"
LIT_MAGIC_STRING_ARRAY_BUFFER_UL = "ArrayBuffer"
LIT_MAGIC_STRING_DESCRIPTION = "description"
LIT_MAGIC_STRING_SYNTAX_ERROR_UL = "SyntaxError"

View File

@ -981,9 +981,9 @@ typedef struct
ecma_object_t *realm_p; /**< realm object */
#endif /* JERRY_BUILTIN_REALMS */
uint32_t refs_and_type; /**< reference counter and type of the function */
#if JERRY_RESOURCE_NAME
ecma_value_t source_name; /**< resource name */
#endif /* JERRY_RESOURCE_NAME */
#if JERRY_SOURCE_NAME
ecma_value_t source_name; /**< source name */
#endif /* JERRY_SOURCE_NAME */
#if JERRY_FUNCTION_TO_STRING
ecma_value_t source_code; /**< source code */
#endif /* JERRY_FUNCTION_TO_STRING */

View File

@ -2108,8 +2108,8 @@ parser_parse_source (void *source_p, /**< source code */
context.user_value = context.options_p->user_value;
}
#if JERRY_RESOURCE_NAME
ecma_value_t source_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
#if JERRY_SOURCE_NAME
ecma_value_t source_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_SOURCE_NAME_ANON);
if (context.options_p != NULL && (context.options_p->options & JERRY_PARSE_HAS_SOURCE_NAME))
{
@ -2120,9 +2120,9 @@ parser_parse_source (void *source_p, /**< source code */
}
else if (context.global_status_flags & ECMA_PARSE_EVAL)
{
source_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_EVAL);
source_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_SOURCE_NAME_EVAL);
}
#endif /* JERRY_RESOURCE_NAME */
#endif /* JERRY_SOURCE_NAME */
context.last_context_p = NULL;
context.last_statement.current_p = NULL;
@ -2262,9 +2262,9 @@ parser_parse_source (void *source_p, /**< source code */
context.script_p->realm_p = (ecma_object_t *) JERRY_CONTEXT (global_object_p);
#endif /* JERRY_BUILTIN_REALMS */
#if JERRY_RESOURCE_NAME
#if JERRY_SOURCE_NAME
context.script_p->source_name = source_name;
#endif /* JERRY_RESOURCE_NAME */
#endif /* JERRY_SOURCE_NAME */
ECMA_SET_INTERNAL_VALUE_POINTER (context.script_value, context.script_p);
@ -2430,9 +2430,9 @@ parser_parse_source (void *source_p, /**< source code */
parser_free_literals (&context.literal_pool);
parser_cbc_stream_free (&context.byte_code);
#if JERRY_RESOURCE_NAME
#if JERRY_SOURCE_NAME
ecma_deref_ecma_string (ecma_get_string_from_value (context.script_p->source_name));
#endif /* JERRY_RESOURCE_NAME */
#endif /* JERRY_SOURCE_NAME */
if (context.script_p != NULL)
{

View File

@ -49,7 +49,7 @@ set(SOURCE_EXT
handler/handler-gc.c
handler/handler-print.c
handler/handler-register.c
handler/handler-resource-name.c
handler/handler-source-name.c
module/module.c
)

View File

@ -16,13 +16,13 @@
#include "jerryscript-ext/handler.h"
/**
* Get the resource name (usually a file name) of the currently executed script or the given function object
* Get the source name (usually a file name) of the currently executed script or the given function object
*
* Note: returned value must be freed with jerry_value_free, when it is no longer needed
*
* @return JS string constructed from
* - the currently executed function object's resource name, if the given value is undefined
* - resource name of the function object, if the given value is a function object
* - the currently executed function object's source name, if the given value is undefined
* - source name of the function object, if the given value is a function object
* - "<anonymous>", otherwise
*/
jerry_value_t

View File

@ -290,7 +290,7 @@ main_init_engine (main_args_t *arguments_p) /**< main arguments */
main_register_global_function ("assert", jerryx_handler_assert);
main_register_global_function ("gc", jerryx_handler_gc);
main_register_global_function ("print", jerryx_handler_print);
main_register_global_function ("resourceName", jerryx_handler_source_name);
main_register_global_function ("sourceName", jerryx_handler_source_name);
main_register_global_function ("createRealm", main_create_realm);
} /* main_init_engine */
@ -449,8 +449,8 @@ main_print_unhandled_exception (jerry_value_t error_value) /**< error value */
* @return result fo the source code execution
*/
jerry_value_t
main_wait_for_source_callback (const jerry_char_t *source_name_p, /**< resource name */
size_t source_name_size, /**< size of resource name */
main_wait_for_source_callback (const jerry_char_t *source_name_p, /**< source name */
size_t source_name_size, /**< size of source name */
const jerry_char_t *source_p, /**< source code */
size_t source_size, /**< source code size */
void *user_p) /**< user pointer */

View File

@ -4,29 +4,29 @@ Stopped at tests/debugger/do_variables.js:15
level | type
0 | global
(jerry-debugger) variables
name | type | value
f | Function |
addX | Function |
z | undefined | undefined
c | undefined | undefined
createRealm | Function |
resourceName | Function |
print | Function |
gc | Function |
assert | Function |
name | type | value
f | Function |
addX | Function |
z | undefined | undefined
c | undefined | undefined
createRealm | Function |
sourceName | Function |
print | Function |
gc | Function |
assert | Function |
(jerry-debugger) variables 1
name | type | value
(jerry-debugger) variables 0
name | type | value
f | Function |
addX | Function |
z | undefined | undefined
c | undefined | undefined
createRealm | Function |
resourceName | Function |
print | Function |
gc | Function |
assert | Function |
name | type | value
f | Function |
addX | Function |
z | undefined | undefined
c | undefined | undefined
createRealm | Function |
sourceName | Function |
print | Function |
gc | Function |
assert | Function |
(jerry-debugger) b tests/debugger/do_variables.js:20
Breakpoint 1 at tests/debugger/do_variables.js:20 (in function() at line:19, col:10)
(jerry-debugger) c
@ -44,17 +44,17 @@ n | Number | 9
name | type | value
x | Number | 3
(jerry-debugger) variables 2
name | type | value
addThree | Function |
f | Function |
addX | Function |
z | Number | 5
c | Number | 4
createRealm | Function |
resourceName | Function |
print | Function |
gc | Function |
assert | Function |
name | type | value
addThree | Function |
f | Function |
addX | Function |
z | Number | 5
c | Number | 4
createRealm | Function |
sourceName | Function |
print | Function |
gc | Function |
assert | Function |
(jerry-debugger) b tests/debugger/do_variables.js:30
Breakpoint 2 at tests/debugger/do_variables.js:30 (in f() at line:28, col:1)
(jerry-debugger) c
@ -64,18 +64,18 @@ level | type
0 | local
1 | global
(jerry-debugger) variables 1
name | type | value
d | Number | 12
addThree | Function |
f | Function |
addX | Function |
z | Number | 5
c | Number | 4
createRealm | Function |
resourceName | Function |
print | Function |
gc | Function |
assert | Function |
name | type | value
d | Number | 12
addThree | Function |
f | Function |
addX | Function |
z | Number | 5
c | Number | 4
createRealm | Function |
sourceName | Function |
print | Function |
gc | Function |
assert | Function |
(jerry-debugger) variables 0
name | type | value
b | undefined | undefined

View File

@ -13,11 +13,11 @@
// limitations under the License.
export function getName() {
return resourceName();
return sourceName();
}
export function getNamePromise(collector) {
return new Promise((resolve) => { collector["start"] = resourceName(); resolve(); })
.then(() => { collector["middle"] = resourceName(); });
return new Promise((resolve) => { collector["start"] = sourceName(); resolve(); })
.then(() => { collector["middle"] = sourceName(); });
}

View File

@ -12,16 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { getName, getNamePromise } from "./module-resource-name-export.mjs"
import { getName, getNamePromise } from "./module-source-name-export.mjs"
assert(getName().endsWith("module-resource-name-export.mjs"));
assert(getName().endsWith("module-source-name-export.mjs"));
var collector = {};
getNamePromise(collector).then(() => { collector["end"] = resourceName(); });
getNamePromise(collector).then(() => { collector["end"] = sourceName(); });
function __checkAsync() {
assert(collector["start"].endsWith("module-resource-name-export.mjs"));
assert(collector["middle"].endsWith("module-resource-name-export.mjs"));
assert(collector["end"].endsWith("module-resource-name.mjs"));
assert(collector["start"].endsWith("module-source-name-export.mjs"));
assert(collector["middle"].endsWith("module-source-name-export.mjs"));
assert(collector["end"].endsWith("module-source-name.mjs"));
assert(Object.keys(collector).length === 3);
}

View File

@ -51,4 +51,4 @@ try {
/* Check properties of a */
assert(Object.keys(a) == "one,two");
/* Check properties of global object */
assert(Object.keys(this) == "assert,gc,print,resourceName,createRealm,a,fail,fail_two");
assert(Object.keys(this) == "assert,gc,print,sourceName,createRealm,a,fail,fail_two");

View File

@ -79,7 +79,7 @@ set(SOURCE_UNIT_TEST_MAIN_MODULES
test-error-callback.c
test-regexp.c
test-regression-3588.c
test-resource-name.c
test-source-name.c
test-script-user-value.c
test-snapshot.c
test-source-info.c

View File

@ -251,7 +251,7 @@ register_callback (jerry_external_handler_t handler_p, /**< callback function */
} /* register_callback */
static jerry_value_t
run (const char *source_name_p, /**< resource name */
run (const char *source_name_p, /**< source name */
const char *source_p) /**< source code */
{
jerry_parse_options_t parse_options;

View File

@ -47,10 +47,10 @@ main (void)
jerry_value_t global = jerry_current_realm ();
/* Register the "resourceName" method. */
/* Register the "sourceName" method. */
{
jerry_value_t func = jerry_function_external (source_name_handler);
jerry_value_t name = jerry_string_sz ("resourceName");
jerry_value_t name = jerry_string_sz ("sourceName");
jerry_value_t result = jerry_object_set (global, name, func);
jerry_value_free (result);
jerry_value_free (name);
@ -63,9 +63,9 @@ main (void)
parse_options.options = JERRY_PARSE_HAS_SOURCE_NAME;
const char *source_1 = ("function f1 () {\n"
" if (resourceName() !== 'demo1.js') return false; \n"
" if (resourceName(f1) !== 'demo1.js') return false; \n"
" if (resourceName(5) !== '<anonymous>') return false; \n"
" if (sourceName() !== 'demo1.js') return false; \n"
" if (sourceName(f1) !== 'demo1.js') return false; \n"
" if (sourceName(5) !== '<anonymous>') return false; \n"
" return f1; \n"
"} \n"
"f1();");
@ -79,23 +79,24 @@ main (void)
TEST_ASSERT (!jerry_value_is_exception (run_result));
TEST_ASSERT (jerry_value_is_object (run_result));
jerry_value_t resource_value = jerry_source_name (run_result);
jerry_value_t compare_result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.source_name);
jerry_value_t source_name_value = jerry_source_name (run_result);
jerry_value_t compare_result =
jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, source_name_value, parse_options.source_name);
TEST_ASSERT (jerry_value_is_true (compare_result));
jerry_value_free (compare_result);
jerry_value_free (resource_value);
jerry_value_free (source_name_value);
jerry_value_free (parse_options.source_name);
jerry_value_free (run_result);
jerry_value_free (program);
const char *source_2 = ("function f2 () { \n"
" if (resourceName() !== 'demo2.js') return false; \n"
" if (resourceName(f2) !== 'demo2.js') return false; \n"
" if (resourceName(f1) !== 'demo1.js') return false; \n"
" if (resourceName(Object.prototype) !== '<anonymous>') return false; \n"
" if (resourceName(Function) !== '<anonymous>') return false; \n"
" if (sourceName() !== 'demo2.js') return false; \n"
" if (sourceName(f2) !== 'demo2.js') return false; \n"
" if (sourceName(f1) !== 'demo1.js') return false; \n"
" if (sourceName(Object.prototype) !== '<anonymous>') return false; \n"
" if (sourceName(Function) !== '<anonymous>') return false; \n"
" return f2; \n"
"} \n"
"f2(); \n");
@ -109,12 +110,12 @@ main (void)
TEST_ASSERT (!jerry_value_is_exception (run_result));
TEST_ASSERT (jerry_value_is_object (run_result));
resource_value = jerry_source_name (run_result);
compare_result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.source_name);
source_name_value = jerry_source_name (run_result);
compare_result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, source_name_value, parse_options.source_name);
TEST_ASSERT (jerry_value_is_true (compare_result));
jerry_value_free (compare_result);
jerry_value_free (resource_value);
jerry_value_free (source_name_value);
jerry_value_free (parse_options.source_name);
jerry_value_free (run_result);
@ -130,33 +131,33 @@ main (void)
program = jerry_parse ((const jerry_char_t *) source_3, strlen (source_3), &parse_options);
TEST_ASSERT (!jerry_value_is_exception (program));
resource_value = jerry_source_name (program);
compare_result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.source_name);
source_name_value = jerry_source_name (program);
compare_result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, source_name_value, parse_options.source_name);
TEST_ASSERT (jerry_value_is_true (compare_result));
jerry_value_free (compare_result);
jerry_value_free (resource_value);
jerry_value_free (source_name_value);
run_result = jerry_module_link (program, NULL, NULL);
TEST_ASSERT (!jerry_value_is_exception (run_result));
resource_value = jerry_source_name (run_result);
compare_result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, resource_value, anon);
source_name_value = jerry_source_name (run_result);
compare_result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, source_name_value, anon);
TEST_ASSERT (jerry_value_is_true (compare_result));
jerry_value_free (compare_result);
jerry_value_free (resource_value);
jerry_value_free (source_name_value);
jerry_value_free (run_result);
run_result = jerry_module_evaluate (program);
TEST_ASSERT (!jerry_value_is_exception (run_result));
resource_value = jerry_source_name (run_result);
compare_result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, resource_value, anon);
source_name_value = jerry_source_name (run_result);
compare_result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, source_name_value, anon);
TEST_ASSERT (jerry_value_is_true (compare_result));
jerry_value_free (compare_result);
jerry_value_free (resource_value);
jerry_value_free (source_name_value);
jerry_value_free (run_result);
jerry_value_free (program);
jerry_value_free (parse_options.source_name);
@ -174,12 +175,12 @@ main (void)
TEST_ASSERT (!jerry_value_is_exception (run_result));
TEST_ASSERT (jerry_value_is_object (run_result));
resource_value = jerry_source_name (run_result);
compare_result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.source_name);
source_name_value = jerry_source_name (run_result);
compare_result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, source_name_value, parse_options.source_name);
TEST_ASSERT (jerry_value_is_true (compare_result));
jerry_value_free (compare_result);
jerry_value_free (resource_value);
jerry_value_free (source_name_value);
jerry_value_free (parse_options.source_name);
jerry_value_free (run_result);
jerry_value_free (program);
@ -193,11 +194,11 @@ main (void)
program = jerry_parse ((const jerry_char_t *) source_5, strlen (source_5), &parse_options);
TEST_ASSERT (!jerry_value_is_exception (program));
resource_value = jerry_source_name (program);
compare_result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.source_name);
source_name_value = jerry_source_name (program);
compare_result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, source_name_value, parse_options.source_name);
TEST_ASSERT (jerry_value_is_true (compare_result));
jerry_value_free (resource_value);
jerry_value_free (source_name_value);
jerry_value_free (compare_result);
jerry_value_free (parse_options.user_value);
jerry_value_free (parse_options.source_name);
@ -211,11 +212,11 @@ main (void)
program = jerry_parse ((const jerry_char_t *) source_6, strlen (source_6), &parse_options);
if (!jerry_value_is_exception (program))
{
resource_value = jerry_source_name (program);
compare_result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.source_name);
source_name_value = jerry_source_name (program);
compare_result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, source_name_value, parse_options.source_name);
TEST_ASSERT (jerry_value_is_true (compare_result));
jerry_value_free (resource_value);
jerry_value_free (source_name_value);
jerry_value_free (compare_result);
}