-
Notifications
You must be signed in to change notification settings - Fork 86
Fix WebLocksMixin state initialization. #293
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
Conversation
Summary of ChangesHello @rhashimoto, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refactors the state initialization mechanism within the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request refactors the lock state initialization in WebLocksMixin by introducing a new private method #getLockState. This is a good change that fixes a bug in jFileControl and improves the overall design. My review includes a couple of suggestions. One is a high-severity issue in jUnlock where the new method introduces an unintended side effect; I've recommended reverting that specific part of the change. The other is a medium-severity suggestion to improve the readability of the new #getLockState method. With these changes, the PR will be in great shape.
| // SQLite can call xUnlock() without ever calling xLock() so | ||
| // the state may not exist. | ||
| const lockState = this.#mapIdToState.get(fileId); | ||
| const lockState = this.#getLockState(fileId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using #getLockState(fileId) here introduces a change in behavior for jUnlock. The new implementation creates a lock state if one doesn't exist. This is unnecessary for an xUnlock operation on a file that was never locked, and it adds a new state to the #mapIdToState map. The previous implementation handled this case correctly by doing nothing.
It would be better to revert to getting the state directly from the map to avoid this side effect. With this change, the optional chaining on the next line (lockState?.type) will be correct and necessary again.
| const lockState = this.#getLockState(fileId); | |
| const lockState = this.#mapIdToState.get(fileId); |
| #getLockState(fileId) { | ||
| let lockState = this.#mapIdToState.get(fileId); | ||
| if (!lockState) { | ||
| // The state doesn't exist yet so create it. | ||
| const name = this.getFilename(fileId); | ||
| lockState = { | ||
| baseName: name, | ||
| type: VFS.SQLITE_LOCK_NONE, | ||
| writeHint: false | ||
| }; | ||
| this.#mapIdToState.set(fileId, lockState); | ||
| } | ||
| return lockState | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation of #getLockState can be slightly simplified to improve readability by separating the state creation from its retrieval. This avoids reassigning the lockState variable.
#getLockState(fileId) {
if (!this.#mapIdToState.has(fileId)) {
// The state doesn't exist yet so create it.
const name = this.getFilename(fileId);
this.#mapIdToState.set(fileId, {
baseName: name,
type: VFS.SQLITE_LOCK_NONE,
writeHint: false
});
}
return this.#mapIdToState.get(fileId);
}* Fix resetting isHandleRequested * Bump package version. * Fix hello demo import paths. * Permit JS booleans to be bound to queries, as integer 0/1 values (rhashimoto#272) * Permit boolean values to be bound to statements, as 0/1 * Add test for boolean binding * Using a single TextEncoder for all string conversions * Export HEAP* module members for recent EMSDK changes. * Bump tar-fs from 3.0.8 to 3.0.9 Bumps [tar-fs](https://github.com/mafintosh/tar-fs) from 3.0.8 to 3.0.9. - [Commits](mafintosh/tar-fs@v3.0.8...v3.0.9) --- updated-dependencies: - dependency-name: tar-fs dependency-version: 3.0.9 dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> * Update SQLite to 3.50.1. * Bump package version. * Update issue templates * Replace Facade Proxy with handwritten proxy. (rhashimoto#285) * Replace Proxy with handwritten proxy for jRead/jWrite buffers. * Replace Proxy with handwritten proxy for VFS return data. --------- Co-authored-by: Roy Hashimoto <[email protected]> * Use non-CAPTCHA SQLite download URL. (rhashimoto#289) * Use non-CAPTCHA SQLite download URL. * Use consistent Makefile variable bracing. --------- Co-authored-by: Roy Hashimoto <[email protected]> * Fix WebLocksMixin state initialization. (rhashimoto#293) * Fix WebLocksMixin state initialization. * Don't fetch state in WebLocksMixin file control unnecessarily. * Minor fixes. --------- Co-authored-by: Roy Hashimoto <[email protected]> * Bump package version. --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Simon Binder <[email protected]> Co-authored-by: Roy Hashimoto <[email protected]> Co-authored-by: Grant Cox <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Update issue templates * Replace Facade Proxy with handwritten proxy. (rhashimoto#285) * Replace Proxy with handwritten proxy for jRead/jWrite buffers. * Replace Proxy with handwritten proxy for VFS return data. --------- Co-authored-by: Roy Hashimoto <[email protected]> * Use non-CAPTCHA SQLite download URL. (rhashimoto#289) * Use non-CAPTCHA SQLite download URL. * Use consistent Makefile variable bracing. --------- Co-authored-by: Roy Hashimoto <[email protected]> * Fix WebLocksMixin state initialization. (rhashimoto#293) * Fix WebLocksMixin state initialization. * Don't fetch state in WebLocksMixin file control unnecessarily. * Minor fixes. --------- Co-authored-by: Roy Hashimoto <[email protected]> * Bump package version. * Bump brace-expansion from 1.1.11 to 1.1.12 Bumps [brace-expansion](https://github.com/juliangruber/brace-expansion) from 1.1.11 to 1.1.12. - [Release notes](https://github.com/juliangruber/brace-expansion/releases) - [Commits](juliangruber/brace-expansion@1.1.11...v1.1.12) --- updated-dependencies: - dependency-name: brace-expansion dependency-version: 1.1.12 dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> * Bump koa from 2.16.1 to 2.16.3 Bumps [koa](https://github.com/koajs/koa) from 2.16.1 to 2.16.3. - [Release notes](https://github.com/koajs/koa/releases) - [Changelog](https://github.com/koajs/koa/blob/master/History.md) - [Commits](koajs/koa@v2.16.1...v2.16.3) --- updated-dependencies: - dependency-name: koa dependency-version: 2.16.3 dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> * Bump tar-fs from 3.0.9 to 3.1.1 Bumps [tar-fs](https://github.com/mafintosh/tar-fs) from 3.0.9 to 3.1.1. - [Commits](mafintosh/tar-fs@v3.0.9...v3.1.1) --- updated-dependencies: - dependency-name: tar-fs dependency-version: 3.1.1 dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> * add changeset --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Roy Hashimoto <[email protected]> Co-authored-by: Roy Hashimoto <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
WebLocksMixin was calling the
jLock()method fromjFileControl()if its state needed initialization, which was sloppy and enabled a bug if any subclasses implemented their ownjLock(), like OPFSAdaptiveVFS. This PR moves initialization into a dedicated private method.