Skip to content

Implement URI for pure Wasm#2

Open
lostflydev wants to merge 55 commits intoscala-wasmfrom
fix/151-uri-normalize-wasm
Open

Implement URI for pure Wasm#2
lostflydev wants to merge 55 commits intoscala-wasmfrom
fix/151-uri-normalize-wasm

Conversation

@lostflydev
Copy link
Copy Markdown
Owner

@lostflydev lostflydev commented Mar 9, 2026

Summary

Make java.net.URI fully compatible with the pure Wasm backend by providing linkTimeIf branches for all JS-dependent operations.

Closes scala-wasm#153

Changes

  • URI parsing: new parseURI() abstraction returns Array[String] instead of js.RegExp.ExecResult; uses java.util.regex.Pattern on Wasm
  • normalize(): separate normalizeJS() (js.Array with mutating ops) and normalizePureWasm() (Scala Array + System.arraycopy + StringBuilder)
  • IPv6 detection: testIPv6() uses java.util.regex on Wasm
  • Quoting functions (userInfo, path, authority, illegal, nonASCII): extract regex strings into *ReStr vals; new quoteWithPattern() and quoteStrFn() for Wasm using java.util.regex + UTF-8 percent-encoding
  • Build.scala: enable URITest and ClassValueTest in Wasm test suite filter
  • Tests: 6 new tests for constructor quoting, IPv6 hosts, normalize edge cases, relative paths with colons, toString round-trips, and non-ASCII percent-encoding

sjrd and others added 13 commits February 16, 2026 10:58
We display a warning in two places:

* when loading an sbt build with sbt-scalajs, and
* when calling the `link` method of a `StandardLinkerImpl`.
This can be used for code that must adapt to the module kind in a
way that would not link otherwise.
Removes [@tootallnate/once](https://github.com/TooTallNate/once). It's no longer used after updating ancestor dependency [jsdom](https://github.com/jsdom/jsdom). These dependencies need to be updated together.


Removes `@tootallnate/once`

Updates `jsdom` from 16.7.0 to 28.1.0
- [Release notes](https://github.com/jsdom/jsdom/releases)
- [Changelog](https://github.com/jsdom/jsdom/blob/main/Changelog.md)
- [Commits](jsdom/jsdom@16.7.0...28.1.0)

---
updated-dependencies:
- dependency-name: "@tootallnate/once"
  dependency-version: 
  dependency-type: indirect
- dependency-name: jsdom
  dependency-version: 28.1.0
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
…n/multi-dae47d5549

Bump @tootallnate/once and jsdom
…nsform

Fix scala-js#5331: Transform the body of a void typed closure as a statement.
Tighten IR checking of NewLambda, and add checker tests.
Add LinkingInfo.moduleKind as a link-time property.
@lostflydev lostflydev force-pushed the fix/151-uri-normalize-wasm branch 2 times, most recently from 6f7a29d to 915b509 Compare March 10, 2026 14:26
sjrd and others added 15 commits March 10, 2026 23:17
Fix scala-js#5144: More direct hashing of method names for lambda class names.
Grow linear memory in malloc if required
The comparison was the wrong way around. On the first resize, we
jumped straight to a buffer of size `min(Int.MaxValue, len)`.

That was not too bad for `readNBytes` per se, but devastating for
`readAllBytes`, which calls `readNBytes` with `len = Int.MaxValue`.
Instead of boolean configs in `WasmFeatures`.

It makes more sense to use a `ModuleKind`, because it affects how
the produced artifacts look like to the external world, which is
exactly what a `ModuleKind` specifies.
…nt-config

Fix scala-js#5335: Throw a user-friendly exception on inconsistent config.
Bumps [undici](https://github.com/nodejs/undici) from 7.22.0 to 7.24.1.
- [Release notes](https://github.com/nodejs/undici/releases)
- [Commits](nodejs/undici@v7.22.0...v7.24.1)

---
updated-dependencies:
- dependency-name: undici
  dependency-version: 7.24.1
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
…n/undici-7.24.1

Bump undici from 7.22.0 to 7.24.1
[pull] scala-wasm from scala-js:main
…y-settings

Use dedicated ModuleKind's for Wasm without a JS environment.
Strengthen the tests when in compliant mode.
…xceptions

In the javalib, always trigger UB for exceptions subject to UB.
@lostflydev lostflydev force-pushed the fix/151-uri-normalize-wasm branch 2 times, most recently from 3ed6ea4 to 2cf48c9 Compare March 18, 2026 10:00
tanishiking and others added 14 commits March 19, 2026 22:22
[pull] scala-wasm from scala-js:main
Fix the remaining special-case handling needed for `Array[resource]` in the
Wasm backend so the component-model example can allocate and use arrays of
resource values.

This is a kind of monkey patch. `WitResourceTypeRef` still does
not behave enough like a normal class type, so we need a resource-specific
branch in the array subtype / type-data path for now.

The real fix is to make resource types behave more like regular classes.
(make resourcs `final class` with some restrictions in class hierarchy,
and make it `ClassType` and `ClassRef`).
Once we do that, this special-case logic should become unnecessary and can be
removed.
…linktime

Don't use js.Map in ClassValue when targeting pure Wasm
They are backed by arrays, which is allowed by the spec.

The motivation is not so much about ES 5.1 (which is deprecated
anyway), but about future support of Wasm without a JS host. In
Wasm without JS host, we should be able to allocate a direct
`ByteBuffer` even if there are no JS typed arrays.
…ithout-typedarrays

Allow to allocate direct byte buffers without typed arrays.
When the offset is out of bounds, it is unclear whether the method
should throw or return false. The JVM is inconsistent. We choose to
be maximally tolerant to delay UB until there is no other choice.
Unfortunately, it is unclear what to do about the two overloads of
`ju.Objects.requireNonNull` with an explicit message. Either we keep
the message and we have to throw an explicit NPE; or we trigger a
UB NPE, but we ignore the message.

We choose to trigger the UB, but then we catch a genuine NPE to
rethrow it with the correct message. The message will still be lost
when the NPEs are Fatal, but at least they are used when NPEs are
Compliant.

For the overload that takes a `messageSupplier`, additionally we
choose to only call its `get()` method when we actually need the
message, i.e., only in Compliant mode.

These changes allow for good optimization opportunities. We
intrinsify the 3 overloads so we can get the best possible code
for every checked behavior. For Unchecked mode, the tests
completely disappear. For Compliant and Fatal, we don't need to
throw a fake NPE that we immediately try to catch and re-throw.
Run NPE tests for String{Builder,Buffer} when they are compliant,
instead of only when executing on the JVM.
Make ju.Objects.requireNonNull overloads follow Semantics for UB NPE.
@lostflydev lostflydev force-pushed the fix/151-uri-normalize-wasm branch 6 times, most recently from b11cec8 to 4ef8731 Compare April 2, 2026 05:55
tanishiking and others added 6 commits April 2, 2026 21:57
…(typerPhase)`

Remove `WitFunctionType` and `WitVariantValueTypes` maps from
`JSGlobalAddons` that were stored during `PrepJSInterop`.
Instead, query the compiler's symbol table directly using
`exitingPhase(currentRun.typerPhase)` during JS code generation.

This eliminates the store/retrieve pattern across compiler phases
and simplifies WitExportInfo by removing its signature field.
Refactor: retrieve WIT type information from symbols in `exitingPhase(typerPhase)`
Use RegExpImpl to abstract over js.RegExp / java.util.regex.Pattern:
- URI parsing: restore _fld pattern using RegExpImpl.impl.exec/matches/
  exists/getOrElse; remove parseURI helper
- IPv6 detection: ipv6Re compiled via RegExpImpl.impl.compile; inline
  the test into uriStr
- uriRe: single val with RegExpImpl.impl.compile at end of block
- Quoting (5 patterns): use RegExpImpl.impl.replaceAll with
  java.util.function.Function; QuoteStrMapper object in object URI
- Path normalization: String#split + ju.Arrays.asList/subList/
  scalaOps.mkString

RegExpImpl additions:
- Flags object (Global/CaseInsensitive as Int) replaces String flags
- compile(patternStr, flags: Int) overload
- replaceAll(pattern, string, Function[String,String]) with jsReplace
  in JSRegExpImpl and Matcher.replaceAll in JavaRegExpImpl

Unblock URITest in pure Wasm test suite. Add tests for previously
untested code paths: multi-component constructors, IPv6 host,
quoteIllegal, normalize edge cases
@lostflydev lostflydev force-pushed the fix/151-uri-normalize-wasm branch from c71aa5b to 2f58550 Compare April 6, 2026 07:33
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.

Support fixed length list type in Component Model

4 participants