Closed Bug 1422557 Opened 7 years ago Closed 4 years ago

Add use counter for global variables

Categories

(Core :: JavaScript Engine, task, P3)

task

Tracking

()

RESOLVED INVALID
Tracking Status
firefox59 --- fix-optional

People

(Reporter: ljharb, Unassigned)

References

(Blocks 1 open bug)

Details

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/604.3.5 (KHTML, like Gecko) Version/11.0.1 Safari/604.3.5 Steps to reproduce: I spoke to Till about this last week at TC39. Basically, I'd like to learn as much as I can about whether the following list: - is typeof-checked, accessed, declared or assigned to, as a global variable - is typeof-checked, accessed, created, or mutated as a property on the global object - exists as a global variable due to being a DOM element ID The hope is to progress the `global` proposal, by eliminating some names from contention due to web incompatibility, as well as hopefully prove an increased likelihood of web compatibility for some of the names. The initial list I'd like to try: - `global`, just as a control (since we know this is wildly web incompatible) - `Global` - `globalThis` - `GlobalThis` - `globalObject` - `GlobalObject` - `globals` - `Globals` - `globalThisValue` - `GlobalThisValue`
Jan, is this something we might be able to do in a way that has an acceptable impact on perf? Sampling would definitely be ok, but I don't know how much it'd help. We could also potentially just do this on Nightly for a few days, though a larger sample would be helpful here, in particular one that's less self-selecting than our Nightly population.
Component: Untriaged → JavaScript Engine
Flags: needinfo?(jdemooij)
Product: Firefox → Core
Priority: -- → P3
(In reply to Till Schneidereit [:till] from comment #1) > Jan, is this something we might be able to do in a way that has an > acceptable impact on perf? It's a bit annoying because we probably want to catch both GetProps like |this.global| and GetNames like |global|. The best place to do this with minimal perf overhead might be JS_MayResolveStandardClass, here: https://searchfox.org/mozilla-central/rev/ba2b0cf4d16711d37d4bf4d267b187c9a27f6638/js/src/jsapi.cpp#1139 This is called for each property name we look up on the global, so all gets/sets/typeof. We could add the list of interesting names to vm/CommonPropertyNames.h, then check for them there. The list in comment 0 has 10 names, that's quite a lot - it might be okay if we add a check for |length >= 6 && s[0] == 'g'| or something.
Flags: needinfo?(jdemooij)
(In reply to ljharb from comment #0) > Basically, I'd like to learn as much as I can about whether the following > list: > - is typeof-checked, accessed, declared or assigned to, as a global variable > - is typeof-checked, accessed, created, or mutated as a property on the > global object > - exists as a global variable due to being a DOM element ID If we want to distinguish these cases, things will get more complicated I'm afraid because we'll have to add checks in multiple places...
Any information is helpful to advance this proposal; it's fine if we can only get a subset of the ideal.
Type: defect → task

I believe this can be closed as we settled on globalThis some time ago.

Status: UNCONFIRMED → RESOLVED
Closed: 4 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.