opencode/packages/codemode-rust/conformance/cases/std-uri.js
kommander ebb15aeb19 feat(codemode): add URI functions, toExponential, Math.sumPrecise, f16round and copyWithin
- encodeURI/encodeURIComponent/decodeURI/decodeURIComponent with the
  reference's URIError messages.
- Number formatting follows JavaScriptCore: toString(radix) ports its exact
  integer digits and shortest-fraction algorithm, toExponential and
  toPrecision round half up on the exact value, toFixed keeps the sign of
  a negative that rounds to zero, and number-to-string picks the even
  digit when two shortest forms tie. Range errors use the host messages.
- Math.sumPrecise sums exactly and rounds once; Math.f16round rounds
  straight from the double; Array.prototype.copyWithin.

Number-to-string and its tie rule live in value.rs, so integers from 2^53
up print their shortest digits instead of every digit.

copyWithin converts its arguments through ToPrimitive like the other Array methods. Number-to-string decides ties in 128-bit integer arithmetic. test262: the reference's skipped.txt drops three copyWithin files the reference passes.
2026-11-18 18:56:09 +01:00

6 lines
764 B
JavaScript

const out = []
const s = "https://ex.test/a b?q=1&r=é€😀#h;/,+"
out.push(encodeURI(s), encodeURIComponent(s), decodeURI(encodeURI(s)), decodeURIComponent(encodeURIComponent(s)), decodeURI("%3B%2F%3f%41%23"), decodeURIComponent("%3B%2F%3f%41%23"), encodeURIComponent("-_.!~*'()"), encodeURI(1), decodeURI(undefined), encodeURIComponent({ toString() { return "a b" } }))
for (const f of [() => decodeURIComponent("%"), () => decodeURI("%E0%A4%A"), () => decodeURI("%C0%80"), () => decodeURI("%ED%A0%80"), () => decodeURI("%F8%80%80%80"), () => decodeURIComponent("%zz"), () => decodeURIComponent("%E2%82")]) { try { out.push(f()) } catch (e) { out.push([e.name, e.message, e instanceof URIError]) } }
out.push(["a b", "c/d"].map(encodeURIComponent))
return out