Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Implement RegExp serialization #153

Merged
merged 1 commit into from
Nov 29, 2023

Conversation

bnoordhuis
Copy link
Contributor

JS_WriteObject() and JS_ReadObject() now support RegExp objects.

JS_WriteObject() and JS_ReadObject() now support RegExp objects.
JS_WriteString(s, regexp.pattern);

if (is_be())
lre_byte_swap(bc->u.str8, bc->len, /*is_byte_swapped*/FALSE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow, why are we calling lre_byte_swap twice, first with false then true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_byte_swapped tells lre_byte_swap whether the size field in the header is in host endianness or not, i.e., whether it needs to byte-swap it. It reads that in order to know how large the bytecode is, because bc->len == header + bytecode + group names.

Why twice? Do and undo: convert from BE to LE, write out data, convert back to BE.

Copy link
Contributor

@saghul saghul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM because the tests are happy, but I'm not sure I fully get it 😅

@bnoordhuis bnoordhuis merged commit 5c3077e into quickjs-ng:master Nov 29, 2023
@bnoordhuis bnoordhuis deleted the regexp-serde branch November 29, 2023 07:50
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants