Skip to content

StdLib Browser ShadowRealm

Roger Johansson edited this page Jan 14, 2026 · 1 revision

Browser APIs and ShadowRealm

Web platform APIs and realm isolation.


Browser APIs

Non-standard APIs commonly expected in JavaScript environments.

Timer Functions

Implementation Status: 100% Complete

Function Status Description
setTimeout(callback, delay, ...args) Implemented Executes callback after delay
setInterval(callback, interval, ...args) Implemented Executes callback repeatedly
clearTimeout(timerId) Implemented Cancels timeout
clearInterval(timerId) Implemented Cancels interval
queueMicrotask(callback) Implemented Queues to microtask queue
const id = setTimeout(() => console.log("hello"), 1000);
clearTimeout(id);

queueMicrotask(() => console.log("microtask"));

localStorage

Implementation Status: 100% Complete

Method Status Description
localStorage.getItem(key) Implemented Returns value or null
localStorage.setItem(key, value) Implemented Stores value
localStorage.removeItem(key) Implemented Removes key
localStorage.clear() Implemented Clears all storage

Note: localStorage is simulated in-memory, not persisted.

Console

Implementation Status: Partial (5/18 methods)

Method Status Description
console.log(...args) Implemented Outputs to stdout
console.error(...args) Implemented Outputs to stderr
console.warn(...args) Implemented "Warning: " prefix
console.info(...args) Implemented Same as log
console.debug(...args) Implemented "Debug: " prefix
console.trace() Not Implemented Stack trace
console.time(label) Not Implemented Start timer
console.timeEnd(label) Not Implemented End timer
console.timeLog(label) Not Implemented Log timer
console.assert(cond, ...args) Not Implemented Conditional log
console.count(label) Not Implemented Call counter
console.countReset(label) Not Implemented Reset counter
console.group(label) Not Implemented Start group
console.groupEnd() Not Implemented End group
console.groupCollapsed(label) Not Implemented Collapsed group
console.clear() Not Implemented Clear console
console.dir(obj) Not Implemented Object inspection
console.table(data) Not Implemented Table display

Not Available

The following common browser APIs are not implemented:

API Description
fetch() HTTP requests
XMLHttpRequest Legacy HTTP
WebSocket Real-time communication
requestAnimationFrame() Animation timing
performance.now() High-resolution timing
atob() / btoa() Base64 encoding
structuredClone() Deep cloning
URL / URLSearchParams URL manipulation
TextEncoder / TextDecoder Text encoding
crypto Cryptography
Web Workers Threading
MessageChannel Inter-context messaging

ShadowRealm

TC39 proposal for isolated JavaScript execution contexts.

Implementation Status: 0% (Stubs Only)

Constructor

Method Status Description
new ShadowRealm() Stub Creates stub instance

Prototype Methods

Method Status Description
evaluate(code) Not Implemented Throws NotImplementedException
importValue(specifier, bindingName) Not Implemented Throws NotImplementedException

Expected Behavior (Not Implemented)

const realm = new ShadowRealm();

// Should execute in isolated global
const result = realm.evaluate('1 + 1');

// Should import from module in realm
const fn = await realm.importValue('./module.js', 'myFunction');

Why Not Implemented

ShadowRealm requires:

  • Isolated global objects
  • Separate module graphs
  • Cross-realm value wrapping
  • Memory isolation

These features require significant engine changes to implement properly.


Files

File Purpose
JsEngine.cs Timer registration
StdLib/Browser/BrowserHelper.cs localStorage
StdLib/Console/ConsolePrototype.cs Console methods
StdLib/ShadowRealm/ShadowRealmConstructor.cs Stub
StdLib/ShadowRealm/ShadowRealmPrototype.cs Stubs

See Also

Clone this wiki locally