Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Feedback on "createRegExp" TODO comment #1

Open
dcodeIO opened this issue Jan 21, 2021 · 0 comments
Open

Feedback on "createRegExp" TODO comment #1

dcodeIO opened this issue Jan 21, 2021 · 0 comments

Comments

@dcodeIO
Copy link

dcodeIO commented Jan 21, 2021

// TODO: do we need this factory function, or can we invoke
// the ctr via the loader?
export function createRegExp(regex: string, flags: string): RegExp {
return new RegExp(regex, flags);
}

The RegExp constructor is exported as exports["RegExp#constructor"] with a signature of (this_: RegExp, regex: string, flags: string) => RegExp (all pointers, the this_ argument is typically 0 to indicate that the ctor should allocate on its own, i.e. not a super() call). During demangling, the loader creates a function exports.RegExp one can use with and without new representing it, and one can invoke new exports.RegExp(regexPtr, flagsPtr) (without this_) effectively corresponding to exports.createRegExp(regexPtr, flagsPtr), but returning a wrapper class instead of just a pointer.

There may be value in exposing createRegExp, though, for where the loader is not used, i.e. when running the binary in a C or Rust host. The AS compiler typically does this to also provide an easy to use C-like interface that works everywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant