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

Function Test262Context_getMetadata

tools/xsbug/Test262Pane.c:56–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54}
55
56void Test262Context_getMetadata(xsMachine* the)
57{
58 FILE* file = NULL;
59 size_t size;
60 char* buffer = NULL;
61 char* begin;
62 char* end;
63 yaml_parser_t _parser;
64 yaml_parser_t* parser = NULL;
65 yaml_document_t _document;
66 yaml_document_t* document = NULL;
67 yaml_node_t* root;
68 yaml_node_t* value;
69 int sloppy = 1;
70 int strict = 1;
71 int module = 0;
72 int async = 0;
73 int pending = 0;
74 xsVars(1);
75 xsResult = xsNewObject();
76 xsVar(0) = xsNewArray(0);
77
78 file = fopen(xsToString(xsArg(0)), "rb");
79 if (!file) goto bail;
80 fseek(file, 0, SEEK_END);
81 size = ftell(file);
82 if (!size) goto bail;
83 fseek(file, 0, SEEK_SET);
84 buffer = malloc(size + 1);
85 if (!buffer) goto bail;
86 if (fread(buffer, 1, size, file) != size) goto bail;
87 buffer[size] = 0;
88 fclose(file);
89 file = NULL;
90
91 begin = strstr(buffer, "/*---");
92 if (!begin) goto bail;
93 begin += 5;
94 end = strstr(begin, "---*/");
95 if (!end) goto bail;
96
97 if (!yaml_parser_initialize(&_parser)) goto bail;
98 parser = &_parser;
99 yaml_parser_set_input_string(parser, (unsigned char *)begin, end - begin);
100 if (!yaml_parser_load(parser, &_document)) goto bail;
101 document = &_document;
102 root = yaml_document_get_root_node(document);
103 if (!root) goto bail;
104
105 value = fxGetMappingValue(document, root, "includes");
106 if (value) {
107 yaml_node_item_t* item = value->data.sequence.items.start;
108 while (item < value->data.sequence.items.top) {
109 yaml_node_t* node = yaml_document_get_node(document, *item);
110 xsCall1(xsVar(0), xsID_push, xsString((char*)node->data.scalar.value));
111 item++;
112 }
113 }

Callers

nothing calls this directly

Calls 8

yaml_parser_initializeFunction · 0.85
yaml_parser_loadFunction · 0.85
yaml_document_get_nodeFunction · 0.85
yaml_document_deleteFunction · 0.85
yaml_parser_deleteFunction · 0.85
fxGetMappingValueFunction · 0.70

Tested by

no test coverage detected