예제 #1
0
void fxBuildFunction(txMachine* the)
{
	mxPush(mxGlobal);
			
	mxPush(mxObjectPrototype);
	fxNewFunctionInstance(the);
	fxNewHostFunction(the, fx_Function_get_length, 0);
	fxQueueID(the, the->lengthID, XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG | XS_GETTER_FLAG);
	fxNewHostFunction(the, fx_Function_get_prototype, 0);
	fxQueueID(the, the->prototypeID, XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_GETTER_FLAG);
	fxNewHostFunction(the, fx_Function_set_prototype, 1);
	fxQueueID(the, the->prototypeID, XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_SETTER_FLAG);
	fxNewHostFunction(the, fx_Function_apply, 2);
	fxQueueID(the, fxID(the, "apply"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_Function_bind, 1);
	fxQueueID(the, fxID(the, "bind"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_Function_call, 1);
	fxQueueID(the, fxID(the, "call"), XS_DONT_ENUM_FLAG);
	
	fxAliasInstance(the, the->stack);
	mxFunctionPrototype = *the->stack;
	fxNewHostConstructor(the, fx_Function, 1);
	the->stack->value.reference->next->next->next->flag |= XS_DONT_SET_FLAG;
	 *(--the->stack) = mxFunctionPrototype;
	fxPutID(the, fxID(the, "constructor"), XS_DONT_ENUM_FLAG, XS_DONT_ENUM_FLAG);
	fxQueueID(the, fxID(the, "Function"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	
	the->stack++;
}
예제 #2
0
txSlot* fxNewHostConstructorGlobal(txMachine* the, txCallback call, txInteger length, txID id, txFlag flag)
{
	txSlot *function, *property;
	function = fxNewHostConstructor(the, call, length, id);
	property = fxSetGlobalProperty(the, mxGlobal.value.reference, id, C_NULL);
	property->flag = flag;
	property->kind = the->stack->kind;
	property->value = the->stack->value;
	return function;
}
예제 #3
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);
}
예제 #4
0
void fxBuildNumber(txMachine* the)
{
	mxPush(mxGlobal);

	mxPush(mxObjectPrototype);
	fxNewNumberInstance(the);
	fxNewHostFunction(the, fx_Number_toExponential, 1);
	fxQueueID(the, fxID(the, "toExponential"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_Number_toFixed, 1);
	fxQueueID(the, fxID(the, "toFixed"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_Number_toString, 0);
	fxQueueID(the, fxID(the, "toLocaleString"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_Number_toPrecision, 1);
	fxQueueID(the, fxID(the, "toPrecision"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_Number_toString, 1);
	fxQueueID(the, fxID(the, "toString"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_Number_valueOf, 0);
	fxQueueID(the, fxID(the, "valueOf"), XS_DONT_ENUM_FLAG);
	
	fxAliasInstance(the, the->stack);
	mxNumberPrototype = *the->stack;
	fxNewHostConstructor(the, fx_Number, 1);
	mxPushNumber(C_DBL_MAX);
	fxQueueID(the, fxID(the, "MAX_VALUE"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	mxPushNumber(C_DBL_MIN);
	fxQueueID(the, fxID(the, "MIN_VALUE"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	mxPushNumber(C_NAN);
	fxQueueID(the, fxID(the, "NaN"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	mxPushNumber(-C_INFINITY);
	fxQueueID(the, fxID(the, "NEGATIVE_INFINITY"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	mxPushNumber(C_INFINITY);
	fxQueueID(the, fxID(the, "POSITIVE_INFINITY"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	//fxAliasInstance(the, the->stack);
	the->stack->value.reference->next->next->next->flag |= XS_DONT_SET_FLAG;
	 *(--the->stack) = mxNumberPrototype;
	fxPutID(the, fxID(the, "constructor"), XS_DONT_ENUM_FLAG, XS_DONT_ENUM_FLAG);
	fxQueueID(the, fxID(the, "Number"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
		
	the->stack++;
}
예제 #5
0
void fxBuildBoolean(txMachine* the)
{
	mxPush(mxGlobal);
	
	mxPush(mxObjectPrototype);
	fxNewBooleanInstance(the);
	fxNewHostFunction(the, fx_Boolean_toString, 0);
	fxQueueID(the, fxID(the, "toLocaleString"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_Boolean_toString, 0);
	fxQueueID(the, fxID(the, "toString"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_Boolean_valueOf, 0);
	fxQueueID(the, fxID(the, "valueOf"), XS_DONT_ENUM_FLAG);

	fxAliasInstance(the, the->stack);
	mxBooleanPrototype = *the->stack;
	fxNewHostConstructor(the, fx_Boolean, 1);
	//fxAliasInstance(the, the->stack);
	the->stack->value.reference->next->next->next->flag |= XS_DONT_SET_FLAG;
	 *(--the->stack) = mxBooleanPrototype;
	fxPutID(the, fxID(the, "constructor"), XS_DONT_ENUM_FLAG, XS_DONT_ENUM_FLAG);
	fxQueueID(the, fxID(the, "Boolean"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	
	the->stack++;
}
예제 #6
0
void fxBuildError(txMachine* the)
{
	mxPush(mxGlobal);
	
	mxPush(mxObjectPrototype);
	fxNewObjectInstance(the);
	mxPushStringC("Error");
	fxQueueID(the, fxID(the, "name"), XS_DONT_ENUM_FLAG);
	mxPush(mxEmptyString);
	fxQueueID(the, fxID(the, "message"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_Error_toString, 0);
	fxQueueID(the, fxID(the, "toLocaleString"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_Error_toString, 0);
	fxQueueID(the, fxID(the, "toString"), XS_DONT_ENUM_FLAG);
	fxAliasInstance(the, the->stack);
	mxErrorPrototype = *the->stack;
	fxNewHostConstructor(the, fx_Error, 1);
	the->stack->value.reference->next->next->next->flag |= XS_DONT_SET_FLAG;
	 *(--the->stack) = mxErrorPrototype;
	fxPutID(the, fxID(the, "constructor"), XS_DONT_ENUM_FLAG, XS_DONT_ENUM_FLAG);
	fxQueueID(the, fxID(the, "Error"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	
	mxPush(mxErrorPrototype);
	fxNewObjectInstance(the);
	mxPushStringC("EvalError");
	fxQueueID(the, fxID(the, "name"), XS_DONT_ENUM_FLAG);
	mxPush(mxEmptyString);
	fxQueueID(the, fxID(the, "message"), XS_DONT_ENUM_FLAG);
	fxAliasInstance(the, the->stack);
	mxEvalErrorPrototype = *the->stack;
	fxNewHostConstructor(the, fx_EvalError, 1);
	the->stack->value.reference->next->next->next->flag |= XS_DONT_SET_FLAG;
	 *(--the->stack) = mxEvalErrorPrototype;
	fxPutID(the, fxID(the, "constructor"), XS_DONT_ENUM_FLAG, XS_DONT_ENUM_FLAG);
	fxQueueID(the, fxID(the, "EvalError"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	
	mxPush(mxErrorPrototype);
	fxNewObjectInstance(the);
	mxPushStringC("RangeError");
	fxQueueID(the, fxID(the, "name"), XS_DONT_ENUM_FLAG);
	mxPush(mxEmptyString);
	fxQueueID(the, fxID(the, "message"), XS_DONT_ENUM_FLAG);
	fxAliasInstance(the, the->stack);
	mxRangeErrorPrototype = *the->stack;
	fxNewHostConstructor(the, fx_RangeError, 1);
	the->stack->value.reference->next->next->next->flag |= XS_DONT_SET_FLAG;
	 *(--the->stack) = mxRangeErrorPrototype;
	fxPutID(the, fxID(the, "constructor"), XS_DONT_ENUM_FLAG, XS_DONT_ENUM_FLAG);
	fxQueueID(the, fxID(the, "RangeError"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	
	mxPush(mxErrorPrototype);
	fxNewObjectInstance(the);
	mxPushStringC("ReferenceError");
	fxQueueID(the, fxID(the, "name"), XS_DONT_ENUM_FLAG);
	mxPush(mxEmptyString);
	fxQueueID(the, fxID(the, "message"), XS_DONT_ENUM_FLAG);
	fxAliasInstance(the, the->stack);
	mxReferenceErrorPrototype = *the->stack;
	fxNewHostConstructor(the, fx_ReferenceError, 1);
	the->stack->value.reference->next->next->next->flag |= XS_DONT_SET_FLAG;
	 *(--the->stack) = mxReferenceErrorPrototype;
	fxPutID(the, fxID(the, "constructor"), XS_DONT_ENUM_FLAG, XS_DONT_ENUM_FLAG);
	fxQueueID(the, fxID(the, "ReferenceError"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);

	mxPush(mxErrorPrototype);
	fxNewObjectInstance(the);
	mxPushStringC("SyntaxError");
	fxQueueID(the, fxID(the, "name"), XS_DONT_ENUM_FLAG);
	mxPush(mxEmptyString);
	fxQueueID(the, fxID(the, "message"), XS_DONT_ENUM_FLAG);
	fxAliasInstance(the, the->stack);
	mxSyntaxErrorPrototype = *the->stack;
	fxNewHostConstructor(the, fx_SyntaxError, 1);
	the->stack->value.reference->next->next->next->flag |= XS_DONT_SET_FLAG;
	 *(--the->stack) = mxSyntaxErrorPrototype;
	fxPutID(the, fxID(the, "constructor"), XS_DONT_ENUM_FLAG, XS_DONT_ENUM_FLAG);
	fxQueueID(the, fxID(the, "SyntaxError"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	
	mxPush(mxErrorPrototype);
	fxNewObjectInstance(the);
	mxPushStringC("TypeError");
	fxQueueID(the, fxID(the, "name"), XS_DONT_ENUM_FLAG);
	mxPush(mxEmptyString);
	fxQueueID(the, fxID(the, "message"), XS_DONT_ENUM_FLAG);
	fxAliasInstance(the, the->stack);
	mxTypeErrorPrototype = *the->stack;
	fxNewHostConstructor(the, fx_TypeError, 1);
	the->stack->value.reference->next->next->next->flag |= XS_DONT_SET_FLAG;
	 *(--the->stack) = mxTypeErrorPrototype;
	fxPutID(the, fxID(the, "constructor"), XS_DONT_ENUM_FLAG, XS_DONT_ENUM_FLAG);
	fxQueueID(the, fxID(the, "TypeError"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	
	mxPush(mxErrorPrototype);
	fxNewObjectInstance(the);
	mxPushStringC("URIError");
	fxQueueID(the, fxID(the, "name"), XS_DONT_ENUM_FLAG);
	mxPush(mxEmptyString);
	fxQueueID(the, fxID(the, "message"), XS_DONT_ENUM_FLAG);
	fxAliasInstance(the, the->stack);
	mxURIErrorPrototype = *the->stack;
	fxNewHostConstructor(the, fx_URIError, 1);
	the->stack->value.reference->next->next->next->flag |= XS_DONT_SET_FLAG;
	 *(--the->stack) = mxURIErrorPrototype;
	fxPutID(the, fxID(the, "constructor"), XS_DONT_ENUM_FLAG, XS_DONT_ENUM_FLAG);
	fxQueueID(the, fxID(the, "URIError"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);

	the->stack++;
}
예제 #7
0
void fxBuildString(txMachine* the)
{
	mxPush(mxGlobal);
	
	mxPush(mxObjectPrototype);
	fxNewStringInstance(the);
	fxNewHostFunction(the, fx_String_charAt, 1);
	fxQueueID(the, fxID(the, "charAt"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_String_charCodeAt, 1);
	fxQueueID(the, fxID(the, "charCodeAt"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_String_compare, 1);
	fxQueueID(the, fxID(the, "compare"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_String_concat, 1);
	fxQueueID(the, fxID(the, "concat"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_String_indexOf, 1);
	fxQueueID(the, fxID(the, "indexOf"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_String_lastIndexOf, 1);
	fxQueueID(the, fxID(the, "lastIndexOf"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_String_compare, 1);
	fxQueueID(the, fxID(the, "localeCompare"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_String_match, 1);
	fxQueueID(the, fxID(the, "match"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_String_replace, 2);
	fxQueueID(the, fxID(the, "replace"), XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	fxNewHostFunction(the, fx_String_search, 1);
	fxQueueID(the, fxID(the, "search"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_String_slice, 2);
	fxQueueID(the, fxID(the, "slice"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_String_split, 2);
	fxQueueID(the, fxID(the, "split"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_String_substring, 2);
	fxQueueID(the, fxID(the, "substring"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_String_toLowerCase, 0);
	fxQueueID(the, fxID(the, "toLocaleLowerCase"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_String_valueOf, 0);
	fxQueueID(the, fxID(the, "toLocaleString"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_String_toUpperCase, 0);
	fxQueueID(the, fxID(the, "toLocaleUpperCase"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_String_toLowerCase, 0);
	fxQueueID(the, fxID(the, "toLowerCase"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_String_valueOf, 0);
	fxQueueID(the, fxID(the, "toString"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_String_toUpperCase, 0);
	fxQueueID(the, fxID(the, "toUpperCase"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_String_trim, 0);
	fxQueueID(the, fxID(the, "trim"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_String_valueOf, 0);
	fxQueueID(the, fxID(the, "valueOf"), XS_DONT_ENUM_FLAG);
	
	fxAliasInstance(the, the->stack);
	mxStringPrototype = *the->stack;
	fxNewHostConstructor(the, fx_String, 1);
	fxNewHostFunction(the, fx_String_fromCharCode, 1);
	fxQueueID(the, fxID(the, "fromCharCode"), XS_DONT_ENUM_FLAG);
	the->stack->value.reference->next->next->next->flag |= XS_DONT_SET_FLAG;
	 *(--the->stack) = mxStringPrototype;
	fxPutID(the, fxID(the, "constructor"), XS_DONT_ENUM_FLAG, XS_DONT_ENUM_FLAG);
	fxQueueID(the, fxID(the, "String"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	
	the->stack++;
}