XXX: could use less memory and go faster */
| 1591 | |
| 1592 | /* XXX: could use less memory and go faster */ |
| 1593 | static JSValue js_std_file_getline(JSContext *ctx, JSValueConst this_val, |
| 1594 | int argc, JSValueConst *argv) |
| 1595 | { |
| 1596 | FILE *f = js_std_file_get(ctx, this_val); |
| 1597 | int c; |
| 1598 | DynBuf dbuf; |
| 1599 | JSValue obj; |
| 1600 | |
| 1601 | if (!f) |
| 1602 | return JS_EXCEPTION; |
| 1603 | |
| 1604 | js_std_dbuf_init(ctx, &dbuf); |
| 1605 | for(;;) { |
| 1606 | c = fgetc(f); |
| 1607 | if (c == EOF) { |
| 1608 | if (dbuf.size == 0) { |
| 1609 | /* EOF */ |
| 1610 | dbuf_free(&dbuf); |
| 1611 | return JS_NULL; |
| 1612 | } else { |
| 1613 | break; |
| 1614 | } |
| 1615 | } |
| 1616 | if (c == '\n') |
| 1617 | break; |
| 1618 | if (dbuf_putc(&dbuf, c)) { |
| 1619 | dbuf_free(&dbuf); |
| 1620 | return JS_ThrowOutOfMemory(ctx); |
| 1621 | } |
| 1622 | } |
| 1623 | obj = JS_NewStringLen(ctx, (const char *)dbuf.buf, dbuf.size); |
| 1624 | dbuf_free(&dbuf); |
| 1625 | return obj; |
| 1626 | } |
| 1627 | |
| 1628 | /* XXX: could use less memory and go faster */ |
| 1629 | static JSValue js_std_file_readAs(JSContext *ctx, JSValueConst this_val, |
nothing calls this directly
no test coverage detected