RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  [email protected]
  Module: rpm                              Date:   02-Jul-2017 15:58:09
  Branch: rpm-5_4                          Handle: 2017070213580900

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

  Log:
    - rpmjs45: WIP.

  Summary:
    Revision    Changes     Path
    1.1.2.15    +115 -124   rpm/rpmio/rpmjs45.cpp
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmjs45.cpp
  ============================================================================
  $ cvs diff -u -r1.1.2.14 -r1.1.2.15 rpmjs45.cpp
  --- rpm/rpmio/rpmjs45.cpp     2 Jul 2017 12:34:29 -0000       1.1.2.14
  +++ rpm/rpmio/rpmjs45.cpp     2 Jul 2017 13:58:09 -0000       1.1.2.15
  @@ -25,6 +25,8 @@
   
   #include "jswrapper.h"
   
  +#include "vm/TypedArrayObject.h"
  +
   using namespace JS;
   using namespace js;
   #ifdef       NOTYET
  @@ -61,6 +63,51 @@
   };
   
   /*==============================================================*/
  +static void
  +rpmjssReportError(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 void
  +rpmjssOOMCallback(JSContext* cx, void* data)
  +{
  +#ifdef       NOTYET
  +    // If a script is running, the engine is about to throw the string "out 
of
  +    // memory", which may or may not be caught. Otherwise the engine will 
just
  +    // unwind and return null/false, with no exception set.
  +    if (!JS_IsRunning(cx))
  +        GetShellRuntime(cx)->gotError = true;
  +#endif
  +}
  +
  +enum JSShellErrNum {
  +#define MSG_DEF(name, count, exception, format) \
  +    name,
  +#include "jsshell.msg"
  +#undef MSG_DEF
  +    JSShellErr_Limit
  +};
  +
  +static const JSErrorFormatString jsShell_ErrorFormatString[JSShellErr_Limit] 
= {
  +#define MSG_DEF(name, count, exception, format) \
  +    { format, count, JSEXN_ERR } ,
  +#include "jsshell.msg"
  +#undef MSG_DEF
  +};
  +
  +const JSErrorFormatString*
  +my_GetErrorMessage(void* userRef, const unsigned errorNumber)
  +{
  +    if (errorNumber == 0 || errorNumber >= JSShellErr_Limit)
  +        return nullptr;
  +
  +    return &jsShell_ErrorFormatString[errorNumber];
  +}
  +
  +/*==============================================================*/
   enum PathResolutionMode {    /* XXX shell/OSObject.h */
       RootRelative,
       ScriptRelative
  @@ -161,7 +208,6 @@
    * command line.) Otherwise, it will be relative to the current working
    * directory.
    */
  -#ifndef      NOTYET
   JSString*
   ResolvePath(JSContext* cx, HandleString filenameStr, PathResolutionMode 
resolveMode)
   {
  @@ -211,9 +257,7 @@
   
       return JS_NewStringCopyZ(cx, buffer);
   }
  -#endif
   
  -#ifdef       NOTYET
   static JSObject*
   FileAsTypedArray(JSContext* cx, const char* pathname)
   {
  @@ -270,11 +314,10 @@
           }
       }
   #if !defined(FIXME)
  -    if (file) (void) fclose(file);
  +    if (file && fileno(file) > 2) (void) fclose(file);
   #endif
       return obj;
   }
  -#endif
   
   #ifdef       NOTYET
   static bool
  @@ -283,18 +326,14 @@
       CallArgs args = CallArgsFromVp(argc, vp);
   
       if (args.length() < 1 || args.length() > 2) {
  -#ifdef       FIXME
           JS_ReportErrorNumber(cx, js::shell::my_GetErrorMessage, nullptr,
                                args.length() < 1 ? JSSMSG_NOT_ENOUGH_ARGS : 
JSSMSG_TOO_MANY_ARGS,
                                "snarf");
  -#endif
           return false;
       }
   
       if (!args[0].isString() || (args.length() == 2 && !args[1].isString())) {
  -#ifdef       FIXME
           JS_ReportErrorNumber(cx, js::shell::my_GetErrorMessage, nullptr, 
JSSMSG_INVALID_ARGS, "snarf");
  -#endif
           return false;
       }
   
  @@ -346,7 +385,6 @@
   }
   #endif
   
  -#ifdef       NOTYET
   static bool
   osfile_writeTypedArrayToFile(JSContext* cx, unsigned argc, Value* vp)
   {
  @@ -376,7 +414,9 @@
           JS_ReportError(cx, "can't open %s: %s", filename.ptr(), 
strerror(errno));
           return false;
       }
  +#ifdef       FIXME
       AutoCloseFile autoClose(file);
  +#endif
   
       TypedArrayObject* obj = &args[1].toObject().as<TypedArrayObject>();
   
  @@ -385,22 +425,33 @@
           //
           // See further comments in FileAsTypedArray, above.
           JS_ReportError(cx, "can't write %s: shared memory buffer", 
filename.ptr());
  +#if !defined(FIXME)
  +        if (file && fileno(file) > 2) (void) fclose(file);
  +#endif
           return false;
       }
       void* buf = obj->viewDataUnshared();
  +#ifdef       FIXME
       if (fwrite(buf, obj->bytesPerElement(), obj->length(), file) != 
obj->length() ||
           !autoClose.release())
       {
           JS_ReportError(cx, "can't write %s", filename.ptr());
           return false;
       }
  +#else
  +    size_t nw = fwrite(buf, obj->bytesPerElement(), obj->length(), file);
  +    if (file && fileno(file) > 2) (void) fclose(file);
  +    if (nw != obj->length()) 
  +    {
  +        JS_ReportError(cx, "can't write %s", filename.ptr());
  +        return false;
  +    }   
  +#endif
   
       args.rval().setUndefined();
       return true;
   }
  -#endif
   
  -#ifdef       NOTYET
   static bool
   Redirect(JSContext* cx, FILE* fp, HandleString relFilename)
   {
  @@ -416,9 +467,7 @@
       }
       return true;
   }
  -#endif
   
  -#ifdef       NOTYET
   static bool
   osfile_redirect(JSContext* cx, unsigned argc, Value* vp)
   {
  @@ -448,7 +497,6 @@
       args.rval().setUndefined();
       return true;
   }
  -#endif
   
   #ifdef       NOTYET
   static const JSFunctionSpecWithHelp osfile_functions[] = {
  @@ -466,7 +514,6 @@
   };
   #endif
   
  -#ifdef       NOTYET
   static const JSFunctionSpecWithHelp osfile_unsafe_functions[] = {
       JS_FN_HELP("writeTypedArrayToFile", osfile_writeTypedArrayToFile, 2, 0,
   "writeTypedArrayToFile(filename, data)",
  @@ -479,9 +526,7 @@
   
       JS_FS_HELP_END
   };
  -#endif
   
  -#ifdef       NOTYET
   static bool
   ospath_isAbsolute(JSContext* cx, unsigned argc, Value* vp)
   {
  @@ -499,7 +544,6 @@
       args.rval().setBoolean(IsAbsolutePath(path));
       return true;
   }
  -#endif
   
   #ifdef       NOTYET
   static bool
  @@ -547,21 +591,20 @@
   }
   #endif
   
  -#ifdef       NOTYET
   static const JSFunctionSpecWithHelp ospath_functions[] = {
       JS_FN_HELP("isAbsolute", ospath_isAbsolute, 1, 0,
   "isAbsolute(path)",
   "  Return whether the given path is absolute."),
   
  +#ifdef       NOTYET
       JS_FN_HELP("join", ospath_join, 1, 0,
   "join(paths...)",
   "  Join one or more path components in a platform independent way."),
  +#endif       /* NOTYET */
   
       JS_FS_HELP_END
   };
  -#endif
   
  -#ifdef       NOTYET
   static bool
   os_getenv(JSContext* cx, unsigned argc, Value* vp)
   {
  @@ -587,9 +630,7 @@
       }
       return true;
   }
  -#endif
   
  -#ifdef       NOTYET
   static bool
   os_getpid(JSContext* cx, unsigned argc, Value* vp)
   {
  @@ -601,7 +642,6 @@
       args.rval().setInt32(getpid());
       return true;
   }
  -#endif
   
   #if !defined(XP_WIN)
   
  @@ -618,7 +658,6 @@
   }
   #endif
   
  -#ifdef       NOTYET
   inline char*
   strerror_message(char* result, char* buffer)
   {
  @@ -626,9 +665,6 @@
   }
   #endif
   
  -#endif
  -
  -#ifdef       NOTYET
   static void
   ReportSysError(JSContext* cx, const char* prefix)
   {
  @@ -660,9 +696,7 @@
       JS_ReportError(cx, final);
       js_free(final);
   }
  -#endif
   
  -#ifdef       NOTYET
   static bool
   os_system(JSContext* cx, unsigned argc, Value* vp)
   {
  @@ -690,10 +724,8 @@
       args.rval().setInt32(result);
       return true;
   }
  -#endif
   
   #ifndef XP_WIN
  -#ifdef       NOTYET
   static bool
   os_spawn(JSContext* cx, unsigned argc, Value* vp)
   {
  @@ -731,9 +763,7 @@
       execvp("sh", (char * const*)cmd);
       exit(1);
   }
  -#endif
   
  -#ifdef       NOTYET
   static bool
   os_kill(JSContext* cx, unsigned argc, Value* vp)
   {
  @@ -767,9 +797,7 @@
       args.rval().setUndefined();
       return true;
   }
  -#endif
   
  -#ifdef       NOTYET
   static bool
   os_waitpid(JSContext* cx, unsigned argc, Value* vp)
   {
  @@ -813,10 +841,8 @@
       args.rval().setObject(*info);
       return true;
   }
  -#endif       /* NOTYET */
   #endif /* !defined(XP_WIN) */
   
  -#ifdef       NOTYET
   static const JSFunctionSpecWithHelp os_functions[] = {
       JS_FN_HELP("getenv", os_getenv, 1, 0,
   "getenv(variable)",
  @@ -850,7 +876,6 @@
   
       JS_FS_HELP_END
   };
  -#endif
   
   #ifdef       NOTYET
   bool
  @@ -914,55 +939,8 @@
   }
   #endif
   
  -#ifndef      NOTYET
   } // namespace shell
   } // namespace js
  -#endif
  -
  -/*==============================================================*/
  -static void
  -rpmjssReportError(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 void
  -rpmjssOOMCallback(JSContext* cx, void* data)
  -{
  -#ifdef       NOTYET
  -    // If a script is running, the engine is about to throw the string "out 
of
  -    // memory", which may or may not be caught. Otherwise the engine will 
just
  -    // unwind and return null/false, with no exception set.
  -    if (!JS_IsRunning(cx))
  -        GetShellRuntime(cx)->gotError = true;
  -#endif
  -}
  -
  -enum JSShellErrNum {
  -#define MSG_DEF(name, count, exception, format) \
  -    name,
  -#include "jsshell.msg"
  -#undef MSG_DEF
  -    JSShellErr_Limit
  -};
  -
  -static const JSErrorFormatString jsShell_ErrorFormatString[JSShellErr_Limit] 
= {
  -#define MSG_DEF(name, count, exception, format) \
  -    { format, count, JSEXN_ERR } ,
  -#include "jsshell.msg"
  -#undef MSG_DEF
  -};
  -
  -const JSErrorFormatString*
  -my_GetErrorMessage(void* userRef, const unsigned errorNumber)
  -{
  -    if (errorNumber == 0 || errorNumber >= JSShellErr_Limit)
  -        return nullptr;
  -
  -    return &jsShell_ErrorFormatString[errorNumber];
  -}
   
   /*==============================================================*/
   enum JSShellExitCode {
  @@ -1671,7 +1649,6 @@
       return true;
   }
   
  -#ifdef       NOTYET
   static bool
   CreateMappedArrayBuffer(JSContext* cx, unsigned argc, Value* vp)
   {
  @@ -1691,7 +1668,7 @@
       // I need a file at a known location, and the only good way I know of to 
do
       // that right now is to include it in the repo alongside the test script.
       // Bug 944164 would introduce an alternative.
  -    JSString* filenameStr = ResolvePath(cx, rawFilenameStr, ScriptRelative);
  +    JSString* filenameStr = js::shell::ResolvePath(cx, rawFilenameStr, 
ScriptRelative);
       if (!filenameStr)
           return false;
       JSAutoByteString filename(cx, filenameStr);
  @@ -1723,7 +1700,9 @@
                                JSSMSG_CANT_OPEN, filename.ptr(), 
strerror(errno));
           return false;
       }
  +#ifdef       FIXME
       AutoCloseFile autoClose(file);
  +#endif
   
       if (!sizeGiven) {
           struct stat st;
  @@ -1734,14 +1713,23 @@
           if (st.st_size < off_t(offset)) {
               JS_ReportErrorNumber(cx, GetErrorMessage, nullptr,
                                    JSMSG_ARG_INDEX_OUT_OF_RANGE, "2");
  +#if !defined(FIXME)
  +            if (file && fileno(file) > 2) (void) fclose(file);
  +#endif
               return false;
           }
           size = st.st_size - offset;
       }
   
       void* contents = JS_CreateMappedArrayBufferContents(fileno(file), 
offset, size);
  +#if !defined(FIXME)
  +    if (file && fileno(file) > 2) (void) fclose(file);
  +#endif
       if (!contents) {
           JS_ReportError(cx, "failed to allocate mapped array buffer contents 
(possibly due to bad alignment)");
  +#if !defined(FIXME)
  +        if (file && fileno(file) > 2) (void) fclose(file);
  +#endif
           return false;
       }
   
  @@ -1752,7 +1740,6 @@
       args.rval().setObject(*obj);
       return true;
   }
  -#endif
   
   static bool
   Options(JSContext* cx, unsigned argc, Value* vp)
  @@ -2052,7 +2039,6 @@
       return v.toString();
   }
   
  -#ifdef       NOTYET
   static uint8_t*
   CacheEntry_getBytecode(HandleObject cache, uint32_t* length)
   {
  @@ -2065,9 +2051,7 @@
       *length = arrayBuffer->byteLength();
       return arrayBuffer->dataPointer();
   }
  -#endif
   
  -#ifdef       NOTYET
   static bool
   CacheEntry_setBytecode(JSContext* cx, HandleObject cache, uint8_t* buffer, 
uint32_t length)
   {
  @@ -2082,9 +2066,7 @@
       SetReservedSlot(cache, CacheEntry_BYTECODE, ObjectValue(*arrayBuffer));
       return true;
   }
  -#endif
   
  -#ifdef       NOTYET
   class AutoSaveFrameChain
   {
       JSContext* cx_;
  @@ -2108,7 +2090,6 @@
               JS_RestoreFrameChain(cx_);
       }
   };
  -#endif
   
   #ifdef       NOTYET
   static bool
  @@ -2366,7 +2347,6 @@
   }
   #endif
   
  -#ifdef       NOTYET
   JSString*
   FileAsString(JSContext* cx, const char* pathname)
   {
  @@ -2420,7 +2400,6 @@
   #endif
       return str;
   }
  -#endif
   
   /*
    * Function to run scripts and return compilation + execution time. Semantics
  @@ -2493,7 +2472,37 @@
    * function readline()
    * Provides a hook for scripts to read a line from stdin.
    */
  -#ifdef       NOTYET
  +#ifndef      NOTYET
  +/* --- js/src/frontend/TokenStream.cpp */
  +JS_FRIEND_API(int)
  +js_fgets(char* buf, int size, FILE* file)
  +{
  +    int n, i, c;
  +    bool crflag;
  +
  +    n = size - 1;
  +    if (n < 0)
  +        return -1;
  +
  +    crflag = false;
  +    for (i = 0; i < n && (c = getc_unlocked(file)) != EOF; i++) {
  +        buf[i] = c;
  +        if (c == '\n') {        // any \n ends a line
  +            i++;                // keep the \n; we know there is room for \0
  +            break;
  +        }
  +        if (crflag) {           // \r not followed by \n ends line at the \r
  +            ungetc(c, file);
  +            break;              // and overwrite c in buf with \0
  +        }
  +        crflag = (c == '\r');
  +    }
  +
  +    buf[i] = '\0';
  +    return i;
  +}
  +#endif
  +
   static bool
   ReadLine(JSContext* cx, unsigned argc, Value* vp)
   {
  @@ -2567,7 +2576,6 @@
       args.rval().setString(str);
       return true;
   }
  -#endif
   
   static bool
   PutStr(JSContext* cx, unsigned argc, Value* vp)
  @@ -2835,14 +2843,12 @@
   }
   #endif
   
  -#ifdef  NOTYET
   static JSScript*
   GetTopScript(JSContext* cx)
   {
       NonBuiltinScriptFrameIter iter(cx);
       return iter.done() ? nullptr : iter.script();
   }
  -#endif
   
   #ifdef  NOTYET
   static bool
  @@ -3708,7 +3714,6 @@
   }
   #endif
   
  -#ifdef       NOTYET
   struct WorkerInput
   {
       JSRuntime* runtime;
  @@ -3723,7 +3728,6 @@
           js_free(chars);
       }
   };
  -#endif
   
   static void SetWorkerRuntimeOptions(JSRuntime* rt);
   
  @@ -3860,13 +3864,11 @@
    * wrap-around between t2 and t1 assuming that t2 and t1 stays within 
INT32_MAX
    * from each other. We use MAX_TIMEOUT_INTERVAL to enforce this restriction.
    */
  -#ifdef       NOTYET
   static bool
   IsBefore(int64_t t1, int64_t t2)
   {
       return int32_t(t1 - t2) < 0;
   }
  -#endif
   
   #ifdef       NOTYET
   static bool
  @@ -4303,7 +4305,6 @@
   }
   #endif
   
  -#ifdef       NOTYET
   static bool
   StackPointerInfo(JSContext* cx, unsigned argc, Value* vp)
   {
  @@ -4314,10 +4315,8 @@
       args.rval().setInt32(int32_t(reinterpret_cast<size_t>(&args) & 
0xfffffff));
       return true;
   }
  -#endif
   
   
  -#ifdef       NOTYET
   static bool
   Elapsed(JSContext* cx, unsigned argc, Value* vp)
   {
  @@ -4341,7 +4340,6 @@
       JS_ReportError(cx, "Wrong number of arguments");
       return false;
   }
  -#endif
   
   #ifdef  NOTYET
   static bool
  @@ -4981,7 +4979,7 @@
   }
   #endif
   
  -#ifdef  NOTYET
  +#ifdef       NOTYET
   static bool
   DecompileFunction(JSContext* cx, unsigned argc, Value* vp)
   {
  @@ -5047,7 +5045,6 @@
   }
   #endif
   
  -#ifdef       NOTYET
   static bool
   WrapWithProto(JSContext* cx, unsigned argc, Value* vp)
   {
  @@ -5073,7 +5070,6 @@
       args.rval().setObject(*wrapped);
       return true;
   }
  -#endif
   
   #ifdef       NOTYET
   static bool
  @@ -5155,7 +5151,6 @@
   }
   #endif
   
  -#ifdef       NOTYET
   static bool
   GetMaxArgs(JSContext* cx, unsigned argc, Value* vp)
   {
  @@ -5163,9 +5158,7 @@
       args.rval().setInt32(ARGS_LENGTH_MAX);
       return true;
   }
  -#endif
   
  -#ifdef       NOTYET
   static bool
   ObjectEmulatingUndefined(JSContext* cx, unsigned argc, Value* vp)
   {
  @@ -5182,7 +5175,6 @@
       args.rval().setObject(*obj);
       return true;
   }
  -#endif
   
   #ifdef  NOTYET
   static bool
  @@ -5297,13 +5289,11 @@
   }
   #endif
   
  -#ifdef       NOTYET
   static void
   PrintProfilerEvents_Callback(const char* msg)
   {
       fprintf(stderr, "PROFILER EVENT: %s\n", msg);
   }
  -#endif
   
   #ifdef       NOTYET
   static bool
  @@ -5421,7 +5411,6 @@
   }
   #endif
   
  -#ifdef       NOTYET
   static bool
   IsLatin1(JSContext* cx, unsigned argc, Value* vp)
   {
  @@ -5430,7 +5419,6 @@
       args.rval().setBoolean(isLatin1);
       return true;
   }
  -#endif
   
   // Global mailbox that is used to communicate a SharedArrayBuffer
   // value from one worker to another.
  @@ -5953,7 +5941,6 @@
   }
   #endif
   
  -
   static const JSFunctionSpec global_functions[] = {
       JS_FN("version",                 Version,                        0,0),
       JS_FN("options",                 Options,                        0,0),
  @@ -5962,8 +5949,8 @@
   #ifdef       NOTYET
       JS_FN("evaluate",                        Evaluate,                       
2,0),
       JS_FN("run",                     Run,                            1,0),
  -    JS_FN("readline",                        ReadLine,                       
0,0),
   #endif       /* NOTYET */
  +    JS_FN("readline",                        ReadLine,                       
0,0),
       JS_FN("print",                   Print,                          0,0),
       JS_FN("printErr",                        PrintErr,                       
0,0),
       JS_FN("putstr",                  PutStr,                         0,0),
  @@ -6014,16 +6001,18 @@
       JS_FN("disableLastWarning",              DisableLastWarning,             
0,0),
       JS_FN("getLastWarning",          GetLastWarning,                 0,0),
       JS_FN("clearLastWarning",                ClearLastWarning,               
0,0),
  +#endif       /* NOTYET */
       JS_FN("elapsed",                 Elapsed,                        0,0),
  +#ifdef       NOTYET
       JS_FN("decompileFunction",               DecompileFunction,              
1,0),
       JS_FN("decompileThis",           DecompileThisScript,            0,0),
       JS_FN("thisFilename",            ThisFilename,                   0,0),
       JS_FN("newGlobal",                       NewGlobal,                      
1,0),
       JS_FN("nukeCCW",                 NukeCCW,                        1,0),
  +#endif       /* NOTYET */
       JS_FN("createMappedArrayBuffer", CreateMappedArrayBuffer,        1,0),
       JS_FN("getMaxArgs",                      GetMaxArgs,                     
0,0),
       JS_FN("objectEmulatingUndefined",        ObjectEmulatingUndefined,       
0,0),
  -#endif       /* NOTYET */
       JS_FN("isCachingEnabled",                IsCachingEnabled,               
0,0),
   #ifdef       NOTYET
       JS_FN("setCachingEnabled",               SetCachingEnabled,              
1,0),
  @@ -6033,8 +6022,10 @@
       JS_FN("printProfilerEvents",     PrintProfilerEvents,            0,0),
       JS_FN("enableSingleStepProfiling",       EnableSingleStepProfiling,      
0,0),
       JS_FN("disableSingleStepProfiling",      DisableSingleStepProfiling,     
0,0),
  +#endif       /* NOTYET */
       JS_FN("isLatin1",                        IsLatin1,                       
1,0),
       JS_FN("stackPointerInfo",                StackPointerInfo,               
0,0),
  +#ifdef       NOTYET
       JS_FN("entryPoints",             EntryPoints,                    1,0),
   
       JS_FS("require",                 Require,                        0,0),
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                [email protected]

Reply via email to