예제 #1
0
void fxBuildGlobal(txMachine* the)
{
    static const txHostFunctionBuilder gx_global_builders[] = {
		{ fx_decodeURI, 1, _decodeURI },
		{ fx_decodeURIComponent, 1, _decodeURIComponent },
		{ fx_encodeURI, 1, _encodeURI },
		{ fx_encodeURIComponent, 1, _encodeURIComponent },
		{ fx_escape, 1, _escape },
		{ fx_eval, 1, _eval },
		{ fx_trace, 1, _trace },
		{ fx_unescape, 1, _unescape },
		{ C_NULL, 0, 0 },
    };
    const txHostFunctionBuilder* builder;
	txSlot* slot;
	
	fxNewGlobalInstance(the);
	mxPull(mxGlobal);

	fxNewInstance(the);
	mxPull(mxObjectPrototype);
	
	mxPush(mxObjectPrototype);
	fxNewFunctionInstance(the, XS_NO_ID);
	mxPull(mxFunctionPrototype);
	
	for (builder = gx_global_builders; builder->callback; builder++) {
		fxNewHostFunctionGlobal(the, builder->callback, builder->length, mxID(builder->id), XS_DONT_ENUM_FLAG);
		the->stack++;
	}
	slot = fxSetGlobalProperty(the, mxGlobal.value.reference, mxID(_undefined), C_NULL);
	slot->flag = XS_GET_ONLY;
	
	mxPush(mxObjectPrototype);
	slot = fxNewObjectInstance(the);
	slot = fxNextHostFunctionProperty(the, slot, fx_Iterator_iterator, 0, mxID(_Symbol_iterator), XS_DONT_ENUM_FLAG);
	mxPull(mxIteratorPrototype);
	
	mxPush(mxIteratorPrototype);
	slot = fxLastProperty(the, fxNewObjectInstance(the));
	slot = fxNextHostFunctionProperty(the, slot, fx_Enumerator_next, 0, mxID(_next), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG);
	fxNewHostConstructor(the, fx_Enumerator, 0, XS_NO_ID);
	mxPull(mxEnumeratorFunction);
}
예제 #2
0
void fxBuildHost(txMachine* the)
{
	fxNewHostFunctionGlobal(the, fx_setTimeout, 1, fxID(the, "setTimeout"), XS_DONT_ENUM_FLAG);
	the->stack++;
}
예제 #3
0
void fxBuildNumber(txMachine* the)
{
    static const txHostFunctionBuilder gx_global_builders[] = {
		{ fx_isFinite, 1, _isFinite },
		{ fx_isNaN, 1, _isNaN },
		{ fx_parseFloat, 1, _parseFloat },
		{ fx_parseInt, 2, _parseInt },
		{ C_NULL, 0, 0 },
    };
  	static const txHostFunctionBuilder gx_Number_prototype_builders[] = {
		{ fx_Number_prototype_toExponential, 1, _toExponential },
		{ fx_Number_prototype_toFixed, 1, _toFixed },
		{ fx_Number_prototype_toString, 0, _toLocaleString },
		{ fx_Number_prototype_toPrecision, 1, _toPrecision },
		{ fx_Number_prototype_toString, 1, _toString },
		{ fx_Number_prototype_valueOf, 0, _valueOf },
		{ C_NULL, 0, 0 },
    };
    static const txHostFunctionBuilder gx_Number_builders[] = {
		{ fx_Number_isFinite, 1, _isFinite },
		{ fx_Number_isInteger, 1, _isInteger },
		{ fx_Number_isNaN, 1, _isNaN },
		{ fx_Number_isSafeInteger, 1, _isSafeInteger },
		{ fx_parseFloat, 1, _parseFloat },
		{ fx_parseInt, 1, _parseInt },
		{ C_NULL, 0, 0 },
    };
	const txHostFunctionBuilder* builder;
	txSlot* slot;
	
	for (builder = gx_global_builders; builder->callback; builder++) {
		fxNewHostFunctionGlobal(the, builder->callback, builder->length, mxID(builder->id), XS_DONT_ENUM_FLAG);
		the->stack++;
	}
	slot = fxSetGlobalProperty(the, mxGlobal.value.reference, mxID(_Infinity), C_NULL);
	slot->flag = XS_GET_ONLY;
	slot->kind = XS_NUMBER_KIND;
	slot->value.number = (txNumber)C_INFINITY;
	slot = fxSetGlobalProperty(the, mxGlobal.value.reference, mxID(_NaN), C_NULL);
	slot->flag = XS_GET_ONLY;
	slot->kind = XS_NUMBER_KIND;
	slot->value.number = C_NAN;

	mxPush(mxObjectPrototype);
	slot = fxLastProperty(the, fxNewNumberInstance(the));
	for (builder = gx_Number_prototype_builders; builder->callback; builder++)
		slot = fxNextHostFunctionProperty(the, slot, builder->callback, builder->length, mxID(builder->id), XS_DONT_ENUM_FLAG);
	mxNumberPrototype = *the->stack;
	slot = fxLastProperty(the, fxNewHostConstructorGlobal(the, fx_Number, 1, mxID(_Number), XS_DONT_ENUM_FLAG));
	for (builder = gx_Number_builders; builder->callback; builder++)
		slot = fxNextHostFunctionProperty(the, slot, builder->callback, builder->length, mxID(builder->id), XS_DONT_ENUM_FLAG);
	slot = fxNextNumberProperty(the, slot, C_EPSILON, mxID(_EPSILON), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	slot = fxNextNumberProperty(the, slot, C_MAX_SAFE_INTEGER, mxID(_MAX_SAFE_INTEGER), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	slot = fxNextNumberProperty(the, slot, C_DBL_MAX, mxID(_MAX_VALUE), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	slot = fxNextNumberProperty(the, slot, C_MIN_SAFE_INTEGER, mxID(_MIN_SAFE_INTEGER), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	slot = fxNextNumberProperty(the, slot, C_DBL_MIN, mxID(_MIN_VALUE), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	slot = fxNextNumberProperty(the, slot, C_NAN, mxID(_NaN), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	slot = fxNextNumberProperty(the, slot, -((txNumber)C_INFINITY), mxID(_NEGATIVE_INFINITY), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	slot = fxNextNumberProperty(the, slot, (txNumber)C_INFINITY, mxID(_POSITIVE_INFINITY), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	the->stack++;
}