Skip to content

prototype: Browser support Map<String,Object> (JS objects) in JSON codec - #3494

Open
laeubi wants to merge 1 commit into
eclipse-platform:masterfrom
laeubi:simple_object_support_for_browser
Open

laeubi wants to merge 1 commit into
eclipse-platform:masterfrom
laeubi:simple_object_support_for_browser

Conversation

@laeubi

@laeubi laeubi commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Currently BrowserFunction/Evaluate only supports primitives and arrays but not objects.

This is a prototype to add support for having a Map<String, Object> support, but is not complete because Object/Map support is inconsistent across the 4 native backends because they use two different marshalling strategies:

┌────────────────────────┬────────────────────────────────────────────┬─────────────────────────────────────────┐
│ Backend                │ evaluate() return                          │ BrowserFunction args/return             │
├────────────────────────┼────────────────────────────────────────────┼─────────────────────────────────────────┤
│ Edge (win32)           │ via JSON.parse/stringify                   │ via JSON.parse/stringify                │
├────────────────────────┼────────────────────────────────────────────┼─────────────────────────────────────────┤
│ WebKitGTK              │ native jsc_value/JSValueRef walk (no JSON) │ via JSON.parse/stringify                │
├────────────────────────┼────────────────────────────────────────────┼─────────────────────────────────────────┤
│ Cocoa (legacy WebView) │ native WebScriptObject walk (no JSON)      │ native WebScriptObject walk (no JSON)   │
├────────────────────────┼────────────────────────────────────────────┼─────────────────────────────────────────┤
│ IE (win32 legacy)      │ native IDispatch/Variant walk (no JSON)    │ native IDispatch/Variant walk (no JSON) │
└────────────────────────┴────────────────────────────────────────────┴─────────────────────────────────────────┘

So  JSON.java  is only the actual conversion path for Edge (fully) and for WebKitGTK's  BrowserFunction  call marshalling (function args come in via a  swt://  URL query string that's JSON-encoded, and the return value is JSON-stringified back to JS). The other native paths inspect JS values directly (JSC API, WebScriptObject, IDispatch) and only ever check for arrays via a  length  property/index — no key enumeration exists for plain objects.

I still wanted to share this here for gathering feedback of others, if such partial support would be helpful (windows+linux) and possibly ideas how we can streamline this across different OS. My main workaround currently is to start a local webserver and using rest calls, but this is a bit brittle and not always possible due to restricted environments.

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

  212 files  ±0    212 suites  ±0   28m 51s ⏱️ + 1m 5s
4 894 tests ±0  4 870 ✅ ±0   24 💤 ±0  0 ❌ ±0 
7 065 runs  ±0  6 897 ✅ ±0  168 💤 ±0  0 ❌ ±0 

Results for commit 0108851. ± Comparison against base commit 4755f49.

@akurtakov

Copy link
Copy Markdown
Member

Can you please add a snippet showing it?

@laeubi

laeubi commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

Can you please add a snippet showing it?

Showing what specifically? e.g. we have Snippet307 showing Browser Function usage.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Backend-dependent public API behavior needs human compatibility review and regression validation.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

Open (2)
What changed in this PR

Prototypes object/Map support in SWT’s shared browser JSON codec, without changing native conversion paths.

Changes:

  • Decode JSON objects into insertion-ordered maps.
  • Encode String-keyed maps, rejecting other key types.
  • Document backend limitations internally.
File Description
bundles/​org.eclipse.swt/​Eclipse SWT Browser/​common/​org/​eclipse/​swt/​browser/​JSON.java Adds object/Map conversion and documents its scope.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +278 to +279
} else if (object instanceof Map) {
writeMap((Map<?, ?>)object);
Comment on lines +23 to +24
// javascript objects are decoded as java.util.LinkedHashMap<String, Object> (insertion order preserved).
// Any java.util.Map with String keys can be encoded back into a javascript object.
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.

3 participants