Closed Bug 1482179 Opened 6 years ago Closed 6 years ago

SpiderMonkey Embedding Examples

Categories

(Core :: JavaScript Engine, defect, P3)

defect

Tracking

()

RESOLVED FIXED

People

(Reporter: tcampbell, Unassigned)

References

(Blocks 1 open bug)

Details

We should create a repository of embedding examples for SpiderMonkey that is outside of tree. Initially will be on personal github's (I think :jorendorff is itching to start this) and later we can move to either mozilla or maybe a "SpiderMonkey Embedders" organization.

One messy issue is releases of SpiderMonkey. Initially, we can leave this out of scope.
My feeling would be to have a number of small examples(jsshell has ballooned in complexity in comparison). Some ideas:

* hello_world: Minimal example that loads a .js and executes it once
* repl: Minimal REPL loop
* jsnative: Example of custom C++ methods, including rooting
* customtracing: Example of storing GC ptrs in embedding data structures and handling tracing
* resolvehook: Example of custom class using resolve hook for lazy resolution

(Feel free to ignore or do something different!)
Blocks: sm-embedding
I love this idea! I will be happy to contribute some of these examples, and maybe getting them code reviewed by a SpiderMonkey team member will teach me something new!

This is a nice, though seriously outdated, tutorial: https://web.archive.org/web/20100820094305/http://egachine.berlios.de/embedding-sm-best-practice/embedding-sm-best-practice.html

I've also started collecting some documentation, although specific to developers of GJS, here: https://gitlab.gnome.org/GNOME/gjs/wikis/Understanding-SpiderMonkey-code
If we do create such collection of examples, I think we should also have some form of CI to know when we break our API.
This will help us provide documentation and code examples on how to fix these.
I've pushed a bare-bones repo: https://github.com/ptomato/spidermonkey-embedding-examples

It's under my own namespace but I can certainly transfer it to a Mozilla organization, or we could create a new SpiderMonkey embedders organization.

The first example is at https://github.com/ptomato/spidermonkey-embedding-examples/pull/1, review is appreciated.

I've also started a REPL example at https://github.com/ptomato/spidermonkey-embedding-examples/tree/repl-example but it's not done yet. It's based on the REPL we have in GJS but it's not really "minimal".

I did format the C++ code with the "Mozilla" preset of clang-format and it looks a bit weird compared to the code I see in Searchfox, but you all would know better whether this preset is correct or not.
I've captured all the ideas here in GitHub issues on https://github.com/spidermonkey-embedders/spidermonkey-embedding-examples/issues, so let's close this.
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.