MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fxToInteger

Function fxToInteger

xs/sources/xsAPI.c:149–194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

147}
148
149txInteger fxToInteger(txMachine* the, txSlot* theSlot)
150{
151#if mxOptimize
152 if (XS_INTEGER_KIND == theSlot->kind)
153 return theSlot->value.integer; // this is the case over 90% of the time, so avoid the switch
154#endif
155
156again:
157 switch (theSlot->kind) {
158 case XS_UNDEFINED_KIND:
159 case XS_NULL_KIND:
160 theSlot->kind = XS_INTEGER_KIND;
161 theSlot->value.integer = 0;
162 break;
163 case XS_BOOLEAN_KIND:
164 theSlot->kind = XS_INTEGER_KIND;
165 if (theSlot->value.boolean == 0)
166 theSlot->value.integer = 0;
167 else
168 theSlot->value.integer = 1;
169 break;
170 case XS_INTEGER_KIND:
171 break;
172 case XS_NUMBER_KIND:
173 theSlot->kind = XS_INTEGER_KIND;
174 theSlot->value.integer = fxNumberToInteger(theSlot->value.number);
175 mxFloatingPointOp("number to integer");
176 break;
177 case XS_STRING_KIND:
178 case XS_STRING_X_KIND:
179 theSlot->kind = XS_NUMBER_KIND;
180 theSlot->value.number = fxStringToNumber(the, theSlot->value.string, 1);
181 mxMeterOne();
182 goto again;
183 case XS_SYMBOL_KIND:
184 mxTypeError("cannot coerce symbol to integer");
185 break;
186 case XS_REFERENCE_KIND:
187 fxToPrimitive(the, theSlot, XS_NUMBER_HINT);
188 goto again;
189 default:
190 mxTypeError("cannot coerce to integer");
191 break;
192 }
193 return theSlot->value.integer;
194}
195
196void fxNumber(txMachine* the, txSlot* theSlot, txNumber theValue)
197{

Callers 15

_xsbug_module_Function · 0.85
_xsbug_script_Function · 0.85
fx_parseURLFunction · 0.85
fx_serializeURLFunction · 0.85
builtinGetSignedIntegerFunction · 0.85
fx_structuredCloneFunction · 0.85
fxFindIntegerFunction · 0.85
fx_Math_idivFunction · 0.85
fx_Math_imodFunction · 0.85

Calls 3

fxNumberToIntegerFunction · 0.85
fxStringToNumberFunction · 0.85
fxToPrimitiveFunction · 0.85

Tested by

no test coverage detected