Skip to content
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

Migration guide entry for Object::get_value() and Object::get_opt() #868

Merged
merged 2 commits into from
Mar 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions MIGRATION_GUIDE_0.10.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,46 @@ obj.get::<V, _, _>(&mut cx, "name")?
let v: Handle<V> = obj.get(&mut cx, "name")?
```

Since `Object::get()` throws an exception when types don't match, use the new `Object::get_value()` or `Object::get_opt()` methods for cases that accept a wider range of allowable types.

**Before:**

```rust
let field: Option<Handle<JsBoolean>> = obj
.get(&mut cx, "optionalField")?
.downcast(&mut cx)
.ok();
```

**After:**

```rust
let field: Option<Handle<JsBoolean>> = obj.get_opt(&mut cx, "optionalField")?;
```

**Before:**

```rust
let length = obj.get(&mut cx, "length")?;
let length: Option<Handle<JsNumber>> = if length.is_a::<JsNull, _>(&mut cx) {
None
} else {
Some(length.downcast_or_throw(&mut cx)?)
};
```

**After:**

```rust
let length = obj.get_value(&mut cx, "length")?;
let length: Option<Handle<JsNumber>> = if length.is_a::<JsNull, _>(&mut cx) {
None
} else {
Some(length.downcast_or_throw(&mut cx)?)
};
```


## Layered APIs for function calls

The API for calling (or constructing, i.e. the Neon equivalent of the JavaScript `new` operator) a JS function has been split into two layered alternatives. The existing `.call()` and `.construct()` functions are now a lower-level primitive, which no longer offers automatic downcasting of arguments or result. But Neon 0.10 now offers a more convenient API for calling functions with an options object and method chaining, with the introduction of the `.call_with()` and `.construct_with()` methods.
Expand Down