New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Which prototype to use when extending an object from another realm and my constructor prototype is not an object? #786

Closed
AnnotationMark opened this Issue Jan 25, 2017 · 2 comments

Comments

Projects
None yet
3 participants
@AnnotationMark

AnnotationMark commented Jan 25, 2017

Let's say we have a script that looks like this:

<script>
let iframe = document.createElement('iframe');
document.body.appendChild(iframe);
let w = iframe.contentWindow;

function MySet() { }
MySet.prototype = undefined;

var o = Reflect.construct(w.Set, [], MySet);
alert(Object.getPrototypeOf(o) == window.Set.prototype); // Case 1
alert(Object.getPrototypeOf(o) == w.Set.prototype); // Case 2
alert(Object.getPrototypeOf(o) == window.Object.prototype); // Case 3
alert(Object.getPrototypeOf(o) == w.Object.prototype); // Case 4
</script>

According to http://w3c-test.org/custom-elements/htmlconstructor/newtarget.html, Case 1 should be true and the others false.

Based on my reading of the ES spec (9.2.2 ECMAScript Function Objects [[Construct]] - https://tc39.github.io/ecma262/#sec-ecmascript-function-objects-construct-argumentslist-newtarget, 9.1.13 OrdinaryCreateFromConstructor - https://tc39.github.io/ecma262/#sec-ordinarycreatefromconstructor, and 9.1.14 GetPrototypeFromConstructor - https://tc39.github.io/ecma262/#sec-getprototypefromconstructor), it appears that Case 3 should be true, and the others false.

Currently, Chrome implements Case 1, while Safari and Firefox implements Case 2.

Which one of these is actually the correct behavior? Thanks.

@claudepache

This comment has been minimized.

Show comment
Hide comment
@claudepache

claudepache Jan 25, 2017

Contributor

The base constructor is w.Set, which uses OrdinaryCreateFromConstructor(NewTarget, "%SetPrototype%", « [[SetData]] ») and not OrdinaryCreateFromConstructor(newTarget, "%ObjectPrototype%"), see https://tc39.github.io/ecma262/#sec-set-iterable. I think it should be Case 2.
Correction: It should be Case 1 according to https://tc39.github.io/ecma262/#sec-getprototypefromconstructor step 4: here constructor is MySet.

Contributor

claudepache commented Jan 25, 2017

The base constructor is w.Set, which uses OrdinaryCreateFromConstructor(NewTarget, "%SetPrototype%", « [[SetData]] ») and not OrdinaryCreateFromConstructor(newTarget, "%ObjectPrototype%"), see https://tc39.github.io/ecma262/#sec-set-iterable. I think it should be Case 2.
Correction: It should be Case 1 according to https://tc39.github.io/ecma262/#sec-getprototypefromconstructor step 4: here constructor is MySet.

@bterlson bterlson added the question label Feb 7, 2017

@bterlson bterlson closed this Feb 7, 2017

@AnnotationMark

This comment has been minimized.

Show comment
Hide comment
@AnnotationMark

AnnotationMark Feb 7, 2017

Thanks for the clarification.

AnnotationMark commented Feb 7, 2017

Thanks for the clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment