define JS type outside of script

[email protected] Mon, 24 Apr 2017 07:38:01 -0700 (PDT)
Newsgroups gmane.comp.mozilla.devel.jseng
Message-ID <[email protected]>
Hi All,

I'm embedding Spidermonkey in a C++ app, compile my script snippets with JS::CompileFunction(..), and execute them later, passing in args converted from C++.
The functions have so far been unaware of each other, but now I need to define a JavaScript contructor for a type "Foo" with a few instance-functions, so that each of our JS script function can do this:

var x = new Foo();
x.Bar();

I'm able to do this with JS_InitClass(), but the "Foo" type need to be written in JavaScript. I do not want to string-concatenate the JavaScript code for "Foo" into each of our script functions before compiling them - if possible.

I'd appreciate some hints on how to achieve this / where to look.

Thanks,
TS.