GetPrototypeFromConstructor needs to retrieve the fallback prototype from the constructor's realm
Categories
(Core :: JavaScript Engine, defect, P3)
Tracking
()
Tracking | Status | |
---|---|---|
firefox66 | --- | fixed |
People
(Reporter: anba, Assigned: jorendorff)
References
(Blocks 1 open bug)
Details
(Keywords: triage-deferred)
Attachments
(1 file)
Updated•8 years ago
|
![]() |
||
Comment 2•8 years ago
|
||
Assignee | ||
Comment 3•7 years ago
|
||
Assignee | ||
Comment 4•7 years ago
|
||
Comment 6•7 years ago
|
||
bugherder |
![]() |
||
Comment 7•7 years ago
|
||
I'm a little confused. It sure looks like we're basically using ctor->global() (after unwrapping cross-compartment wrappers), which per comment 2 is not what the spec says to do here...
Is that the part that's going to another bug? What is that other bug?
(Also, we still need jsapi for this stuff to fix bug 1317658... I was under the impression that it would get added here, but maybe we need a separate bug for that too?)
Assignee | ||
Comment 8•7 years ago
|
||
Yes, we're basically using ctor->global()
.
This is correct because GetPrototypeFromConstructor
is called exclusively from the builtin constructors themselves. If it's possible to get to any of these points while args.callee()
is a proxy or bound function, we have a bug. But I don't think that's possible. For bound functions, here's what I observe:
let g = newGlobal({newCompartment:true});
let C = g.Function.prototype.bind.call(Object);
let obj = new C;
assertEq(obj.__proto__, Object.prototype); // not g.Object.prototype
C
is a CCW to a bound function to a CCW to Object
. Everything seems to go through as expected.
The fact that args.callee()
was originally C
is not carried forward into the nested invocations. Thus when the Object constructor runs, args.callee()
and args.newTarget()
are both Object
, not the bound function object or a cross-compartment wrapper.
Assignee | ||
Comment 9•7 years ago
|
||
(has creeping feeling Xray wrappers can blow all this up)
![]() |
||
Comment 10•7 years ago
|
||
This is correct because GetPrototypeFromConstructor is called exclusively from the builtin constructors themselves.
It's called from the builtin constructors, but the thing passed to GetPrototypeFromConstructor is not args.callee(); it's args.newTarget(). Which could be absolutely anything, including proxy or bound function, no?
The fact that args.callee() was originally C is not carried forward into the nested invocations
Sure, if you're invoking C via new C
. But here's the testcase I'm thinking about:
let g = newGlobal({newCompartment:true});
let C = g.Function.prototype.bind.call(Object);
let obj = Reflect.construct(Object, [], C);
assertEq(obj.__proto__, Object.prototype);
That assert should pass per spec, afaict. I believe it fails with this patch.
Assignee | ||
Comment 11•7 years ago
|
||
Continuing reply to comment 7:
Is that the part that's going to another bug? What is that other bug?
The other bug is bug 1515167, and it does cover at least bound functions.
(Also, we still need jsapi for this stuff to fix bug 1317658... I was under the impression that it would get added here, but maybe we need a separate bug for that too?)
Maybe that's bug 1275312?
![]() |
||
Comment 12•7 years ago
|
||
Maybe that's bug 1275312?
Yes, perfect, thanks.
Assignee | ||
Comment 13•7 years ago
|
||
(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #10)
This is correct because GetPrototypeFromConstructor is called exclusively from the builtin constructors themselves.
It's called from the builtin constructors, but the thing passed to GetPrototypeFromConstructor is not args.callee(); it's args.newTarget(). Which could be absolutely anything, including proxy or bound function, no?
Yes, any callable object. Sorry, I was looking at the happy case in GetPrototypeFromBuiltinConstructor
, which isn't even the code affected by this patch.
You're right, this was a half measure. The patch does not do a proper implementation of GetFunctionRealm. I just wanted to get intrinsicDefaultProto threaded through so I could scratch off a bunch of test262 tests.
Your test case in comment 10 does fail, as you expect.
Updated•7 years ago
|
Description
•