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

new hello world?

87 views
Skip to first unread message

exe...@gmail.com

unread,
May 15, 2013, 3:45:52 AM5/15/13
to
This "hello world" is not compiling for me with the new version of SM

https://developer.mozilla.org/en-US/docs/How_to_embed_the_JavaScript_engine

hello.cpp:15:55: fatal error: use of undeclared identifier 'JS_FinalizeStub'
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,

Of course I tried to do something about it, but the program will crash even if I can compile. So I think this hello_world is outdated. Anyone can suggest the new one? Or I am supposed to use shell.c? But that is a huge version of hello world really.


exe...@gmail.com

unread,
May 16, 2013, 11:16:45 PM5/16/13
to
Here is SM 17 hello world:

#include "jsapi.h"
JSRuntime *rt;
JSContext *cx;
JSObject *global;
JSClass GlobalClass = {
"global", JSCLASS_GLOBAL_FLAGS,
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub};

int main() {
rt = JS_NewRuntime(32L * 1024L * 1024L);
cx = JS_NewContext (rt, 10*20*8192);
global = JS_NewGlobalObject(cx, &GlobalClass, NULL);
JS_InitStandardClasses(cx, global);
jsval R;
char *script = "2+2";
JS_EvaluateScript(cx, global, script, strlen(script), "arg", 1, &R);
double d;
JS_ValueToNumber(cx, R, &d);
printf("%f\n", d);
return 0;
}

michael...@teksavvy.com

unread,
May 24, 2013, 1:36:30 PM5/24/13
to
I am using Debian 7, and the package libmozjs185 version 1.8.5-1.0.0+dfsg-4.

In jsapi.h, JS_NewGlobalObjects mentions only two parameters, and seems to need a third. So I have added:
JSPrincipals *principals

The Hello World program above now compiles, but gives a seg fault when run.

What am I supposed to do?
0 new messages