Embedding spidermonkey in Visual Studio

Hi there, I am new here. I am trying to embed SpiderMonkey in my Visual Studio project.

I was able to successfully build the “JS Shell” and it works fine but when I include it in my Visual Studio project, I get some error regarding “Constant expressions” for some header files like “ColumnNumber.h”, “Span.h”, “jspubtd.h” etc. There are around 64 errors they are all the same for the files. expression must have a constant value

here is how my MozConfig file is set up.

ac_add_options --enable-application=js
ac_add_options --disable-jemalloc
ac_add_options --enable-debug
ac_add_options --with-intl-api
ac_add_options --enable-strip
ac_add_options --enable-install-strip
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/js/src/releaseob

Is there any guide that shows the embedding of SpiderMonkey with Visual Studio Project? I have spent a lot of time searching on YouTube if there are any tutorials but found none that can guide me to embed SpiderMonkey successfully.

I am using the hg for SpiderMonkey and I believe it is the latest one and not ESR 102. I want to try and embed the latest one. I also tried embedding the ESR102 but was not able to build the shell, because of some missing dependency.

I found a git repo that guides to embed the SpiderMonkey, but it is not working for me either.

Any help on the topic is appreciated. Thanks :slight_smile:

So after lots of trial and error, I was able to resolve all the errors, and now there are only 2 errors.

syntax error: missing ‘}’ before identifier ‘JSProto_LIMIT’ in file jspubtd.h at line 55

the next error is related to the same JSProto_Limit Assertion in Class.h

Also, I switched to this repo for the SpiderMonkey build.

Just for debugging purposes I commented out the JSProto_Limit from both the files to atleast get rid of errors, and I was able to compile the project, I was using the test code provided in the above repo testjs.cpp it did compiled sucesfully but throw me an error regarding “Debug Assertion Failure” I think this is because I commented out the Assertion Code for JSProto_Limit.

Maybe someone can guide me on how to compile a sample example C++ project with the embedded SpiderMonkey. Or provide a sample VS project with the embedded SpiderMonkey and example. So that others can learn from it.

Thank you.

I was finally able to embed and run the example test file in my Visual Studio project. I am not sure if I did the right thing, but I was getting the error for the Free() heap allocator so I commented out that code and the interpreter worked fine.

Though I was able to make it work, it works in the release build just fine but in debug build I still get that many errors in the files I mentioned in the original post.

and I really need a working debug build as well. Let me know if anybody knows how to build the debug version, without any compilation error, I am using ESR115 if anybody wants to know.

So, one thing I’d say is that we don’t support building with MSVC these days – I believe all our builds happen via Clang today. What it looks like you’re running into is cases where we’ve diverged from what MSVC supports.

Spider Monkey contains the following main components: Interpreter: A fast interpreter that executes untyped bytecode and operates on JS::Value type-tagged values to represent the full range of JS values . Just-In-Time Compiler: Contains a JIT compiler called IonMonkey that optimizes hot code.