Skip to content
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

"Named constructor without 'new'" WPT failures #25394

Open
pshaughn opened this issue Dec 26, 2019 · 5 comments
Open

"Named constructor without 'new'" WPT failures #25394

pshaughn opened this issue Dec 26, 2019 · 5 comments

Comments

@pshaughn
Copy link
Member

@pshaughn pshaughn commented Dec 26, 2019

Servo's implementations of named constructors, for Audio and Image (and Option after #25393), aren't throwing an exception when they're called like normal functions; for comparison try typing just Image() without 'new' into the Firefox console. https://html.spec.whatwg.org/#dom-image specifies "When invoked, the constructor must perform the following steps"; what it seems to actually mean here is when invoked /as a constructor/, via new, not just with a regular function call. Within Javascript itself this distinction is detectable via the special expression "new.target", as described in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new.target ; I don't know what the mozjs equivalent is.

@pshaughn
Copy link
Member Author

@pshaughn pshaughn commented Dec 26, 2019

The test is here:

subsetTestByKey(this.name, test, function()
{
// This function tests WebIDL as of 2019-01-14.
// "1. Let steps be the following steps:
// " 1. If NewTarget is undefined, then throw a TypeError."
var name = constructor.rhs.value;
var args = constructor.arguments.map(function(arg) {
return create_suitable_object(arg.idlType);
});
assert_throws(new TypeError(), function() {
self[name](...args);
}.bind(this));
}.bind(this), this.name + " interface: named constructor without 'new'");

https://heycam.github.io/webidl/#named-constructors 1.1 seems to be the verbiage referred to; the substeps of 1 here are the steps for the constructor function itself.

@jdm jdm added this to To do in web-platform-test failures via automation Dec 26, 2019
@jdm
Copy link
Member

@jdm jdm commented Dec 26, 2019

We're missing the equivalent code for https://searchfox.org/mozilla-central/rev/c79fc6e32a5b561205a71fcfef9112d34b4037ae/dom/bindings/Codegen.py#1875-1895 in

else:
name = self.constructor.identifier.name
nativeName = MakeNativeName(self.descriptor.binaryNameFor(name))
constructorCall = CGMethodCall(["&global"], nativeName, True,
self.descriptor, self.constructor)
return CGList([preamble, constructorCall])
.

@jdm
Copy link
Member

@jdm jdm commented Dec 26, 2019

That's https://doc.servo.org/mozjs/jsapi/struct.CallArgs.html#method.constructing_ from the args variable that's already present in the generated constructor code.

@pshaughn
Copy link
Member Author

@pshaughn pshaughn commented Jan 1, 2020

rooted!(in(*cx) let new_target = UnwrapObjectDynamic(args.new_target().to_object(), *cx, 1));
if new_target.is_null() {
throw_dom_exception(cx, global.upcast::<GlobalScope>(), Error::Type("new.target is null".to_owned()));
return false;
}
looks like it should already be making the required check.

@jdm
Copy link
Member

@jdm jdm commented Jan 2, 2020

That code only runs in HTML element constructors, though:

if self.constructor.isHTMLConstructor():
. That will be more clear when #25395 is fixed.

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.