-
Notifications
You must be signed in to change notification settings - Fork 18
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
Support builtin modules #32
Conversation
While we still don't have tests of building builtins, this is a little tricky to get coverage on, but I can confirm that it is working in my work-in-progress branch to support Fastly builtins. |
aaf91d2
to
d0acb1d
Compare
include/extension-api.h
Outdated
* | ||
* Once loaded, the instance is cached and reused as a singleton. | ||
*/ | ||
bool define_builtin_import(const char* id, HandleValue builtin); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An example usage here might look like:
define_builtin_import("fastly:env", envObject);
d0acb1d
to
2f8019f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, thank you so much!
if (firstValue) { | ||
firstValue = false; | ||
} else { | ||
code += ", "; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not at all important, but I think it'd be fine to append the ,
unconditionally, and then just remove the leading space before the closing }
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah agreed, although I still prefer the proper formatting I must admit!
This adds support for defining builtin modules from JS objects, which are then lazily turned into synthetic modules when imported, based on enumerating the own keys of the object and making those the exports of the synthetic module.
Useful for supporting custom internal APIs without needing to define globals.