mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Throw SyntaxError when module resolving is failed (#4765)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
parent
fea10bb7e3
commit
2c2539c6b8
@ -278,12 +278,12 @@ ecma_module_resolve_throw (ecma_module_resolve_result_t *resolve_result_p, /**<
|
||||
}
|
||||
}
|
||||
|
||||
return ecma_raise_standard_error_with_format (JERRY_ERROR_REFERENCE, msg_p, name_val);
|
||||
return ecma_raise_standard_error_with_format (JERRY_ERROR_SYNTAX, msg_p, name_val);
|
||||
#else /* JERRY_ERROR_MESSAGES */
|
||||
JERRY_UNUSED (resolve_result_p);
|
||||
JERRY_UNUSED (name_p);
|
||||
|
||||
return ecma_raise_reference_error (NULL);
|
||||
return ecma_raise_syntax_error (NULL);
|
||||
#endif /* !JERRY_ERROR_MESSAGES */
|
||||
} /* ecma_module_resolve_throw */
|
||||
|
||||
|
||||
@ -265,6 +265,19 @@ module_state_changed (jerry_module_state_t new_state, /**< new state of the modu
|
||||
}
|
||||
} /* module_state_changed */
|
||||
|
||||
static jerry_value_t
|
||||
resolve_callback5 (const jerry_value_t specifier, /**< module specifier */
|
||||
const jerry_value_t referrer, /**< parent module */
|
||||
void *user_p) /**< user data */
|
||||
{
|
||||
(void) specifier;
|
||||
(void) user_p;
|
||||
|
||||
/* This circular reference is valid. However, import resolving triggers
|
||||
* a SyntaxError, because the module does not export a default binding. */
|
||||
return referrer;
|
||||
} /* resolve_callback5 */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
@ -549,6 +562,16 @@ main (void)
|
||||
|
||||
TEST_ASSERT (counter == 4);
|
||||
|
||||
jerry_char_t source6[] = TEST_STRING_LITERAL (
|
||||
"import a from 'self'\n"
|
||||
);
|
||||
module = jerry_parse (source6, sizeof (source6) - 1, &module_parse_options);
|
||||
|
||||
result = jerry_module_link (module, resolve_callback5, NULL);
|
||||
TEST_ASSERT (jerry_value_is_error (result)
|
||||
&& jerry_get_error_type (result) == JERRY_ERROR_SYNTAX);
|
||||
jerry_release_value (result);
|
||||
|
||||
jerry_cleanup ();
|
||||
|
||||
return 0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user