You should only use the first code snippet using
JS_EnsureLinearString. Like Steve said it would be a good idea to add
those tracing kinds, because right now you strings seem to be
unrooted.
Most (all?) of the public API is either in jsapi.h or in of the header
files in public/ folder.
> I was following the examples in the js-shell, however, they do the same thing about 4 different ways, so I was rather confused!
I assume you are talking about:
https://searchfox.org/mozilla-central/source/js/src/shell/js.cpp ? In
that case you really should not necessarily be using this file as a
template. The shell is considered part of the JavaScript engine proper
and uses many internal APIs. (Out of necessity really, many APIs that
need testing are only internal) Of course our public API usually only
has stuff that is actually required by Gecko/Firefox, so it is likely
that you might be running into a situation where a public API is
missing. In that case it's best to report a bug.
https://github.com/mozilla-spidermonkey/spidermonkey-embedding-examples
is a good place to find examples of SpiderMonkey's public API.
Aside: The static version of ensureLinear is silly and should just be
removed .. There seems to be only a single user:
https://searchfox.org/mozilla-central/rev/d9d492eda787a6eda66016e6f8398ee759f7bc25/js/src/shell/js.cpp#9307
Good luck,
Tom