User defined classes #58

Merged
merged 8 commits into from Mar 26, 2016

Projects

None yet

1 participant

@dherman
Collaborator
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
@dherman dherman create a `Managed` supertrait of `ValueInternal` 4f6f0c4
@dherman dherman basic class support 386e93b
@dherman dherman classes mostly working, with some remaining safety issues
details:
- 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
cfd587a
@dherman dherman finalizer properly drops the internal Rust value of neon class instances 7245391
@dherman dherman 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>()`
084edd9
@dherman dherman implement remaining error cases
6df76ae
@dherman dherman eliminate compiler warnings cac9d48
@dherman dherman class macro allows arbitrary types in `for` clause but then requires …
…name to be spelled out explicitly with `as` clause
1a52c8e
@dherman dherman merged commit c0b32f5 into master Mar 26, 2016

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@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