Skip to content

Javascript Binding - Store JavascriptObjects per CefBrowser #4475

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

amaitland
Copy link
Member

@amaitland amaitland commented Apr 18, 2023

Fixes: #2306

Summary:

  • Historically JSB objects are cached per process, for shared render processes this can be problematic
    This optionally allows for a new Per Browser cache.

Use the following command line arg to opt into this behaviour.

--jsb-cache-perbrowser
// CefSettings
settings.CefCommandLineArgs.Add("jsb-cache-perbrowser");

Changes:

  • Add cache abstraction to allow for legacy and new per browser configuration
  • Add new CefSharp specific command line arg to optionally enable new code path
  • Settings haven't been moved to per Browser as that requires additional code changes to pass in extraInfo to the Popups

How Has This Been Tested?

  • New tests added

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Updated documentation

Checklist:

  • Tested the code(if applicable)
  • Commented my code
  • Changed the documentation(if applicable)
  • New files have a license disclaimer
  • The formatting is consistent with the project (project supports .editorconfig)

Summary by CodeRabbit

  • New Features

    • Introduced support for per-browser JavaScript object caching, allowing JavaScript objects to be managed separately for each browser instance using a new command-line argument.
    • Added new cache management options for JavaScript binding objects, including both legacy (process-wide) and per-browser caching modes.
  • Bug Fixes

    • Improved cleanup and isolation of JavaScript object caches when browsers are destroyed.
  • Tests

    • Added comprehensive tests for both legacy and per-browser JavaScript object caches to ensure correct behavior and isolation.
  • Documentation

    • Updated public interfaces and class signatures to reflect new caching capabilities and configuration options.

@AppVeyorBot
Copy link

@AppVeyorBot
Copy link

@amaitland amaitland force-pushed the jsb/perbrowsercache branch from f18c0ff to 8eb2376 Compare August 5, 2023 20:06
@AppVeyorBot
Copy link

@amaitland
Copy link
Member Author

This is required for #5001

I originally added a command line arg, I think this should be plan b as it is hard to test. If we can have it configured per ChromiumWebBrowser instance that would make life a lot easier to test.

@amaitland amaitland force-pushed the jsb/perbrowsercache branch from 8eb2376 to fcc0cdb Compare January 31, 2025 20:50
@AppVeyorBot
Copy link

@amaitland
Copy link
Member Author

I originally added a command line arg, I think this should be plan b as it is hard to test. If we can have it configured per ChromiumWebBrowser instance that would make life a lot easier to test.

This would require a totally different approach.

@amaitland amaitland force-pushed the jsb/perbrowsercache branch from fcc0cdb to 1fed9c9 Compare May 10, 2025 23:14
Copy link

coderabbitai bot commented May 10, 2025

## Walkthrough

This change introduces a new per-browser JavaScript object cache for the render process, allowing JavaScript binding objects to be stored and managed separately for each browser instance. It adds two cache implementations, updates constructors and interfaces, and modifies logic to use the appropriate cache based on a command-line flag. Comprehensive tests for both cache types are included.

## Changes

| File(s)                                                                                      | Change Summary |
|----------------------------------------------------------------------------------------------|---------------|
| CefSharp/Internals/IJavaScriptObjectCache.cs<br>CefSharp/Internals/LegacyJavaScriptObjectCache.cs<br>CefSharp/Internals/PerBrowserJavaScriptObjectCache.cs | Introduced a new interface for JavaScript object caching and two implementations: one for legacy (process-wide) and one for per-browser caching. |
| CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp<br>CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h<br>CefSharp.BrowserSubprocess.Core/SubProcess.h | Replaced direct dictionary management with the new cache abstraction. Updated constructors to accept a cache-per-browser flag and use the appropriate cache implementation. |
| CefSharp.BrowserSubprocess.Core/BindObjectAsyncHandler.h<br>CefSharp.BrowserSubprocess.Core/RegisterBoundObjectHandler.h | Updated constructor and member variable types from concrete dictionaries to interface-based types for flexibility. |
| CefSharp/Internals/CefSharpArguments.cs | Added a new command-line argument constant for enabling per-browser cache. |
| CefSharp.Test/JavascriptBinding/LegacyJavaScriptObjectCacheTests.cs<br>CefSharp.Test/JavascriptBinding/PerBrowserJavaScriptObjectCacheTests.cs | Added comprehensive unit tests for both legacy and per-browser JavaScript object cache implementations. |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant SubProcess
    participant CefAppUnmanagedWrapper
    participant IJavaScriptObjectCache
    participant BrowserInstance

    SubProcess->>CefAppUnmanagedWrapper: Create(jsbCachePerBrowser)
    CefAppUnmanagedWrapper->>IJavaScriptObjectCache: Instantiate (per-browser or legacy)
    BrowserInstance->>IJavaScriptObjectCache: InsertOrUpdate(browserId, jsObjects)
    BrowserInstance->>IJavaScriptObjectCache: GetCacheValues(browserId)
    BrowserInstance->>IJavaScriptObjectCache: ClearCache(browserId)

Assessment against linked issues

Objective Addressed Explanation
Store JavascriptObjects/Settings per CefBrowser instead of per subprocess (#2306)

Poem

A cache for each browser, oh what a delight!
No more shared objects in the render process night.
With tests for each path and a flag to select,
Browsers now keep their bindings correct.
🐇 Code hops ahead, per-browser and bright!


<!-- walkthrough_end -->

<!-- announcements_start -->

> [!NOTE]
> <details>
> <summary>⚡️ AI Code Reviews for VS Code, Cursor, Windsurf</summary>
> 
> CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
> Learn more [here](http://coderabbit.ai/ide).
> 
> </details>

---

> [!NOTE]
> <details>
> <summary>⚡️ Faster reviews with caching</summary>
> 
> CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure `Review - Disable Cache` at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the `Data Retention` setting under your Organization Settings.
> Enjoy the performance boost—your workflow just got faster.
> 
> </details>

<!-- announcements_end -->

---

<details>
<summary>📜 Recent review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**
**Cache: Disabled due to data retention organization setting**
**Knowledge Base: Disabled due to data retention organization setting**


<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 83b67475e2e6dbba53e8eacb1909b5f5e54b7b04 and 1d190857f25075b97a79fc6799bf59a4b49d34ba.

</details>

<details>
<summary>📒 Files selected for processing (11)</summary>

* `CefSharp.BrowserSubprocess.Core/BindObjectAsyncHandler.h` (1 hunks)
* `CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp` (5 hunks)
* `CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h` (1 hunks)
* `CefSharp.BrowserSubprocess.Core/RegisterBoundObjectHandler.h` (1 hunks)
* `CefSharp.BrowserSubprocess.Core/SubProcess.h` (1 hunks)
* `CefSharp.Test/JavascriptBinding/LegacyJavaScriptObjectCacheTests.cs` (1 hunks)
* `CefSharp.Test/JavascriptBinding/PerBrowserJavaScriptObjectCacheTests.cs` (1 hunks)
* `CefSharp/Internals/CefSharpArguments.cs` (1 hunks)
* `CefSharp/Internals/IJavaScriptObjectCache.cs` (1 hunks)
* `CefSharp/Internals/LegacyJavaScriptObjectCache.cs` (1 hunks)
* `CefSharp/Internals/PerBrowserJavaScriptObjectCache.cs` (1 hunks)

</details>

<details>
<summary>✅ Files skipped from review due to trivial changes (1)</summary>

* CefSharp/Internals/PerBrowserJavaScriptObjectCache.cs

</details>

<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (10)</summary>

* CefSharp/Internals/IJavaScriptObjectCache.cs
* CefSharp/Internals/CefSharpArguments.cs
* CefSharp.BrowserSubprocess.Core/SubProcess.h
* CefSharp.BrowserSubprocess.Core/RegisterBoundObjectHandler.h
* CefSharp.BrowserSubprocess.Core/BindObjectAsyncHandler.h
* CefSharp/Internals/LegacyJavaScriptObjectCache.cs
* CefSharp.Test/JavascriptBinding/LegacyJavaScriptObjectCacheTests.cs
* CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h
* CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp
* CefSharp.Test/JavascriptBinding/PerBrowserJavaScriptObjectCacheTests.cs

</details>

</details>
<!--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ox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=cefsharp/CefSharp&utm_content=4475):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Explain this complex logic.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai explain this code block.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and explain its main purpose.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

### Support

Need help? Create a ticket on our [support page](https://www.coderabbit.ai/contact-us/support) for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### CodeRabbit Configuration File (`.coderabbit.yaml`)

- You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository.
- Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json`

### Documentation and Community

- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

@amaitland
Copy link
Member Author

@coderabbitai review

Copy link

coderabbitai bot commented May 10, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@amaitland amaitland marked this pull request as ready for review May 10, 2025 23:53
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (5)
CefSharp/Internals/PerBrowserJavaScriptObjectCache.cs (1)

1-68: Well-implemented per-browser JavaScript object cache

This implementation correctly manages separate JavaScript object caches for each browser instance, addressing the issue with shared render processes. The code handles edge cases appropriately, such as creating new caches when needed and returning empty collections when a cache doesn't exist.

One minor consideration: GetCache will always create a new cache dictionary if one doesn't exist for the specified browser ID. This could potentially create unnecessary empty caches if the caller just wants to check for existence. However, this aligns with the interface contract and is a reasonable implementation decision.

CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp (2)

109-110: ClearCache result is silently ignored – verify intention

_javascriptObjectCache->ClearCache(browser->GetIdentifier());

For the legacy cache implementation this is a no-op by design, while for the per-browser cache it frees memory.
A reader might assume the call always does something, so please:

  1. Add a short explanatory comment (// no-op for Legacy cache) to prevent future confusion.
  2. Optionally gate the call behind an if (_jsbCachePerBrowser) flag to save an unnecessary virtual dispatch.

628-629: Potential duplication of cached objects

InsertOrUpdate is invoked both here and in OnBrowserCreated. If the browser process re-sends the same objects (e.g. after a navigation) the cache might now hold duplicates unless the implementation performs a replace-by-name.

Confirm that:

  1. InsertOrUpdate overwrites existing entries that share the same key.
  2. Unit tests cover this message path (currently only constructor-time insertion is tested).
CefSharp.Test/JavascriptBinding/LegacyJavaScriptObjectCacheTests.cs (1)

102-116: Test encodes legacy “no-op” behaviour – document rationale

ClearCacheShouldDoNothing intentionally expects the cache to remain populated.
Add a comment explaining that the legacy cache is process-wide and intentionally retains objects to avoid accidental refactors flipping the expectation.

CefSharp.Test/JavascriptBinding/PerBrowserJavaScriptObjectCacheTests.cs (1)

90-105: Missing negative check after overwrite

After overwriting the cache you assert only that the new value is present:

Assert.Equal(2, cachedObjects.First().Value);

To fully validate overwrite semantics, also assert that the previous value (1) no longer exists:

Assert.DoesNotContain(cachedObjects, o => o.Value == 1);

This prevents false positives where both objects remain in the list.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8fe8810 and 83b6747.

📒 Files selected for processing (11)
  • CefSharp.BrowserSubprocess.Core/BindObjectAsyncHandler.h (1 hunks)
  • CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp (5 hunks)
  • CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h (1 hunks)
  • CefSharp.BrowserSubprocess.Core/RegisterBoundObjectHandler.h (1 hunks)
  • CefSharp.BrowserSubprocess.Core/SubProcess.h (1 hunks)
  • CefSharp.Test/JavascriptBinding/LegacyJavaScriptObjectCacheTests.cs (1 hunks)
  • CefSharp.Test/JavascriptBinding/PerBrowserJavaScriptObjectCacheTests.cs (1 hunks)
  • CefSharp/Internals/CefSharpArguments.cs (1 hunks)
  • CefSharp/Internals/IJavaScriptObjectCache.cs (1 hunks)
  • CefSharp/Internals/LegacyJavaScriptObjectCache.cs (1 hunks)
  • CefSharp/Internals/PerBrowserJavaScriptObjectCache.cs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (7)
CefSharp/Internals/CefSharpArguments.cs (1)
CefSharp/Internals/PerBrowserJavaScriptObjectCache.cs (1)
  • PerBrowserJavaScriptObjectCache (14-68)
CefSharp.BrowserSubprocess.Core/RegisterBoundObjectHandler.h (3)
CefSharp/Internals/IJavaScriptObjectCache.cs (1)
  • IDictionary (25-25)
CefSharp/Internals/LegacyJavaScriptObjectCache.cs (1)
  • IDictionary (40-43)
CefSharp/Internals/PerBrowserJavaScriptObjectCache.cs (2)
  • IDictionary (48-53)
  • IDictionary (55-67)
CefSharp/Internals/IJavaScriptObjectCache.cs (2)
CefSharp/Internals/LegacyJavaScriptObjectCache.cs (2)
  • ClearCache (19-22)
  • InsertOrUpdate (25-31)
CefSharp/Internals/PerBrowserJavaScriptObjectCache.cs (2)
  • ClearCache (20-23)
  • InsertOrUpdate (26-34)
CefSharp.BrowserSubprocess.Core/SubProcess.h (1)
CefSharp/Internals/PerBrowserJavaScriptObjectCache.cs (1)
  • PerBrowserJavaScriptObjectCache (14-68)
CefSharp/Internals/PerBrowserJavaScriptObjectCache.cs (2)
CefSharp/Internals/IJavaScriptObjectCache.cs (4)
  • ClearCache (18-18)
  • InsertOrUpdate (40-40)
  • ICollection (33-33)
  • IDictionary (25-25)
CefSharp/Internals/LegacyJavaScriptObjectCache.cs (4)
  • ClearCache (19-22)
  • InsertOrUpdate (25-31)
  • ICollection (34-37)
  • IDictionary (40-43)
CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h (2)
CefSharp/Internals/PerBrowserJavaScriptObjectCache.cs (1)
  • PerBrowserJavaScriptObjectCache (14-68)
CefSharp/Internals/LegacyJavaScriptObjectCache.cs (1)
  • LegacyJavaScriptObjectCache (13-44)
CefSharp/Internals/LegacyJavaScriptObjectCache.cs (2)
CefSharp/Internals/IJavaScriptObjectCache.cs (4)
  • ClearCache (18-18)
  • InsertOrUpdate (40-40)
  • ICollection (33-33)
  • IDictionary (25-25)
CefSharp/Internals/PerBrowserJavaScriptObjectCache.cs (5)
  • ClearCache (20-23)
  • InsertOrUpdate (26-34)
  • ICollection (37-45)
  • IDictionary (48-53)
  • IDictionary (55-67)
🔇 Additional comments (11)
CefSharp/Internals/CefSharpArguments.cs (1)

13-13: LGTM: Command-line argument for per-browser JavaScript object caching added.

The new constant follows the existing naming conventions and pattern in the class, providing a clear toggle to enable per-browser JavaScript object caching.

CefSharp.BrowserSubprocess.Core/SubProcess.h (2)

36-36: LGTM: Command-line flag parser for per-browser JavaScript object caching.

The implementation correctly uses the CommandLineArgsParser::HasArgument method to check for the new command-line argument, consistent with how other arguments are parsed in this class.


39-39: LGTM: Updated constructor call with new parameter.

The CefAppUnmanagedWrapper constructor is now called with the new jsbCachePerBrowser parameter, allowing the appropriate cache implementation to be selected at runtime.

CefSharp.BrowserSubprocess.Core/RegisterBoundObjectHandler.h (1)

30-30: LGTM: Updated to use interface instead of concrete implementation.

Good change to use the more abstract IDictionary interface instead of the concrete Dictionary class. This modification supports the new cache abstraction by allowing different cache implementations to be injected, promoting loose coupling and better maintainability.

Also applies to: 33-33

CefSharp.BrowserSubprocess.Core/BindObjectAsyncHandler.h (1)

28-28: LGTM: Updated to use interface instead of concrete implementation.

Good change to use the more abstract IDictionary interface instead of the concrete Dictionary class. This enables the class to work with different cache implementations (either legacy process-wide cache or per-browser cache) through dependency injection.

Also applies to: 32-32

CefSharp/Internals/IJavaScriptObjectCache.cs (1)

1-42: Well-designed interface for JavaScript object caching

This interface provides a clean and well-documented contract for managing JavaScript binding objects in the render process, with support for both per-process (legacy) and per-browser caching strategies. The method signatures are clear, focused, and appropriate for the operations being performed.

CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h (2)

38-38: LGTM: Good abstraction for JavaScript object caching

The replacement of the concrete dictionary with an interface type provides better abstraction and flexibility.


45-64: LGTM: Proper initialization based on caching strategy

The constructor now correctly initializes the appropriate cache implementation based on the jsbCachePerBrowser flag. This allows for easy switching between caching strategies without modifying the rest of the code.

CefSharp/Internals/LegacyJavaScriptObjectCache.cs (1)

1-44: LGTM: Legacy cache implementation maintains backward compatibility

This implementation correctly maintains the legacy behavior of caching JavaScript objects per process rather than per browser. The ClearCache method is appropriately implemented as a no-op, and the other methods ignore the browser ID parameter as expected.

CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp (1)

133-139: Gracefully handle an empty or null value collection

GetCacheValues is assumed to return a non-null collection. If the implementation ever changes to return nullptr when the browserId is not present, the subsequent ->Count dereference will crash.

-auto values = _javascriptObjectCache->GetCacheValues(browser->GetIdentifier());
-if (values->Count > 0 && rootObject != nullptr)
+auto values = _javascriptObjectCache->GetCacheValues(browser->GetIdentifier());
+if (values != nullptr && values->Count > 0 && rootObject != nullptr)

Adding the extra guard costs nothing and improves robustness.

CefSharp.Test/JavascriptBinding/LegacyJavaScriptObjectCacheTests.cs (1)

15-26: Equality semantics might mask duplicate objects

Assert.Contains(javascriptObjects[0], cachedValues);

Contains relies on reference equality unless JavascriptObject overrides Equals/GetHashCode.
If equality is not overridden, a scenario where two distinct JavascriptObject instances share the same Name but both remain in the cache would not be detected by these tests.

Please either:

  1. Override equality on JavascriptObject to be value-based (preferred), or
  2. Assert against the cache dictionary keys instead of values.

This will make the test guard the contract more strictly.

@AppVeyorBot
Copy link

@amaitland amaitland force-pushed the jsb/perbrowsercache branch from 83b6747 to 1d19085 Compare May 16, 2025 22:22
@AppVeyorBot
Copy link

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.

Javascript Binding - Store JavascriptObjects/Settings per CefBrowser
3 participants