-
Notifications
You must be signed in to change notification settings - Fork 465
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: add SyntaxError #1326
Merged
Merged
src: add SyntaxError #1326
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# SyntaxError | ||
|
||
The `Napi::SyntaxError` class is a representation of the JavaScript | ||
`SyntaxError` that is thrown when the engine encounters tokens or token order | ||
that does not conform to the syntax of the language when parsing code. | ||
|
||
The `Napi::SyntaxError` class inherits its behaviors from the `Napi::Error` | ||
class (for more info see: [`Napi::Error`](error.md)). | ||
|
||
For more details about error handling refer to the section titled [Error | ||
handling](error_handling.md). | ||
|
||
## Methods | ||
|
||
### New | ||
|
||
Creates a new instance of a `Napi::SyntaxError` object. | ||
|
||
```cpp | ||
Napi::SyntaxError::New(Napi::Env env, const char* message); | ||
``` | ||
|
||
- `[in] Env`: The environment in which to construct the `Napi::SyntaxError` | ||
object. | ||
- `[in] message`: Null-terminated string to be used as the message for the | ||
`Napi::SyntaxError`. | ||
|
||
Returns an instance of a `Napi::SyntaxError` object. | ||
|
||
### New | ||
|
||
Creates a new instance of a `Napi::SyntaxError` object. | ||
|
||
```cpp | ||
Napi::SyntaxError::New(Napi::Env env, const std::string& message); | ||
``` | ||
|
||
- `[in] Env`: The environment in which to construct the `Napi::SyntaxError` | ||
object. | ||
- `[in] message`: Reference string to be used as the message for the | ||
`Napi::SyntaxError`. | ||
|
||
Returns an instance of a `Napi::SyntaxError` object. | ||
|
||
### Constructor | ||
|
||
Creates a new empty instance of a `Napi::SyntaxError`. | ||
|
||
```cpp | ||
Napi::SyntaxError::SyntaxError(); | ||
``` | ||
|
||
### Constructor | ||
|
||
Initializes a `Napi::SyntaxError` instance from an existing Javascript error | ||
object. | ||
|
||
```cpp | ||
Napi::SyntaxError::SyntaxError(napi_env env, napi_value value); | ||
``` | ||
|
||
- `[in] Env`: The environment in which to construct the `Napi::SyntaxError` | ||
object. | ||
- `[in] value`: The `Napi::Error` reference to wrap. | ||
|
||
Returns an instance of a `Napi::SyntaxError` object. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ if (process.argv[2] === 'fatal') { | |
|
||
module.exports = require('./common').runTestWithBindingPath(test); | ||
|
||
const napiVersion = Number(process.env.NAPI_VERSION ?? process.versions.napi); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be better to move the |
||
|
||
function test (bindingPath) { | ||
const binding = require(bindingPath); | ||
binding.error.testErrorCopySemantics(); | ||
|
@@ -46,6 +48,20 @@ function test (bindingPath) { | |
return err instanceof RangeError && err.message === 'rangeTypeError'; | ||
}); | ||
|
||
if (napiVersion > 8) { | ||
assert.throws(() => binding.error.throwSyntaxErrorCStr('test'), function (err) { | ||
return err instanceof SyntaxError && err.message === 'test'; | ||
}); | ||
|
||
assert.throws(() => binding.error.throwSyntaxError('test'), function (err) { | ||
return err instanceof SyntaxError && err.message === 'test'; | ||
}); | ||
|
||
assert.throws(() => binding.error.throwSyntaxErrorCtor(new SyntaxError('syntaxTypeError')), function (err) { | ||
return err instanceof SyntaxError && err.message === 'syntaxTypeError'; | ||
}); | ||
} | ||
|
||
assert.throws( | ||
() => binding.error.doNotCatch( | ||
() => { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should it say here that it's only supported in node-api version 9 and higher?
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.
I don't think so... We don't have any other node-api version information in our docs, eg.
Napi::Object::Freeze()
does not mention being Node-API v8 only.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.
That might be a gap though ? I go to try to use an API and it's not there? Either way agree that we don't need to be block this PR on it, but might be worth thinking about wether adding that info makes sense.