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

Function fxToBoolean

xs/sources/xsAPI.c:81–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79}
80
81txBoolean fxToBoolean(txMachine* the, txSlot* theSlot)
82{
83 switch (theSlot->kind) {
84 case XS_UNDEFINED_KIND:
85 case XS_NULL_KIND:
86 theSlot->kind = XS_BOOLEAN_KIND;
87 theSlot->value.boolean = 0;
88 break;
89 case XS_BOOLEAN_KIND:
90 break;
91 case XS_INTEGER_KIND:
92 theSlot->kind = XS_BOOLEAN_KIND;
93 theSlot->value.boolean = (theSlot->value.integer == 0) ? 0 : 1;
94 break;
95 case XS_NUMBER_KIND:
96 theSlot->kind = XS_BOOLEAN_KIND;
97 switch (c_fpclassify(theSlot->value.number)) {
98 case C_FP_NAN:
99 case C_FP_ZERO:
100 theSlot->value.boolean = 0;
101 break;
102 default:
103 theSlot->value.boolean = 1;
104 break;
105 }
106 break;
107 case XS_BIGINT_KIND:
108 case XS_BIGINT_X_KIND:
109 if ((theSlot->value.bigint.size == 1) && (theSlot->value.bigint.data[0] == 0))
110 theSlot->value.boolean = 0;
111 else
112 theSlot->value.boolean = 1;
113 theSlot->kind = XS_BOOLEAN_KIND;
114 break;
115 case XS_STRING_KIND:
116 case XS_STRING_X_KIND:
117 theSlot->kind = XS_BOOLEAN_KIND;
118 if (c_isEmpty(theSlot->value.string))
119 theSlot->value.boolean = 0;
120 else
121 theSlot->value.boolean = 1;
122 break;
123#if mxHostFunctionPrimitive
124 case XS_HOST_FUNCTION_KIND:
125#endif
126 case XS_SYMBOL_KIND:
127 case XS_REFERENCE_KIND:
128 theSlot->kind = XS_BOOLEAN_KIND;
129 theSlot->value.boolean = 1;
130 break;
131 default:
132 mxTypeError("cannot coerce to boolean");
133 break;
134 }
135 return theSlot->value.boolean;
136}
137
138txInteger fxArgc(txMachine* the)

Callers 15

fx_deepEqualFunction · 0.85
fxFindBooleanFunction · 0.85
fxSetRecordHasFunction · 0.85
fxRunInstanceOfFunction · 0.85
fxIsScopableSlotFunction · 0.85
fxIteratorNextFunction · 0.85
fx_Iterator_fromFunction · 0.85

Calls 1

c_fpclassifyFunction · 0.85

Tested by

no test coverage detected