src,doc: add SyntaxError napi support#40736
Conversation
Add `napi_create_syntax_error` and `napi_throw_syntax_error`. Fixes: nodejs/node-addon-api#1099
|
@nodejs/node-api |
NickNaso
left a comment
There was a problem hiding this comment.
The new apis should be considered experimental.
src/js_native_api.h
Outdated
| napi_value code, | ||
| napi_value msg, | ||
| napi_value* result); | ||
| NAPI_EXTERN napi_status napi_create_syntax_error(napi_env env, |
There was a problem hiding this comment.
This is a new api and it should be enabled / disabled throw NAPI_EXPERIMENTAL:
#ifdef NAPI_EXPERIMENTAL
NAPI_EXTERN
napi_status napi_create_syntax_error(napi_env env,
napi_value code,
napi_value msg,
napi_value* result);
#endif // NAPI_EXPERIMENTAL
src/js_native_api.h
Outdated
| NAPI_EXTERN napi_status napi_throw_range_error(napi_env env, | ||
| const char* code, | ||
| const char* msg); | ||
| NAPI_EXTERN napi_status napi_throw_syntax_error(napi_env env, |
There was a problem hiding this comment.
This is a new api and it should be enabled / disabled throw NAPI_EXPERIMENTAL:
#ifdef NAPI_EXPERIMENTAL
NAPI_EXTERN
napi_status napi_throw_syntax_error(napi_env env,
const char* code,
const char* msg,);
#endif // NAPI_EXPERIMENTALThere was a problem hiding this comment.
@NickNaso I see that adding this ifdef failed the tests on Mac (due to implicit declaration of function 'napi_throw_syntax_error' is invalid in C99 [-Werror,-Wimplicit-function-declaration]), tho not on the other platforms.
I assume it's either that the compiler is stricter on Mac (or defined to be stricter), or that the tests in this setup are not running with NAPI_EXPERIMENTAL.
What do you recommend to do?
There was a problem hiding this comment.
You should add this declaration:
#define NAPI_EXPERIMENTALto the head of file /test/js-native-api/test_error/test_error.c
There was a problem hiding this comment.
@NickNaso Thanks. It helped.
The failing action (test-asan / test-asan (pull_request)) seems flaky, I see:
[UNEXPECTED_FAILURE][FAIL] Entry 0 startTime is approximately correct (up to 20ms difference allowed)
assert_approx_equals: expected 4102.578573999926 +/- 20 but got 4077.9045040002093
at Test.<anonymous> (/home/runner/work/node/node/test/fixtures/wpt/user-timing/mark.any.js:61:8)
at Test.step (/home/runner/work/node/node/test/fixtures/wpt/resources/testharness.js:2087:25)
at test (/home/runner/work/node/node/test/fixtures/wpt/resources/testharness.js:557:30)
at test_mark (/home/runner/work/node/node/test/fixtures/wpt/user-timing/mark.any.js:59:4)
at /home/runner/work/node/node/test/fixtures/wpt/user-timing/mark.any.js:117:3
Command: /home/runner/work/node/node/out/Release/node /home/runner/work/node/node/test/wpt/test-user-timing.js mark.any.js
I don't have the permissions to re-run. can you please?
There was a problem hiding this comment.
@NickNaso yes, that is what we agreed to do for new functions use node_api instead of napi
It is what we said we'd do in https://nodejs.medium.com/renaming-n-api-to-node-api-27aa8ca30ed8
Please @idan-at could you please rename the functions you added like reported below?
- node_api_throw_syntax_error
- node_api_create_syntax_error
|
@gabrielschulhof @mhdawson should the new functions to be called |
|
@NickNaso yes, that is what we agreed to do for new functions use node_api instead of napi It is what we said we'd do in https://nodejs.medium.com/renaming-n-api-to-node-api-27aa8ca30ed8 |
|
@Trott I was asking about that lint-md action failure that just says Is there any way to see what needs to change, fix from the UI? I suspect we may run into failures with that job where people have made updates through the UI and then switching to the command line may not be easy for many people. |
|
@Trott since I think I messed up the first at mention. |
Signed-off-by: Michael Dawson <mdawson@devrus.com>
To see the changes, we'd need to output the diffs in node/tools/lint-md/lint-md.src.mjs Lines 43 to 47 in 94fa781 Once the diffs are shown, people can manually fix them in the UI, I suppose. |
Add `napi_create_syntax_error` and `napi_throw_syntax_error`. Fixes: nodejs/node-addon-api#1099 PR-URL: #40736 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
|
"Landed in 4265f27" |
Add `napi_create_syntax_error` and `napi_throw_syntax_error`. Fixes: nodejs/node-addon-api#1099 PR-URL: #40736 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
Add `napi_create_syntax_error` and `napi_throw_syntax_error`. Fixes: nodejs/node-addon-api#1099 PR-URL: #40736 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
Add `napi_create_syntax_error` and `napi_throw_syntax_error`. Fixes: nodejs/node-addon-api#1099 PR-URL: #40736 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
Add
napi_create_syntax_errorandnapi_throw_syntax_error.Fixes: nodejs/node-addon-api#1099