Skip to content

Constructor & prototype reform#2691

Merged
pmdartus merged 18 commits intojsdom:masterfrom
pmdartus:pmdartus/constructor-reform-pt2
Nov 27, 2019
Merged

Constructor & prototype reform#2691
pmdartus merged 18 commits intojsdom:masterfrom
pmdartus:pmdartus/constructor-reform-pt2

Conversation

@pmdartus
Copy link
Member

@pmdartus pmdartus commented Oct 23, 2019

Changes

This PR applies the webdidl2js constructor & prototype reform to jsdom.

Fixes #1453 #2687

package.json Outdated
"watchify": "^3.11.1",
"wd": "^1.11.2",
"webidl2js": "^10.0.0"
"webidl2js": "https://github.com/pmdartus/webidl2js.git#pmdartus/constructor-reform-pt2"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️Use the released version of webidl2js before merging ⚠️
Using the WIP version to run the test suite on the CI.

// That is why we assign everything inside of the constructor, instead of using a shared prototype.
// You can verify this in e.g. Firefox or Internet Explorer, which do a good job with Web IDL compliance.

function Window(options) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, the weirdness where this is named Window but the actual Window constructor is created on line 47 is strange... I'm not sure what the right architecture is. I guess we can try to straighten it out later, or just wait until we move Window to webidl2js.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to minimize the amount of code change made to lib/jsdom/browser/Window.js, a clean up is overdue. Adding support for [Global] and [NamedConstructor] would greatly help. Let's do that in another PR.

const xpath = require("../level3/xpath");
const nodeFilter = require("./node-filter");

const GENERATED_INTERFACES = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to SHOUTY_CASE this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But isn’t it a common convention that constants are in UPPER_SNAKE_CASE?

if (properties.uploadListener) {
fireAnEvent(event, xhr.upload, ProgressEvent, { loaded: 0, total: 0, lengthComputable: false });
fireAnEvent("loadend", xhr.upload, ProgressEvent, { loaded: 0, total: 0, lengthComputable: false });
const uploadWrapper = idlUtils.tryImplForWrapper(xhr.upload);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name seems wrong here; should it be uploadImpl? In general not sure why this changed; was it a bug you found?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, XMLHttpRequest doesn't uses wedidl2js. All the properties including upload are wrappers and not impls. With this PR the fireAnEvent function expects an impl and not a wrapper, so I need to unwrap before the invocation.

I initially undertook the task of converting the XMLHttpRequest interface to leverage webidl2js, however it was too much change to fit into a single PR. Once this PR is merged, I need to open couple of issues to remove some of the hacks now that all the interfaces have access to the global object.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, I'm just confused why the variable name is uploadWrapper if you're calling (try)ImplForWrapper, which returns an impl.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should probably be renamed to uploadImpl or something.

Comment on lines +118 to +120
const uploadWrapper = idlUtils.implForWrapper(xhr.upload);
fireAnEvent(event, uploadWrapper, ProgressEvent, { loaded: 0, total: 0, lengthComputable: false });
fireAnEvent("loadend", uploadWrapper, ProgressEvent, { loaded: 0, total: 0, lengthComputable: false });
Copy link
Contributor

@ExE-Boss ExE-Boss Oct 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From #2691 (comment):

It should probably be renamed to uploadImpl or something.

Suggested change
const uploadWrapper = idlUtils.implForWrapper(xhr.upload);
fireAnEvent(event, uploadWrapper, ProgressEvent, { loaded: 0, total: 0, lengthComputable: false });
fireAnEvent("loadend", uploadWrapper, ProgressEvent, { loaded: 0, total: 0, lengthComputable: false });
const uploadImpl = idlUtils.implForWrapper(xhr.upload);
fireAnEvent(event, uploadImpl, ProgressEvent, { loaded: 0, total: 0, lengthComputable: false });
fireAnEvent("loadend", uploadImpl, ProgressEvent, { loaded: 0, total: 0, lengthComputable: false });

Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK sweet, this LGTM; we can merge once we get the webidl2js work merged.

I assume the plan of record for DOMException/URL/URLSearchParams/XMLSerializer is to do them as you did in this PR for now, consuming their old-webidl2js versions and adding to window directly. Then we can work on updating them later.

@pmdartus pmdartus force-pushed the pmdartus/constructor-reform-pt2 branch from 54fa585 to ff5e3c5 Compare November 11, 2019 15:12
@domenic domenic force-pushed the pmdartus/constructor-reform-pt2 branch from ff5e3c5 to 618d57e Compare November 22, 2019 01:25
@pmdartus
Copy link
Member Author

Yes, you are right the plan is to migrate the dependant projects as we go. I already opened a PR on domexception, I will try to update the other one soon.

@pmdartus pmdartus merged commit 5e39a4c into jsdom:master Nov 27, 2019
@pmdartus pmdartus deleted the pmdartus/constructor-reform-pt2 branch November 27, 2019 16:56
devrelm pushed a commit to devrelm/resize-observer that referenced this pull request Nov 15, 2021
devrelm added a commit to devrelm/resize-observer that referenced this pull request Nov 15, 2021
* allow observing elements within iframes (fixes #98)

* upgrade jsdom; needed to get fix from jsdom/jsdom#2691

* test that observe can be called with Element created in an iframe

* upgrade node on CircleCI to work with new jsdom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

All classes are shared between separate jsdom windows

3 participants