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

Function fx_JSON_parse

xs/sources/xsJSON.c:130–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128}
129
130void fx_JSON_parse(txMachine* the)
131{
132 volatile txJSONParser aParser = {0};
133 if (mxArgc < 1)
134 mxSyntaxError("no buffer");
135 fxToString(the, mxArgv(0));
136 aParser.slot = mxArgv(0);
137 aParser.offset = 0;
138 mxPush(mxEmptyString);
139 aParser.string = the->stack;
140 aParser.line = 1;
141 if ((mxArgc > 1) && mxIsReference(mxArgv(1))) {
142 if (fxIsArray(the, mxArgv(1)->value.reference))
143 aParser.keys = fxToJSONKeys(the, mxArgv(1));
144 else if (mxIsCallable(mxArgv(1)->value.reference))
145 aParser.sourceFlag = 1;
146 }
147 fxParseJSON(the, (txJSONParser*)&aParser);
148 if (aParser.sourceFlag) {
149 txSlot* valueReference = the->stack + 1;
150 txSlot* sourceReference = the->stack;
151 txSlot* instance;
152 txID id;
153 mxPush(mxObjectPrototype);
154 instance = fxNewObjectInstance(the);
155 id = fxID(the, "");
156 mxBehaviorDefineOwnProperty(the, instance, id, 0, valueReference, XS_GET_ONLY);
157 mxPushSlot(mxArgv(1));
158 mxCall();
159 mxPushUndefined();
160 fxKeyAt(the, id, 0, the->stack);
161 mxPushSlot(valueReference);
162 mxPushSlot(sourceReference);
163 fxReviveJSON(the, (txJSONParser*)&aParser, mxArgv(1));
164 }
165 mxPullSlot(mxResult);
166}
167
168void fxParseJSON(txMachine* the, txJSONParser* theParser)
169{

Callers

nothing calls this directly

Calls 8

fxToStringFunction · 0.85
fxIsArrayFunction · 0.85
fxToJSONKeysFunction · 0.85
fxParseJSONFunction · 0.85
fxNewObjectInstanceFunction · 0.85
fxIDFunction · 0.85
fxKeyAtFunction · 0.85
fxReviveJSONFunction · 0.85

Tested by

no test coverage detected