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++; }
void fx_Function_bind(txMachine* the) { txSlot* aFunction; txSlot* aProperty; txSlot* anArray; txSlot* anItem; txSize aCount, anIndex; aFunction = fxGetInstance(the, mxThis); if (!mxIsFunction(aFunction)) mxDebug0(the, XS_TYPE_ERROR, "this is no Function"); if (mxArgc < 1) mxDebug0(the, XS_SYNTAX_ERROR, "Function.prototype.bind: no this parameter"); aProperty = aFunction->next; if (aProperty->kind == XS_CODE_KIND) aCount = *(aProperty->value.code + 4); else aCount = aProperty->value.callback.length; aCount -= mxArgc - 1; if (aCount < 0) aCount = 0; mxPush(mxFunctionPrototype); aFunction = fxNewFunctionInstance(the); *mxResult = *(the->stack++); aProperty = aFunction->next; aProperty->kind = XS_CALLBACK_KIND; aProperty->value.callback.address = fx_Function_bound; aProperty->value.callback.length = aCount; aProperty = fxSetProperty(the, aFunction, fxID(the, "boundFunction"), C_NULL); aProperty->kind = mxThis->kind; aProperty->value = mxThis->value; aProperty = fxSetProperty(the, aFunction, fxID(the, "boundThis"), C_NULL); aProperty->kind = mxArgv(0)->kind; aProperty->value = mxArgv(0)->value; aProperty = fxSetProperty(the, aFunction, fxID(the, "boundArguments"), C_NULL); mxPush(mxArrayPrototype); anArray = fxNewArrayInstance(the); aProperty->kind = the->stack->kind; aProperty->value = the->stack->value; the->stack++; anItem = anArray->next; for (anIndex = 1; anIndex < mxArgc; anIndex++) { anItem->next = fxNewSlot(the); anItem = anItem->next; anItem->kind = mxArgv(anIndex)->kind; anItem->value = mxArgv(anIndex)->value; } anArray->next->value.array.length = mxArgc - 1; fxCacheArray(the, anArray); }
void fxLoadModuleXML(txMachine* the, txString path, txID moduleID) { FskFileMapping map = NULL; txFileMapStream fileMapStream; txStringStream stringStream; txScript* script = NULL; mxTry(the) { fxBeginHost(the); xsThrowIfFskErr(FskFileMap(path, &fileMapStream.buffer, &fileMapStream.size, 0, &map)); fileMapStream.offset = 0; mxPushInteger(0); mxPushInteger(0); mxPushInteger(0); mxPushInteger(0); mxPushInteger(3); fxParse(the, &fileMapStream, fxFileMapGetter, path, 1, xsSourceFlag | xsDebugFlag); fxCallID(the, fxID(the, "generate")); fxToString(the, the->stack); stringStream.slot = the->stack; stringStream.size = c_strlen(stringStream.slot->value.string); stringStream.offset = 0; script = fxParseScript(the, &stringStream, fxStringGetter, mxDebugFlag); fxEndHost(the); } mxCatch(the) { break; } FskFileDisposeMap(map); fxResolveModule(the, moduleID, script, NULL, NULL); }
/* * Copyright (C) 2010-2015 Marvell International Ltd. * Copyright (C) 2002-2010 Kinoma, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ void fxBuildJSON(txMachine* the) { txSlot* xs; mxPush(mxGlobal); mxPush(mxObjectPrototype); fxNewObjectInstance(the); fxNewHostFunction(the, fx_JSON_parse, 2); fxQueueID(the, fxID(the, "parse"), XS_DONT_ENUM_FLAG); fxNewHostFunction(the, fx_JSON_stringify, 3); fxQueueID(the, fxID(the, "stringify"), XS_DONT_ENUM_FLAG); fxQueueID(the, fxID(the, "JSON"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG); the->stack++; xs = fxGetProperty(the, mxGlobal.value.reference, fxID(the, "xs")); mxPush(*xs); mxPush(mxObjectPrototype); fxNewObjectInstance(the); fxNewHostFunction(the, fx_JSON_parse, 1); fxQueueID(the, fxID(the, "parse"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG); fxNewHostFunction(the, fx_JSON_stringify, 1); fxQueueID(the, fxID(the, "serialize"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG); fxQueueID(the, fxID(the, "json"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG); the->stack++; }
void fx_Error_aux(txMachine* the) { txSlot* aProperty; if ((mxArgc > 0) && (mxArgv(0)->kind != XS_UNDEFINED_KIND)) { aProperty = fxSetProperty(the, fxGetOwnInstance(the, mxResult), fxID(the, "message"), C_NULL); aProperty->value.string = fxToString(the, mxArgv(0)); aProperty->kind = mxArgv(0)->kind; } }
void fxIDs(txMachine* the, txInteger count, txString* names) { txInteger i; txID* IDs = fxNewChunk(the, count * sizeof(txID)); mxFunction->value.reference->next->value.callback.IDs = IDs; the->code = (txByte*)IDs; for (i = 0; i < count; i++) { ((txID*)the->code)[i] = fxID(the, names[i]); } }
void fxThrowMessage(txMachine* the, txError theError, txString theMessage) { if ((theError <= XS_NO_ERROR) || (XS_ERROR_COUNT <= theError)) theError = XS_UNKNOWN_ERROR; mxPush(mxErrorPrototypes(theError)); fxNewObjectInstance(the); mxPushStringC(theMessage); fxQueueID(the, fxID(the, "message"), XS_DONT_ENUM_FLAG); mxException = *(the->stack++); fxJump(the); }
void fx_Error_toString(txMachine* the) { txSlot* anError; txSlot* aProperty; txInteger aLength; anError = fxGetInstance(the, mxThis); aProperty = fxGetProperty(the, anError, fxID(the, "name")); --the->stack; the->stack->kind = aProperty->kind; the->stack->value = aProperty->value; if (the->stack->kind == XS_UNDEFINED_KIND) fxCopyStringC(the, the->stack, "Error"); else fxToString(the, the->stack); aProperty = fxGetProperty(the, anError, fxID(the, "message")); --the->stack; the->stack->kind = aProperty->kind; the->stack->value = aProperty->value; if (the->stack->kind == XS_UNDEFINED_KIND) fxCopyStringC(the, the->stack, ""); else fxToString(the, the->stack); aLength = c_strlen(the->stack->value.string); if (aLength) { aLength += c_strlen((the->stack + 1)->value.string) + 2; mxResult->value.string = (txString)fxNewChunk(the, aLength + 1); mxResult->kind = XS_STRING_KIND; c_strcpy(mxResult->value.string, (the->stack + 1)->value.string); c_strcat(mxResult->value.string, ": "); c_strcat(mxResult->value.string, the->stack->value.string); the->stack++; the->stack++; } else { the->stack++; *mxResult = *(the->stack++); } }
void fx_Function_bound(txMachine* the) { txSlot* boundArguments; txInteger aCount, anIndex; txSlot* aParameter; mxPush(*mxFunction); fxGetID(the, fxID(the, "boundArguments")); boundArguments = fxGetInstance(the, the->stack); the->stack++; aCount = boundArguments->next->value.array.length; aParameter = boundArguments->next->value.array.address; for (anIndex = 0; anIndex < aCount; anIndex++) { mxZeroSlot(--the->stack); the->stack->kind = aParameter->kind; the->stack->value = aParameter->value; aParameter++; } for (anIndex = 0; anIndex < mxArgc; anIndex++) { mxZeroSlot(--the->stack); the->stack->kind = mxArgv(anIndex)->kind; the->stack->value = mxArgv(anIndex)->value; } /* #PARAM */ mxZeroSlot(--the->stack); the->stack->kind = XS_INTEGER_KIND; the->stack->value.integer = aCount + mxArgc; /* THIS */ mxPush(*mxFunction); fxGetID(the, fxID(the, "boundThis")); /* FUNCTION */ mxPush(*mxFunction); fxGetID(the, fxID(the, "boundFunction")); /* RESULT */ mxZeroSlot(--the->stack); fxRunID(the, XS_NO_ID); *mxResult = *(the->stack++); }
void fxBuildKeys(txMachine* the) { txArchive* archive = the->archive; if (archive && archive->keys) (*archive->keys)(the); else { #ifdef mxParse txSlot* code = &mxIDs; txID c, i; if (archive) { c = archive->symbolCount; code->value.code = (txByte *)fxNewChunk(the, c * sizeof(txID)); code->kind = XS_CODE_KIND; for (i = 0; i < XS_SYMBOL_ID_COUNT; i++) { txString string = archive->symbols[i]; txID id = the->keyIndex; txSlot* description = fxNewSlot(the); description->flag = XS_DONT_ENUM_FLAG; fxCopyStringC(the, description, string); the->keyArray[id] = description; the->keyIndex++; mxID(i) = 0x8000 | id; } for (; i < c; i++) { txString string = archive->symbols[i]; mxID(i) = fxNewNameX(the, string)->ID; } } else { code->value.code = (txByte *)fxNewChunk(the, XS_ID_COUNT * sizeof(txID)); code->kind = XS_CODE_KIND; for (i = 0; i < XS_SYMBOL_ID_COUNT; i++) { txID id = the->keyIndex; txSlot* description = fxNewSlot(the); description->flag = XS_DONT_ENUM_FLAG; fxCopyStringC(the, description, gxIDStrings[i]); the->keyArray[id] = description; the->keyIndex++; mxID(i) = 0x8000 | id; } for (; i < XS_ID_COUNT; i++) { mxID(i) = fxID(the, gxIDStrings[i]); } } #else fxCheck(the, __FILE__, __LINE__); #endif } }
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++; }
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++; }
void fxBuildHost(txMachine* the) { fxNewHostFunctionGlobal(the, fx_setTimeout, 1, fxID(the, "setTimeout"), XS_DONT_ENUM_FLAG); the->stack++; }
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++; }
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++; }
void fxBuildHost(txMachine* the) { txSlot* property; txSlot* slot; fxNewHostAccessorGlobal(the, fx_get_sandbox, C_NULL, fxID(the, "sandbox"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG); property = fxLastProperty(the, mxObjectPrototype.value.reference); property = fxNextHostAccessorProperty(the, property, fx_Object_prototype_get_sandbox, C_NULL, fxID(the, "sandbox"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG); mxPush(mxObjectPrototype); property = fxLastProperty(the, fxNewObjectInstance(the)); property = fxNextHostFunctionProperty(the, property, fx_xs_execute, 1, fxID(the, "execute"), XS_GET_ONLY); property = fxNextHostFunctionProperty(the, property, fx_xs_isInstanceOf, 2, fxID(the, "isInstanceOf"), XS_GET_ONLY); property = fxNextHostFunctionProperty(the, property, fx_xs_newInstanceOf, 1, fxID(the, "newInstanceOf"), XS_GET_ONLY); property = fxNextHostFunctionProperty(the, property, fx_xs_script, 1, fxID(the, "script"), XS_GET_ONLY); #ifdef mxProfile property = fxNextHostFunctionProperty(the, property, fx_xs_isProfiling, 0, fxID(the, "isProfiling"), XS_GET_ONLY); property = fxNextHostFunctionProperty(the, property, fx_xs_getProfilingDirectory, 0, fxID(the, "getProfilingDirectory"), XS_GET_ONLY); property = fxNextHostFunctionProperty(the, property, fx_xs_setProfilingDirectory, 1, fxID(the, "setProfilingDirectory"), XS_GET_ONLY); property = fxNextHostFunctionProperty(the, property, fx_xs_startProfiling, 0, fxID(the, "startProfiling"), XS_GET_ONLY); property = fxNextHostFunctionProperty(the, property, fx_xs_stopProfiling, 0, fxID(the, "stopProfiling"), XS_GET_ONLY); #endif #ifdef mxDebug mxPush(mxObjectPrototype); slot = fxLastProperty(the, fxNewObjectInstance(the)); slot = fxNextHostFunctionProperty(the, slot, fx_xs_debug_getAddress, 0, fxID(the, "getAddress"), XS_GET_ONLY); slot = fxNextHostFunctionProperty(the, slot, fx_xs_debug_setAddress, 1, fxID(the, "setAddress"), XS_GET_ONLY); slot = fxNextHostFunctionProperty(the, slot, fx_xs_debug_getAutomatic, 0, fxID(the, "getAutomatic"), XS_GET_ONLY); slot = fxNextHostFunctionProperty(the, slot, fx_xs_debug_setAutomatic, 1, fxID(the, "setAutomatic"), XS_GET_ONLY); slot = fxNextHostFunctionProperty(the, slot, fx_xs_debug_getBreakOnException, 0, fxID(the, "getBreakOnException"), XS_GET_ONLY); slot = fxNextHostFunctionProperty(the, slot, fx_xs_debug_setBreakOnException, 1, fxID(the, "setBreakOnException"), XS_GET_ONLY); slot = fxNextHostFunctionProperty(the, slot, fx_xs_debug_getConnected, 0, fxID(the, "getConnected"), XS_GET_ONLY); slot = fxNextHostFunctionProperty(the, slot, fx_xs_debug_setConnected, 1, fxID(the, "setConnected"), XS_GET_ONLY); slot = fxNextHostFunctionProperty(the, slot, fx_xs_debug_clearAllBreakpoints, 0, fxID(the, "clearAllBreakpoints"), XS_GET_ONLY); slot = fxNextHostFunctionProperty(the, slot, fx_xs_debug_clearBreakpoint, 2, fxID(the, "clearBreakpoint"), XS_GET_ONLY); slot = fxNextHostFunctionProperty(the, slot, fx_xs_debug_setBreakpoint, 2, fxID(the, "setBreakpoint"), XS_GET_ONLY); property = fxNextSlotProperty(the, property, the->stack, fxID(the, "debug"), XS_GET_ONLY); the->stack++; #endif slot = fxSetGlobalProperty(the, mxGlobal.value.reference, fxID(the, "xs"), C_NULL); slot->flag = XS_GET_ONLY; slot->kind = the->stack->kind; slot->value = the->stack->value; the->stack++; }
void fxIncludeScript(txParser* parser, txString string) { txBoolean done = 0; char* base = NULL; char name[PATH_MAX]; char* slash = NULL; char* dot = NULL; char* extension = NULL; char* url = NULL; char* path = NULL; FskFileInfo fileInfo; FskFileMapping map= NULL; txFileMapStream fileMapStream; txStringStream stringStream; txMachine* the = parser->console; fxBeginHost(the); { mxTry(the) { xsThrowIfFskErr(KprPathToURL(parser->path->string, &base)); FskStrCopy(name, string); slash = FskStrRChr(name, '/'); if (!slash) slash = name; dot = FskStrRChr(slash, '.'); if (dot) extension = dot; else extension = name + FskStrLen(name); if (!dot) FskStrCopy(extension, ".js"); if (!FskStrCompare(extension, ".js")) { xsThrowIfFskErr(KprURLMerge(base, name, &url)); xsThrowIfFskErr(KprURLToPath(url, &path)); if (kFskErrNone == FskFileGetFileInfo(path, &fileInfo)) { xsThrowIfFskErr(FskFileMap(path, (unsigned char**)&(fileMapStream.buffer), &(fileMapStream.size), 0, &map)); fileMapStream.offset = 0; fxIncludeTree(parser, &fileMapStream, fxFileMapGetter, parser->flags, path); done = 1; FskFileDisposeMap(map); map = NULL; } FskMemPtrDisposeAt(&path); FskMemPtrDisposeAt(&url); } if (!dot) FskStrCopy(extension, ".xml"); if (!FskStrCompare(extension, ".xml")) { xsThrowIfFskErr(KprURLMerge(base, name, &url)); xsThrowIfFskErr(KprURLToPath(url, &path)); if (kFskErrNone == FskFileGetFileInfo(path, &fileInfo)) { xsThrowIfFskErr(FskFileMap(path, &fileMapStream.buffer, &fileMapStream.size, 0, &map)); fileMapStream.offset = 0; mxPushInteger(0); mxPushInteger(0); mxPushInteger(0); mxPushInteger(0); mxPushInteger(3); fxParse(the, &fileMapStream, fxFileMapGetter, path, 1, xsSourceFlag | xsDebugFlag); fxCallID(the, fxID(the, "generate")); fxToString(the, the->stack); stringStream.slot = the->stack; stringStream.size = c_strlen(stringStream.slot->value.string); stringStream.offset = 0; fxIncludeTree(parser, &stringStream, fxStringGetter, parser->flags, path); done = 1; FskFileDisposeMap(map); map = NULL; } FskMemPtrDisposeAt(&path); FskMemPtrDisposeAt(&url); } FskMemPtrDispose(base); } mxCatch(the) { FskFileDisposeMap(map); FskMemPtrDispose(path); FskMemPtrDispose(url); FskMemPtrDispose(base); break; } } fxEndHost(the); if (!done) fxReportParserError(parser, "include file not found: %s", string); }