Commit 0fc4f20d authored by rswindell's avatar rswindell
Browse files

Created js_DefineConstIntegers() to easily define a set of const integer

properties, using for errno values.
Eliminated some errno values not supported by BCC.
parent 0ca04ecb
......@@ -2335,6 +2335,57 @@ static jsMethodSpec js_global_functions[] = {
{0}
};
static jsConstIntSpec js_global_const_ints[] = {
/* Numeric error constants from errno.h (platform-dependant) */
{"EPERM" ,EPERM },
{"ENOENT" ,ENOENT },
{"ESRCH" ,ESRCH },
{"EIO" ,EIO },
{"ENXIO" ,ENXIO },
{"E2BIG" ,E2BIG },
{"ENOEXEC" ,ENOEXEC },
{"EBADF" ,EBADF },
{"ECHILD" ,ECHILD },
{"EAGAIN" ,EAGAIN },
{"ENOMEM" ,ENOMEM },
{"EACCES" ,EACCES },
{"EFAULT" ,EFAULT },
{"EBUSY" ,EBUSY },
{"EEXIST" ,EEXIST },
{"EXDEV" ,EXDEV },
{"ENODEV" ,ENODEV },
{"ENOTDIR" ,ENOTDIR },
{"EISDIR" ,EISDIR },
{"EINVAL" ,EINVAL },
{"ENFILE" ,ENFILE },
{"EMFILE" ,EMFILE },
{"ENOTTY" ,ENOTTY },
{"EFBIG" ,EFBIG },
{"ENOSPC" ,ENOSPC },
{"ESPIPE" ,ESPIPE },
{"EROFS" ,EROFS },
{"EMLINK" ,EMLINK },
{"EPIPE" ,EPIPE },
{"EDOM" ,EDOM },
{"ERANGE" ,ERANGE },
{"EDEADLOCK" ,EDEADLOCK },
{"ENAMETOOLONG" ,ENAMETOOLONG },
{"ENOTEMPTY" ,ENOTEMPTY },
/* Socket errors */
{"EINTR" ,EINTR },
{"ENOTSOCK" ,ENOTSOCK },
{"EMSGSIZE" ,EMSGSIZE },
{"EWOULDBLOCK" ,EWOULDBLOCK },
{"ECONNRESET" ,ECONNRESET },
{"ESHUTDOWN" ,ESHUTDOWN },
{"ECONNABORTED" ,ECONNABORTED },
{"EINPROGRESS" ,EINPROGRESS },
/* Terminator (Governor Arnold) */
{0}
};
JSObject* DLLCALL js_CreateGlobalObject(JSContext* cx, scfg_t* cfg, jsMethodSpec* methods)
{
JSObject* glob;
......@@ -2361,140 +2412,7 @@ JSObject* DLLCALL js_CreateGlobalObject(JSContext* cx, scfg_t* cfg, jsMethodSpec
js_DescribeObject(cx,glob,"Top-level functions and properties (common to all servers and services)");
#endif
/* Numeric error constants from errno.h (platform-dependant) */
if(!JS_DefineProperty(cx, glob, "EPERM",INT_TO_JSVAL(EPERM)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "ENOENT",INT_TO_JSVAL(ENOENT)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "ESRCH",INT_TO_JSVAL(ESRCH)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "EIO",INT_TO_JSVAL(EIO)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "ENXIO",INT_TO_JSVAL(ENXIO)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "E2BIG",INT_TO_JSVAL(E2BIG)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "ENOEXEC",INT_TO_JSVAL(ENOEXEC)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "EBADF",INT_TO_JSVAL(EBADF)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "ECHILD",INT_TO_JSVAL(ECHILD)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "EAGAIN",INT_TO_JSVAL(EAGAIN)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "ENOMEM",INT_TO_JSVAL(ENOMEM)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "EACCES",INT_TO_JSVAL(EACCES)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "EFAULT",INT_TO_JSVAL(EFAULT)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "EBUSY",INT_TO_JSVAL(EBUSY)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "EEXIST",INT_TO_JSVAL(EEXIST)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "EXDEV",INT_TO_JSVAL(EXDEV)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "ENODEV",INT_TO_JSVAL(ENODEV)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "ENOTDIR",INT_TO_JSVAL(ENOTDIR)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "EISDIR",INT_TO_JSVAL(EISDIR)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "EINVAL",INT_TO_JSVAL(EINVAL)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "ENFILE",INT_TO_JSVAL(ENFILE)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "EMFILE",INT_TO_JSVAL(EMFILE)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "ENOTTY",INT_TO_JSVAL(ENOTTY)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "EFBIG",INT_TO_JSVAL(EFBIG)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "ENOSPC",INT_TO_JSVAL(ENOSPC)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "ESPIPE",INT_TO_JSVAL(ESPIPE)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "EROFS",INT_TO_JSVAL(EROFS)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "EMLINK",INT_TO_JSVAL(EMLINK)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "EPIPE",INT_TO_JSVAL(EPIPE)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "EDOM",INT_TO_JSVAL(EDOM)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "ERANGE",INT_TO_JSVAL(ERANGE)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "EDEADLK",INT_TO_JSVAL(EDEADLK)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "ENAMETOOLONG",INT_TO_JSVAL(ENAMETOOLONG)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "ENOLCK",INT_TO_JSVAL(ENOLCK)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "ENOSYS",INT_TO_JSVAL(ENOSYS)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "ENOTEMPTY",INT_TO_JSVAL(ENOTEMPTY)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
/* Socket errors */
if(!JS_DefineProperty(cx, glob, "EINTR",INT_TO_JSVAL(EINTR)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "ENOTSOCK",INT_TO_JSVAL(ENOTSOCK)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "EMSGSIZE",INT_TO_JSVAL(EMSGSIZE)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "EWOULDBLOCK",INT_TO_JSVAL(EWOULDBLOCK)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "ECONNRESET",INT_TO_JSVAL(ECONNRESET)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "ESHUTDOWN",INT_TO_JSVAL(ESHUTDOWN)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "ECONNABORTED",INT_TO_JSVAL(ECONNABORTED)
,NULL,NULL,JSPROP_READONLY))
return(NULL);
if(!JS_DefineProperty(cx, glob, "EINPROGRESS",INT_TO_JSVAL(EINPROGRESS)
,NULL,NULL,JSPROP_READONLY))
if(!js_DefineConstIntegers(cx, glob, js_global_const_ints, JSPROP_READONLY))
return(NULL);
return(glob);
......
......@@ -411,7 +411,7 @@ DLLCALL js_DefineMethods(JSContext* cx, JSObject* obj, jsMethodSpec *funcs, BOOL
JSBool
DLLCALL js_DefineMethods(JSContext* cx, JSObject* obj, jsMethodSpec *funcs, BOOL append)
{
int i;
uint i;
for(i=0;funcs[i].name;i++)
JS_DefineFunction(cx, obj, funcs[i].name, funcs[i].call, funcs[i].nargs, 0);
......@@ -420,6 +420,24 @@ DLLCALL js_DefineMethods(JSContext* cx, JSObject* obj, jsMethodSpec *funcs, BOOL
#endif
/* This is a stream-lined version of JS_DefineConstDoubles */
JSBool
DLLCALL js_DefineConstIntegers(JSContext* cx, JSObject* obj, jsConstIntSpec* ints, int flags)
{
uint i;
jsval val;
for(i=0;ints[i].name;i++) {
if(!JS_NewNumberValue(cx, ints[i].val, &val))
return(JS_FALSE);
if(!JS_DefineProperty(cx, obj, ints[i].name, val ,NULL, NULL, flags))
return(JS_FALSE);
}
return(JS_TRUE);
}
static JSBool
js_log(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
......
......@@ -879,6 +879,11 @@ extern "C" {
const char* desc; /* description */
} jsMethodSpec;
typedef struct {
const char* name;
int val;
} jsConstIntSpec;
#define JSTYPE_ARRAY JSTYPE_LIMIT
#define JSTYPE_ALIAS JSTYPE_LIMIT+1
......@@ -891,7 +896,8 @@ extern "C" {
/* main.cpp */
DLLEXPORT JSBool DLLCALL js_DescribeObject(JSContext* cx, JSObject* obj, const char*);
DLLEXPORT JSBool DLLCALL js_DescribeConstructor(JSContext* cx, JSObject* obj, const char*);
DLLEXPORT JSBool DLLCALL js_DefineMethods(JSContext* cx, JSObject* obj, jsMethodSpec *fs, BOOL append);
DLLEXPORT JSBool DLLCALL js_DefineMethods(JSContext* cx, JSObject* obj, jsMethodSpec*, BOOL append);
DLLEXPORT JSBool DLLCALL js_DefineConstIntegers(JSContext* cx, JSObject* obj, jsConstIntSpec*, int flags);
DLLEXPORT JSBool DLLCALL js_CreateArrayOfStrings(JSContext* cx, JSObject* parent
,const char* name, char* str[], uintN flags);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment