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

Fix #1365: Support image loading through node-canvas module. #1366

Closed
wants to merge 1 commit into from

Conversation

lehni
Copy link
Contributor

@lehni lehni commented Jan 25, 2016

Also add support for:

  • HTMLImageElement.naturalWidth, naturalHeight, complet, currentSrc
  • Image drawing through HTMLCanvasElement
  • HTMLCanvasElement.toBlob()

@lehni
Copy link
Contributor Author

lehni commented Jan 26, 2016

The change in de89791 has fixed all failing tests as far as I can see. You may want to look into handling statusCodes properly elsewhere in the library, as it doesn't look like there is any handling of it right now.

I think whit this commit, my work is so far completed. i have done extensive tests with the paper.js library, and haven't managed to find any issues. What's missing for this still is unit tests. How are you testing the other parts of the library?

lehni added a commit to paperjs/paper.js that referenced this pull request Jan 26, 2016
lehni added a commit to lehni/jsdom that referenced this pull request Jan 26, 2016
@domenic
Copy link
Member

domenic commented Jan 27, 2016

To test things that only work with the canvas package installed, we probably need to follow the pattern in test/living-html/htmlcanvaselement.js. The new web platform tests framework won't work as well for that.

get width() {
const parsed = parseInt(this.getAttribute("width"));
const parsed = parseInt(this.getAttribute("width"), 10);
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 for the 10s; that is the default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, ok! But it used to be that parseInt("0...")returned an octal value on some browsers? I'll take it out again : )

Copy link
Member

Choose a reason for hiding this comment

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

ES5 removed octal interpretation. older browsers will indeed interpret it as octal, however those older browsers are not supported anyway, since we require ES6 features. Do note that: parseInt('0x123', 10) === 0 and parseInt('0x123') === 291

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I read up on it in the meantime. There are definitely too many things to keep track of in the ES* universe, but it's an exciting time!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But looking through the jsdom source, I can spot other places where this is still in use, e.g. three locations in xmlhttprequest alone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And lastly, I am wondering why HTMLImageElement-Impl.jsuses this:

 conversions["unsigned long"](this.getAttribute("width"))

While HTMLCanvasElement-Impl.js uses this:

parseInt(this.getAttribute("width"))

@lehni
Copy link
Contributor Author

lehni commented Feb 8, 2016

Do you need more work from me for this PR, or is it just awaiting review now?

@domenic
Copy link
Member

domenic commented Feb 8, 2016

It needs tests!

@lehni
Copy link
Contributor Author

lehni commented Feb 8, 2016

I've been a bit frightened of touching that part, as it seems massive... Where do I find the canvas tests?

@domenic
Copy link
Member

domenic commented Feb 8, 2016

#1366 (comment)

@lehni
Copy link
Contributor Author

lehni commented Mar 14, 2016

Which command runs the sub-set of tests that test/living-html/htmlcanvaselement.js is part of?

@domenic
Copy link
Member

domenic commented Mar 14, 2016

npm run test-old -- -s htmlcanvaselement

@lehni
Copy link
Contributor Author

lehni commented Mar 14, 2016

Great, thanks! Is there a way to run both htmlcanvaselement and htmlimageelement?

@lehni
Copy link
Contributor Author

lehni commented Mar 14, 2016

npm run test-old -- -s htmlcanvaselement,htmlimageelement seems to do that. No need to respond.

@lehni
Copy link
Contributor Author

lehni commented Mar 27, 2016

I have finally started to implement unit tests for this in 3d9060d, but some are currently failing: When setting image.src to a data URL, the image does not get loaded immediately, due to the use of process.nextTick() in resourceLoader.load(): https://github.com/tmpvar/jsdom/blob/master/lib/jsdom/browser/resource-loader.js#L81

Could you tell me why this is used there? If I replace the call with the content of its callback, then it all works as expected. But I cannot judge if this would break things elsewhere.

@domenic
Copy link
Member

domenic commented Mar 27, 2016

I am not sure exactly why that is there; maybe there was just a desire that fetch() always be async. You can remove it, as long as it doesn't break other tests.

It would be great if you could rebase, instead of merge. This branch is not really readable or reviewable as-is.

@lehni
Copy link
Contributor Author

lehni commented Mar 27, 2016

Ok, I will give that a go. And I'm sorry about the merges. How can I fix this now?

@domenic
Copy link
Member

domenic commented Mar 27, 2016

If you rebase on master (and preferably squash your commits), you can then force-push once the local history looks reasonable.

@lehni
Copy link
Contributor Author

lehni commented Mar 27, 2016

Oh dear, that's all news to me...

@lehni
Copy link
Contributor Author

lehni commented Mar 27, 2016

I might just create a patch from all my changes and reapply it to master in one commit.

@domenic
Copy link
Member

domenic commented Mar 27, 2016

Yeah, that will work great!

@lehni
Copy link
Contributor Author

lehni commented Mar 27, 2016

Cool, I keep working with the current branch, and once I'm done I do that as the last move, if you're OK with that. I'm nearly done with finishing the tests.

@lehni
Copy link
Contributor Author

lehni commented Mar 27, 2016

Hmm I can't seem to be able to run all tests locally either way. It stalls at this line:

living-html/cookie.js: .FFF. 

Do you have any ideas why?

@domenic
Copy link
Member

domenic commented Mar 27, 2016

I'm not really sure. Maybe try doing npm install in case the cookie dependency we use has not been updated on your system recently?

@lehni lehni force-pushed the 1365-image-loading branch 2 times, most recently from 370e8f0 to 9326a2c Compare March 28, 2016 03:36
Also adds support for:
- HTMLImageElement.naturalWidth, naturalHeight, complete, currentSrc
- HTMLCanvasElement.drawImage()
- HTMLCanvasElement.toBlob()
@lehni
Copy link
Contributor Author

lehni commented Mar 28, 2016

So here we go: Commit 86d9470 contains all my changes along with unit tests for them, and my modifications now pass all tests. This is good to go from my end, please review.

@lehni
Copy link
Contributor Author

lehni commented Mar 31, 2016

Is there anything else that I can do to help out and expedite the merging in of this? The upcoming v0.10.0 of paper.js depends on it and we are otherwise good to go, so hoping it can find its way into a release soonish...

@domenic
Copy link
Member

domenic commented Mar 31, 2016

Well, if you want to do my day job then that would certainly expedite things :). I generally work on jsdom on weekends when I have free time.

@lehni
Copy link
Contributor Author

lehni commented Mar 31, 2016

Haha, gotcha :) I didn't mean to put pressure on, just wanted to make sure I do what I can to get the ball rolling.

t.strictEqual(image.naturalWidth, 0, "before loading, naturalWidth should be 0");
t.strictEqual(image.naturalHeight, 0, "before loading, naturalHeight should be 0");
t.strictEqual(image.complete, false, "before loading, complete should be false");
t.strictEqual(image.src, "", "before loading, src should be an empty string");
Copy link
Member

Choose a reason for hiding this comment

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

This is incorrect. src should, per spec, reflect the src="" content attribute. It should not change in the course of loading.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see, you simply haven't set src yet. OK, no problem.

@domenic
Copy link
Member

domenic commented Apr 3, 2016

Merged as 59f277b; thank you! Very cool stuff.

@domenic domenic closed this Apr 3, 2016
@lehni
Copy link
Contributor Author

lehni commented Apr 4, 2016

Sweet, thanks! I'm happy to help out where I can. As soon as I find the time, I will tackle #1368 next.

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.

None yet

3 participants