Show HN: My weekend project - Common API for Javascript Engines
github.com
github.com
For example, in the source you use JS_AddValueRoot/JS_RemoveValueRoot, which will bog down performance if the app purposely wants to keep values on the stack to avoid having to call into the engine to manage roots. CAJE::MozValueRef::AsString() always allocates memory and potentially flattens the string and copies it every time the method is called. You might want to simply peek at the bytes without allocating a copy. All of these things will add up over time and you'd basically wind up with disjoint features again and a large subset of what is already in jsapi.h.
It's true that some of the current APIs are implemented in a clunky way, but I'm quite confident there are better ways to do things while still maintaining support for both engines.
I know you think this is a futile effort, but I'd welcome any improvements from someone who knows more about the engine internals than I do. I'm currently working out what I can do instead of rooting every ValueRef.
[1] In the end, the way stack-scanning GC works is that it has OS-specific code (see jsnativestack.cpp[2] in SM) to get the highest stack address (stack grows down in all the archs you care about). Then since you know someone is calling into your constructor, you can declare a variable on the stack and get its address to find out the current stack pointer. If 'this' is between the current stack pointer and the stack base, you are on the stack and do not need to root yourself.[3]
[2] http://hg.mozilla.org/mozilla-central/file/a1b89b4913ca/js/s...
[3] I coded an example up to show you (it uses an OSX-specific pthread API to get the stack base -- see the SM code for other platforms) http://pastebin.com/dVDGWJP5
It can happily wrap existing contexts, so it means that eg. one set of function bindings can be used with both V8 and TraceMonkey (even without the embedding application using the CAJE API, only the bindings).
http://www.adrianboeing.com/pal/
Great in theory, but not worth the effort, so very low rate of adoption.