Compartment transforms can't seem to add endowments
See original GitHub issueThe failure I’m seeing in import-bundle (in https://github.com/Agoric/agoric-sdk/pull/762) seems to stem from
Compartment` transforms not working the way I think they’re supposed to. The minimal test case is:
function transform(rewriterState) {
const { src, endowments } = rewriterState;
return { src: src.replace('replaceme', 'substitution'),
endowments: { added: 'by transform', ...endowments },
};
}
test.only('transforms can add endowments', t => {
const src = '(function f4(a) { return `replaceme ${added} ${a}`; })';
const transforms = [transform];
const c = new Compartment({}, {}, { transforms });
const f4 = c.evaluate(src);
const out = f4('ok');
t.equal(out, 'substitution by transform ok');
t.end();
});
I’ll add a branch with this appended to test/compartment.test.js
for convenience.
What I’m seeing is that the c.evaluate
fails with ReferenceError: added is not defined
. When I read through compartment-shim.js
, I thought each transform accepted a { src, endowments }
object and returned a new one of the same shape, so my transform()
ought to leave an added
endowment that should show up by the time f4
is evaluated.
I also tried providing the transforms as an option to c.evaluate(src, { transforms })
, but that didn’t work either.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
You should (usually) log transform your positive data
I have trouble believing log transformed data is easier for most people to interpret, no matter what it represents. Any transformation is adding...
Read more >Why You Can't Just Use the Endowment for That
If we start to consume the endowment principal, there will be less to invest and therefore less income to support the university in...
Read more >RLCraft Advanced Guide! How To Be OP In Version 2.9!!!
Your browser can't play this video. ... and Maxed Enchanted Weapons 38:10 Lost Cities Dimension 41:00 New Transformation Rings (New Baubles) ...
Read more >Five Strategies to Support U.S. Democracy
American democracy is at a dangerous inflection point. The moment requires a step-change in strategy and support. Without such momentum, the ...
Read more >Transforming Health Care from the Ground Up
In this article, we look at two examples of bottom-up innovation involving a radical transformation of health care delivery. The University of Mississippi ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Since I’m familiar with the SES1 per-evaluation endowments mechanism, I could add such a thing to the SES-shim. However, it would be peculiar to the shim. We’ve already covered with Moddable that the XS SES machine will not support such a mechanism. Therefore we are also unlikely to propose such a mechanism.
Are the per-compartments endowments problematic because they are per-compartment, or because they’re on the global object? If the only problem is the latter, then we could get per-compartment global lexical endowments using the “optimizer” mechanism in the 8 magic lines. This also fits better with what Moddable can smoothly implement (attn @phoddie @patrick-soquet ). The shim would only support
const
bindings, but that’s all that what we need here. Yes?I suspect tc39 would also be more tolerant to see a per-compartment global lexical environment added to the proposal, as a construction option, than to see one added as a per-evaluation option.
The latter. As long as the meter endowment is at least a const binding, it can only be referenced directly by name in an evaluation. That makes it possible for a transform to ensure that the evaluated pre-transformed code doesn’t reference it.