void fx_Function_prototype_hasInstance(txMachine* the) { txSlot* instance; txSlot* prototype; mxResult->value.boolean = 0; mxResult->kind = XS_BOOLEAN_KIND; if (mxArgc == 0) return; instance = fxGetInstance(the, mxArgv(0)); if (!instance) return; mxPushSlot(mxThis); fxGetID(the, mxID(_prototype)); prototype = fxGetInstance(the, the->stack); if (!prototype) mxTypeError("prototype is no object"); while (instance) { if (instance == prototype) { mxResult->value.boolean = 1; break; } instance = fxGetParent(the, instance); } the->stack++; }
void fxRunForIn(txMachine* the) { txSlot* limit = the->stack; txSlot* slot = fxToInstance(the, limit); while (slot) { fxEachInstanceProperty(the, slot, XS_EACH_ENUMERABLE_FLAG | XS_EACH_STRING_FLAG, fxRunForInProperty, limit, slot); slot = fxGetParent(the, slot); } slot = the->stack; while (slot < limit) { txInteger id = slot->value.integer; if (id < 0) { txSlot* key = fxGetKey(the, (txID)id); if (key && (key->flag & XS_DONT_ENUM_FLAG)) { if (key->kind == XS_KEY_KIND) { slot->kind = XS_STRING_KIND; slot->value.string = key->value.key.string; } else { slot->kind = XS_STRING_X_KIND; slot->value.string = key->value.key.string; } } else { slot->kind = XS_SYMBOL_KIND; slot->value.ID = (txID)id; } } slot++; } limit->kind = XS_NULL_KIND; }
txBoolean fxIsInstanceOf(txMachine* the) { txBoolean result = 0; txSlot* theInstance = the->stack++; txSlot* thePrototype = the->stack++; if (mxIsReference(theInstance) && mxIsReference(thePrototype)) { theInstance = fxGetInstance(the, theInstance); thePrototype = fxGetInstance(the, thePrototype); while (theInstance) { if (theInstance == thePrototype) { result = 1; break; } theInstance = fxGetParent(the, theInstance); } } return result; }