Minor cleanup before release.

This commit is contained in:
Stephen Chung
2020-10-22 12:26:44 +08:00
parent e89d12c42f
commit 2c7c719cd5
16 changed files with 125 additions and 120 deletions

View File

@@ -61,6 +61,7 @@ Reserved Keywords
| `with` | scope |
| `module` | module |
| `package` | package |
| `thread` | threading |
| `spawn` | threading |
| `go` | threading |
| `await` | async |

View File

@@ -16,8 +16,6 @@ it raises an evaluation error.
It is possible, through a special syntax, to capture the calling scope - i.e. the scope
that makes the function call - and access variables defined there.
Capturing can be disabled via the [`no_closure`] feature.
```rust
fn foo(y) { // function accesses 'x' and 'y', but 'x' is not defined
x += y; // 'x' is modified in this function

View File

@@ -5,21 +5,21 @@ Keywords
The following are reserved keywords in Rhai:
| Active keywords | Reserved keywords | Usage | Inactive under feature |
| ------------------------------------------------- | ------------------------------------------------ | --------------------- | :--------------------: |
| `true`, `false` | | boolean constants | |
| `let`, `const` | `var`, `static` | variable declarations | |
| `is_shared` | | shared values | [`no_closure`] |
| `if`, `else` | `then`, `goto`, `exit` | control flow | |
| | `switch`, `match`, `case` | matching | |
| `while`, `loop`, `for`, `in`, `continue`, `break` | `do`, `each` | looping | |
| `fn`, `private` | `public`, `new` | functions | [`no_function`] |
| `return` | | return values | |
| `throw` | `try`, `catch` | throw exceptions | |
| `import`, `export`, `as` | `use`, `with`, `module`, `package` | modules/packages | [`no_module`] |
| `Fn`, `call`, `curry` | | function pointers | |
| | `spawn`, `go`, `sync`, `async`, `await`, `yield` | threading/async | |
| `type_of`, `print`, `debug`, `eval` | | special functions | |
| | `default`, `void`, `null`, `nil` | special values | |
| Active keywords | Reserved keywords | Usage | Inactive under feature |
| ------------------------------------------------- | ---------------------------------------------------------- | ---------------------- | :--------------------: |
| `true`, `false` | | boolean constants | |
| `let`, `const` | `var`, `static` | variable declarations | |
| `is_shared` | | shared values | [`no_closure`] |
| `if`, `else` | `then`, `goto`, `exit` | control flow | |
| | `switch`, `match`, `case` | matching | |
| `while`, `loop`, `for`, `in`, `continue`, `break` | `do`, `each` | looping | |
| `fn`, `private` | `public`, `new` | functions | [`no_function`] |
| `return` | | return values | |
| `throw`, `try`, `catch` | | throw/catch exceptions | |
| `import`, `export`, `as` | `use`, `with`, `module`, `package` | modules/packages | [`no_module`] |
| `Fn`, `call`, `curry` | | function pointers | |
| | `spawn`, `thread`, `go`, `sync`, `async`, `await`, `yield` | threading/async | |
| `type_of`, `print`, `debug`, `eval` | | special functions | |
| | `default`, `void`, `null`, `nil` | special values | |
Keywords cannot become the name of a [function] or [variable], even when they are disabled.

View File

@@ -4,11 +4,12 @@ Catch Exceptions
{{#include ../links.md}}
When an [exception] is thrown via a `throw` statement, evaluation of the script halts
When an [exception] is thrown via a [`throw`] statement, evaluation of the script halts
and the [`Engine`] returns with `Err(Box<EvalAltResult::ErrorRuntime>)` containing the
exception value that has been thrown.
It is possible, via the `try` ... `catch` statement, to _catch_ exceptions.
It is possible, via the `try` ... `catch` statement, to _catch_ exceptions, optionally
with an _error variable_.
```rust
// Catch an exception and capturing its value
@@ -26,7 +27,7 @@ try
{
print(42/0); // deliberate divide-by-zero exception
}
catch // no catch variable - exception value is discarded
catch // no error variable - exception value is discarded
{
print("Ouch!");
}
@@ -50,7 +51,7 @@ Re-Throw Exception
------------------
Like the `try` ... `catch` syntax in most languages, it is possible to _re-throw_
an exception within the `catch` block simply by another `throw` statement without
an exception within the `catch` block simply by another [`throw`] statement without
a value.
@@ -76,20 +77,23 @@ Catchable Exceptions
Many script-oriented exceptions can be caught via `try` ... `catch`:
* Runtime error thrown by a `throw` statement
* Arithmetic error
* Variable not found
* [Function] not found
* [Module] not found
* Unbound [`this`]
* Data type mismatch
* [Array]/[string] indexing out-of-bounds
* Indexing with an inappropriate type
* `for` statement without an iterator
* Error in an `in` expression
* Data race detected
* Assignment to a calculated value/constant value
* Dot expression error
| Error type | Error value |
| --------------------------------------------- | :------------------------: |
| Runtime error thrown by a [`throw`] statement | value in `throw` statement |
| Other runtime error | error message [string] |
| Arithmetic error | error message [string] |
| Variable not found | error message [string] |
| [Function] not found | error message [string] |
| [Module] not found | error message [string] |
| Unbound [`this`] | error message [string] |
| Data type mismatch | error message [string] |
| Assignment to a calculated/constant value | error message [string] |
| [Array]/[string] indexing out-of-bounds | error message [string] |
| Indexing with an inappropriate data type | error message [string] |
| Error in a dot expression | error message [string] |
| `for` statement without an iterator | error message [string] |
| Error in an `in` expression | error message [string] |
| Data race detected | error message [string] |
Non-Catchable Exceptions
@@ -99,6 +103,6 @@ Some exceptions _cannot_ be caught:
* Syntax error during parsing
* System error - e.g. script file not found
* Script evaluation over [limits]({{rootUrl}}/safety/index.md)
* [Stack overflow][maximum call stack depth]
* Script evaluation metrics over [safety limits]({{rootUrl}}/safety/index.md)
* Function calls nesting exceeding [maximum call stack depth]
* Script evaluation manually terminated

View File

@@ -89,6 +89,7 @@
[function overloading]: {{rootUrl}}/rust/functions.md#function-overloading
[fallible function]: {{rootUrl}}/rust/fallible.md
[fallible functions]: {{rootUrl}}/rust/fallible.md
[`throw`]: {{rootUrl}}/language/throw.md
[exception]: {{rootUrl}}/language/throw.md
[exceptions]: {{rootUrl}}/language/throw.md
[function pointer]: {{rootUrl}}/language/fn-ptr.md

View File

@@ -33,3 +33,13 @@ The most important resources to watch out for are:
* **Data**: A malicious script may attempt to read from and/or write to data that it does not own. If this happens,
it is a severe security breach and may put the entire system at risk.
`unchecked`
-----------
All these safe-guards can be turned off via the [`unchecked`] feature, which disables all
safety checks (even fatal errors such as arithmetic overflows and division-by-zero).
This will increase script evaluation performance, at the expense of having an erroneous
script able to panic the entire system.