question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Endowments are not on the global

See original GitHub issue

Since endowments are not accessible on the global it is not possible to match some unsandboxed behavior.

browser example:

this.postMessage === postMessage
//=> true
SES.makeSESRootRealm().evaluate('this.postMessage === postMessage', { postMessage })
//=> false

nodejs example

this.process === process
//=> true
SES.makeSESRootRealm().evaluate('this.process === process', { process })
//=> false

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
erightscommented, Aug 22, 2019

Yes, only a compartment’s global. The global of an SES root realm must be immutable.

1reaction
erightscommented, Jun 15, 2019

Yes. I’ve been meaning to mention that (especially as this is currently a difference with the XS/tc53 Compartment API).

background:

The endowments are per-evaluation, and emulate the so-called “global lexical scope”, which is closer than the global scope, and which does not correspond to properties on any reified object. (In our shim implementation, they are properties on an internal object, but this object is never revealed.) Outside of the realms and SES shims, AFAIK, no one has ever used the global lexical scope on purpose. It was introduced to the EcmaScript spec to account for top-level let, const, and IIRC class declarations, so that they can be shared between scripts without becoming global properties. (Personal note: IMO this entire design was probably a very bad idea, but I did not object at the time, when it would have made a difference.)

end background

It is important for us that different evaluations can share the same global while having different endowments. This makes it possible for us to emulate the CommonJS module system, where different modules at different locations in the relative module naming system can be endowed with different require functions and module objects while sharing the same global.

The workaround for now: After you make a root realm or compartment, but before you evaluate user code in that root realm or compartment, copy the desired global properties onto that global object:

Object.assign(realm.global, globalEndowments);

or

Object.defineProperties(realm.global, Object.getPropertyDescriptors(globalEndowments));

The first will only copy enumerable properties, and will invoke getters of accessor properties of the globalEndowments. The latter with copy all own properties, and will create new accessors that mimic the old accessors, by reusing the old accessor’s getter and setter functions. I would generally recommend the latter, though it should rarely make a difference.

Please let me know if this helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding Endowments: Types and Policies That ...
An endowment is a donation of money or property to a nonprofit organization, which uses the resulting investment income for a specific purpose....
Read more >
Interest Rates Are Rising and the Global Economy Is ...
Endowments shed a median 7.8% in the latest fiscal year, according to Cambridge Associates, against a drop of 10.6% in the S&P 500...
Read more >
GLOBAL ENDOWMENT AS A TOOL TO ELIMINATE ...
Endowments (or endowment funds) are legal entities entrusted with financial resources whose proceeds are used for funding charitable activities. Endowments.
Read more >
World's largest academic endowment lost money for the ...
Harvard University's endowment lost $2.3 billion in fiscal 2022, blaming the loss on both the global market downturn as well as the university' ......
Read more >
Top considerations for Endowments and Foundations in ...
According to Mercer's survey of endowments and foundations, half of respondents cited higher inflation as one of their two main investment ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found