Exemple #1
0
void fxBuildDate(txMachine* the)
{
    static const txHostFunctionBuilder gx_Date_prototype_builders[] = {
		{ fx_Date_prototype_getMilliseconds, 0, _getMilliseconds },
		{ fx_Date_prototype_getSeconds, 0, _getSeconds },
		{ fx_Date_prototype_getMinutes, 0, _getMinutes },
		{ fx_Date_prototype_getHours, 0, _getHours },
		{ fx_Date_prototype_getDay, 0, _getDay },
		{ fx_Date_prototype_getDate, 0, _getDate },
		{ fx_Date_prototype_getMonth, 0, _getMonth },
		{ fx_Date_prototype_getYear, 0, _getYear },
		{ fx_Date_prototype_getFullYear, 0, _getFullYear },
		{ fx_Date_prototype_getUTCMilliseconds, 0, _getUTCMilliseconds },
		{ fx_Date_prototype_getUTCSeconds, 0, _getUTCSeconds },
		{ fx_Date_prototype_getUTCMinutes, 0, _getUTCMinutes },
		{ fx_Date_prototype_getUTCHours, 0, _getUTCHours },
		{ fx_Date_prototype_getUTCDay, 0, _getUTCDay },
		{ fx_Date_prototype_getUTCDate, 0, _getUTCDate },
		{ fx_Date_prototype_getUTCMonth, 0, _getUTCMonth },
		{ fx_Date_prototype_getUTCFullYear, 0, _getUTCFullYear },
		{ fx_Date_prototype_valueOf, 0, _getTime },
		{ fx_Date_prototype_getTimezoneOffset, 0, _getTimezoneOffset },
		{ fx_Date_prototype_setMilliseconds, 1, _setMilliseconds },
		{ fx_Date_prototype_setSeconds, 1, _setSeconds },
		{ fx_Date_prototype_setMinutes, 1, _setMinutes },
		{ fx_Date_prototype_setHours, 1, _setHours },
		{ fx_Date_prototype_setDate, 1, _setDate },
		{ fx_Date_prototype_setMonth, 1, _setMonth },
		{ fx_Date_prototype_setYear, 1, _setYear },
		{ fx_Date_prototype_setFullYear, 1, _setFullYear },
		{ fx_Date_prototype_setTime, 1, _setTime },
		{ fx_Date_prototype_setUTCMilliseconds, 1, _setUTCMilliseconds },
		{ fx_Date_prototype_setUTCSeconds, 1, _setUTCSeconds },
		{ fx_Date_prototype_setUTCMinutes, 1, _setUTCMinutes },
		{ fx_Date_prototype_setUTCHours, 1, _setUTCHours },
		{ fx_Date_prototype_setUTCDate, 1, _setUTCDate },
		{ fx_Date_prototype_setUTCMonth, 1, _setUTCMonth },
		{ fx_Date_prototype_setUTCFullYear, 1, _setUTCFullYear },
		{ fx_Date_prototype_toDateString, 0, _toDateString },
		{ fx_Date_prototype_toUTCString, 0, _toGMTString },
		{ fx_Date_prototype_toISOString, 0, _toISOString },
		{ fx_Date_prototype_toJSON, 1, _toJSON },
		{ fx_Date_prototype_toDateString, 0, _toLocaleDateString },
		{ fx_Date_prototype_toString, 0, _toLocaleString },
		{ fx_Date_prototype_toTimeString, 0, _toLocaleTimeString },
		{ fx_Date_prototype_toPrimitive, 0, _Symbol_toPrimitive },
		{ fx_Date_prototype_toString, 0, _toString },
		{ fx_Date_prototype_toTimeString, 0, _toTimeString },
		{ fx_Date_prototype_toUTCString, 0, _toUTCString },
		{ fx_Date_prototype_valueOf, 0, _valueOf },
		{ C_NULL, 0, 0 },
    };
    static const txHostFunctionBuilder gx_Date_builders[] = {
		{ fx_Date_now, 0, _now },
		{ fx_Date_parse, 1, _parse },
		{ fx_Date_UTC, 2, _UTC },
		{ C_NULL, 0, 0 },
    };
    const txHostFunctionBuilder* builder;
	txSlot* slot;
	txTimeDescription td;
	mxPush(mxObjectPrototype);
	slot = fxLastProperty(the, fxNewDateInstance(the));
	for (builder = gx_Date_prototype_builders; builder->callback; builder++)
		slot = fxNextHostFunctionProperty(the, slot, builder->callback, builder->length, mxID(builder->id), XS_DONT_ENUM_FLAG);
	slot = fxNextStringProperty(the, slot, "Date", mxID(_Symbol_toStringTag), XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	mxDatePrototype = *the->stack;
	slot = fxLastProperty(the, fxNewHostConstructorGlobal(the, fx_Date, 1, mxID(_Date), XS_GET_ONLY));
	for (builder = gx_Date_builders; builder->callback; builder++)
		slot = fxNextHostFunctionProperty(the, slot, builder->callback, builder->length, mxID(builder->id), XS_DONT_ENUM_FLAG);
	the->stack++;
	c_memset(&td, 0, sizeof(txTimeDescription));
    td.tm.tm_mday = 2;
    td.tm.tm_year = 70;
	td.tm.tm_isdst = -1;
	gxDeltaTime = 1000.0 * ((long)c_mktime(&(td.tm)) - (24L * 3600L));
	gxMaxTime = TIME_2100; //extend from LONG_MAX to this number to support year upto 2099
	gxMinTime = LONG_MIN;
}
Exemple #2
0
void fxNewInstanceOf(txMachine* the)
{
	txSlot* aParent;

	if (the->stack->kind == XS_NULL_KIND) {
		txSlot* instance = fxNewSlot(the);
		instance->kind = XS_INSTANCE_KIND;
		instance->value.instance.garbage = C_NULL;
		instance->value.instance.prototype = C_NULL;
		the->stack->value.reference = instance;
		the->stack->kind = XS_REFERENCE_KIND;
	}
	else {
		fxToInstance(the, the->stack);
		aParent = fxGetInstance(the, the->stack);
		if (aParent->flag & XS_VALUE_FLAG) {
			switch (aParent->next->kind) {
			case XS_CALLBACK_KIND:
			case XS_CODE_KIND:
				fxNewFunctionInstance(the, XS_NO_ID);
				break;
			case XS_ARRAY_KIND:
				fxNewArrayInstance(the);
				break;
			case XS_STRING_KIND:
			case XS_STRING_X_KIND:
				fxNewStringInstance(the);
				break;
			case XS_BOOLEAN_KIND:
				fxNewBooleanInstance(the);
				break;
			case XS_NUMBER_KIND:
				fxNewNumberInstance(the);
				break;
			case XS_DATE_KIND:
				fxNewDateInstance(the);
				break;
			case XS_REGEXP_KIND:
				fxNewRegExpInstance(the);
				break;
			case XS_SYMBOL_KIND:
				fxNewSymbolInstance(the);
				break;
			case XS_HOST_KIND:
				fxNewHostInstance(the);
				break;
			case XS_PROMISE_KIND:
				fxNewPromiseInstance(the);
				break;
			case XS_PROXY_KIND:
				fxNewProxyInstance(the);
				break;
			case XS_MAP_KIND:
				fxNewMapInstance(the);
				break;
			case XS_SET_KIND:
				fxNewSetInstance(the);
				break;
			case XS_WEAK_MAP_KIND:
				fxNewWeakMapInstance(the);
				break;
			case XS_WEAK_SET_KIND:
				fxNewWeakSetInstance(the);
				break;
			case XS_ARRAY_BUFFER_KIND:
				fxNewArrayBufferInstance(the);
				break;
			case XS_DATA_VIEW_KIND:
				fxNewDataViewInstance(the);
				break;
			case XS_TYPED_ARRAY_KIND:
				fxNewTypedArrayInstance(the, aParent->next->value.typedArray);
				break;
			case XS_STACK_KIND:
				fxNewGeneratorInstance(the);
				break;
			default:
				mxSyntaxError("C: xsNewInstanceOf: invalid prototype");
				break;
			}
		}
		else
			fxNewObjectInstance(the);
	}
}