Figure out what to do with CreateThis
Categories
(Core :: JavaScript Engine, task, P1)
Tracking
()
People
(Reporter: jandem, Assigned: jandem)
References
Details
(Keywords: sec-other, Whiteboard: [post-critsmash-triage][adv-main74-])
Attachments
(8 files)
6.71 KB,
text/plain
|
Details | |
261 bytes,
text/plain
|
Details | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review |
Fixing 0-day bug 1607443 made us discover some weirdness with MCreateThis
. It made sense before, but since ES6 classes it's now an effectful operation (see the GetPrototypeFromConstructor
call in CreateThisForFunction
) and we don't handle that well.
We have a number of options:
-
We add
JSOP_CREATETHIS
and use that right beforeJSOP_NEW
andJSOP_SUPERCALL
. A bit annoying is that we have to emit this after evaluating the arguments due to side-effects. -
We keep
JSOP_NEW
as-is, but disallow using it with an arbitrary new.target. The complicated cases where new.target != callee (Reflect.construct, super calls?) would then useJSOP_CREATETHIS
with an op that's notJSOP_NEW
. This results in two different paths which isn't great. -
More radical: move this-allocation into the callee with a
JSOP_CREATETHIS
in the prologue. This is nice because it matches the spec better and is consistent with native functions (where callee constructs |this|) so it means we can remove special cases for bound functions, derived class constructors, native functions. It could also improve performance of polymorphic constructor calls.
Downside is that it would add an extra guard to non-constructing calls (although Ion could probably avoid that), and would require rethinking |this| TI type checks...
Comment 1•5 years ago
|
||
The current approach isn't actually spec-compliant: bug 1380953, which shows we retrieve callee.prototype
too often. (IonBuilder::createThisScripted()
emits code which isn't idempotent, contrary to the comment in that method.)
Assignee | ||
Comment 2•5 years ago
|
||
You're right, that's one of the issues we need to fix.
For what it's worth, JSC does callee-side |this| allocation, but they have specialized bytecode for constructing vs non-constructing so that's nicer for them than it is for us...
Updated•5 years ago
|
Assignee | ||
Comment 3•5 years ago
|
||
Current plan is to have calls with non-function new.target always go through the slow invoke path, for now. So basically:
- In IonBuilder always use MCreateThis if callee != new.target.
- In jit::CreateThis, if new.target is not a JSFunction, return a magic value similar to some other cases.
- In scripted call codegen check for new.target not being a function and take the slow path.
Comment 4•5 years ago
|
||
Bug 1607443 comment 10 says "We've looked at the MCreateThis case and while it is weird, it is not a sec concern" so I'm going to mark this sec-other.
Assignee | ||
Comment 5•5 years ago
|
||
I'm working on this. It's a bit complicated because some (scripted) constructor functions don't have a builtin .prototype property (bound functions..), but this is work that should have happened when classes/newTarget were added...
Comment 6•5 years ago
|
||
Comment 7•5 years ago
|
||
Comment 8•5 years ago
|
||
[Tracking Requested - why for this release]:
Comment 9•5 years ago
•
|
||
I crafted a new test-case that also trips the assert.
Comment 10•5 years ago
|
||
Comment 11•5 years ago
|
||
(In reply to Ted Campbell [:tcampbell] from comment #9)
Created attachment 9119929 [details]
Simple testcaseI crafted a new test-case that also trips the assert.
Hah, your test is nicer, you win ;)
Assignee | ||
Comment 12•5 years ago
|
||
Assignee | ||
Comment 13•5 years ago
|
||
We can call isDerivedClassConstructor() on the function instead.
Depends on D59502
Assignee | ||
Comment 14•5 years ago
|
||
The callers are very different and have different constraints, especially in
later patches in this stack.
Depends on D59503
Assignee | ||
Comment 15•5 years ago
|
||
Depends on D59505
Assignee | ||
Comment 16•5 years ago
|
||
In particular, we can't do effectful .prototype lookups in CreateThis and
elsewhere before the call instruction. This patch returns NullValue from
CreateThisFromIon in that case and changes LCallGeneric to take the slow
invoke path when it sees this value.
Depends on D59506
Assignee | ||
Comment 17•5 years ago
|
||
Depends on D59507
Comment 18•5 years ago
|
||
Per tcampbell "[this bug] is internally identified, probably-not-exploitable, and complex to fix so it is not a good uplift target."
Comment 19•5 years ago
|
||
Given comment 18, I don't think we want to rush this into Fx73 either. I'm going to leave ESR68 set to affected for now in case we want to look at uplifting it there next cycle (i.e. for 68.6esr shipping alongside Fx74), but I'd be OK with calling it wontfix too if others agree.
Assignee | ||
Comment 20•5 years ago
|
||
https://hg.mozilla.org/integration/autoland/rev/596958878df0b51e5e672cd6c274509d5d249dd2
https://hg.mozilla.org/integration/autoland/rev/878930cde05bd79f5dcbd03b3b80e3cac3442206
https://hg.mozilla.org/integration/autoland/rev/e062ea07194dbd8ef065d150ff5ecf01f8d84636
https://hg.mozilla.org/integration/autoland/rev/b2162495abd782b2fa3637935dbcccd7e0eb1561
https://hg.mozilla.org/integration/autoland/rev/c20655f4a4c12382c1fb71f332fc52ff78ea935b
https://hg.mozilla.org/integration/autoland/rev/a1d01d3c0bafc51dc745cc7f66f2b595aa4b4934
Comment 21•5 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/596958878df0
https://hg.mozilla.org/mozilla-central/rev/878930cde05b
https://hg.mozilla.org/mozilla-central/rev/e062ea07194d
https://hg.mozilla.org/mozilla-central/rev/b2162495abd7
https://hg.mozilla.org/mozilla-central/rev/c20655f4a4c1
https://hg.mozilla.org/mozilla-central/rev/a1d01d3c0baf
Updated•5 years ago
|
Assignee | ||
Updated•5 years ago
|
Updated•5 years ago
|
Updated•4 years ago
|
Description
•