Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

error: incomplete type ‘JSLinearString’ used in nested name specifier

67 views
Skip to first unread message

Kram Jordy

unread,
May 30, 2020, 12:18:29 PM5/30/20
to
Hi, I'm trying to compile a SpiderMonkey embedded project using 76.0.1, but I'm getting a compilation error when I try to compile a function containing a rooted linear string:

JS::RootedString rs( cx, JS::ToString(cx,args[0]) );
JS::Rooted<JSLinearString*> rls( cx, rs->ensureLinear(cx) );

I'm probably doing something stupid; any suggestions would be greatly appreciated. I've tried using all the build & include options exactly as the shell uses them, but it didn't change a thing.

Here are all the gory details:

g++ -c -g -O3 -std=c++17 -funsigned-char -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fstack-protector-strong -DNDEBUG=1 -DTRIMMED=1 -DMOZ_HAS_MOZGLUE -DWASM_SUPPORTS_HUGE_MEMORY -DEXPORT_JS_API -DMOZILLA_CLIENT -Dtopsrcdir=./firefox-76.0.1/js/src -include ./firefox-76.0.1/js/src/obj/dist/include/js/RequiredDefines.h -I./firefox-76.0.1/js/src/obj/dist/include -o ../out/js_api.o js_api.cpp
In file included from ./firefox-76.0.1/js/src/obj/dist/include/jspubtd.h:18,
from ./firefox-76.0.1/js/src/obj/dist/include/jsapi.h:27,
from js.hpp:25,
from js_api.hpp:23,
from js_api.cpp:23:
./firefox-76.0.1/js/src/obj/dist/include/js/TraceKind.h: In instantiation of ‘const JS::TraceKind JS::MapTypeToTraceKind<JSLinearString>::kind’:
./firefox-76.0.1/js/src/obj/dist/include/js/TraceKind.h:171:29: required from ‘const JS::RootKind JS::MapTypeToRootKind<JSLinearString*>::kind’
./firefox-76.0.1/js/src/obj/dist/include/js/RootingAPI.h:1040:51: required by substitution of ‘template<class T> using MaybeWrapped = std::conditional_t<(JS::MapTypeToRootKind<T>::kind == JS::RootKind::Traceable), js::DispatchWrapper<T>, T> [with T = JSLinearString*]’
./firefox-76.0.1/js/src/obj/dist/include/js/RootingAPI.h:1147:27: required from ‘class JS::Rooted<JSLinearString*>’
js_api.cpp:553:38: required from here
./firefox-76.0.1/js/src/obj/dist/include/js/TraceKind.h:82:30: error: incomplete type ‘JSLinearString’ used in nested name specifier
82 | static const JS::TraceKind kind = T::TraceKind;
| ^~~~
js_api.cpp: In static member function ‘static bool Js_Api::toCSV(JSContext*, unsigned int, JS::Value*)’:
js_api.cpp:553:44: error: invalid use of incomplete type ‘class JSString’
553 | JS::Rooted<JSLinearString*> rls( cx, rs->ensureLinear(cx) );
| ^~
In file included from ./firefox-76.0.1/js/src/obj/dist/include/js/TraceKind.h:12,
from ./firefox-76.0.1/js/src/obj/dist/include/jspubtd.h:18,
from ./firefox-76.0.1/js/src/obj/dist/include/jsapi.h:27,
from js.hpp:25,
from js_api.hpp:23,
from js_api.cpp:23:
./firefox-76.0.1/js/src/obj/dist/include/js/TypeDecls.h:36:21: note: forward declaration of ‘class JSString’
36 | class JS_PUBLIC_API JSString;
| ^~~~~~~~

Steve Fink

unread,
May 30, 2020, 3:28:37 PM5/30/20
to Kram Jordy, dev-tech-...@lists.mozilla.org
I think it's a bug. js/public/TraceKind.h looks like it should have a
specialization of MapTypeToTraceKind for JSLinearString, since it's part
of the public API, and it doesn't.

You could patch around it:

  namespace JS {
  template <>
  struct MapTypeToTraceKind<JSLinearString> {
    static const JS::TraceKind kind = JS::TraceKind::String;
  };
  } // namespace JS

but please file a bug. And mention that there should be a
RootedLinearString typedef as well.

Also, methods on JSString are sadly not part of the public API. So I
think that should be

  JS::RootedString rs(cx, JS::ToString(cx, args[0]));
  if (!rs) return false;
  JS::Rooted<JSLinearString*> rls(cx, JS_EnsureLinearString(cx, rs));
  if (!rls) return false;
> _______________________________________________
> dev-tech-js-engine mailing list
> dev-tech-...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-tech-js-engine


Kram Jordy

unread,
May 30, 2020, 5:42:23 PM5/30/20
to
Thanks for your insights Steve, I've filed a bug report as suggested, #1642154.

I was following the examples in the js-shell, however, they do the same thing about 4 different ways, so I was rather confused!


JSString* str = argv[0].toString();
JSLinearString* linearStr = JS_EnsureLinearString(cx, str);
if (!linearStr) {
return false;
}

----

RootedLinearString linearFormat(
cx, optionFormat.toString()->ensureLinear(cx));
if (!linearFormat) {
return false;
}

----

Rooted<JSLinearString*> linear(cx, str->ensureLinear(cx));
if (!linear) {
return false;
}

----

if (!JSString::ensureLinear(cx, v.toString())) {
return false;
}
RootedLinearString input(cx, &v.toString()->asLinear());

Tom Schuster

unread,
May 30, 2020, 5:55:52 PM5/30/20
to Kram Jordy, JS list
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

Kram Jordy

unread,
May 31, 2020, 2:39:04 AM5/31/20
to
On Saturday, 30 May 2020 22:55:52 UTC+1, Tom Schuster wrote:
> 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.

Hi Tom. Yes I'll make sure I use this API function. I've not actually posted any of my code, so if there are any bugs in the snippets, then they are also bugs in the javascript shell js.cpp.


> > 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)

Yes that's the one. Like it or not, this is the *only* up-to-date piece of code that spidermonkey embedders can look to for examples that I'm aware of. It would be great if the spidermonkey team could do regular code reviews on it to ensure it reflects the current best practices and idioms.


Steve Fink

unread,
May 31, 2020, 10:28:35 PM5/31/20
to Kram Jordy, dev-tech-...@lists.mozilla.org
On 5/30/20 11:39 PM, Kram Jordy wrote:
> On Saturday, 30 May 2020 22:55:52 UTC+1, Tom Schuster wrote:
>> 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.
> Hi Tom. Yes I'll make sure I use this API function. I've not actually posted any of my code, so if there are any bugs in the snippets, then they are also bugs in the javascript shell js.cpp.

That's a natural expectation, but unfortunately shell/js.cpp is *not* a
SpiderMonkey embedding, but is rather an internal application that has
access to more APIs than would an embedding that is only linking with mozjs.


>
>>> 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)
> Yes that's the one. Like it or not, this is the *only* up-to-date piece of code that spidermonkey embedders can look to for examples that I'm aware of. It would be great if the spidermonkey team could do regular code reviews on it to ensure it reflects the current best practices and idioms.

Sorry, I should have mentioned earlier: you should look at
https://github.com/mozilla-spidermonkey/spidermonkey-embedding-examples
<https://github.com/mozilla-spidermonkey/spidermonkey-embedding-examples>

0 new messages