-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new apis should be considered experimental.
src/js_native_api.h
Outdated
@@ -111,6 +111,10 @@ NAPI_EXTERN napi_status napi_create_range_error(napi_env env, | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -370,6 +374,9 @@ NAPI_EXTERN napi_status napi_throw_type_error(napi_env env, | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_EXPERIMENTAL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, it's here: 6fafc06
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add this declaration:
#define NAPI_EXPERIMENTAL
to the head of file /test/js-native-api/test_error/test_error.c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of course - did it here a9cc563
@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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done @idan-at
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @idan-at
@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_error
andnapi_throw_syntax_error
.Fixes: nodejs/node-addon-api#1099