RPM Package Manager, CVS Repository http://rpm5.org/cvs/ ____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson Root: /v/rpm/cvs Email: j...@rpm5.org Module: rpm Date: 22-Jun-2017 19:25:47 Branch: rpm-5_4 Handle: 2017062217254700 Modified files: (Branch: rpm-5_4) rpm/rpmio Makefile.am rpmjs.h rpmjs17.cpp rpmjs185.cpp rpmjs24.cpp rpmjs31.cpp rpmjs38.cpp rpmjs45.cpp Log: - rpmjs: collect the whole set. Summary: Revision Changes Path 1.293.2.95 +13 -3 rpm/rpmio/Makefile.am 1.10.2.3 +13 -0 rpm/rpmio/rpmjs.h 1.1.2.2 +156 -90 rpm/rpmio/rpmjs17.cpp 1.1.2.2 +166 -94 rpm/rpmio/rpmjs185.cpp 1.1.2.3 +52 -38 rpm/rpmio/rpmjs24.cpp 1.1.2.3 +55 -42 rpm/rpmio/rpmjs31.cpp 1.1.2.3 +51 -40 rpm/rpmio/rpmjs38.cpp 1.1.2.3 +54 -40 rpm/rpmio/rpmjs45.cpp ____________________________________________________________________________ patch -p0 <<'@@ .' Index: rpm/rpmio/Makefile.am ============================================================================ $ cvs diff -u -r1.293.2.94 -r1.293.2.95 Makefile.am --- rpm/rpmio/Makefile.am 21 Jun 2017 17:26:24 -0000 1.293.2.94 +++ rpm/rpmio/Makefile.am 22 Jun 2017 17:25:47 -0000 1.293.2.95 @@ -18,7 +18,7 @@ getdate.y html-parse.c html-parse.h libsqlio.c \ rpmcpio.c rpmcpio.h rpmgenbasedir.c rpmgenpkglist.c rpmgensrclist.c \ rpmjsio.msg rpmtar.c rpmtar.h \ - rpmjs24.cpp rpmjs31.cpp rpmjs38.cpp rpmjs45.cpp \ + rpmjs185.cpp rpmjs17.cpp rpmjs24.cpp rpmjs31.cpp rpmjs38.cpp rpmjs45.cpp \ tdir.c teio.c tfts.c tget.c tgfs.c tgit.c tglob.c thkp.c thtml.c \ tinv.c tkey.c tmire.c tmq.c tmqtt.c todbc.c tput.c tpython.c trpmio.c \ tsexp.c tsvn.c tsw.c lookup3.c duktape.c tjsmn.c tjson.c yajl.c \ @@ -32,7 +32,7 @@ EXTRA_PROGRAMS += bsdiff bspatch fanotify pcrsed rpmborg rpmcurl \ rpmgenbasedir rpmgenpkglist rpmgensrclist rpmgpg \ rpmpbzip2 rpmpigz rpmzstd \ - rpmjs24 rpmjs31 rpmjs38 rpmjs45 \ + rpmjs185 rpmjs17 rpmjs24 rpmjs31 rpmjs38 rpmjs45 \ tasn tbf tcap tder tdir teio tfts tget tglob thkp tmagic tmire \ tmount todbc toid tperl tpython tput trpmio tsexp tsvn tsw ttcl \ dumpasn1 lookup3 trel twitter github tmicrojson @@ -550,6 +550,14 @@ rpmgpg_SOURCES = rpmgpg.c rpmgpg_LDADD = $(RPMIO_LDADD_COMMON) +rpmjs185_SOURCES = rpmjs185.cpp +rpmjs185_CPPFLAGS = -DXP_UNIX=1 -DJS_THREADSAFE=1 -I/usr/include/js -fPIC +rpmjs185_LDADD = -L/usr/lib64 -ljs + +rpmjs17_SOURCES = rpmjs17.cpp +rpmjs17_CPPFLAGS = -include /usr/include/js-17.0/js/RequiredDefines.h -I/usr/include/js-17.0 -fPIC +rpmjs17_LDADD = -L/usr/lib64 -lmozjs-17.0 + rpmjs24_SOURCES = rpmjs24.cpp rpmjs24_CPPFLAGS = -include /usr/include/mozjs-24/js/RequiredDefines.h -I/usr/include/mozjs-24 -fPIC rpmjs24_LDADD = -L/usr/lib64 -lmozjs-24 @@ -566,7 +574,9 @@ rpmjs45_CPPFLAGS = -include /usr/include/mozjs-45/js/RequiredDefines.h -I/usr/include/mozjs-45 -fPIC rpmjs45_LDADD = -L/usr/lib64 -lmozjs-45 -mozjs: rpmjs24 rpmjs31 rpmjs38 rpmjs45 +mozjs: rpmjs185 rpmjs17 rpmjs24 rpmjs31 rpmjs38 rpmjs45 + -./rpmjs185 + -./rpmjs17 -./rpmjs24 -./rpmjs31 -./rpmjs38 @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmjs.h ============================================================================ $ cvs diff -u -r1.10.2.2 -r1.10.2.3 rpmjs.h --- rpm/rpmio/rpmjs.h 17 May 2017 12:34:40 -0000 1.10.2.2 +++ rpm/rpmio/rpmjs.h 22 Jun 2017 17:25:47 -0000 1.10.2.3 @@ -50,9 +50,22 @@ RPMJS_FLAGS_GLOBAL = (1<<31), }; +typedef struct JSIO_s * JSIO_t; +struct JSIO_s { + void (*mozFini) (rpmjs js); + void * (*mozInit) (rpmjs js); + int (*mozRun) (rpmjs js, const char * script, const char * filename, int lineno); +}; + +extern JSIO_t mozjs24; +extern JSIO_t mozjs31; +extern JSIO_t mozjs38; +extern JSIO_t mozjs45; + struct rpmjs_s { struct rpmioItem_s _item; /*!< usage mutex and pool identifier. */ uint32_t flags; /*!< JSOPTION_FOO in 0xffff bits */ + JSIO_t jsio; void * I; /*!< JS interpreter {rt, cx, globalObj} */ }; @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmjs17.cpp ============================================================================ $ cvs diff -u -r1.1.2.1 -r1.1.2.2 rpmjs17.cpp --- rpm/rpmio/rpmjs17.cpp 22 Jun 2017 17:03:52 -0000 1.1.2.1 +++ rpm/rpmio/rpmjs17.cpp 22 Jun 2017 17:25:47 -0000 1.1.2.2 @@ -1,94 +1,160 @@ -/* - * This define is for Windows only, it is a work-around for bug 661663. - */ -#ifdef _MSC_VER -# define XP_WIN -#endif - -/* Include the JSAPI header file to get access to SpiderMonkey. */ -#include "jsapi.h" - -/* The class of the global object. */ -static JSClass global_class = { - "global", JSCLASS_GLOBAL_FLAGS, - JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub, - JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, -}; - -/* The error reporter callback. */ -void reportError(JSContext *cx, const char *message, JSErrorReport *report) -{ - fprintf(stderr, "%s:%u:%s\n", - report->filename ? report->filename : "<no filename=\"filename\">", - (unsigned int) report->lineno, - message); -} - -int main(int argc, const char *argv[]) -{ - /* JSAPI variables. */ - JSRuntime *rt; - JSContext *cx; - +// following code might be needed in some cases +// #define __STDC_LIMIT_MACROS +// #include <stdint.h> + +#include "system.h" + +#define js jsns +#include "jsapi.h" +#undef js + +#define _RPMJS_INTERNAL +#include <rpmjs.h> + +#include "debug.h" + +/* The class of the global object. */ +static JSClass global_class = { + "global", + JSCLASS_GLOBAL_FLAGS, + JS_PropertyStub, + JS_PropertyStub, + JS_PropertyStub, + JS_StrictPropertyStub, + JS_EnumerateStub, + JS_ResolveStub, + JS_ConvertStub, +}; + +struct rpmjs_s _js; +rpmjs js = &_js; + +/*==============================================================*/ +typedef struct JSI_s * JSI_t; +struct JSI_s { + JSRuntime *rt; + JSContext *cx; + JSObject *global; +}; + +static void +rpmjsReportError(JSContext *cx, const char *message, JSErrorReport *report) +{ + fprintf(stderr, "%s:%u:%s\n", + report->filename ? report->filename : "<no filename=\"filename\">", + (unsigned int) report->lineno, message); +} + +/*==============================================================*/ +static int rpmjs_nopens; + +static void mozFini(rpmjs js) +{ + JSI_t I = (JSI_t) js->I; + + if (I->cx) + JS_DestroyContext(I->cx); + I->cx = NULL; + + if (I->rt) + JS_DestroyRuntime(I->rt); + I->rt = NULL; + + if (--rpmjs_nopens <= 0) { + JS_ShutDown(); + rpmjs_nopens = 0; + } + free(I); +} + +static void * mozInit(rpmjs js) +{ + JSI_t I = NULL; + uint32_t flags = js->flags; + static uint32_t _maxbytes = 8L * 1024L * 1024L; static size_t _stackChunkSize = 8192; - /* Create a JS runtime. You always need at least one runtime per process. */ - rt = JS_NewRuntime(_maxbytes); - if (rt == NULL) - return 1; - - /* - * Create a context. You always need a context per thread. - * Note that this program is not multi-threaded. - */ - cx = JS_NewContext(rt, _stackChunkSize); - if (cx == NULL) - return 1; - - /* - * Create the global object in a new compartment. - * You always need a global object per context. - */ - JS::RootedObject global(cx, - JS_NewGlobalObject(cx, &global_class, NULL)); - if (global == NULL) - return 1; - - /* - * Populate the global object with the standard JavaScript - * function and object classes, such as Object, Array, Date. - */ - if (!JS_InitStandardClasses(cx, global)) - return 1; - - /* Your application code here. This may include JSAPI calls - * to create your own custom JavaScript objects and to run scripts. - * - * The following example code creates a literal JavaScript script, - * evaluates it, and prints the result to stdout. - * - * Errors are conventionally saved in a JSBool variable named ok. - */ - const char *script = "'hello'+'world, it is '+new Date()"; - jsval rval; - JSBool ok; - const char *filename = "noname"; - unsigned lineno = 0; - - ok = JS_EvaluateScript(cx, global, script, strlen(script), - filename, lineno, &rval); - if (!ok) - return 1; - - JSString * str = JS_ValueToString(cx, rval); - printf("%s\n", JS_EncodeString(cx, str)); - - /* End of your application code */ - - /* Clean things up and shut down SpiderMonkey. */ - JS_DestroyContext(cx); - JS_DestroyRuntime(rt); - JS_ShutDown(); - return 0; + if (rpmjs_nopens++ == 0) { +#ifdef NOTYET /* XXX collides with ancient JS_NewRuntime */ + JS_Init(); +#endif + } + + I = (JSI_t) calloc(1, sizeof(*I)); +assert(I); + + I->rt = JS_NewRuntime(_maxbytes); +assert(I->rt); + JS_SetRuntimePrivate(I->rt, (void *)js); + + I->cx = JS_NewContext(I->rt, _stackChunkSize); +assert(I->cx); + JS_SetContextPrivate(I->cx, (void *)js); + + return I; +} + +static int mozRun(rpmjs js, + const char * script, const char * filename, int lineno) +{ + JSI_t I = (JSI_t) js->I; + + JSClass * _clasp = (JSClass *)&global_class; +#ifdef NOTYET + JSFunctionSpec * _functions = global_functions; +#endif + JSPrincipals * _principals = NULL; + JSBool ok; + + // In practice, you would want to exit this any + // time you're spinning the event loop + JSAutoRequest ar(I->cx); + + JS::RootedObject global(I->cx, + JS_NewGlobalObject(I->cx, _clasp, _principals)); + if (!global) + return 1; + I->global = global; +assert(I->global); + JS_SetGlobalObject(I->cx, I->global); + + JS::RootedValue rval(I->cx); + { // Scope for JSAutoCompartment + JSAutoCompartment ac(I->cx, global); + JS_InitStandardClasses(I->cx, global); + + ok = JS_EvaluateScript(I->cx, global, + script, strlen(script), filename, lineno, + rval.address()); + if (!ok) + return 1; + } + JSString *str = rval.toString(); + printf("%s\n", JS_EncodeString(I->cx, str)); + + return 0; +} + +static struct JSIO_s _mozjs17 = { mozFini, mozInit, mozRun }; +JSIO_t mozjs17 = &_mozjs17; + +/*==============================================================*/ +int main(int argc, const char *argv[]) +{ + int rc = 0; + + JSI_t I = (JSI_t) mozInit(js); + js->I = I; + + { + const char *script = "'hello'+'world, it is '+new Date()"; + const char *filename = "noname"; + int lineno = 1; + rc = mozRun(js, script, filename, lineno); + } + + mozFini(js); + + return rc; } @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmjs185.cpp ============================================================================ $ cvs diff -u -r1.1.2.1 -r1.1.2.2 rpmjs185.cpp --- rpm/rpmio/rpmjs185.cpp 22 Jun 2017 17:03:52 -0000 1.1.2.1 +++ rpm/rpmio/rpmjs185.cpp 22 Jun 2017 17:25:47 -0000 1.1.2.2 @@ -1,95 +1,167 @@ -/* - * This define is for Windows only, it is a work-around for bug 661663. - */ -#ifdef _MSC_VER -# define XP_WIN -#endif - -/* Include the JSAPI header file to get access to SpiderMonkey. */ -#include "jsapi.h" - -/* The class of the global object. */ -static JSClass global_class = { - "global", JSCLASS_GLOBAL_FLAGS, - JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub, - JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub, - JSCLASS_NO_OPTIONAL_MEMBERS -}; - -/* The error reporter callback. */ -void reportError(JSContext *cx, const char *message, JSErrorReport *report) -{ - fprintf(stderr, "%s:%u:%s\n", - report->filename ? report->filename : "<no filename=\"filename\">", - (unsigned int) report->lineno, - message); -} - -int main(int argc, const char *argv[]) -{ - /* JSAPI variables. */ - JSRuntime *rt; - JSContext *cx; - JSObject *global; - - /* Create a JS runtime. You always need at least one runtime per process. */ - rt = JS_NewRuntime(8 * 1024 * 1024); - if (rt == NULL) - return 1; - - /* - * Create a context. You always need a context per thread. - * Note that this program is not multi-threaded. - */ - cx = JS_NewContext(rt, 8192); - if (cx == NULL) - return 1; - JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_METHODJIT); - JS_SetVersion(cx, JSVERSION_LATEST); - JS_SetErrorReporter(cx, reportError); - - /* - * Create the global object in a new compartment. - * You always need a global object per context. - */ - global = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL); - if (global == NULL) - return 1; - - /* - * Populate the global object with the standard JavaScript - * function and object classes, such as Object, Array, Date. - */ - if (!JS_InitStandardClasses(cx, global)) - return 1; - - /* Your application code here. This may include JSAPI calls - * to create your own custom JavaScript objects and to run scripts. - * - * The following example code creates a literal JavaScript script, - * evaluates it, and prints the result to stdout. - * - * Errors are conventionally saved in a JSBool variable named ok. - */ - const char *script = "'hello'+'world, it is '+new Date()"; - jsval rval; - JSBool ok; - const char *filename = "noname"; - uintN lineno = 0; - - ok = JS_EvaluateScript(cx, global, script, strlen(script), - filename, lineno, &rval); - if (!ok) - return 1; - - JSString * str = JS_ValueToString(cx, rval); - printf("%s\n", JS_EncodeString(cx, str)); - - /* End of your application code */ - - /* Clean things up and shut down SpiderMonkey. */ - JS_DestroyContext(cx); - JS_DestroyRuntime(rt); - JS_ShutDown(); - return 0; +// following code might be needed in some cases +// #define __STDC_LIMIT_MACROS +// #include <stdint.h> + +#include "system.h" + +#define js jsns +#include "jsapi.h" +#undef js + +#define _RPMJS_INTERNAL +#include <rpmjs.h> + +#include "debug.h" + +/* The class of the global object. */ +static JSClass global_class = { + "global", + JSCLASS_GLOBAL_FLAGS, + JS_PropertyStub, + JS_PropertyStub, + JS_PropertyStub, + JS_StrictPropertyStub, + JS_EnumerateStub, + JS_ResolveStub, + JS_ConvertStub, +}; + +struct rpmjs_s _js; +rpmjs js = &_js; + +/*==============================================================*/ +typedef struct JSI_s * JSI_t; +struct JSI_s { + JSRuntime *rt; + JSContext *cx; + JSObject *global; +}; + +static void +rpmjsReportError(JSContext *cx, const char *message, JSErrorReport *report) +{ + fprintf(stderr, "%s:%u:%s\n", + report->filename ? report->filename : "<no filename=\"filename\">", + (unsigned int) report->lineno, message); +} + +/*==============================================================*/ +static int rpmjs_nopens; + +static void mozFini(rpmjs js) +{ + JSI_t I = (JSI_t) js->I; + + if (I->cx) + JS_DestroyContext(I->cx); + I->cx = NULL; + + if (I->rt) + JS_DestroyRuntime(I->rt); + I->rt = NULL; + + if (--rpmjs_nopens <= 0) { + JS_ShutDown(); + rpmjs_nopens = 0; + } + free(I); +} + +static void * mozInit(rpmjs js) +{ + JSI_t I = NULL; + uint32_t flags = js->flags; + + static uint32 _maxbytes = 8L * 1024L * 1024L; + static size_t _stackChunkSize = 8192; + JSClass * _clasp = (JSClass *)&global_class; +#ifdef NOTYET + JSFunctionSpec * _functions = global_functions; +#endif + JSPrincipals * _principals = NULL; + + if (rpmjs_nopens++ == 0) { +#ifdef NOTYET /* XXX collides with ancient JS_NewRuntime */ + JS_Init(); +#endif + } + + I = (JSI_t) calloc(1, sizeof(*I)); +assert(I); + + I->rt = JS_NewRuntime(_maxbytes); +assert(I->rt); + JS_SetRuntimePrivate(I->rt, (void *)js); + + I->cx = JS_NewContext(I->rt, _stackChunkSize); +assert(I->cx); + JS_SetContextPrivate(I->cx, (void *)js); + + JS_SetOptions(I->cx, + JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_METHODJIT); + JS_SetVersion(I->cx, JSVERSION_LATEST); + JS_SetErrorReporter(I->cx, rpmjsReportError); + + I->global = JS_NewCompartmentAndGlobalObject(I->cx, + _clasp, _principals); + + return I; +} + +static int mozRun(rpmjs js, + const char * script, const char * filename, int lineno) +{ + JSI_t I = (JSI_t) js->I; + + JSClass * _clasp = (JSClass *)&global_class; +#ifdef NOTYET + JSFunctionSpec * _functions = global_functions; +#endif + JSPrincipals * _principals = NULL; + JSBool ok; + + jsval rval; + { // Scope for JSAutoCompartment + +#ifdef NOTYET + JSAutoEnterCompartment ac; + if (!ac.enter(I->cx, I->global)) + return 1; +#endif + + JS_InitStandardClasses(I->cx, I->global); + + ok = JS_EvaluateScript(I->cx, I->global, + script, strlen(script), filename, lineno, + &rval); + if (!ok) + return 1; + } + JSString *str = JS_ValueToString(I->cx, rval); + printf("%s\n", JS_EncodeString(I->cx, str)); + + return 0; +} + +static struct JSIO_s _mozjs185 = { mozFini, mozInit, mozRun }; +JSIO_t mozjs185 = &_mozjs185; + +/*==============================================================*/ +int main(int argc, const char *argv[]) +{ + int rc = 0; + + JSI_t I = (JSI_t) mozInit(js); + js->I = I; + + { + const char *script = "'hello'+'world, it is '+new Date()"; + const char *filename = "noname"; + int lineno = 1; + rc = mozRun(js, script, filename, lineno); + } + + mozFini(js); + + return rc; } @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmjs24.cpp ============================================================================ $ cvs diff -u -r1.1.2.2 -r1.1.2.3 rpmjs24.cpp --- rpm/rpmio/rpmjs24.cpp 22 Jun 2017 12:35:43 -0000 1.1.2.2 +++ rpm/rpmio/rpmjs24.cpp 22 Jun 2017 17:25:47 -0000 1.1.2.3 @@ -69,7 +69,7 @@ free(I); } -static JSI_t mozInit(rpmjs js) +static void * mozInit(rpmjs js) { JSI_t I = NULL; uint32_t flags = js->flags; @@ -94,52 +94,66 @@ return I; } -/*==============================================================*/ -static void rpmjsFini(void * _js) -{ - rpmjs js = (rpmjs) _js; +static int mozRun(rpmjs js, + const char * script, const char * filename, int lineno) +{ + JSI_t I = (JSI_t) js->I; - mozFini(js); - js->I = NULL; + JSClass * _clasp = (JSClass *)&global_class; +#ifdef NOTYET + JSFunctionSpec * _functions = global_functions; +#endif + JSPrincipals * _principals = NULL; + JSBool ok; + + // In practice, you would want to exit this any + // time you're spinning the event loop + JSAutoRequest ar(I->cx); + + JS::RootedObject global(I->cx, + JS_NewGlobalObject(I->cx, _clasp, _principals)); + if (!global) + return 1; + I->global = global; +assert(I->global); + JS_SetGlobalObject(I->cx, I->global); + + JS::RootedValue rval(I->cx); + { // Scope for JSAutoCompartment + JSAutoCompartment ac(I->cx, global); + JS_InitStandardClasses(I->cx, global); + + ok = JS_EvaluateScript(I->cx, global, + script, strlen(script), filename, lineno, + rval.address()); + if (!ok) + return 1; + } + JSString *str = rval.toString(); + printf("%s\n", JS_EncodeString(I->cx, str)); + + return 0; } +static struct JSIO_s _mozjs24 = { mozFini, mozInit, mozRun }; +JSIO_t mozjs24 = &_mozjs24; + /*==============================================================*/ int main(int argc, const char *argv[]) { - JSI_t I = mozInit(js); - js->I = I; + int rc = 0; - { // Scope for our various stack objects (JSAutoRequest, RootedObject), - // so they all go out of scope before we JS_DestroyContext. - - // In practice, you would want to exit this any - // time you're spinning the event loop - JSAutoRequest ar(I->cx); - - JS::RootedObject global(I->cx, JS_NewGlobalObject(I->cx, &global_class, nullptr)); - if (!global) - return 1; - I->global = global; - - JS::RootedValue rval(I->cx); - - { // Scope for JSAutoCompartment - JSAutoCompartment ac(I->cx, global); - JS_InitStandardClasses(I->cx, global); - - const char *script = "'hello'+'world, it is '+new Date()"; - const char *filename = "noname"; - int lineno = 1; - bool ok = JS_EvaluateScript(I->cx, global, script, strlen(script), filename, lineno, rval.address()); - if (!ok) - return 1; - } + JSI_t I = (JSI_t) mozInit(js); + js->I = I; - JSString *str = rval.toString(); - printf("%s\n", JS_EncodeString(I->cx, str)); + { + const char *script = "'hello'+'world, it is '+new Date()"; + const char *filename = "noname"; + int lineno = 1; + rc = mozRun(js, script, filename, lineno); } - rpmjsFini((void *)js); + mozFini(js); - return 0; + return rc; } @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmjs31.cpp ============================================================================ $ cvs diff -u -r1.1.2.2 -r1.1.2.3 rpmjs31.cpp --- rpm/rpmio/rpmjs31.cpp 22 Jun 2017 12:35:43 -0000 1.1.2.2 +++ rpm/rpmio/rpmjs31.cpp 22 Jun 2017 17:25:47 -0000 1.1.2.3 @@ -41,7 +41,7 @@ JSContext *cx; JSObject *global; }; - + static void rpmjsReportError(JSContext *cx, const char *message, JSErrorReport *report) { @@ -72,20 +72,20 @@ free(I); } -static JSI_t mozInit(rpmjs js) +static void * mozInit(rpmjs js) { JSI_t I = NULL; uint32_t flags = js->flags; - + static uint32_t _maxbytes = 8L * 1024L * 1024L; static size_t _stackChunkSize = 8192; - + if (rpmjs_nopens++ == 0) JS_Init(); I = (JSI_t) calloc(1, sizeof(*I)); assert(I); - + I->rt = JS_NewRuntime(_maxbytes, JS_USE_HELPER_THREADS); assert(I->rt); JS_SetRuntimePrivate(I->rt, (void *)js); @@ -97,52 +97,65 @@ return I; } -/*==============================================================*/ -static void rpmjsFini(void * _js) -{ - rpmjs js = (rpmjs) _js; +static int mozRun(rpmjs js, + const char * script, const char * filename, int lineno) +{ + JSI_t I = (JSI_t) js->I; - mozFini(js); - js->I = NULL; + JSClass * _clasp = (JSClass *)&global_class; +#ifdef NOTYET + JSFunctionSpec * _functions = global_functions; +#endif + JSPrincipals * _principals = NULL; + bool ok; + + // In practice, you would want to exit this any + // time you're spinning the event loop + JSAutoRequest ar(I->cx); + + JS::RootedObject global(I->cx, + JS_NewGlobalObject(I->cx, _clasp, _principals, JS::FireOnNewGlobalHook)); + if (!global) + return 1; + I->global = global; +assert(I->global); + + JS::RootedValue rval(I->cx); + { // Scope for JSAutoCompartment + JSAutoCompartment ac(I->cx, global); + JS_InitStandardClasses(I->cx, global); + + ok = JS_EvaluateScript(I->cx, global, + script, strlen(script), filename, lineno, + &rval); + if (!ok) + return 1; + } + JSString *str = rval.toString(); + printf("%s\n", JS_EncodeString(I->cx, str)); + + return 0; } +static struct JSIO_s _mozjs31 = { mozFini, mozInit, mozRun }; +JSIO_t mozjs31 = &_mozjs31; + /*==============================================================*/ int main(int argc, const char *argv[]) { - JSI_t I = mozInit(js); - js->I = I; + int rc = 0; - { // Scope for our various stack objects (JSAutoRequest, RootedObject), - // so they all go out of scope before we JS_DestroyContext. - - // In practice, you would want to exit this any - // time you're spinning the event loop - JSAutoRequest ar(I->cx); - - JS::RootedObject global(I->cx, JS_NewGlobalObject(I->cx, &global_class, nullptr, JS::FireOnNewGlobalHook)); - if (!global) - return 1; - I->global = global; - - JS::RootedValue rval(I->cx); - - { // Scope for JSAutoCompartment - JSAutoCompartment ac(I->cx, global); - JS_InitStandardClasses(I->cx, global); - - const char *script = "'hello'+'world, it is '+new Date()"; - const char *filename = "noname"; - int lineno = 1; - bool ok = JS_EvaluateScript(I->cx, global, script, strlen(script), filename, lineno, &rval); - if (!ok) - return 1; - } + JSI_t I = (JSI_t) mozInit(js); + js->I = I; - JSString *str = rval.toString(); - printf("%s\n", JS_EncodeString(I->cx, str)); + { + const char *script = "'hello'+'world, it is '+new Date()"; + const char *filename = "noname"; + int lineno = 1; + rc = mozRun(js, script, filename, lineno); } - rpmjsFini((void *)js); + mozFini(js); - return 0; + return rc; } @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmjs38.cpp ============================================================================ $ cvs diff -u -r1.1.2.2 -r1.1.2.3 rpmjs38.cpp --- rpm/rpmio/rpmjs38.cpp 22 Jun 2017 12:35:43 -0000 1.1.2.2 +++ rpm/rpmio/rpmjs38.cpp 22 Jun 2017 17:25:47 -0000 1.1.2.3 @@ -72,7 +72,7 @@ free(I); } -static JSI_t mozInit(rpmjs js) +static void * mozInit(rpmjs js) { JSI_t I = NULL; uint32_t flags = js->flags; @@ -97,54 +97,65 @@ return I; } -/*==============================================================*/ -static void rpmjsFini(void * _js) -{ - rpmjs js = (rpmjs) _js; +static int mozRun(rpmjs js, + const char * script, const char * filename, int lineno) +{ + JSI_t I = (JSI_t) js->I; - mozFini(js); - js->I = NULL; + JSClass * _clasp = (JSClass *)&global_class; +#ifdef NOTYET + JSFunctionSpec * _functions = global_functions; +#endif + JSPrincipals * _principals = NULL; + bool ok; + + // In practice, you would want to exit this any + // time you're spinning the event loop + JSAutoRequest ar(I->cx); + + JS::RootedObject global(I->cx, + JS_NewGlobalObject(I->cx, _clasp, _principals, JS::FireOnNewGlobalHook)); + if (!global) + return 1; + I->global = global; +assert(I->global); + + JS::RootedValue rval(I->cx); + { // Scope for JSAutoCompartment + JSAutoCompartment ac(I->cx, global); + JS_InitStandardClasses(I->cx, global); + + JS::CompileOptions opts(I->cx); + opts.setFileAndLine(filename, lineno); + ok = JS::Evaluate(I->cx, global, opts, script, strlen(script), &rval); + if (!ok) + return 1; + } + JSString *str = rval.toString(); + printf("%s\n", JS_EncodeString(I->cx, str)); + + return 0; } +static struct JSIO_s _mozjs38 = { mozFini, mozInit, mozRun }; +JSIO_t mozjs38 = &_mozjs38; + /*==============================================================*/ int main(int argc, const char *argv[]) { - JSI_t I = mozInit(js); - js->I = I; + int rc = 0; - { // Scope for our various stack objects (JSAutoRequest, RootedObject), - // so they all go out of scope before we JS_DestroyContext. - - // In practice, you would want to exit this any - // time you're spinning the event loop - JSAutoRequest ar(I->cx); - - JS::RootedObject global(I->cx, JS_NewGlobalObject(I->cx, &global_class, nullptr, JS::FireOnNewGlobalHook)); - if (!global) - return 1; - I->global = global; - - JS::RootedValue rval(I->cx); - - { // Scope for JSAutoCompartment - JSAutoCompartment ac(I->cx, global); - JS_InitStandardClasses(I->cx, global); - - const char *script = "'hello'+'world, it is '+new Date()"; - const char *filename = "noname"; - int lineno = 1; - JS::CompileOptions opts(I->cx); - opts.setFileAndLine(filename, lineno); - bool ok = JS::Evaluate(I->cx, global, opts, script, strlen(script), &rval); - if (!ok) - return 1; - } + JSI_t I = (JSI_t) mozInit(js); + js->I = I; - JSString *str = rval.toString(); - printf("%s\n", JS_EncodeString(I->cx, str)); + { + const char *script = "'hello'+'world, it is '+new Date()"; + const char *filename = "noname"; + int lineno = 1; + rc = mozRun(js, script, filename, lineno); } - rpmjsFini((void *)js); + mozFini(js); - return 0; + return rc; } @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmjs45.cpp ============================================================================ $ cvs diff -u -r1.1.2.2 -r1.1.2.3 rpmjs45.cpp --- rpm/rpmio/rpmjs45.cpp 22 Jun 2017 12:35:43 -0000 1.1.2.2 +++ rpm/rpmio/rpmjs45.cpp 22 Jun 2017 17:25:47 -0000 1.1.2.3 @@ -73,7 +73,7 @@ free(I); } -static JSI_t mozInit(rpmjs js) +static void * mozInit(rpmjs js) { JSI_t I = NULL; uint32_t flags = js->flags; @@ -98,54 +98,68 @@ return I; } -/*==============================================================*/ -static void rpmjsFini(void * _js) -{ - rpmjs js = (rpmjs) _js; +static int mozRun(rpmjs js, + const char * script, const char * filename, int lineno) +{ + JSI_t I = (JSI_t) js->I; - mozFini(js); - js->I = NULL; -} + JSClass * _clasp = (JSClass *)&global_class; +#ifdef NOTYET + JSFunctionSpec * _functions = global_functions; +#endif + JSPrincipals * _principals = NULL; + bool ok; + + // In practice, you would want to exit this any + // time you're spinning the event loop + JSAutoRequest ar(I->cx); + + JS::RootedObject global(I->cx, + JS_NewGlobalObject(I->cx, _clasp, _principals, JS::FireOnNewGlobalHook)); + if (!global) + return 1; + I->global = global; +assert(I->global); + + JS::RootedValue rval(I->cx); + + { // Scope for JSAutoCompartment + JSAutoCompartment ac(I->cx, global); + JS_InitStandardClasses(I->cx, global); + + JS::CompileOptions opts(I->cx); + opts.setFileAndLine(filename, lineno); + ok = JS::Evaluate(I->cx, opts, script, strlen(script), &rval); -/*==============================================================*/ -int main(int argc, const char *argv[]) -{ - JSI_t I = mozInit(js); - js->I = I; + if (!ok) + return 1; + } - { // Scope for our various stack objects (JSAutoRequest, RootedObject), - // so they all go out of scope before we JS_DestroyContext. + JSString *str = rval.toString(); + printf("%s\n", JS_EncodeString(I->cx, str)); - // In practice, you would want to exit this any - // time you're spinning the event loop - JSAutoRequest ar(I->cx); + return 0; +} - JS::RootedObject global(I->cx, JS_NewGlobalObject(I->cx, &global_class, nullptr, JS::FireOnNewGlobalHook)); - if (!global) - return 1; - I->global = global; +static struct JSIO_s _mozjs45 = { mozFini, mozInit, mozRun }; +JSIO_t mozjs45 = &_mozjs45; - JS::RootedValue rval(I->cx); +/*==============================================================*/ +int main(int argc, const char *argv[]) +{ + int rc = 0; - { // Scope for JSAutoCompartment - JSAutoCompartment ac(I->cx, global); - JS_InitStandardClasses(I->cx, global); - - const char *script = "'hello'+'world, it is '+new Date()"; - const char *filename = "noname"; - int lineno = 1; - JS::CompileOptions opts(I->cx); - opts.setFileAndLine(filename, lineno); - bool ok = JS::Evaluate(I->cx, opts, script, strlen(script), &rval); - if (!ok) - return 1; - } + JSI_t I = (JSI_t) mozInit(js); + js->I = I; - JSString *str = rval.toString(); - printf("%s\n", JS_EncodeString(I->cx, str)); + { + const char *script = "'hello'+'world, it is '+new Date()"; + const char *filename = "noname"; + int lineno = 1; + rc = mozRun(js, script, filename, lineno); } - rpmjsFini((void *)js); + mozFini(js); - return 0; + return rc; } @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository rpm-cvs@rpm5.org