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

Expose Proxy builtin as a public API #2075

Closed
mikroskeem opened this issue May 17, 2022 · 0 comments
Closed

Expose Proxy builtin as a public API #2075

mikroskeem opened this issue May 17, 2022 · 0 comments
Labels
API builtins PRs and Issues related to builtins/intrinsics enhancement New feature or request

Comments

@mikroskeem
Copy link

As per discussion in Discord:

[8:23 PM] Jedel: I see. We currently haven't exposed the Proxy builtin as a public API. However, we're implementing safe wrappers for every object type to make them easier to use in use cases like yours
[8:25 PM] Jedel: If you want, you can open an issue in our repo and we'll work on implementing a safe wrapper for Proxy
[8:30 PM] mikroskeem: hm, I'm not sure if that is the best approach to simply create a rust wrapper for Proxy object
[8:30 PM] mikroskeem: but then again I'm not familiar with Boa internals at all
[8:30 PM] Jedel: The difference would be that a wrapper for Proxy would make it possible to pass native functions as proxy handlers
[8:31 PM] Jedel: whereas a Proxy object inside JS uses JS functions

My use-case would be defining an proxy in native code, e.g to emulate process.env[key] for code I cannot control.

Simply put, instead of evaluating this before running vendor code:

globalThis.process = {
  env: new Proxy({}, {
    get: (_self, key) => myBoaNativeFuncToGetEnv(key),
    //set: (_self, key, value) => { throw new Error("Not supported"); },
  }),
};

could be replaced with 100% Rust counterpart.

@mikroskeem mikroskeem added the enhancement New feature or request label May 17, 2022
@jedel1043 jedel1043 added builtins PRs and Issues related to builtins/intrinsics API labels May 17, 2022
@bors bors bot closed this as completed in 406c642 May 21, 2022
Razican pushed a commit that referenced this issue Jun 8, 2022
This Pull Request fixes/closes #2075.

It changes the following:

- Implements a `ProxyBuilder` struct to be able to create `Proxy` objects from native function traps.
- Documents `ProxyBuilder` and adjusts some documentation.
- Fixes a clippy lint.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API builtins PRs and Issues related to builtins/intrinsics enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants