Пример #1
0
void fx_String_charCodeAt(txMachine* the)
{
	txString aString;
	txInteger aLength;
	txInteger anOffset;

	aString = fxCoerceToString(the, mxThis);
	if (!aString)
		mxDebug0(the, XS_TYPE_ERROR, "String.prototype.charCodeAt: this is null or undefined");
	aLength = fxUnicodeLength(aString);
	if ((mxArgc > 0) && (mxArgv(0)->kind != XS_UNDEFINED_KIND))
		anOffset = fxToInteger(the, mxArgv(0));
	else
		anOffset = -1;
	if ((0 <= anOffset) && (anOffset < aLength)) {
		anOffset = fxUnicodeToUTF8Offset(aString, anOffset);
		aLength = fxUnicodeToUTF8Offset(aString + anOffset, 1);
		if ((anOffset >= 0) && (aLength > 0)) {
			mxResult->value.integer = fxUnicodeCharacter(aString + anOffset);
			mxResult->kind = XS_INTEGER_KIND;
		}
		else {
			mxResult->value.number = C_NAN;
			mxResult->kind = XS_NUMBER_KIND;
		}
	}
	else {
		mxResult->value.number = C_NAN;
		mxResult->kind = XS_NUMBER_KIND;
	}
}
Пример #2
0
void fx_String_charAt(txMachine* the)
{
	txString aString;
	txInteger aLength;
	txInteger anOffset;

	aString = fxCoerceToString(the, mxThis);
	if (!aString)
		mxDebug0(the, XS_TYPE_ERROR, "String.prototype.charAt: this is null or undefined");
	aLength = fxUnicodeLength(aString);
	if ((mxArgc > 0) && (mxArgv(0)->kind != XS_UNDEFINED_KIND))
		anOffset = fxToInteger(the, mxArgv(0));
	else
		anOffset = -1;
	if ((0 <= anOffset) && (anOffset < aLength)) {
		anOffset = fxUnicodeToUTF8Offset(aString, anOffset);
		aLength = fxUnicodeToUTF8Offset(aString + anOffset, 1);
		if ((anOffset >= 0) && (aLength > 0)) {
			mxResult->value.string = (txString)fxNewChunk(the, aLength + 1);
			c_memcpy(mxResult->value.string, mxThis->value.string + anOffset, aLength);
			mxResult->value.string[aLength] = 0;
			mxResult->kind = XS_STRING_KIND;
		}
		else {
			mxResult->value.string = mxEmptyString.value.string;
			mxResult->kind = mxEmptyString.kind;
		}
	}
	else {
		mxResult->value.string = mxEmptyString.value.string;
		mxResult->kind = mxEmptyString.kind;
	}
}
Пример #3
0
txSlot* fxToInstance(txMachine* the, txSlot* theSlot)
{
	txSlot* anInstance = C_NULL;
	
	switch (theSlot->kind) {
	case XS_UNDEFINED_KIND:
		mxTypeError("cannot coerce undefined to object");
		break;
	case XS_NULL_KIND:
		mxTypeError("cannot coerce null to object");
		break;
	case XS_BOOLEAN_KIND:
		mxPush(mxBooleanPrototype);
		anInstance = fxNewBooleanInstance(the);
		anInstance->next->value.boolean = theSlot->value.boolean;
		mxPullSlot(theSlot);
		break;
	case XS_INTEGER_KIND:
		mxPush(mxNumberPrototype);
		anInstance = fxNewNumberInstance(the);
		anInstance->next->value.number = theSlot->value.integer;
		mxPullSlot(theSlot);
		break;
	case XS_NUMBER_KIND:
		mxPush(mxNumberPrototype);
		anInstance = fxNewNumberInstance(the);
		anInstance->next->value.number = theSlot->value.number;
		mxPullSlot(theSlot);
		break;
	case XS_STRING_KIND:
	case XS_STRING_X_KIND:
		mxPush(mxStringPrototype);
		anInstance = fxNewStringInstance(the);
		anInstance->next->value.string = theSlot->value.string;
		anInstance->next->next->next->value.integer = fxUnicodeLength(theSlot->value.string);
		mxPullSlot(theSlot);
		break;
	case XS_SYMBOL_KIND:
		mxPush(mxSymbolPrototype);
		anInstance = fxNewSymbolInstance(the);
		anInstance->next->value.ID = theSlot->value.ID;
		mxPullSlot(theSlot);
		break;
	case XS_REFERENCE_KIND:
		anInstance = theSlot->value.reference;
		break;
	default:
		mxTypeError("cannot coerce to instance");
		break;
	}
	return anInstance;
}
Пример #4
0
FskErr KprLabelSetText(KprLabel self, char* text, UInt32 size)
{
	FskErr err = kFskErrNone;
	char* buffer;
	bailIfError(FskMemPtrNew(size + 1, &buffer));
	if (size > 0)
		FskMemMove(buffer, text, size); 
	buffer[size] = 0;
	self->length = fxUnicodeLength(text);
	self->from = self->to = 0;
	FskMemPtrDispose(self->text);
	self->text = buffer;
bail:
	if (self->shell) {
		KprLabelMeasureSelection(self);
		KprContentInvalidate((KprContent)self);
		KprContentReflow((KprContent)self, kprSizeChanged);
	}
	return err;
}
Пример #5
0
FskErr KprLabelInsertStringWithLength(KprLabel self, char* text, UInt32 size)
{
	FskErr err = kFskErrNone;
	UInt32 oldSize = FskStrLen(self->text);
	SInt32 fromSize = fxUnicodeToUTF8Offset(self->text, self->from);
	SInt32 toSize = fxUnicodeToUTF8Offset(self->text, self->to);
	UInt32 newSize = oldSize - (toSize - fromSize) + size;
	char* buffer;
	bailIfError(FskMemPtrNew(newSize + 1, &buffer));
	if (fromSize > 0)
		FskMemMove(buffer, self->text, fromSize); 
	if (size > 0)
		FskMemMove(buffer + fromSize, text, size); 
	if (oldSize - toSize > 0)
		FskMemMove(buffer + fromSize + size, self->text + toSize, oldSize - toSize);
	buffer[newSize] = 0;
	FskMemPtrDispose(self->text);
	if (self->flags & kprTextHidden) {
		if ((self->from == self->length) && (self->to == self->length) && (fxUTF8ToUnicodeOffset(text, size) == 1)) {
			self->flags |= kprTextShowLast;
			if (!self->showLastCallback)
				FskTimeCallbackNew(&self->showLastCallback);
			FskTimeCallbackScheduleFuture(self->showLastCallback, 1, 0, KprLabelShowLastCallback, self);		
		}
		else {
			if (self->showLastCallback)
				FskTimeCallbackRemove(self->showLastCallback);
			self->flags &= ~kprTextShowLast;
		}
	}
	self->text = buffer;
	self->length = fxUnicodeLength(buffer);
	self->from = self->to = fxUTF8ToUnicodeOffset(buffer, fromSize + size);
bail:
	if (self->shell) {
		KprLabelMeasureSelection(self);
		KprContentInvalidate((KprContent)self);
		KprContentReflow((KprContent)self, kprSizeChanged);
	}
	return err;
}
Пример #6
0
void fx_String(txMachine* the)
{
	if ((mxThis->kind == XS_REFERENCE_KIND) && ((mxThis->value.reference->flag & XS_SHARED_FLAG) == 0)) {
		txSlot* anInstance = mxThis->value.reference;
        if (mxIsString(anInstance)) {
            if (mxArgc > 0) {
                txString aString = fxToString(the, mxArgv(0));
                anInstance->next->value.string = aString;
                anInstance->next->next->value.integer = fxUnicodeLength(aString);
            }
            *mxResult = *mxThis;
        }
        return;
    }

    if (mxArgc > 0) {
        *mxResult = *mxArgv(0);
        fxToString(the, mxResult);
    }
    else {
        mxResult->value.string = mxEmptyString.value.string;
        mxResult->kind = mxEmptyString.kind;
    }
}
Пример #7
0
void fxEachOwnProperty(txMachine* the, txSlot* theInstance, txFlag theFlag, txStep theStep, txSlot* theContext)
{
	txSlot* aProperty;
	txIndex aCount;
	txIndex anIndex;

	txFlag propertyFlag = theFlag & XS_DONT_ENUM_FLAG;
	if (!(theFlag & XS_DONT_ENUM_STRING_FLAG)) {
		aProperty = theInstance->next;
		if (theInstance->flag & XS_VALUE_FLAG) {
			if (aProperty->kind == XS_STAR_KIND) {
				aProperty = aProperty->next;
				while (aProperty) {
					if (!(aProperty->flag & propertyFlag)) {
						if (aProperty->ID != XS_NO_ID)
							(*theStep)(the, theContext, aProperty->ID, aProperty->value.closure);
					}
					aProperty = aProperty->next;
				}
				return;
			}
			else if ((aProperty->kind == XS_STRING_KIND) || (aProperty->kind == XS_STRING_X_KIND)) {
				aCount = fxUnicodeLength(aProperty->value.string);
				for (anIndex = 0; anIndex < aCount; anIndex++) {
					(*theStep)(the, theContext, anIndex, &mxEmptyString);
				}
			}
		}
		while (aProperty) {
			if (!(aProperty->flag & propertyFlag)) {
				if (aProperty->ID == XS_NO_ID) {
					if (aProperty->kind == XS_ARRAY_KIND) {
						aCount = aProperty->value.array.length;
						for (anIndex = 0; anIndex < aCount; anIndex++) {
							if ((aProperty->value.array.address + anIndex)->ID)
								(*theStep)(the, theContext, anIndex, aProperty->value.array.address + anIndex);
						}
						break;
					}
				}
			}
			aProperty = aProperty->next;
		}
		aProperty = theInstance->next;
		while (aProperty) {
			if (!(aProperty->flag & propertyFlag)) {
				if (aProperty->ID < XS_NO_ID) {
					txSlot* key = fxGetKey(the, aProperty->ID);
					if (key && (key->flag & XS_DONT_ENUM_FLAG)) {
						(*theStep)(the, theContext, aProperty->ID, aProperty);
					}
				}
			}
			aProperty = aProperty->next;
		}
	}
	if (!(theFlag & XS_DONT_ENUM_SYMBOL_FLAG)) {
		aProperty = theInstance->next;
		while (aProperty) {
			if (!(aProperty->flag & propertyFlag)) {
				if (aProperty->ID < XS_NO_ID) {
					txSlot* key = fxGetKey(the, aProperty->ID);
					if (!key || !(key->flag & XS_DONT_ENUM_FLAG)) {
						(*theStep)(the, theContext, aProperty->ID, aProperty);
					}
				}
			}
			aProperty = aProperty->next;
		}
	}
}