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: 17-Apr-2009 14:41:57 Branch: HEAD Handle: 2009041712415501 Modified files: rpm CHANGES configure.ac devtool.conf rpm/build parseScript.c rpm/lib psm.c rpmds.c rpm/misc Makefile.am rpm/rpmio Makefile.am librpmio.vers macro.c poptIO.c rpmio.c rpmjs.c rpmjs.h Log: - js: wire-up %post -p <js>. much more todo++. - js: wire-up %{js:...}. much more todo++. Summary: Revision Changes Path 1.2941 +2 -0 rpm/CHANGES 2.72 +6 -0 rpm/build/parseScript.c 2.365 +2 -2 rpm/configure.ac 2.289 +1 -1 rpm/devtool.conf 2.364 +13 -2 rpm/lib/psm.c 2.151 +5 -0 rpm/lib/rpmds.c 1.46 +10 -8 rpm/misc/Makefile.am 1.225 +5 -4 rpm/rpmio/Makefile.am 2.108 +3 -0 rpm/rpmio/librpmio.vers 2.226 +29 -0 rpm/rpmio/macro.c 1.47 +3 -0 rpm/rpmio/poptIO.c 1.191 +7 -3 rpm/rpmio/rpmio.c 1.2 +324 -3 rpm/rpmio/rpmjs.c 1.2 +3 -1 rpm/rpmio/rpmjs.h ____________________________________________________________________________ patch -p0 <<'@@ .' Index: rpm/CHANGES ============================================================================ $ cvs diff -u -r1.2940 -r1.2941 CHANGES --- rpm/CHANGES 16 Apr 2009 20:26:42 -0000 1.2940 +++ rpm/CHANGES 17 Apr 2009 12:41:55 -0000 1.2941 @@ -1,5 +1,7 @@ 5.2a4 -> 5.2b1: + - jbj: js: wire-up %post -p <js>. much more todo++. + - jbj: js: wire-up %{js:...}. much more todo++. - jbj: js: stub-in a javascript interpreter wrapper. - jbj: tcl: load and use $argv and $argc. - jbj: tcl: fix: don't append multiple newlines. @@ . patch -p0 <<'@@ .' Index: rpm/build/parseScript.c ============================================================================ $ cvs diff -u -r2.71 -r2.72 parseScript.c --- rpm/build/parseScript.c 16 Apr 2009 04:04:45 -0000 2.71 +++ rpm/build/parseScript.c 17 Apr 2009 12:41:55 -0000 2.72 @@ -313,6 +313,12 @@ "BuiltinLuaScripts", "4.2.2-1"); } else #endif +#ifdef WITH_JS + if (!strcmp(progArgv[0], "<js>")) { + (void) rpmlibNeedsFeature(pkg->header, + "BuiltinJavaScript", "5.2-1"); + } else +#endif #ifdef WITH_PERLEMBED if (!strcmp(progArgv[0], "<perl>")) { (void) rpmlibNeedsFeature(pkg->header, @@ . patch -p0 <<'@@ .' Index: rpm/configure.ac ============================================================================ $ cvs diff -u -r2.364 -r2.365 configure.ac --- rpm/configure.ac 16 Apr 2009 20:26:42 -0000 2.364 +++ rpm/configure.ac 17 Apr 2009 12:41:55 -0000 2.365 @@ -1274,9 +1274,9 @@ dnl # JavaScript RPM_CHECK_LIB( - [JavaScript], [javascript], + [JavaScript], [js], [js], [JS_NewContext], [jsstddef.h], - [no,internal:none], [js:src/Linux_All_DBG.OBJ], + [no,internal:none], [js/src:Linux_All_DBG.OBJ], [ if test ".$RPM_CHECK_LIB_LOCATION" = .internal; then AC_DEFINE(HAVE_JSSTDDEF_H, 1, [Define to 1 if you have <jsstddef.h>]) AC_DEFINE(HAVE_LIBJS, 1, [Define to 1 if you have the 'js' library (-ljs).]) @@ . patch -p0 <<'@@ .' Index: rpm/devtool.conf ============================================================================ $ cvs diff -u -r2.288 -r2.289 devtool.conf --- rpm/devtool.conf 16 Apr 2009 20:26:42 -0000 2.288 +++ rpm/devtool.conf 17 Apr 2009 12:41:55 -0000 2.289 @@ -97,7 +97,7 @@ --with-perl \ --with-perlembed=/usr/lib/perl5/5.10.0/i386-linux-thread-multi/CORE \ --with-rubyembed=/usr/lib/ruby/1.8/i386-linux \ - --with-javascript=internal \ + --with-js=internal \ --with-build-extlibdep \ --with-build-maxextlibdep \ --enable-build-pic \ @@ . patch -p0 <<'@@ .' Index: rpm/lib/psm.c ============================================================================ $ cvs diff -u -r2.363 -r2.364 psm.c --- rpm/lib/psm.c 16 Apr 2009 18:28:32 -0000 2.363 +++ rpm/lib/psm.c 17 Apr 2009 12:41:56 -0000 2.364 @@ -11,11 +11,13 @@ #include <rpmcb.h> /* XXX fnpyKey */ #include <rpmmacro.h> #include <rpmurl.h> +#include <rpmjs.h> #include <rpmlua.h> #include <rpmperl.h> #include <rpmpython.h> #include <rpmruby.h> #include <rpmtcl.h> + #include <rpmtag.h> #include <rpmtypes.h> #include <rpmlib.h> @@ -558,7 +560,7 @@ } #endif /* WITH_LUA */ -#if defined(WITH_LUA) || defined(WITH_TCL) || defined(WITH_PERLEMBED) || defined(WITH_PYTHONEMBED) || defined(WITH_RUBYEMBED) +#if defined(WITH_LUA) || defined(WITH_JS) || defined(WITH_PERLEMBED) || defined(WITH_PYTHONEMBED) || defined(WITH_RUBYEMBED) || defined(WITH_TCL) static int enterChroot(rpmpsm psm, int * fdnop) /*...@globals fileSystem, internalState @*/ /*...@modifies *fdnop, fileSystem, internalState @*/ @@ -653,6 +655,14 @@ rc = runLuaScript(psm, sln, Phe, script, arg1, arg2); } else #endif +#if defined(WITH_JS) + if (!strcmp(Phe->p.argv[0], "<js>")) { + rpmjs js = rpmjsNew((const char **)av, 0); + rc = rpmjsRun(js, script, NULL) == RPMRC_OK + ? RPMRC_OK : RPMRC_FAIL; + js = rpmjsFree(js); + } else +#endif #if defined(WITH_PERLEMBED) if (!strcmp(Phe->p.argv[0], "<perl>")) { rpmperl perl = rpmperlNew((const char **)av, 0); @@ -772,12 +782,13 @@ if (Phe->p.argv && Phe->p.argv[0]) if (!strcmp(Phe->p.argv[0], "<lua>") + || !strcmp(Phe->p.argv[0], "<js>") || !strcmp(Phe->p.argv[0], "<perl>") || !strcmp(Phe->p.argv[0], "<python>") || !strcmp(Phe->p.argv[0], "<ruby>") || !strcmp(Phe->p.argv[0], "<tcl>")) { -#if defined(WITH_LUA) || defined(WITH_TCL) || defined(WITH_PERLEMBED) || defined(WITH_PYTHONEMBED) || defined(WITH_RUBY) +#if defined(WITH_LUA) || defined(WITH_JS) || defined(WITH_PERLEMBED) || defined(WITH_PYTHONEMBED) || defined(WITH_RUBY) || defined(WITH_TCL) rpmlog(RPMLOG_DEBUG, D_("%s: %s(%s) running %s scriptlet.\n"), psm->stepName, tag2sln(psm->scriptTag), NVRA, Phe->p.argv[0]); @@ . patch -p0 <<'@@ .' Index: rpm/lib/rpmds.c ============================================================================ $ cvs diff -u -r2.150 -r2.151 rpmds.c --- rpm/lib/rpmds.c 16 Apr 2009 04:04:45 -0000 2.150 +++ rpm/lib/rpmds.c 17 Apr 2009 12:41:56 -0000 2.151 @@ -1474,6 +1474,11 @@ ( RPMSENSE_EQUAL), N_("internal embedded lua scripts.") }, #endif +#if defined(WITH_JS) + { "rpmlib(BuiltinJavaScript)", "5.2-1", + ( RPMSENSE_EQUAL), + N_("internal embedded JavaScript.") }, +#endif #if defined(WITH_PERLEMBED) { "rpmlib(BuiltinPerlScripts)", "5.2-1", ( RPMSENSE_EQUAL), @@ . patch -p0 <<'@@ .' Index: rpm/misc/Makefile.am ============================================================================ $ cvs diff -u -r1.45 -r1.46 Makefile.am --- rpm/misc/Makefile.am 13 Apr 2009 18:31:55 -0000 1.45 +++ rpm/misc/Makefile.am 17 Apr 2009 12:41:56 -0000 1.46 @@ -32,23 +32,25 @@ endif librpmmisc_la_LDFLAGS += \ @WITH_DB_LDFLAGS@ \ - @WITH_ZLIB_LDFLAGS@ \ - @WITH_XZ_LDFLAGS@ \ - @WITH_LUA_LDFLAGS@ \ @WITH_FILE_LDFLAGS@ \ + @WITH_JS_LDFLAGS@/Linux_All_DBG.OBJ \ + @WITH_LUA_LDFLAGS@ \ @WITH_PCRE_LDFLAGS@ \ @WITH_SYCK_LDFLAGS@ \ - @WITH_XAR_LDFLAGS@ + @WITH_XAR_LDFLAGS@ \ + @WITH_XZ_LDFLAGS@ \ + @WITH_ZLIB_LDFLAGS@ librpmmisc_la_LIBADD = \ @ALLOCA@ \ @WITH_DB_LIBS@ \ - @WITH_ZLIB_LIBS@ \ - @WITH_XZ_LIBS@ \ - @WITH_LUA_LIBS@ \ @WITH_FILE_LIBS@ \ + @WITH_JS_LIBS@ \ + @WITH_LUA_LIBS@ \ @WITH_PCRE_LIBS@ \ @WITH_SYCK_LIBS@ \ - @WITH_XAR_LIBS@ + @WITH_XAR_LIBS@ \ + @WITH_XZ_LIBS@ \ + @WITH_ZLIB_LIBS@ if ENABLE_BUILD_EXTLIBDEP librpmmisc_la_LDFLAGS += $(LDFLAGS) librpmmisc_la_LIBADD += $(LIBS) @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/Makefile.am ============================================================================ $ cvs diff -u -r1.224 -r1.225 Makefile.am --- rpm/rpmio/Makefile.am 16 Apr 2009 20:26:43 -0000 1.224 +++ rpm/rpmio/Makefile.am 17 Apr 2009 12:41:56 -0000 1.225 @@ -38,13 +38,14 @@ -I$(top_srcdir)/rpmio \ -I$(top_srcdir)/misc \ @WITH_DB_CPPFLAGS@ \ - @WITH_ZLIB_CPPFLAGS@ \ - @WITH_LUA_CPPFLAGS@ \ @WITH_FILE_CPPFLAGS@ \ - @WITH_SYCK_CPPFLAGS@ \ + @WITH_JS_CPPFLAGS@ \ + @WITH_LUA_CPPFLAGS@ \ @WITH_PCRE_CPPFLAGS@ \ + @WITH_SYCK_CPPFLAGS@ \ @WITH_XAR_CPPFLAGS@ \ - @WITH_XZ_CPPFLAGS@ + @WITH_XZ_CPPFLAGS@ \ + @WITH_ZLIB_CPPFLAGS@ RPMIO_LDADD_COMMON = \ librpmio.la \ @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/librpmio.vers ============================================================================ $ cvs diff -u -r2.107 -r2.108 librpmio.vers --- rpm/rpmio/librpmio.vers 8 Apr 2009 17:31:56 -0000 2.107 +++ rpm/rpmio/librpmio.vers 17 Apr 2009 12:41:56 -0000 2.108 @@ -321,6 +321,9 @@ rpmioPutPool; rpmioRootDir; rpmioUnlinkPoolItem; + _rpmjs_debug; + rpmjsNew; + rpmjsRun; rpmKeyringAddKey; rpmKeyringFindKeyid; rpmKeyringFree; @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/macro.c ============================================================================ $ cvs diff -u -r2.225 -r2.226 macro.c --- rpm/rpmio/macro.c 16 Apr 2009 04:04:46 -0000 2.225 +++ rpm/rpmio/macro.c 17 Apr 2009 12:41:56 -0000 2.226 @@ -70,6 +70,7 @@ #include <rpmlua.h> #endif +#include <rpmjs.h> #include <rpmperl.h> #include <rpmpython.h> #include <rpmruby.h> @@ -1878,6 +1879,34 @@ } #endif +#ifdef WITH_JS + if (STREQ("js", f, fn)) { + const char ** av = NULL; + char * script = parseEmbedded(s, (size_t)(se-s), &av); + rpmjs js = rpmjsNew(av, _globalI); + const char * result = NULL; + + if (rpmjsRun(js, script, &result) != RPMRC_OK) + rc = 1; + else { + if (result == NULL) result = "FIXME"; + if (result != NULL && *result != '\0') { + size_t len = strlen(result); + if (len > mb->nb) + len = mb->nb; + memcpy(mb->t, result, len); + mb->t += len; + mb->nb -= len; + } + } + js = rpmjsFree(js); + av = _free(av); + script = _free(script); + s = se; + continue; + } +#endif + #ifdef WITH_PERLEMBED if (STREQ("perl", f, fn)) { const char ** av = NULL; @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/poptIO.c ============================================================================ $ cvs diff -u -r1.46 -r1.47 poptIO.c --- rpm/rpmio/poptIO.c 15 Apr 2009 18:41:30 -0000 1.46 +++ rpm/rpmio/poptIO.c 17 Apr 2009 12:41:56 -0000 1.47 @@ -25,6 +25,7 @@ #include <rpmssl.h> #endif +#include <rpmjs.h> #include <rpmperl.h> #include <rpmpython.h> #include <rpmruby.h> @@ -412,6 +413,8 @@ N_("Debug rpmio I/O"), NULL}, { "rpmiobdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmiob_debug, -1, N_("Debug rpmio I/O buffers"), NULL}, + { "rpmjsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmjs_debug, -1, + N_("Debug embedded JavaScript interpreter"), NULL}, #ifdef WITH_LUA { "rpmluadebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmlua_debug, -1, N_("Debug embedded Lua interpreter"), NULL}, @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmio.c ============================================================================ $ cvs diff -u -r1.190 -r1.191 rpmio.c --- rpm/rpmio/rpmio.c 15 Apr 2009 18:41:30 -0000 1.190 +++ rpm/rpmio/rpmio.c 17 Apr 2009 12:41:56 -0000 1.191 @@ -65,6 +65,7 @@ #include <rpmiotypes.h> #include <rpmmacro.h> /* XXX rpmioAccess needs rpmCleanPath() */ #include <rpmlua.h> /* XXX rpmioClean() calls rpmluaFree() */ +#include <rpmjs.h> #include <rpmperl.h> #include <rpmpython.h> #include <rpmruby.h> @@ -3133,10 +3134,11 @@ extern rpmioPool _rpmmgPool; extern rpmioPool _rpmluavPool; extern rpmioPool _rpmluaPool; - extern rpmioPool _rpmtclPool; + extern rpmioPool _rpmjsPool; extern rpmioPool _rpmperlPool; extern rpmioPool _rpmpythonPool; extern rpmioPool _rpmrubyPool; + extern rpmioPool _rpmtclPool; /*...@=nestedextern@*/ #if defined(WITH_LUA) @@ -3153,14 +3155,16 @@ #endif urlFreeCache(); + _rpmtclI = rpmtclFree(_rpmtclI); + _rpmtclPool = rpmioFreePool(_rpmtclPool); _rpmrubyI = rpmrubyFree(_rpmrubyI); _rpmrubyPool = rpmioFreePool(_rpmrubyPool); _rpmpythonI = rpmpythonFree(_rpmpythonI); _rpmpythonPool = rpmioFreePool(_rpmpythonPool); _rpmperlI = rpmperlFree(_rpmperlI); _rpmperlPool = rpmioFreePool(_rpmperlPool); - _rpmtclI = rpmtclFree(_rpmtclI); - _rpmtclPool = rpmioFreePool(_rpmtclPool); + _rpmjsI = rpmperlFree(_rpmjsI); + _rpmjsPool = rpmioFreePool(_rpmjsPool); _rpmluavPool = rpmioFreePool(_rpmluavPool); _rpmluaPool = rpmioFreePool(_rpmluaPool); _mirePool = rpmioFreePool(_mirePool); @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmjs.c ============================================================================ $ cvs diff -u -r1.1 -r1.2 rpmjs.c --- rpm/rpmio/rpmjs.c 16 Apr 2009 20:26:43 -0000 1.1 +++ rpm/rpmio/rpmjs.c 17 Apr 2009 12:41:56 -0000 1.2 @@ -3,7 +3,26 @@ #include <argv.h> #ifdef WITH_JS -#include <js.h> +#define XP_UNIX 1 +#include "jsstddef.h" +#include "jstypes.h" +#include "jsarena.h" +#include "jsutil.h" +#include "jsprf.h" +#include "jsapi.h" +#include "jsarray.h" +#include "jsatom.h" +#include "jscntxt.h" +#include "jsdbgapi.h" +#include "jsemit.h" +#include "jsfun.h" +#include "jsgc.h" +#include "jslock.h" +#include "jsnum.h" +#include "jsobj.h" +#include "jsparse.h" +#include "jsscope.h" +#include "jsscript.h" #endif #define _RPMJS_INTERNAL #include "rpmjs.h" @@ -11,11 +30,273 @@ #include "debug.h" /*...@unchecked@*/ -int _rpmjs_debug = 0; +int _rpmjs_debug = 1; /*...@unchecked@*/ /*...@relnull@*/ rpmjs _rpmjsI = NULL; +#if defined(WITH_JS) + +typedef enum JSShellExitCode { + EXITCODE_RUNTIME_ERROR = 3, + EXITCODE_FILE_NOT_FOUND = 4, + EXITCODE_OUT_OF_MEMORY = 5 +} JSShellExitCode; + +static size_t gStackChunkSize = 8192; +static size_t gMaxStackSize = 500000; +static jsuword gStackBase; +static size_t gScriptStackQuota = JS_DEFAULT_SCRIPT_STACK_QUOTA; +static JSBool gEnableBranchCallback = JS_FALSE; +static uint32 gBranchCount; +static uint32 gBranchLimit; +static int gExitCode = 0; + +static FILE *gErrFile = NULL; +static FILE *gOutFile = NULL; + +static JSBool reportWarnings = JS_TRUE; + +/* We use a mix of JS_FS and JS_FN to test both kinds of natives. */ +static JSFunctionSpec shell_functions[] = { + JS_FS_END +}; + +static JSBool +global_enumerate(JSContext *cx, JSObject *obj) +{ +#ifdef LAZY_STANDARD_CLASSES + return JS_EnumerateStandardClasses(cx, obj); +#else + return JS_TRUE; +#endif +} + +static JSBool +global_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, + JSObject **objp) +{ +#ifdef LAZY_STANDARD_CLASSES + if ((flags & JSRESOLVE_ASSIGNING) == 0) { + JSBool resolved; + + if (!JS_ResolveStandardClass(cx, obj, id, &resolved)) + return JS_FALSE; + if (resolved) { + *objp = obj; + return JS_TRUE; + } + } +#endif + +#if defined(SHELL_HACK) && defined(DEBUG) && defined(XP_UNIX) + if ((flags & (JSRESOLVE_QUALIFIED | JSRESOLVE_ASSIGNING)) == 0) { + /* + * Do this expensive hack only for unoptimized Unix builds, which are + * not used for benchmarking. + */ + char *path, *comp, *full; + const char *name; + JSBool ok, found; + JSFunction *fun; + + if (!JSVAL_IS_STRING(id)) + return JS_TRUE; + path = getenv("PATH"); + if (!path) + return JS_TRUE; + path = JS_strdup(cx, path); + if (!path) + return JS_FALSE; + name = JS_GetStringBytes(JSVAL_TO_STRING(id)); + ok = JS_TRUE; + for (comp = strtok(path, ":"); comp; comp = strtok(NULL, ":")) { + if (*comp != '\0') { + full = JS_smprintf("%s/%s", comp, name); + if (!full) { + JS_ReportOutOfMemory(cx); + ok = JS_FALSE; + break; + } + } else { + full = (char *)name; + } + found = (access(full, X_OK) == 0); + if (*comp != '\0') + free(full); + if (found) { + fun = JS_DefineFunction(cx, obj, name, Exec, 0, + JSPROP_ENUMERATE); + ok = (fun != NULL); + if (ok) + *objp = obj; + break; + } + } + JS_free(cx, path); + return ok; + } +#else + return JS_TRUE; +#endif +} + +JSClass global_class = { + "global", JSCLASS_NEW_RESOLVE | JSCLASS_GLOBAL_FLAGS, + JS_PropertyStub, JS_PropertyStub, + JS_PropertyStub, JS_PropertyStub, + global_enumerate, (JSResolveOp) global_resolve, + JS_ConvertStub, JS_FinalizeStub, + JSCLASS_NO_OPTIONAL_MEMBERS +}; + +static void +my_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report) +{ + int i, j, k, n; + char *prefix, *tmp; + const char *ctmp; + + if (!report) { + fprintf(gErrFile, "%s\n", message); + return; + } + + /* Conditionally ignore reported warnings. */ + if (JSREPORT_IS_WARNING(report->flags) && !reportWarnings) + return; + + prefix = NULL; + if (report->filename) + prefix = JS_smprintf("%s:", report->filename); + if (report->lineno) { + tmp = prefix; + prefix = JS_smprintf("%s%u: ", tmp ? tmp : "", report->lineno); + JS_free(cx, tmp); + } + if (JSREPORT_IS_WARNING(report->flags)) { + tmp = prefix; + prefix = JS_smprintf("%s%swarning: ", + tmp ? tmp : "", + JSREPORT_IS_STRICT(report->flags) ? "strict " : ""); + JS_free(cx, tmp); + } + + /* embedded newlines -- argh! */ + while ((ctmp = strchr(message, '\n')) != 0) { + ctmp++; + if (prefix) + fputs(prefix, gErrFile); + fwrite(message, 1, ctmp - message, gErrFile); + message = ctmp; + } + + /* If there were no filename or lineno, the prefix might be empty */ + if (prefix) + fputs(prefix, gErrFile); + fputs(message, gErrFile); + + if (!report->linebuf) { + fputc('\n', gErrFile); + goto out; + } + + /* report->linebuf usually ends with a newline. */ + n = strlen(report->linebuf); + fprintf(gErrFile, ":\n%s%s%s%s", + prefix, + report->linebuf, + (n > 0 && report->linebuf[n-1] == '\n') ? "" : "\n", + prefix); + n = PTRDIFF(report->tokenptr, report->linebuf, char); + for (i = j = 0; i < n; i++) { + if (report->linebuf[i] == '\t') { + for (k = (j + 8) & ~7; j < k; j++) { + fputc('.', gErrFile); + } + continue; + } + fputc('.', gErrFile); + j++; + } + fputs("^\n", gErrFile); + out: + if (!JSREPORT_IS_WARNING(report->flags)) { + if (report->errorNumber == JSMSG_OUT_OF_MEMORY) { + gExitCode = EXITCODE_OUT_OF_MEMORY; + } else { + gExitCode = EXITCODE_RUNTIME_ERROR; + } + } + JS_free(cx, prefix); +} + +static JSBool +my_BranchCallback(JSContext *cx, JSScript *script) +{ + if (++gBranchCount == gBranchLimit) { + if (script) { + if (script->filename) + fprintf(gErrFile, "%s:", script->filename); + fprintf(gErrFile, "%u: script branch callback (%u callbacks)\n", + script->lineno, gBranchLimit); + } else { + fprintf(gErrFile, "native branch callback (%u callbacks)\n", + gBranchLimit); + } + gBranchCount = 0; + return JS_FALSE; + } +#ifdef JS_THREADSAFE + if ((gBranchCount & 0xff) == 1) { +#endif + if ((gBranchCount & 0x3fff) == 1) + JS_MaybeGC(cx); +#ifdef JS_THREADSAFE + else + JS_YieldRequest(cx); + } +#endif + return JS_TRUE; +} + +static void +SetContextOptions(JSContext *cx) +{ + jsuword stackLimit; + + if (gMaxStackSize == 0) { + /* + * Disable checking for stack overflow if limit is zero. + */ + stackLimit = 0; + } else { +#if JS_STACK_GROWTH_DIRECTION > 0 + stackLimit = gStackBase + gMaxStackSize; +#else + stackLimit = gStackBase - gMaxStackSize; +#endif + } + JS_SetThreadStackLimit(cx, stackLimit); + JS_SetScriptStackQuota(cx, gScriptStackQuota); + if (gEnableBranchCallback) { + JS_SetBranchCallback(cx, my_BranchCallback); + JS_ToggleOptions(cx, JSOPTION_NATIVE_BRANCH_CALLBACK); + } +} + +static JSBool +ContextCallback(JSContext *cx, uintN contextOp) +{ + if (contextOp == JSCONTEXT_NEW) { + JS_SetErrorReporter(cx, my_ErrorReporter); + JS_SetVersion(cx, JSVERSION_LATEST); + SetContextOptions(cx); + } + return JS_TRUE; +} +#endif + static void rpmjsFini(void * _js) /*...@globals fileSystem @*/ /*...@modifies *_js, fileSystem @*/ @@ -23,8 +304,10 @@ rpmjs js = _js; #if defined(WITH_JS) + JS_DestroyContext((JSContext *)js->cx); js->cx = NULL; + JS_DestroyRuntime((JSRuntime *)js->rt); js->rt = NULL; + JS_ShutDown(); #endif - js->I = NULL; } /*...@unchecked@*/ /*...@only@*/ /*...@null@*/ @@ -49,7 +332,45 @@ rpmjs js = rpmjsGetPool(_rpmjsPool); #if defined(WITH_JS) + int stackDummy; static const char * _av[] = { "rpmjs", NULL }; + JSRuntime *rt; + JSContext *cx; + JSObject *glob, *it, *envobj; + int result; + int ac; + + if (av == NULL) av = _av; + ac = argvCount(av); + + gStackBase = (jsuword)&stackDummy; + + if (gErrFile == NULL) gErrFile = stderr; + if (gOutFile == NULL) gOutFile = stdout; + + rt = JS_NewRuntime(64L * 1024L * 1024L); + JS_SetContextCallback(rt, ContextCallback); + js->rt = rt; + + cx = JS_NewContext(rt, gStackChunkSize); + js->cx = cx; + + glob = JS_NewObject(cx, &global_class, NULL, NULL); + JS_SetGlobalObject(cx, glob); + JS_DefineFunctions(cx, glob, shell_functions); + js->glob = glob; + +#ifdef NOTYET + it = JS_DefineObject(cx, glob, "it", &its_class, NULL, 0); + JS_DefineProperties(cx, it, its_props); + JS_DefineFunctions(cx, it, its_methods); + + envobj = JS_DefineObject(cx, glob, "environment", &env_class, NULL, 0); + JS_SetPrivate(cx, envobj, envp); + + result = ProcessArgs(cx, glob, av, ac); +#endif /* NOTYET */ + #endif return rpmjsLink(js); @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmjs.h ============================================================================ $ cvs diff -u -r1.1 -r1.2 rpmjs.h --- rpm/rpmio/rpmjs.h 16 Apr 2009 20:26:43 -0000 1.1 +++ rpm/rpmio/rpmjs.h 17 Apr 2009 12:41:56 -0000 1.2 @@ -19,7 +19,9 @@ #if defined(_RPMJS_INTERNAL) struct rpmjs_s { struct rpmioItem_s _item; /*!< usage mutex and pool identifier. */ - void * I; + void * rt; + void * cx; + void * glob; }; #endif /* _RPMJS_INTERNAL */ @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository rpm-cvs@rpm5.org