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

User defined classes #58

merged 8 commits into from Mar 26, 2016


None yet
1 participant

dherman commented Mar 26, 2016

This patch implements the ability to define custom JS classes that wrap (owned) Rust data. The classes can implement native methods that operate on the Rust data (and any JS properties too), and they are guaranteed safe by guarding their bodies with a dynamic brand check.

dherman added some commits Jan 13, 2016

classes mostly working, with some remaining safety issues
- the isolate gets a class map, which maps the static Rust class type to runtime class metadata
- the runtime class metadata contains a `v8::FunctionTemplate`, which automatically instantiates different constructor/prototype instances per-realm
- `Class` trait extends `Managed` so you can get a handle to its GC'ed function template
- `Class::setup` is required in order to tell Neon how to set up the function template
- `Class::class` lets you get access to a GC'ed `JsClass<Self>`
- function call protocol just uses `v8::FunctionCallbackInfo` directly (instead of NAN), with metadata saved in a `v8::External` (instead of ObjectWrap)
- changed `internal::vm::Isolate` to abstract the `*mut` pointer (should probably do that with more types, like `CallbackInfo`)
- moved `.this` and `.callee` into `Arguments`, since the borrow checker wouldn't allow them to be called as methods of `Call` with the mutable borrowed scope
- `declare_types!` front-end macro
- `.this()` method now returns impl of new `This` trait, which is `JsUndefined` for allocators, `JsObject` for normal functions, and `T` for classes
- `Kernel` abstraction for describing kernels of behavior in Rust that are triggered by v8
brand checking and error messages
- implicit brand checking on methods
- better error messages using the class name
- C++ helpers for manipulating Rust strings and slices
- added `handle::is_a<T>()`
class macro allows arbitrary types in `for` clause but then requires …
…name to be spelled out explicitly with `as` clause

@dherman dherman merged commit c0b32f5 into master Mar 26, 2016

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
continuous-integration/travis-ci/push The Travis CI build passed

@dherman dherman deleted the user-defined-classes branch Mar 26, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment