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 14:35:43
  Branch: rpm-5_4                          Handle: 2017062212354300

  Modified files:           (Branch: rpm-5_4)
    rpm/rpmio               rpmjs24.cpp rpmjs31.cpp rpmjs38.cpp rpmjs45.cpp

  Log:
    - rpmjs: WIP.

  Summary:
    Revision    Changes     Path
    1.1.2.2     +121 -37    rpm/rpmio/rpmjs24.cpp
    1.1.2.2     +118 -38    rpm/rpmio/rpmjs31.cpp
    1.1.2.2     +120 -40    rpm/rpmio/rpmjs38.cpp
    1.1.2.2     +120 -40    rpm/rpmio/rpmjs45.cpp
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmjs24.cpp
  ============================================================================
  $ cvs diff -u -r1.1.2.1 -r1.1.2.2 rpmjs24.cpp
  --- rpm/rpmio/rpmjs24.cpp     21 Jun 2017 17:26:24 -0000      1.1.2.1
  +++ rpm/rpmio/rpmjs24.cpp     22 Jun 2017 12:35:43 -0000      1.1.2.2
  @@ -1,7 +1,17 @@
  -// following code might be needed in some case
  +// 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 = {
  @@ -16,46 +26,120 @@
       JS_ConvertStub,
   };
   
  +#define      JS_Init()
  +
  +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 JSI_t 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);
  +
  +    I->cx = JS_NewContext(I->rt, _stackChunkSize);
  +assert(I->cx);
  +    JS_SetContextPrivate(I->cx, (void *)js);
  +
  +    return I;
  +}
  +
  +/*==============================================================*/
  +static void rpmjsFini(void * _js)
  +{                               
  +    rpmjs js = (rpmjs) _js;
  +
  +    mozFini(js);
  +    js->I = NULL;
  +}
  +
  +/*==============================================================*/
   int main(int argc, const char *argv[])
   {
  -    JSRuntime *rt = JS_NewRuntime(8L * 1024 * 1024, JS_USE_HELPER_THREADS);
  -    if (!rt)
  -        return 1;
  -
  -    JSContext *cx = JS_NewContext(rt, 8192);
  -    if (!cx)
  -        return 1;
  -
  -    { // Scope for our various stack objects (JSAutoRequest, RootedObject), 
so they all go
  -      // out of scope before we JS_DestroyContext.
  -
  -      JSAutoRequest ar(cx); // In practice, you would want to exit this any
  -                            // time you're spinning the event loop
  -
  -      JS::RootedObject global(cx, JS_NewGlobalObject(cx, &global_class, 
nullptr));
  -      if (!global)
  -          return 1;
  -
  -      JS::RootedValue rval(cx);
  -
  -      { // Scope for JSAutoCompartment
  -        JSAutoCompartment ac(cx, global);
  -        JS_InitStandardClasses(cx, global);
  -
  -        const char *script = "'hello'+'world, it is '+new Date()";
  -        const char *filename = "noname";
  -        int lineno = 1;
  -        bool ok = JS_EvaluateScript(cx, global, script, strlen(script), 
filename, lineno, rval.address());
  -        if (!ok)
  -          return 1;
  -      }
  +    JSI_t I = mozInit(js);
  +    js->I = I;
   
  -      JSString *str = rval.toString();
  -      printf("%s\n", JS_EncodeString(cx, str));
  +    {        // 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;
  +     }
  +
  +     JSString *str = rval.toString();
  +     printf("%s\n", JS_EncodeString(I->cx, str));
       }
   
  -    JS_DestroyContext(cx);
  -    JS_DestroyRuntime(rt);
  -    JS_ShutDown();
  +    rpmjsFini((void *)js);
  +
       return 0;
   }
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmjs31.cpp
  ============================================================================
  $ cvs diff -u -r1.1.2.1 -r1.1.2.2 rpmjs31.cpp
  --- rpm/rpmio/rpmjs31.cpp     21 Jun 2017 17:26:24 -0000      1.1.2.1
  +++ rpm/rpmio/rpmjs31.cpp     22 Jun 2017 12:35:43 -0000      1.1.2.2
  @@ -1,7 +1,17 @@
  -// following code might be needed in some case
  +// 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 = {
  @@ -21,48 +31,118 @@
       JS_GlobalObjectTraceHook
   };
   
  +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 JSI_t 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);
  +
  +    I->cx = JS_NewContext(I->rt, _stackChunkSize);
  +assert(I->cx);
  +    JS_SetContextPrivate(I->cx, (void *)js);
  +
  +    return I;
  +}
  +
  +/*==============================================================*/
  +static void rpmjsFini(void * _js)
  +{                               
  +    rpmjs js = (rpmjs) _js;
  +
  +    mozFini(js);
  +    js->I = NULL;
  +}
  +
  +/*==============================================================*/
   int main(int argc, const char *argv[])
   {
  -    JS_Init();
  +    JSI_t I = mozInit(js);
  +    js->I = I;
   
  -    JSRuntime *rt = JS_NewRuntime(8L * 1024 * 1024, JS_USE_HELPER_THREADS);
  -    if (!rt)
  -        return 1;
  -
  -    JSContext *cx = JS_NewContext(rt, 8192);
  -    if (!cx)
  -        return 1;
  -
  -    { // Scope for our various stack objects (JSAutoRequest, RootedObject), 
so they all go
  -      // out of scope before we JS_DestroyContext.
  -
  -      JSAutoRequest ar(cx); // In practice, you would want to exit this any
  -                            // time you're spinning the event loop
  -
  -      JS::RootedObject global(cx, JS_NewGlobalObject(cx, &global_class, 
nullptr, JS::FireOnNewGlobalHook));
  -      if (!global)
  -          return 1;
  -
  -      JS::RootedValue rval(cx);
  -
  -      { // Scope for JSAutoCompartment
  -        JSAutoCompartment ac(cx, global);
  -        JS_InitStandardClasses(cx, global);
  -
  -        const char *script = "'hello'+'world, it is '+new Date()";
  -        const char *filename = "noname";
  -        int lineno = 1;
  -        bool ok = JS_EvaluateScript(cx, global, script, strlen(script), 
filename, lineno, &rval);
  -        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(cx, str));
  +     // 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;
  +     }
  +
  +     JSString *str = rval.toString();
  +     printf("%s\n", JS_EncodeString(I->cx, str));
       }
   
  -    JS_DestroyContext(cx);
  -    JS_DestroyRuntime(rt);
  -    JS_ShutDown();
  +    rpmjsFini((void *)js);
  +
       return 0;
   }
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmjs38.cpp
  ============================================================================
  $ cvs diff -u -r1.1.2.1 -r1.1.2.2 rpmjs38.cpp
  --- rpm/rpmio/rpmjs38.cpp     21 Jun 2017 17:26:24 -0000      1.1.2.1
  +++ rpm/rpmio/rpmjs38.cpp     22 Jun 2017 12:35:43 -0000      1.1.2.2
  @@ -1,7 +1,17 @@
  -// following code might be needed in some case
  +// 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 = {
  @@ -21,50 +31,120 @@
       JS_GlobalObjectTraceHook
   };
   
  +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 JSI_t 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);
  +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 void rpmjsFini(void * _js)
  +{                               
  +    rpmjs js = (rpmjs) _js;
  +
  +    mozFini(js);
  +    js->I = NULL;
  +}
  +
  +/*==============================================================*/
   int main(int argc, const char *argv[])
   {
  -    JS_Init();
  +    JSI_t I = mozInit(js);
  +    js->I = I;
  +
  +    {        // Scope for our various stack objects (JSAutoRequest, 
RootedObject),
  +     // so they all go out of scope before we JS_DestroyContext.
   
  -    JSRuntime *rt = JS_NewRuntime(8L * 1024 * 1024);
  -    if (!rt)
  -        return 1;
  -
  -    JSContext *cx = JS_NewContext(rt, 8192);
  -    if (!cx)
  -        return 1;
  -
  -    { // Scope for our various stack objects (JSAutoRequest, RootedObject), 
so they all go
  -      // out of scope before we JS_DestroyContext.
  -
  -      JSAutoRequest ar(cx); // In practice, you would want to exit this any
  -                            // time you're spinning the event loop
  -
  -      JS::RootedObject global(cx, JS_NewGlobalObject(cx, &global_class, 
nullptr, JS::FireOnNewGlobalHook));
  -      if (!global)
  -          return 1;
  -
  -      JS::RootedValue rval(cx);
  -
  -      { // Scope for JSAutoCompartment
  -        JSAutoCompartment ac(cx, global);
  -        JS_InitStandardClasses(cx, global);
  -
  -        const char *script = "'hello'+'world, it is '+new Date()";
  -        const char *filename = "noname";
  -        int lineno = 1;
  -        JS::CompileOptions opts(cx);
  -        opts.setFileAndLine(filename, lineno);
  -        bool ok = JS::Evaluate(cx, global, opts, script, strlen(script), 
&rval);
  -        if (!ok)
  -          return 1;
  -      }
  +     // 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;
  +     }
   
  -      JSString *str = rval.toString();
  -      printf("%s\n", JS_EncodeString(cx, str));
  +     JSString *str = rval.toString();
  +     printf("%s\n", JS_EncodeString(I->cx, str));
       }
   
  -    JS_DestroyContext(cx);
  -    JS_DestroyRuntime(rt);
  -    JS_ShutDown();
  +    rpmjsFini((void *)js);
  +
       return 0;
   }
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmjs45.cpp
  ============================================================================
  $ cvs diff -u -r1.1.2.1 -r1.1.2.2 rpmjs45.cpp
  --- rpm/rpmio/rpmjs45.cpp     21 Jun 2017 17:26:24 -0000      1.1.2.1
  +++ rpm/rpmio/rpmjs45.cpp     22 Jun 2017 12:35:43 -0000      1.1.2.2
  @@ -1,8 +1,18 @@
  -// following code might be needed in some case
  +// following code might be needed in some cases
   // #define __STDC_LIMIT_MACROS
   // #include <stdint.h>
  +
  +#include "system.h"
  +
  +#define      js      jsns
   #include "jsapi.h"
   #include "js/Initialization.h"
  +#undef       js
  +
  +#define      _RPMJS_INTERNAL
  +#include <rpmjs.h>
  +
  +#include "debug.h"
   
   /* The class of the global object. */
   static JSClass global_class = {
  @@ -22,50 +32,120 @@
       JS_GlobalObjectTraceHook
   };
   
  +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 JSI_t 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);
  +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 void rpmjsFini(void * _js)
  +{                               
  +    rpmjs js = (rpmjs) _js;
  +
  +    mozFini(js);
  +    js->I = NULL;
  +}
  +
  +/*==============================================================*/
   int main(int argc, const char *argv[])
   {
  -    JS_Init();
  +    JSI_t I = mozInit(js);
  +    js->I = I;
  +
  +    {        // Scope for our various stack objects (JSAutoRequest, 
RootedObject),
  +     // so they all go out of scope before we JS_DestroyContext.
   
  -    JSRuntime *rt = JS_NewRuntime(8L * 1024 * 1024);
  -    if (!rt)
  -        return 1;
  -
  -    JSContext *cx = JS_NewContext(rt, 8192);
  -    if (!cx)
  -        return 1;
  -
  -    { // Scope for our various stack objects (JSAutoRequest, RootedObject), 
so they all go
  -      // out of scope before we JS_DestroyContext.
  -
  -      JSAutoRequest ar(cx); // In practice, you would want to exit this any
  -                            // time you're spinning the event loop
  -
  -      JS::RootedObject global(cx, JS_NewGlobalObject(cx, &global_class, 
nullptr, JS::FireOnNewGlobalHook));
  -      if (!global)
  -          return 1;
  -
  -      JS::RootedValue rval(cx);
  -
  -      { // Scope for JSAutoCompartment
  -        JSAutoCompartment ac(cx, global);
  -        JS_InitStandardClasses(cx, global);
  -
  -        const char *script = "'hello'+'world, it is '+new Date()";
  -        const char *filename = "noname";
  -        int lineno = 1;
  -        JS::CompileOptions opts(cx);
  -        opts.setFileAndLine(filename, lineno);
  -        bool ok = JS::Evaluate(cx, opts, script, strlen(script), &rval);
  -        if (!ok)
  -          return 1;
  -      }
  +     // 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, opts, script, strlen(script), &rval);
  +         if (!ok)
  +             return 1;
  +     }
   
  -      JSString *str = rval.toString();
  -      printf("%s\n", JS_EncodeString(cx, str));
  +     JSString *str = rval.toString();
  +     printf("%s\n", JS_EncodeString(I->cx, str));
       }
   
  -    JS_DestroyContext(cx);
  -    JS_DestroyRuntime(rt);
  -    JS_ShutDown();
  +    rpmjsFini((void *)js);
  +
       return 0;
   }
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-cvs@rpm5.org

Reply via email to