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

[api-minor] Implement a permissions API #10033

Merged
merged 4 commits into from
Sep 2, 2018

Conversation

timvandermeij
Copy link
Contributor

@timvandermeij timvandermeij commented Sep 2, 2018

Fixes #9972.

@Snuffleupagus Would you be willing to review this if you have time? I recommend to review this per commit and with the ?w=1 flag. For some reason the ?w=1 flag doesn't seem to work on GitHub for the second commit, but it does locally if you use git show HEAD~1 --ignore-all-space with this branch checked out.

@timvandermeij
Copy link
Contributor Author

/botio test

@pdfjsbot
Copy link

pdfjsbot commented Sep 2, 2018

From: Bot.io (Linux m4)


Received

Command cmd_test from @timvandermeij received. Current queue size: 0

Live output at: http://54.67.70.0:8877/58015d08e6b16dc/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Sep 2, 2018

From: Bot.io (Windows)


Received

Command cmd_test from @timvandermeij received. Current queue size: 0

Live output at: http://54.215.176.217:8877/3d7a20169b2726a/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Sep 2, 2018

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/58015d08e6b16dc/output.txt

Total script time: 19.44 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@pdfjsbot
Copy link

pdfjsbot commented Sep 2, 2018

From: Bot.io (Windows)


Failed

Full output at http://54.215.176.217:8877/3d7a20169b2726a/output.txt

Total script time: 24.59 mins

  • Font tests: FAILED
  • Unit tests: Passed
  • Regression tests: Passed

@timvandermeij
Copy link
Contributor Author

/botio-linux fonttest

@pdfjsbot
Copy link

pdfjsbot commented Sep 2, 2018

From: Bot.io (Linux m4)


Received

Command cmd_fonttest from @timvandermeij received. Current queue size: 0

Live output at: http://54.67.70.0:8877/29d10d6e619a0ff/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Sep 2, 2018

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/29d10d6e619a0ff/output.txt

Total script time: 1.76 mins

  • Font Tests: Passed

@timvandermeij
Copy link
Contributor Author

/botio-windows fonttest

@pdfjsbot
Copy link

pdfjsbot commented Sep 2, 2018

From: Bot.io (Windows)


Received

Command cmd_fonttest from @timvandermeij received. Current queue size: 0

Live output at: http://54.215.176.217:8877/e307900554adc4f/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Sep 2, 2018

From: Bot.io (Windows)


Success

Full output at http://54.215.176.217:8877/e307900554adc4f/output.txt

Total script time: 3.23 mins

  • Font Tests: Passed

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

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

For some reason the ?w=1 flag doesn't seem to work on GitHub for the second commit,

Thanks for the heads-up, I was wondering why the diff looked so broken :-)

Overall this seems fine to me, modulo a couple of minor comments; nice work!

this._fullReader.cancel(reason);
setupMessageHandler() {
const messageHandler = this.messageHandler;
const loadingTask = this.loadingTask;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Optional change, but this could be shortened to const { messageHandler, loadingTask, } = this; instead.

if (this.destroyed) {
return Promise.reject(new Error('Worker was destroyed'));
}
if (this.loadingTask.onProgress) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can't you use loadingTask as defined in the surrounding scope, both here and on the next line?

// PDF integer objects are represented internally in signed 2's complement
// form. Therefore, convert the signed decimal integer to a signed 2's
// complement binary integer so we can use regular bitwise operations on it.
flags += 2 ** 32;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I assuming that you've already checked, but otherwise please make sure that Webpack/Babel is able to convert this into code compatible with older browsers. (Note that I'm expecting this to "just work" given this option).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I found that babel-present-env fortunately includes the exponentiation operator plugin (see https://github.com/babel/babel/blob/master/packages/babel-preset-env/package.json#L36), so that should be fine.


const permissions = [];
for (const key in PermissionFlag) {
const value = PermissionFlag[key];
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you include something along these lines e59f952, then you ought to be able to use for...of instead here:

for (const flag of PermissionFlag) {
  if (flags & flag) {
    ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried this and unfortunately it doesn't work. Objects, unlike other data structures such as Maps, are not iterable in JavaScript. According to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/is_not_iterable there are some other ways to do this but I don't think it's much more readable.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I totally overlooked that it's an Object, sorry about wasting your time here.

}

/**
* Cleans up resources allocated by the document, e.g., created `@font-face`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Remove the comma placed after e.g.

@@ -691,6 +691,14 @@ class PDFDocumentProxy {
return this._transport.getOutline();
}

/**
* @return {Promise} A promise that is resolved with an {Array} that contains
* the permission flags for the PDF document.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar to the getPageLabel JSDocs, please mention the null case as well.

expect(permissions).toEqual(null);

done();
}).catch(function(reason) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here, and elsewhere below, the slightly less verbose }).catch(done.fail); ought to work.

@timvandermeij
Copy link
Contributor Author

/botio-linux preview

@pdfjsbot
Copy link

pdfjsbot commented Sep 2, 2018

From: Bot.io (Linux m4)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://54.67.70.0:8877/b438b966042ab6c/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Sep 2, 2018

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/b438b966042ab6c/output.txt

Total script time: 2.99 mins

Published

@timvandermeij
Copy link
Contributor Author

/botio unittest

@pdfjsbot
Copy link

pdfjsbot commented Sep 2, 2018

From: Bot.io (Linux m4)


Received

Command cmd_unittest from @timvandermeij received. Current queue size: 0

Live output at: http://54.67.70.0:8877/49ae4a9a7ea1de2/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Sep 2, 2018

From: Bot.io (Windows)


Received

Command cmd_unittest from @timvandermeij received. Current queue size: 0

Live output at: http://54.215.176.217:8877/cb3e726cc626952/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Sep 2, 2018

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/49ae4a9a7ea1de2/output.txt

Total script time: 3.72 mins

  • Unit Tests: Passed

@pdfjsbot
Copy link

pdfjsbot commented Sep 2, 2018

From: Bot.io (Windows)


Success

Full output at http://54.215.176.217:8877/cb3e726cc626952/output.txt

Total script time: 5.28 mins

  • Unit Tests: Passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants