Exemplo n.º 1
0
js_free_symbol(void *priv, PRHashEntry *he, uintN flag)
{
    JSContext *cx;
    JSSymbol *sym, **sp;
    JSProperty *prop;

    cx = priv;
    PR_ASSERT(JS_IS_LOCKED(cx));
    sym = (JSSymbol *)he;
    prop = sym->entry.value;
    if (prop) {
        sym->entry.value = NULL;
        prop = js_DropProperty(cx, prop);
        if (prop) {
            for (sp = &prop->symbols; *sp; sp = &(*sp)->next) {
                if (*sp == sym) {
                    *sp = sym->next;
                    if (!*sp)
                        break;
                }
            }
            sym->next = NULL;
        }
    }

    if (flag == HT_FREE_ENTRY) {
        if (!JSVAL_IS_INT(sym_id(sym)))
            JS_LOCK_VOID(cx, js_DropAtom(cx, sym_atom(sym)));
        JS_free(cx, he);
    }
}
Exemplo n.º 2
0
void
js_TryMethod(JSContext *cx, JSObject *obj, JSAtom *atom,
	     uintN argc, jsval *argv, jsval *rval)
{
    JSErrorReporter older;
    JSProperty *prop;
    jsval fval;

    older = JS_SetErrorReporter(cx, NULL);
    JS_LOCK_VOID(cx, prop = js_GetProperty(cx, obj, (jsval)atom, &fval));
    if (prop &&
	JSVAL_IS_OBJECT(fval) &&
	fval != JSVAL_NULL) {
	(void) js_Call(cx, obj, fval, argc, argv, rval);
    }
    JS_SetErrorReporter(cx, older);
}
Exemplo n.º 3
0
JSObject *
js_ConstructObject(JSContext *cx, JSClass *clasp, JSObject *proto,
		   JSObject *parent)
{
    JSObject *obj;
    JSBool ok;
    jsval ctor, rval;

    obj = js_NewObject(cx, clasp, proto, parent);
    if (!obj)
	return NULL;
    JS_LOCK_VOID(cx, ok = FindConstructor(cx, clasp, &ctor));
    if (!ok || !js_Call(cx, obj, ctor, 0, NULL, &rval)) {
	cx->newborn[GCX_OBJECT] = NULL;
	return NULL;
    }
    return JSVAL_IS_OBJECT(rval) ? JSVAL_TO_OBJECT(rval) : obj;
}
Exemplo n.º 4
0
JSObject *
js_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent)
{
    JSObject *obj;
    JSScope *scope;

    /* Allocate an object from the GC heap and zero it. */
    obj = js_AllocGCThing(cx, GCX_OBJECT);
    if (!obj)
	return NULL;

    /* Bootstrap the ur-object, and make it the default prototype object. */
    if (!proto) {
	if (!js_GetClassPrototype(cx, clasp, &proto) ||
	    (!proto && !js_GetClassPrototype(cx, &js_ObjectClass, &proto))) {
	    cx->newborn[GCX_OBJECT] = NULL;
	    return NULL;
	}
    }

    /* Share the given prototype's scope (create one if necessary). */
    if (proto && proto->map->clasp == clasp) {
	scope = (JSScope *)proto->map;
	JS_LOCK_VOID(cx, obj->map = (JSObjectMap *)js_HoldScope(cx, scope));
    } else {
	scope = js_NewScope(cx, clasp, obj);
	if (!scope) {
	    cx->newborn[GCX_OBJECT] = NULL;
	    return NULL;
	}
	scope->map.nrefs = 1;
	obj->map = &scope->map;
    }

    /* Set the prototype and parent properties. */
    if (!js_SetSlot(cx, obj, JSSLOT_PROTO, OBJECT_TO_JSVAL(proto)) ||
	!js_SetSlot(cx, obj, JSSLOT_PARENT, OBJECT_TO_JSVAL(parent))) {
	cx->newborn[GCX_OBJECT] = NULL;
	return NULL;
    }
    return obj;
}
Exemplo n.º 5
0
static JSBool
obj_getSlot(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
    JS_LOCK_VOID(cx, *vp = js_GetSlot(cx, obj, JSVAL_TO_INT(id)));
    return JS_TRUE;
}
Exemplo n.º 6
0
static JSBool
obj_unwatch(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
    JS_LOCK_VOID(cx, JS_ClearWatchPoint(cx, obj, argv[0], NULL, NULL));
    return JS_TRUE;
}