Esempio n. 1
0
link_array_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
    JSObjectArray *array;
    MochaDecoder *decoder;
    MWContext *context;
    jsint count, slot;
    LO_AnchorData *anchor_data;
    int32 active_layer_id;

    if (!JSVAL_IS_INT(id))
	return JS_TRUE;

    slot = JSVAL_TO_INT(id);

    array = JS_GetInstancePrivate(cx, obj, &lm_link_array_class, NULL);
    if (!array)
	return JS_TRUE;
    decoder = array->decoder;
    context = decoder->window_context;
    if (!context) return JS_TRUE;

    LO_LockLayout();
    switch (slot) {
      case ANCHOR_ARRAY_LENGTH:
	active_layer_id = LM_GetActiveLayer(context);
	LM_SetActiveLayer(context, array->layer_id);
	count = LO_EnumerateLinks(context, array->layer_id);
	LM_SetActiveLayer(context, active_layer_id);
	if (count > array->length)
	    array->length = count;
	*vp = INT_TO_JSVAL(count);
	break;

      default:
	if (slot < 0) {
	    /* Don't mess with user-defined or method properties. */
	    LO_UnlockLayout();
	    return JS_TRUE;
	}
	if (slot >= array->length)
	    array->length = slot + 1;
	anchor_data = LO_GetLinkByIndex(context, array->layer_id, (uint)slot);
	if (anchor_data) {
	    *vp = OBJECT_TO_JSVAL(LM_ReflectLink(context, anchor_data, NULL,
						 array->layer_id, (uint)slot));
	}
	break;
    }
    LO_UnlockLayout();
    return JS_TRUE;
}
Esempio n. 2
0
anchor_array_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
    JSObjectArray *array;
    MochaDecoder *decoder;
    MWContext *context;
    jsint count, slot;
    lo_NameList *name_rec;
    int32 active_layer_id;

    if (!JSVAL_IS_INT(id))
	return JS_TRUE;

    slot = JSVAL_TO_INT(id);

    array = JS_GetInstancePrivate(cx, obj, &lm_anchor_array_class, NULL);
    if (!array)
	return JS_TRUE;
    decoder = array->decoder;
    context = decoder->window_context;
    if (!context) return JS_TRUE;
    LO_LockLayout();
    switch (slot) {
      case ANCHOR_ARRAY_LENGTH:
	active_layer_id = LM_GetActiveLayer(context);
	LM_SetActiveLayer(context, array->layer_id);
	count = LO_EnumerateNamedAnchors(context, array->layer_id);
	LM_SetActiveLayer(context, active_layer_id);
	if (count > array->length)
	    array->length = count;
	*vp = INT_TO_JSVAL(count);
	break;

      default:
	if (slot >= array->length)
	    array->length = slot + 1;
	name_rec = LO_GetNamedAnchorByIndex(context, array->layer_id,
                                            (uint)slot);
	if (name_rec) {
	    *vp = OBJECT_TO_JSVAL(LM_ReflectNamedAnchor(context, name_rec,
							NULL, array->layer_id,
                                                        (uint)slot));
	}
	break;
    }
    LO_UnlockLayout();
    return JS_TRUE;
}
Esempio n. 3
0
embed_array_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
    JSObjectArray *array;
    MochaDecoder *decoder;
    MWContext *context;
    jsint count, slot;
    LO_EmbedStruct *embed_data;
    int32 active_layer_id;

    if (!JSVAL_IS_INT(id))
	return JS_TRUE;

    slot = JSVAL_TO_INT(id);

    array = JS_GetInstancePrivate(cx, obj, &lm_embed_array_class, NULL);
    if (!array)
	return JS_TRUE;
    decoder = array->decoder;
    context = decoder->window_context;

    if (!context) return JS_TRUE;

    if (LM_MOJA_OK != ET_InitMoja(context))
        return JS_FALSE;

    LO_LockLayout();
    switch (slot) {
      case EMBED_ARRAY_LENGTH:
	active_layer_id = LM_GetActiveLayer(context);
	LM_SetActiveLayer(context, array->layer_id);
	count = LO_EnumerateEmbeds(context, array->layer_id);
	LM_SetActiveLayer(context, active_layer_id);
	if (count > array->length)
	    array->length = count;
        *vp = INT_TO_JSVAL(array->length);
	break;

      default:
	if (slot < 0) {
	    /* Don't mess with user-defined or method properties. */
	    LO_UnlockLayout();
	    return JS_TRUE;
	}
	embed_data = LO_GetEmbedByIndex(context, array->layer_id, (uint)slot);
	if (embed_data) {
            JSObject *mo = LM_ReflectEmbed(context, embed_data, NULL,
					   array->layer_id, (uint)slot);
            if (!mo) {
                JS_ReportError(cx,
                 "unable to reflect embed with index %d - not loaded yet?",
                 (uint) slot);
                goto err;
            }
            *vp = OBJECT_TO_JSVAL(mo);
            XP_ASSERT(slot < array->length);
	} else {
            JS_ReportError(cx, "no embed with index %d\n");
            goto err;
        }
	break;
    }
    LO_UnlockLayout();
    return JS_TRUE;
  err:
    LO_UnlockLayout();
    return JS_FALSE;
}