rpmaug-js.c | rpmaug-js.c | |||
---|---|---|---|---|
skipping to change at line 32 | skipping to change at line 32 | |||
#define AUGEAS_META_TREE "/augeas" | #define AUGEAS_META_TREE "/augeas" | |||
/*@unchecked@*/ | /*@unchecked@*/ | |||
static const char _defvar[] = AUGEAS_META_TREE "/version/defvar"; | static const char _defvar[] = AUGEAS_META_TREE "/version/defvar"; | |||
/* --- helpers */ | /* --- helpers */ | |||
/* --- Object methods */ | /* --- Object methods */ | |||
/* XXX does aug_defnode() need binding? */ | /* XXX does aug_defnode() need binding? */ | |||
/* XXX unclear whether aug.defvar("foo", "bar") or aug.foo = "bar" is bette r */ | /* XXX unclear whether aug.defvar("foo", "bar") or aug.foo = "bar" is bette r */ | |||
static JSBool | static JSBool | |||
rpmaug_defvar(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) | rpmaug_defvar(JSContext *cx, uintN argc, jsval *vp) | |||
{ | { | |||
jsval *argv = JS_ARGV(cx, vp); | ||||
JSObject *obj = JS_THIS_OBJECT(cx, vp); | ||||
void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | |||
rpmaug aug = ptr; | rpmaug aug = ptr; | |||
JSBool ok = JS_FALSE; | JSBool ok = JS_FALSE; | |||
const char * _name = NULL; | const char * _name = NULL; | |||
const char * _expr = NULL; | const char * _expr = NULL; | |||
_METHOD_DEBUG_ENTRY(_debug); | _METHOD_DEBUG_ENTRY(_debug); | |||
/* XXX note optional EXPR. If EXPR is NULL, then NAME is deleted. */ | /* XXX note optional EXPR. If EXPR is NULL, then NAME is deleted. */ | |||
if (!(ok = JS_ConvertArguments(cx, argc, argv, "s/s", &_name, &_expr))) | if (!(ok = JS_ConvertArguments(cx, argc, argv, "s/s", &_name, &_expr))) | |||
goto exit; | goto exit; | |||
switch (rpmaugDefvar(aug, _name, _expr)) { | switch (rpmaugDefvar(aug, _name, _expr)) { | |||
default: | default: | |||
case 0: /* failure (but success if EXPR was NULL?) */ | case 0: /* failure (but success if EXPR was NULL?) */ | |||
case 1: /* success */ | case 1: /* success */ | |||
/* XXX return NAME or EXPR on success? or bool for success/failure? */ | /* XXX return NAME or EXPR on success? or bool for success/failure? */ | |||
/* XXX hmmm, bool and string mixed returns. */ | /* XXX hmmm, bool and string mixed returns. */ | |||
*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, _name)); | *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, _name)); | |||
break; | break; | |||
} | } | |||
ok = JS_TRUE; | ok = JS_TRUE; | |||
exit: | exit: | |||
return ok; | return ok; | |||
} | } | |||
static JSBool | static JSBool | |||
rpmaug_get(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rv al) | rpmaug_get(JSContext *cx, uintN argc, jsval *vp) | |||
{ | { | |||
jsval *argv = JS_ARGV(cx, vp); | ||||
JSObject *obj = JS_THIS_OBJECT(cx, vp); | ||||
void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | |||
rpmaug aug = ptr; | rpmaug aug = ptr; | |||
JSBool ok = JS_FALSE; | JSBool ok = JS_FALSE; | |||
const char * _path = NULL; | const char * _path = NULL; | |||
const char * _value = NULL; | const char * _value = NULL; | |||
_METHOD_DEBUG_ENTRY(_debug); | _METHOD_DEBUG_ENTRY(_debug); | |||
if (!(ok = JS_ConvertArguments(cx, argc, argv, "s", &_path))) | if (!(ok = JS_ConvertArguments(cx, argc, argv, "s", &_path))) | |||
goto exit; | goto exit; | |||
switch (rpmaugGet(aug, _path, &_value)) { | switch (rpmaugGet(aug, _path, &_value)) { | |||
case 1: /* found */ | case 1: /* found */ | |||
*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, _value)); | *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, _value)); | |||
#ifdef NOTYET | #ifdef NOTYET | |||
_value = _free(_value); | _value = _free(_value); | |||
#endif | #endif | |||
break; | break; | |||
default: | default: | |||
case 0: /* not found */ | case 0: /* not found */ | |||
case -1: /* multiply defined */ | case -1: /* multiply defined */ | |||
*rval = JSVAL_VOID; | *vp = JSVAL_VOID; | |||
break; | break; | |||
} | } | |||
ok = JS_TRUE; | ok = JS_TRUE; | |||
exit: | exit: | |||
return ok; | return ok; | |||
} | } | |||
static JSBool | static JSBool | |||
rpmaug_set(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rv al) | rpmaug_set(JSContext *cx, uintN argc, jsval *vp) | |||
{ | { | |||
jsval *argv = JS_ARGV(cx, vp); | ||||
JSObject *obj = JS_THIS_OBJECT(cx, vp); | ||||
void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | |||
rpmaug aug = ptr; | rpmaug aug = ptr; | |||
JSBool ok = JS_FALSE; | JSBool ok = JS_FALSE; | |||
const char * _path = NULL; | const char * _path = NULL; | |||
const char * _value = NULL; | const char * _value = NULL; | |||
_METHOD_DEBUG_ENTRY(_debug); | _METHOD_DEBUG_ENTRY(_debug); | |||
if (!(ok = JS_ConvertArguments(cx, argc, argv, "ss", &_path, &_value))) | if (!(ok = JS_ConvertArguments(cx, argc, argv, "ss", &_path, &_value))) | |||
goto exit; | goto exit; | |||
switch (rpmaugSet(aug, _path, _value)) { | switch (rpmaugSet(aug, _path, _value)) { | |||
case 0: /* found */ | case 0: /* found */ | |||
*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, _value)); | *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, _value)); | |||
break; | break; | |||
default: | default: | |||
case -1: /* multiply defined */ | case -1: /* multiply defined */ | |||
*rval = JSVAL_VOID; | *vp = JSVAL_VOID; | |||
break; | break; | |||
} | } | |||
ok = JS_TRUE; | ok = JS_TRUE; | |||
exit: | exit: | |||
return ok; | return ok; | |||
} | } | |||
static JSBool | static JSBool | |||
rpmaug_insert(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) | rpmaug_insert(JSContext *cx, uintN argc, jsval *vp) | |||
{ | { | |||
jsval *argv = JS_ARGV(cx, vp); | ||||
JSObject *obj = JS_THIS_OBJECT(cx, vp); | ||||
void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | |||
rpmaug aug = ptr; | rpmaug aug = ptr; | |||
JSBool ok = JS_FALSE; | JSBool ok = JS_FALSE; | |||
const char * _path = NULL; | const char * _path = NULL; | |||
const char * _label = NULL; | const char * _label = NULL; | |||
int _before; | int _before; | |||
_METHOD_DEBUG_ENTRY(_debug); | _METHOD_DEBUG_ENTRY(_debug); | |||
if (!(ok = JS_ConvertArguments(cx, argc, argv, "ssi", &_path, &_label, &_before))) | if (!(ok = JS_ConvertArguments(cx, argc, argv, "ssi", &_path, &_label, &_before))) | |||
goto exit; | goto exit; | |||
switch (rpmaugInsert(aug, _path, _label, _before)) { | switch (rpmaugInsert(aug, _path, _label, _before)) { | |||
case 0: /* success */ | case 0: /* success */ | |||
*rval = JSVAL_TRUE; | *vp = JSVAL_TRUE; | |||
break; | break; | |||
default: | default: | |||
case -1: /* failure */ | case -1: /* failure */ | |||
*rval = JSVAL_FALSE; | *vp = JSVAL_FALSE; | |||
break; | break; | |||
} | } | |||
ok = JS_TRUE; | ok = JS_TRUE; | |||
exit: | exit: | |||
return ok; | return ok; | |||
} | } | |||
static JSBool | static JSBool | |||
rpmaug_rm(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rva l) | rpmaug_rm(JSContext *cx, uintN argc, jsval *vp) | |||
{ | { | |||
jsval *argv = JS_ARGV(cx, vp); | ||||
JSObject *obj = JS_THIS_OBJECT(cx, vp); | ||||
void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | |||
rpmaug aug = ptr; | rpmaug aug = ptr; | |||
JSBool ok = JS_FALSE; | JSBool ok = JS_FALSE; | |||
const char * _path = NULL; | const char * _path = NULL; | |||
_METHOD_DEBUG_ENTRY(_debug); | _METHOD_DEBUG_ENTRY(_debug); | |||
if (!(ok = JS_ConvertArguments(cx, argc, argv, "s", &_path))) | if (!(ok = JS_ConvertArguments(cx, argc, argv, "s", &_path))) | |||
goto exit; | goto exit; | |||
/* XXX rpmaug_rm() returns number of deleted nodes. */ | /* XXX rpmaug_rm() returns number of deleted nodes. */ | |||
*rval = INT_TO_JSVAL(rpmaugRm(aug, _path)); | *vp = INT_TO_JSVAL(rpmaugRm(aug, _path)); | |||
ok = JS_TRUE; | ok = JS_TRUE; | |||
exit: | exit: | |||
return ok; | return ok; | |||
} | } | |||
static JSBool | static JSBool | |||
rpmaug_mv(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rva l) | rpmaug_mv(JSContext *cx, uintN argc, jsval *vp) | |||
{ | { | |||
jsval *argv = JS_ARGV(cx, vp); | ||||
JSObject *obj = JS_THIS_OBJECT(cx, vp); | ||||
void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | |||
rpmaug aug = ptr; | rpmaug aug = ptr; | |||
JSBool ok = JS_FALSE; | JSBool ok = JS_FALSE; | |||
const char * _src = NULL; | const char * _src = NULL; | |||
const char * _dst = NULL; | const char * _dst = NULL; | |||
_METHOD_DEBUG_ENTRY(_debug); | _METHOD_DEBUG_ENTRY(_debug); | |||
if (!(ok = JS_ConvertArguments(cx, argc, argv, "ss", &_src, &_dst))) | if (!(ok = JS_ConvertArguments(cx, argc, argv, "ss", &_src, &_dst))) | |||
goto exit; | goto exit; | |||
switch (rpmaugMv(aug, _src, _dst)) { | switch (rpmaugMv(aug, _src, _dst)) { | |||
case 0: /* success */ | case 0: /* success */ | |||
*rval = JSVAL_TRUE; | *vp = JSVAL_TRUE; | |||
break; | break; | |||
default: | default: | |||
case -1: /* failure */ | case -1: /* failure */ | |||
*rval = JSVAL_FALSE; | *vp = JSVAL_FALSE; | |||
break; | break; | |||
} | } | |||
ok = JS_TRUE; | ok = JS_TRUE; | |||
exit: | exit: | |||
return ok; | return ok; | |||
} | } | |||
static JSBool | static JSBool | |||
rpmaug_match(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval * rval) | rpmaug_match(JSContext *cx, uintN argc, jsval *vp) | |||
{ | { | |||
jsval *argv = JS_ARGV(cx, vp); | ||||
JSObject *obj = JS_THIS_OBJECT(cx, vp); | ||||
void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | |||
rpmaug aug = ptr; | rpmaug aug = ptr; | |||
JSBool ok = JS_FALSE; | JSBool ok = JS_FALSE; | |||
const char * _path = NULL; | const char * _path = NULL; | |||
char ** _matches = NULL; | char ** _matches = NULL; | |||
int nmatches; | int nmatches; | |||
_METHOD_DEBUG_ENTRY(_debug); | _METHOD_DEBUG_ENTRY(_debug); | |||
if (!(ok = JS_ConvertArguments(cx, argc, argv, "s", &_path))) | if (!(ok = JS_ConvertArguments(cx, argc, argv, "s", &_path))) | |||
goto exit; | goto exit; | |||
nmatches = rpmaugMatch(aug, _path, &_matches); | nmatches = rpmaugMatch(aug, _path, &_matches); | |||
if (nmatches <= 0) { /* not found */ | if (nmatches <= 0) { /* not found */ | |||
*rval = JSVAL_VOID; | *vp = JSVAL_VOID; | |||
goto exit; | goto exit; | |||
} else { | } else { | |||
JSObject *o; | JSObject *o; | |||
jsval v; | jsval v; | |||
int i; | int i; | |||
*rval = OBJECT_TO_JSVAL(o=JS_NewArrayObject(cx, 0, NULL)); | *vp = OBJECT_TO_JSVAL(o=JS_NewArrayObject(cx, 0, NULL)); | |||
for (i = 0; i < nmatches; i++) { | for (i = 0; i < nmatches; i++) { | |||
v = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, _matches[i])); | v = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, _matches[i])); | |||
ok = JS_SetElement(cx, o, i, &v); | ok = JS_SetElement(cx, o, i, &v); | |||
_matches[i] = _free(_matches[i]); | _matches[i] = _free(_matches[i]); | |||
} | } | |||
_matches = _free(_matches); | _matches = _free(_matches); | |||
} | } | |||
ok = JS_TRUE; | ok = JS_TRUE; | |||
exit: | exit: | |||
return ok; | return ok; | |||
} | } | |||
static JSBool | static JSBool | |||
rpmaug_save(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r val) | rpmaug_save(JSContext *cx, uintN argc, jsval *vp) | |||
{ | { | |||
jsval *argv = JS_ARGV(cx, vp); | ||||
JSObject *obj = JS_THIS_OBJECT(cx, vp); | ||||
void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | |||
rpmaug aug = ptr; | rpmaug aug = ptr; | |||
JSBool ok = JS_FALSE; | JSBool ok = JS_FALSE; | |||
_METHOD_DEBUG_ENTRY(_debug); | _METHOD_DEBUG_ENTRY(_debug); | |||
switch (rpmaugSave(aug)) { | switch (rpmaugSave(aug)) { | |||
case 0: /* success */ | case 0: /* success */ | |||
*rval = JSVAL_TRUE; | *vp = JSVAL_TRUE; | |||
break; | break; | |||
default: | default: | |||
case -1: /* failure */ | case -1: /* failure */ | |||
*rval = JSVAL_FALSE; | *vp = JSVAL_FALSE; | |||
break; | break; | |||
} | } | |||
ok = JS_TRUE; | ok = JS_TRUE; | |||
return ok; | return ok; | |||
} | } | |||
static JSBool | static JSBool | |||
rpmaug_load(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r val) | rpmaug_load(JSContext *cx, uintN argc, jsval *vp) | |||
{ | { | |||
jsval *argv = JS_ARGV(cx, vp); | ||||
JSObject *obj = JS_THIS_OBJECT(cx, vp); | ||||
void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | |||
rpmaug aug = ptr; | rpmaug aug = ptr; | |||
JSBool ok = JS_FALSE; | JSBool ok = JS_FALSE; | |||
_METHOD_DEBUG_ENTRY(_debug); | _METHOD_DEBUG_ENTRY(_debug); | |||
switch (rpmaugLoad(aug)) { | switch (rpmaugLoad(aug)) { | |||
case 0: /* success */ | case 0: /* success */ | |||
*rval = JSVAL_TRUE; | *vp = JSVAL_TRUE; | |||
break; | break; | |||
default: | default: | |||
case -1: /* failure */ | case -1: /* failure */ | |||
*rval = JSVAL_FALSE; | *vp = JSVAL_FALSE; | |||
break; | break; | |||
} | } | |||
ok = JS_TRUE; | ok = JS_TRUE; | |||
return ok; | return ok; | |||
} | } | |||
/* XXX print is uselss method because of FILE * in Augeas API. */ | /* XXX print is uselss method because of FILE * in Augeas API. */ | |||
static JSBool | static JSBool | |||
rpmaug_print(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval * rval) | rpmaug_print(JSContext *cx, uintN argc, jsval *vp) | |||
{ | { | |||
jsval *argv = JS_ARGV(cx, vp); | ||||
JSObject *obj = JS_THIS_OBJECT(cx, vp); | ||||
void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | |||
rpmaug aug = ptr; | rpmaug aug = ptr; | |||
JSBool ok = JS_FALSE; | JSBool ok = JS_FALSE; | |||
const char * _path = NULL; | const char * _path = NULL; | |||
_METHOD_DEBUG_ENTRY(_debug); | _METHOD_DEBUG_ENTRY(_debug); | |||
if (!(ok = JS_ConvertArguments(cx, argc, argv, "s", &_path))) | if (!(ok = JS_ConvertArguments(cx, argc, argv, "s", &_path))) | |||
goto exit; | goto exit; | |||
switch (rpmaugPrint(aug, NULL, _path)) { | switch (rpmaugPrint(aug, NULL, _path)) { | |||
case 0: /* success */ | case 0: /* success */ | |||
*rval = JSVAL_TRUE; | *vp = JSVAL_TRUE; | |||
break; | break; | |||
default: | default: | |||
case -1: /* failure */ | case -1: /* failure */ | |||
*rval = JSVAL_FALSE; | *vp = JSVAL_FALSE; | |||
break; | break; | |||
} | } | |||
ok = JS_TRUE; | ok = JS_TRUE; | |||
exit: | exit: | |||
return ok; | return ok; | |||
} | } | |||
static JSFunctionSpec rpmaug_funcs[] = { | static JSFunctionSpec rpmaug_funcs[] = { | |||
JS_FS("defvar", rpmaug_defvar, 0,0), | JS_FS("defvar", rpmaug_defvar, 0,0), | |||
JS_FS("get", rpmaug_get, 0,0), | JS_FS("get", rpmaug_get, 0,0), | |||
skipping to change at line 333 | skipping to change at line 353 | |||
_DEBUG = -2, | _DEBUG = -2, | |||
_LENGTH = -3, | _LENGTH = -3, | |||
}; | }; | |||
static JSPropertySpec rpmaug_props[] = { | static JSPropertySpec rpmaug_props[] = { | |||
{"debug", _DEBUG, JSPROP_ENUMERATE, NULL, NULL}, | {"debug", _DEBUG, JSPROP_ENUMERATE, NULL, NULL}, | |||
{NULL, 0, 0, NULL, NULL} | {NULL, 0, 0, NULL, NULL} | |||
}; | }; | |||
static JSBool | static JSBool | |||
rpmaug_getprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp) | rpmaug_getprop(JSContext *cx, JSObject *obj, jsid id, jsval *vp) | |||
{ | { | |||
void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | |||
rpmaug aug = ptr; | rpmaug aug = ptr; | |||
jsint tiny = JSVAL_TO_INT(id); | jsint tiny = JSVAL_TO_INT(id); | |||
_PROP_DEBUG_ENTRY(_debug < 0); | _PROP_DEBUG_ENTRY(_debug < 0); | |||
/* XXX the class has ptr == NULL, instances have ptr != NULL. */ | /* XXX the class has ptr == NULL, instances have ptr != NULL. */ | |||
if (ptr == NULL) | if (ptr == NULL) | |||
return JS_TRUE; | return JS_TRUE; | |||
switch (tiny) { | switch (tiny) { | |||
case _DEBUG: | case _DEBUG: | |||
*vp = INT_TO_JSVAL(_debug); | *vp = INT_TO_JSVAL(_debug); | |||
break; | break; | |||
default: | default: | |||
if (JSVAL_IS_STRING(id) && *vp == JSVAL_VOID) { | if (JSVAL_IS_STRING(id) && *vp == JSVAL_VOID) { | |||
const char * name = JS_GetStringBytes(JS_ValueToString(cx, id)); | const char * name = JS_EncodeString(cx, JS_ValueToString(cx, id) ); | |||
const char * _path = rpmGetPath(_defvar, "/", name, NULL); | const char * _path = rpmGetPath(_defvar, "/", name, NULL); | |||
const char * _value = NULL; | const char * _value = NULL; | |||
if (rpmaugGet(aug, _path, &_value) >= 0 && _value != NULL) | if (rpmaugGet(aug, _path, &_value) >= 0 && _value != NULL) | |||
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, _value)); | *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, _value)); | |||
_path = _free(_path); | ||||
_value = _free(_value); | _value = _free(_value); | |||
_path = _free(_path); | ||||
name = _free(name); | ||||
break; | break; | |||
} | } | |||
break; | break; | |||
} | } | |||
return JS_TRUE; | return JS_TRUE; | |||
} | } | |||
static JSBool | static JSBool | |||
rpmaug_setprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp) | rpmaug_setprop(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp) | |||
{ | { | |||
void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | |||
rpmaug aug = ptr; | rpmaug aug = ptr; | |||
jsint tiny = JSVAL_TO_INT(id); | jsint tiny = JSVAL_TO_INT(id); | |||
_PROP_DEBUG_ENTRY(_debug < 0); | _PROP_DEBUG_ENTRY(_debug < 0); | |||
/* XXX the class has ptr == NULL, instances have ptr != NULL. */ | /* XXX the class has ptr == NULL, instances have ptr != NULL. */ | |||
if (ptr == NULL) | if (ptr == NULL) | |||
return JS_TRUE; | return JS_TRUE; | |||
switch (tiny) { | switch (tiny) { | |||
case _DEBUG: | case _DEBUG: | |||
if (!JS_ValueToInt32(cx, *vp, &_debug)) | if (!JS_ValueToInt32(cx, *vp, &_debug)) | |||
break; | break; | |||
break; | break; | |||
default: | default: | |||
/* XXX expr = undefined same as deleting? */ | /* XXX expr = undefined same as deleting? */ | |||
if (JSVAL_IS_STRING(id)) { | if (JSVAL_IS_STRING(id)) { | |||
const char * name = JS_GetStringBytes(JS_ValueToString(cx, id)) | const char * name = JS_EncodeString(cx, JS_ValueToString(cx, id | |||
; | )); | |||
const char * expr = JS_GetStringBytes(JS_ValueToString(cx, *vp) | const char * expr = JS_EncodeString(cx, JS_ValueToString(cx, *v | |||
); | p)); | |||
/* XXX should *setprop be permitted to delete NAME?!? */ | /* XXX should *setprop be permitted to delete NAME?!? */ | |||
/* XXX return is no. nodes in EXPR match. */ | /* XXX return is no. nodes in EXPR match. */ | |||
(void) rpmaugDefvar(aug, name, expr); | (void) rpmaugDefvar(aug, name, expr); | |||
expr = _free(expr); | ||||
name = _free(name); | ||||
break; | break; | |||
} | } | |||
break; | break; | |||
} | } | |||
return JS_TRUE; | return JS_TRUE; | |||
} | } | |||
static JSBool | static JSBool | |||
rpmaug_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, | rpmaug_resolve(JSContext *cx, JSObject *obj, jsid id, uintN flags, | |||
JSObject **objp) | JSObject **objp) | |||
{ | { | |||
void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | |||
rpmaug aug = ptr; | rpmaug aug = ptr; | |||
_RESOLVE_DEBUG_ENTRY(_debug); | _RESOLVE_DEBUG_ENTRY(_debug); | |||
if (ptr == NULL) { /* don't resolve to parent prototypes objects. */ | if (ptr == NULL) { /* don't resolve to parent prototypes objects. */ | |||
*objp = NULL; | *objp = NULL; | |||
goto exit; | goto exit; | |||
} | } | |||
/* Lazily resolve new strings, with duplication to Augeas defvar too. * / | /* Lazily resolve new strings, with duplication to Augeas defvar too. * / | |||
if ((flags & JSRESOLVE_ASSIGNING) && JSVAL_IS_STRING(id)) { | if ((flags & JSRESOLVE_ASSIGNING) && JSVAL_IS_STRING(id)) { | |||
const char *name = JS_GetStringBytes(JS_ValueToString(cx, id)); | const char *name = JS_EncodeString(cx, JS_ValueToString(cx, id)); | |||
const char * _path; | const char * _path; | |||
const char * _value; | const char * _value; | |||
int xx; | int xx; | |||
JSFunctionSpec *fsp; | JSFunctionSpec *fsp; | |||
/* XXX avoid "aug.print" method namess duped into defvar space? */ | /* XXX avoid "aug.print" method namess duped into defvar space? */ | |||
for (fsp = rpmaug_funcs; fsp->name != NULL; fsp++) { | for (fsp = rpmaug_funcs; fsp->name != NULL; fsp++) { | |||
if (!strcmp(fsp->name, name)) { | if (!strcmp(fsp->name, name)) { | |||
*objp = obj; /* XXX always resolve in this object. */ | *objp = obj; /* XXX always resolve in this object. */ | |||
goto exit; | goto exit; | |||
skipping to change at line 457 | skipping to change at line 480 | |||
NULL, NULL, JSPROP_ENUMERATE)) | NULL, NULL, JSPROP_ENUMERATE)) | |||
break; | break; | |||
/*@fallthrough@*/ | /*@fallthrough@*/ | |||
default: | default: | |||
assert(0); | assert(0); | |||
break; | break; | |||
} | } | |||
_path = _free(_path); | _path = _free(_path); | |||
_value = _free(_value); | _value = _free(_value); | |||
name = _free(name); | ||||
} | } | |||
*objp = obj; /* XXX always resolve in this object. */ | *objp = obj; /* XXX always resolve in this object. */ | |||
exit: | exit: | |||
return JS_TRUE; | return JS_TRUE; | |||
} | } | |||
static JSBool | static JSBool | |||
rpmaug_enumerate(JSContext *cx, JSObject *obj, JSIterateOp op, | rpmaug_enumerate(JSContext *cx, JSObject *obj, JSIterateOp op, | |||
jsval *statep, jsid *idp) | jsval *statep, jsid *idp) | |||
{ | { | |||
_ENUMERATE_DEBUG_ENTRY(_debug); | _ENUMERATE_DEBUG_ENTRY(_debug); | |||
switch (op) { | switch (op) { | |||
case JSENUMERATE_INIT: | case JSENUMERATE_INIT: | |||
case JSENUMERATE_INIT_ALL: | ||||
*statep = JSVAL_VOID; | *statep = JSVAL_VOID; | |||
if (idp) | if (idp) | |||
*idp = JSVAL_ZERO; | *idp = JSVAL_ZERO; | |||
break; | break; | |||
case JSENUMERATE_NEXT: | case JSENUMERATE_NEXT: | |||
*statep = JSVAL_VOID; | *statep = JSVAL_VOID; | |||
if (*idp != JSVAL_VOID) | if (!JSID_IS_VOID(*idp)) | |||
break; | break; | |||
/*@fallthrough@*/ | /*@fallthrough@*/ | |||
case JSENUMERATE_DESTROY: | case JSENUMERATE_DESTROY: | |||
*statep = JSVAL_NULL; | *statep = JSVAL_NULL; | |||
break; | break; | |||
} | } | |||
return JS_TRUE; | return JS_TRUE; | |||
} | } | |||
/* --- Object ctors/dtors */ | /* --- Object ctors/dtors */ | |||
skipping to change at line 518 | skipping to change at line 543 | |||
{ | { | |||
void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); | |||
rpmaug aug = ptr; | rpmaug aug = ptr; | |||
_DTOR_DEBUG_ENTRY(_debug); | _DTOR_DEBUG_ENTRY(_debug); | |||
aug = rpmaugFree(aug); | aug = rpmaugFree(aug); | |||
} | } | |||
static JSBool | static JSBool | |||
rpmaug_ctor( JSContext* cx, uintN argc, jsval* vp ) | rpmaug_ctor(JSContext *cx, uintN argc, jsval *vp) | |||
{ | { | |||
jsval *argv = JS_ARGV( cx , vp ); | jsval *argv = JS_ARGV(cx, vp); | |||
JSObject *obj = JS_NewObjectForConstructor( cx , vp ); | JSObject *obj = JS_NewObjectForConstructor(cx, vp); | |||
if( ! obj ) { | ||||
JS_ReportError( cx , "Failed to create 'this' object" ); | ||||
return JS_FALSE; | ||||
} | ||||
JSBool ok = JS_FALSE; | JSBool ok = JS_FALSE; | |||
const char * _root = _rpmaugRoot; | const char * _root = _rpmaugRoot; | |||
const char * _loadpath = _rpmaugLoadpath; | const char * _loadpath = _rpmaugLoadpath; | |||
unsigned int _flags = _rpmaugFlags; | unsigned int _flags = _rpmaugFlags; | |||
_CTOR_DEBUG_ENTRY(_debug, vp); | _CTOR_DEBUG_ENTRY(_debug); | |||
if (!(ok = JS_ConvertArguments(cx, argc, argv, "/ssu", &_root, &_loadpa th, &_flags))) | if (!(ok = JS_ConvertArguments(cx, argc, argv, "/ssu", &_root, &_loadpa th, &_flags))) | |||
goto exit; | goto exit; | |||
if (JS_IsConstructing(cx, vp)) { | if (JS_IsConstructing(cx, vp)) { | |||
if (rpmaug_init(cx, obj, _root, _loadpath, _flags) == NULL) | if (rpmaug_init(cx, obj, _root, _loadpath, _flags) == NULL) | |||
goto exit; | goto exit; | |||
} else { | } else { | |||
if ((obj = JS_NewObject(cx, &rpmaugClass, NULL, NULL)) == NULL) | if ((obj = JS_NewObject(cx, &rpmaugClass, NULL, NULL)) == NULL) | |||
goto exit; | goto exit; | |||
skipping to change at line 580 | skipping to change at line 601 | |||
assert(o != NULL); | assert(o != NULL); | |||
return o; | return o; | |||
} | } | |||
JSObject * | JSObject * | |||
rpmjs_NewAugObject(JSContext *cx, const char * _root, | rpmjs_NewAugObject(JSContext *cx, const char * _root, | |||
const char * _loadpath, unsigned int _flags) | const char * _loadpath, unsigned int _flags) | |||
{ | { | |||
JSObject *obj; | JSObject *obj; | |||
rpmaug aug; | rpmaug aug; | |||
if( ! obj ) { | ||||
JS_ReportError( cx , "Failed to create 'this' object" ); | ||||
return JS_FALSE; | ||||
} | ||||
if ((obj = JS_NewObject(cx, &rpmaugClass, NULL, NULL)) == NULL) { | if ((obj = JS_NewObject(cx, &rpmaugClass, NULL, NULL)) == NULL) { | |||
/* XXX error msg */ | /* XXX error msg */ | |||
return NULL; | return NULL; | |||
} | } | |||
if ((aug = rpmaug_init(cx, obj, _root, _loadpath, _flags)) == NULL) { | if ((aug = rpmaug_init(cx, obj, _root, _loadpath, _flags)) == NULL) { | |||
/* XXX error msg */ | /* XXX error msg */ | |||
return NULL; | return NULL; | |||
} | } | |||
return obj; | return obj; | |||
End of changes. 54 change blocks. | ||||
47 lines changed or deleted | 72 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |