diff --git a/js.h b/js.h index 50b76f3..4479996 100644 --- a/js.h +++ b/js.h @@ -95,12 +95,14 @@ void js_getproperty(js_State *J, int idx, const char *name); void js_setproperty(js_State *J, int idx, const char *name); void js_defproperty(js_State *J, int idx, const char *name, int atts); void js_delproperty(js_State *J, int idx, const char *name); +void js_defaccessor(js_State *J, int idx, const char *name); int js_hasindex(js_State *J, int idx, unsigned int i); void js_getindex(js_State *J, int idx, unsigned int i); void js_setindex(js_State *J, int idx, unsigned int i); void js_delindex(js_State *J, int idx, unsigned int i); +void js_currentfunction(js_State *J); void js_pushglobal(js_State *J); void js_pushundefined(js_State *J); void js_pushnull(js_State *J); diff --git a/jsrun.c b/jsrun.c index 76c894d..e33083a 100644 --- a/jsrun.c +++ b/jsrun.c @@ -108,6 +108,13 @@ void js_pushglobal(js_State *J) js_pushobject(J, J->G); } +void js_currentfunction(js_State *J) +{ + CHECKSTACK(1); + STACK[TOP] = STACK[BOT-1]; + ++TOP; +} + /* Read values from stack */ static const js_Value *stackidx(js_State *J, int idx) @@ -245,6 +252,8 @@ void *js_touserdata(js_State *J, const char *tag, int idx) static js_Object *jsR_tofunction(js_State *J, int idx) { const js_Value *v = stackidx(J, idx); + if (v->type == JS_TNULL) + return NULL; if (v->type == JS_TOBJECT) if (v->u.object->type == JS_CFUNCTION || v->u.object->type == JS_CCFUNCTION) return v->u.object; @@ -603,6 +612,12 @@ void js_delproperty(js_State *J, int idx, const char *name) jsR_delproperty(J, js_toobject(J, idx), name); } +void js_defaccessor(js_State *J, int idx, const char *name) +{ + jsR_defproperty(J, js_toobject(J, idx), name, 0, NULL, jsR_tofunction(J, -2), jsR_tofunction(J, -1)); + js_pop(J, 2); +} + int js_hasproperty(js_State *J, int idx, const char *name) { return jsR_hasproperty(J, js_toobject(J, idx), name);