From bb6907285b10ac65b29d67890e4957f53ae3146c Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Thu, 30 Jul 2026 16:11:14 +0000 Subject: [PATCH 01/10] Remove dead code from SerializedScriptValue, WebSocket, Performance, JSDOMConvert*, rescle, wasi SerializedScriptValue.cpp/.h (-2360 LOC): delete all #if ENABLE(WEB_RTC), ENABLE(WEB_CODECS), ENABLE(OFFSCREEN_CANVAS_IN_WORKERS), ENABLE(PREDEFINED_COLOR_SPACE_DISPLAY_P3) blocks (all =0 in Bun's JSCOnly cmakeconfig.h; the guarded types have no headers under src/). Delete ~1200 lines of long-commented-out DOM geometry / ImageBitmap / File / Blob / ImageData serialization paths. Delete uncalled public methods create(StringView), create(JSContextRef,...), deserialize(JSContextRef,...), toString(), nullValue(), wireFormatVersion(), encode<>/decode<>() and their private-only helpers (CloneSerializer::serialize(StringView,...), CloneDeserializer::deserializeString, blobFilePathForBlobURL, wrapCryptoKey, unwrapCryptoKey, write/read(DestinationColorSpaceTag), PLATFORM(COCOA) CFDataRef helpers). Delete orphaned enums PredefinedColorSpaceTag, DestinationColorSpaceTag, ImageDataPoolTag and 18 never-written SerializationTag values. WebSocket.cpp/.h (-212 LOC): delete uncalled create/connect overloads, didUpdateBufferedAmount, offerPerMessageDeflate getter, and 2022-era commented-out CSP / MixedContentChecker / suspend/resume / INTELLIGENT_TRACKING_PREVENTION / ConnectedWebSocketKind::Server blocks. Remove the now-orphaned m_dispatchedErrorEvent field. JSDOMConvert*.h/.cpp (-381 LOC): delete NumericSequenceConverter and the five SequenceConverter specializations (IDLSequence is only instantiated with string/enum/interface/dictionary element types in Bun). Delete Converter>, JSConverter>, IDLAllowSharedAdaptor> specs, propertyNameTo{,Atom}String, the IDLLegacyNullToEmpty{,Atom}StringAdaptor and IDLAtomStringAdaptor converters, and valueTo{Byte,USV}AtomString. windows/rescle.cpp/.h (-278 LOC): rescle__setWindowsMetadata uses only Load, SetIcon, SetVersionString, SetFileVersion, SetProductVersion, Commit. Delete SetExecutionLevel/IsExecutionLevelSet/SetApplicationManifest/ IsApplicationManifestSet, GetVersionString, ChangeString, ChangeRcData, GetString, OnEnumResourceManifest and its Load() registration, the now always-empty execution-level/manifest branches in Commit(), ReadFileToString, and five unused RU_VS_* macros. Performance.cpp/.h (-150 LOC): delete uncalled addResourceTiming and its private-only isResourceTimingBufferFull/m_backupResourceTimingBuffer/ m_waitingForBackupBufferToBeProcessed, allowHighPrecisionTime/ highTimePrecision, timeResolution, relativeTimeFromTimeOriginInReducedResolution, and the long-commented-out navigation()/addNavigationTiming()/resourceTimingBufferFullTimerFired blocks. PerformanceObserver.h: delete hasNavigationTiming/addedNavigationTiming/ m_hasNavigationTiming (only referenced by the above commented-out code). EventTarget.cpp/.h + EventListenerMap (-51 LOC): delete isPaymentRequest() (no callers, no overriders), hasCapturingEventListeners and its only caller EventListenerMap::containsCapturing, the decl-only invalidateJSEventListeners, and the legacyType() static + its fallback block in fireEventListeners (legacyType unconditionally returned nullAtom() since 2022). AbortSignal.cpp/.h + JSAbortSignalCustom.cpp (-29 LOC): delete signalFollow (no callers). It was the only writer of m_followingSignal, so also delete m_followingSignal, isFollowingSignal(), and its always-false check in JSAbortSignalOwner::isReachableFromOpaqueRoots. wasi.ts (-280 LOC): delete the four exports.X = ... = void 0 pre-declaration chains (tsc emit artifact from the wasi-js bundle; every property is re-assigned immediately after). Delete WASIExitError/WASIKillError classes, exports.SOCKET_DEFAULT_RIGHTS, initWasiFdInfo() (unreferenced, contains debug console.log), and the if(log.enabled){...} blocks (log is hard-coded to () => {}). ws.js: delete the long-commented-out secWebSocketExtensions / PerMessageDeflate block (May 2023). Rust: delete bun_http's PRINT_EVERY/PRINT_EVERY_I debug scaffolding and its always-false block; drop the unused GuardedBy/RawMutex/RwLockReadGuard/ RwLockWriteGuard re-exports from bun_threading (the backing types stay); delete standalone_graph::Error::UnsupportedTarget (never constructed); delete the unused bunfig::OfflineMode re-export. Verified: bun bd, bun run rust:check-all (all 10 targets), and smoke tests for structured-clone, worker_threads, websocket-client, abort, performance-entries, wasi, event-target all pass. --- src/bunfig/bunfig.rs | 2 - src/http/lib.rs | 12 - src/js/node/wasi.ts | 282 +-- src/js/thirdparty/ws.js | 19 - src/jsc/bindings/webcore/AbortSignal.cpp | 19 - src/jsc/bindings/webcore/AbortSignal.h | 4 - src/jsc/bindings/webcore/EventListenerMap.cpp | 13 - src/jsc/bindings/webcore/EventListenerMap.h | 1 - src/jsc/bindings/webcore/EventTarget.cpp | 29 +- src/jsc/bindings/webcore/EventTarget.h | 9 - .../bindings/webcore/JSAbortSignalCustom.cpp | 6 - src/jsc/bindings/webcore/JSDOMConvertRecord.h | 31 - .../bindings/webcore/JSDOMConvertSequences.h | 209 -- .../bindings/webcore/JSDOMConvertStrings.cpp | 25 - .../bindings/webcore/JSDOMConvertStrings.h | 95 - src/jsc/bindings/webcore/JSDOMConvertUnion.h | 21 - src/jsc/bindings/webcore/Performance.cpp | 134 - src/jsc/bindings/webcore/Performance.h | 16 - .../bindings/webcore/PerformanceObserver.h | 4 - .../webcore/SerializedScriptValue.cpp | 2157 +---------------- .../bindings/webcore/SerializedScriptValue.h | 213 +- src/jsc/bindings/webcore/WebSocket.cpp | 197 -- src/jsc/bindings/webcore/WebSocket.h | 15 - src/jsc/bindings/windows/rescle.cpp | 257 -- src/jsc/bindings/windows/rescle.h | 21 - src/standalone_graph/StandaloneModuleGraph.rs | 4 - src/standalone_graph/error.rs | 3 - src/threading/lib.rs | 5 +- .../dead-symbols-ssv-wasi-webcore.test.ts | 157 ++ 29 files changed, 166 insertions(+), 3794 deletions(-) create mode 100644 test/internal/source-lints/dead-symbols-ssv-wasi-webcore.test.ts diff --git a/src/bunfig/bunfig.rs b/src/bunfig/bunfig.rs index a84c97858010..7a28fb26a4b7 100644 --- a/src/bunfig/bunfig.rs +++ b/src/bunfig/bunfig.rs @@ -27,8 +27,6 @@ use bun_options_types::schema::api; use bun_options_types::command_tag::Tag as CommandTag; use bun_options_types::context::ContextData; -pub use bun_options_types::offline_mode::OfflineMode; - // TODO: replace api.TransformOptions with Bunfig pub(crate) struct Bunfig; diff --git a/src/http/lib.rs b/src/http/lib.rs index c0d854921532..8545899918d9 100644 --- a/src/http/lib.rs +++ b/src/http/lib.rs @@ -1042,8 +1042,6 @@ bun_core::comptime_string_map! { // ── shared per-thread buffers ─────────────────────────────────────────── // All four are HTTP-thread-only scratch (single uws loop thread); `RacyCell` // is the alias-safe static cell per docs/PORTING.md §Global mutable state. -const PRINT_EVERY: usize = 0; -static PRINT_EVERY_I: AtomicUsize = AtomicUsize::new(0); // we always rewrite the entire HTTP request when write() returns EAGAIN // so we can reuse this buffer @@ -4274,16 +4272,6 @@ impl<'a> HTTPClient<'a> { if has_more { self.maybe_pause_receive(socket); } - - if PRINT_EVERY != 0 { - let i = PRINT_EVERY_I.fetch_add(1, Ordering::Relaxed) + 1; - if i.is_multiple_of(PRINT_EVERY) { - bun_core::prettyln!("Heap stats for HTTP thread\n"); - Output::flush(); - // Per-thread allocator stats are no longer collected here. - PRINT_EVERY_I.store(0, Ordering::Relaxed); - } - } } /// `send_progress_update_without_stage_check` minus the per-request TCP socket diff --git a/src/js/node/wasi.ts b/src/js/node/wasi.ts index b08416edf5e6..2f952a86120e 100644 --- a/src/js/node/wasi.ts +++ b/src/js/node/wasi.ts @@ -20,7 +20,7 @@ var require_types = __commonJS({ "node_modules/wasi-js/dist/types.js"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); - exports.WASIKillError = exports.WASIExitError = exports.WASIError = void 0; + exports.WASIError = void 0; var WASIError = class extends Error { constructor(errno) { super(); @@ -29,22 +29,6 @@ var require_types = __commonJS({ } }; exports.WASIError = WASIError; - var WASIExitError = class extends Error { - constructor(code) { - super(`WASI Exit error: ${code}`); - this.code = code; - Object.setPrototypeOf(this, WASIExitError.prototype); - } - }; - exports.WASIExitError = WASIExitError; - var WASIKillError = class extends Error { - constructor(signal) { - super(`WASI Kill signal: ${signal}`); - this.signal = signal; - Object.setPrototypeOf(this, WASIKillError.prototype); - } - }; - exports.WASIKillError = WASIKillError; }, }); @@ -53,192 +37,6 @@ var require_constants = __commonJS({ "node_modules/wasi-js/dist/constants.js"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); - exports.WASI_ENOMSG = - exports.WASI_ENOMEM = - exports.WASI_ENOLINK = - exports.WASI_ENOLCK = - exports.WASI_ENOEXEC = - exports.WASI_ENOENT = - exports.WASI_ENODEV = - exports.WASI_ENOBUFS = - exports.WASI_ENFILE = - exports.WASI_ENETUNREACH = - exports.WASI_ENETRESET = - exports.WASI_ENETDOWN = - exports.WASI_ENAMETOOLONG = - exports.WASI_EMULTIHOP = - exports.WASI_EMSGSIZE = - exports.WASI_EMLINK = - exports.WASI_EMFILE = - exports.WASI_ELOOP = - exports.WASI_EISDIR = - exports.WASI_EISCONN = - exports.WASI_EIO = - exports.WASI_EINVAL = - exports.WASI_EINTR = - exports.WASI_EINPROGRESS = - exports.WASI_EILSEQ = - exports.WASI_EIDRM = - exports.WASI_EHOSTUNREACH = - exports.WASI_EFBIG = - exports.WASI_EFAULT = - exports.WASI_EEXIST = - exports.WASI_EDQUOT = - exports.WASI_EDOM = - exports.WASI_EDESTADDRREQ = - exports.WASI_EDEADLK = - exports.WASI_ECONNRESET = - exports.WASI_ECONNREFUSED = - exports.WASI_ECONNABORTED = - exports.WASI_ECHILD = - exports.WASI_ECANCELED = - exports.WASI_EBUSY = - exports.WASI_EBADMSG = - exports.WASI_EBADF = - exports.WASI_EALREADY = - exports.WASI_EAGAIN = - exports.WASI_EAFNOSUPPORT = - exports.WASI_EADDRNOTAVAIL = - exports.WASI_EADDRINUSE = - exports.WASI_EACCES = - exports.WASI_E2BIG = - exports.WASI_ESUCCESS = - void 0; - exports.WASI_SIGVTALRM = - exports.WASI_SIGUSR2 = - exports.WASI_SIGUSR1 = - exports.WASI_SIGURG = - exports.WASI_SIGTTOU = - exports.WASI_SIGTTIN = - exports.WASI_SIGTSTP = - exports.WASI_SIGTRAP = - exports.WASI_SIGTERM = - exports.WASI_SIGSTOP = - exports.WASI_SIGSEGV = - exports.WASI_SIGQUIT = - exports.WASI_SIGPIPE = - exports.WASI_SIGKILL = - exports.WASI_SIGINT = - exports.WASI_SIGILL = - exports.WASI_SIGHUP = - exports.WASI_SIGFPE = - exports.WASI_SIGCONT = - exports.WASI_SIGCHLD = - exports.WASI_SIGBUS = - exports.WASI_SIGALRM = - exports.WASI_SIGABRT = - exports.WASI_ENOTCAPABLE = - exports.WASI_EXDEV = - exports.WASI_ETXTBSY = - exports.WASI_ETIMEDOUT = - exports.WASI_ESTALE = - exports.WASI_ESRCH = - exports.WASI_ESPIPE = - exports.WASI_EROFS = - exports.WASI_ERANGE = - exports.WASI_EPROTOTYPE = - exports.WASI_EPROTONOSUPPORT = - exports.WASI_EPROTO = - exports.WASI_EPIPE = - exports.WASI_EPERM = - exports.WASI_EOWNERDEAD = - exports.WASI_EOVERFLOW = - exports.WASI_ENXIO = - exports.WASI_ENOTTY = - exports.WASI_ENOTSUP = - exports.WASI_ENOTSOCK = - exports.WASI_ENOTRECOVERABLE = - exports.WASI_ENOTEMPTY = - exports.WASI_ENOTDIR = - exports.WASI_ENOTCONN = - exports.WASI_ENOSYS = - exports.WASI_ENOSPC = - exports.WASI_ENOPROTOOPT = - void 0; - exports.RIGHTS_REGULAR_FILE_BASE = - exports.RIGHTS_CHARACTER_DEVICE_INHERITING = - exports.RIGHTS_CHARACTER_DEVICE_BASE = - exports.RIGHTS_BLOCK_DEVICE_INHERITING = - exports.RIGHTS_BLOCK_DEVICE_BASE = - exports.RIGHTS_ALL = - exports.WASI_RIGHT_SOCK_SHUTDOWN = - exports.WASI_RIGHT_POLL_FD_READWRITE = - exports.WASI_RIGHT_PATH_UNLINK_FILE = - exports.WASI_RIGHT_PATH_REMOVE_DIRECTORY = - exports.WASI_RIGHT_PATH_SYMLINK = - exports.WASI_RIGHT_FD_FILESTAT_SET_TIMES = - exports.WASI_RIGHT_FD_FILESTAT_SET_SIZE = - exports.WASI_RIGHT_FD_FILESTAT_GET = - exports.WASI_RIGHT_PATH_FILESTAT_SET_TIMES = - exports.WASI_RIGHT_PATH_FILESTAT_SET_SIZE = - exports.WASI_RIGHT_PATH_FILESTAT_GET = - exports.WASI_RIGHT_PATH_RENAME_TARGET = - exports.WASI_RIGHT_PATH_RENAME_SOURCE = - exports.WASI_RIGHT_PATH_READLINK = - exports.WASI_RIGHT_FD_READDIR = - exports.WASI_RIGHT_PATH_OPEN = - exports.WASI_RIGHT_PATH_LINK_TARGET = - exports.WASI_RIGHT_PATH_LINK_SOURCE = - exports.WASI_RIGHT_PATH_CREATE_FILE = - exports.WASI_RIGHT_PATH_CREATE_DIRECTORY = - exports.WASI_RIGHT_FD_ALLOCATE = - exports.WASI_RIGHT_FD_ADVISE = - exports.WASI_RIGHT_FD_WRITE = - exports.WASI_RIGHT_FD_TELL = - exports.WASI_RIGHT_FD_SYNC = - exports.WASI_RIGHT_FD_FDSTAT_SET_FLAGS = - exports.WASI_RIGHT_FD_SEEK = - exports.WASI_RIGHT_FD_READ = - exports.WASI_RIGHT_FD_DATASYNC = - exports.WASI_FDFLAG_SYNC = - exports.WASI_FDFLAG_RSYNC = - exports.WASI_FDFLAG_NONBLOCK = - exports.WASI_FDFLAG_DSYNC = - exports.WASI_FDFLAG_APPEND = - exports.WASI_FILETYPE_SYMBOLIC_LINK = - exports.WASI_FILETYPE_SOCKET_STREAM = - exports.WASI_FILETYPE_SOCKET_DGRAM = - exports.WASI_FILETYPE_REGULAR_FILE = - exports.WASI_FILETYPE_DIRECTORY = - exports.WASI_FILETYPE_CHARACTER_DEVICE = - exports.WASI_FILETYPE_BLOCK_DEVICE = - exports.WASI_FILETYPE_UNKNOWN = - exports.WASI_SIGXFSZ = - exports.WASI_SIGXCPU = - void 0; - exports.SIGNAL_MAP = - exports.ERROR_MAP = - exports.WASI_WHENCE_END = - exports.WASI_WHENCE_CUR = - exports.WASI_WHENCE_SET = - exports.WASI_STDERR_FILENO = - exports.WASI_STDOUT_FILENO = - exports.WASI_STDIN_FILENO = - exports.WASI_DIRCOOKIE_START = - exports.WASI_PREOPENTYPE_DIR = - exports.WASI_O_TRUNC = - exports.WASI_O_EXCL = - exports.WASI_O_DIRECTORY = - exports.WASI_O_CREAT = - exports.WASI_FILESTAT_SET_MTIM_NOW = - exports.WASI_FILESTAT_SET_MTIM = - exports.WASI_FILESTAT_SET_ATIM_NOW = - exports.WASI_FILESTAT_SET_ATIM = - exports.WASI_EVENTTYPE_FD_WRITE = - exports.WASI_EVENTTYPE_FD_READ = - exports.WASI_EVENTTYPE_CLOCK = - exports.WASI_CLOCK_THREAD_CPUTIME_ID = - exports.WASI_CLOCK_PROCESS_CPUTIME_ID = - exports.WASI_CLOCK_MONOTONIC = - exports.WASI_CLOCK_REALTIME = - exports.RIGHTS_TTY_INHERITING = - exports.RIGHTS_TTY_BASE = - exports.RIGHTS_SOCKET_INHERITING = - exports.RIGHTS_SOCKET_BASE = - exports.RIGHTS_DIRECTORY_INHERITING = - exports.RIGHTS_DIRECTORY_BASE = - exports.RIGHTS_REGULAR_FILE_INHERITING = - void 0; exports.WASI_ESUCCESS = 0; exports.WASI_E2BIG = 1; exports.WASI_EACCES = 2; @@ -610,9 +408,6 @@ var require_wasi = __commonJS({ }; let fs; Object.defineProperty(exports, "__esModule", { value: true }); - exports.SOCKET_DEFAULT_RIGHTS = void 0; - var log = () => {}; - var logOpen = () => {}; var SC_OPEN_MAX = 32768; var types_1 = require_types(); @@ -632,14 +427,6 @@ var require_wasi = __commonJS({ constants_1.WASI_RIGHT_FD_FILESTAT_GET | constants_1.WASI_RIGHT_POLL_FD_READWRITE; var STDERR_DEFAULT_RIGHTS = STDOUT_DEFAULT_RIGHTS; - exports.SOCKET_DEFAULT_RIGHTS = - constants_1.WASI_RIGHT_FD_DATASYNC | - constants_1.WASI_RIGHT_FD_READ | - constants_1.WASI_RIGHT_FD_WRITE | - constants_1.WASI_RIGHT_FD_ADVISE | - constants_1.WASI_RIGHT_FD_FILESTAT_GET | - constants_1.WASI_RIGHT_POLL_FD_READWRITE | - constants_1.WASI_RIGHT_FD_FDSTAT_SET_FLAGS; var msToNs = ms => { const msInt = Math.trunc(ms); @@ -871,7 +658,6 @@ var require_wasi = __commonJS({ bufLen, total_memory: byteLength, }); - log("getiovs: warning -- truncating buffer to fit in memory"); bufLen = Math.min(bufLen, Math.max(0, byteLength - buf)); } try { @@ -896,7 +682,6 @@ var require_wasi = __commonJS({ bufLen, total_memory: byteLength, }); - log("getiovs: warning -- truncating buffer to fit in memory"); bufLen = Math.min(bufLen, Math.max(0, byteLength - buf)); } try { @@ -1562,7 +1347,6 @@ var require_wasi = __commonJS({ this.view.setUint32(fdPtr, constants_1.WASI_STDIN_FILENO, true); return constants_1.WASI_ESUCCESS; } - logOpen("path_open", p); if (p.startsWith("proc/")) { throw new types_1.WASIError(constants_1.WASI_EBADF); } @@ -1712,7 +1496,6 @@ var require_wasi = __commonJS({ }), poll_oneoff: (sin, sout, nsubscriptions, neventsPtr) => { let nevents = 0; - let name = ""; let waitTimeNs = BigInt(0); let fd = -1; let fd_type = "read"; @@ -1725,16 +1508,6 @@ var require_wasi = __commonJS({ const type = this.view.getUint8(sin); sin += 1; sin += 7; - if (log.enabled) { - if (type == constants_1.WASI_EVENTTYPE_CLOCK) { - name = "poll_oneoff (type=WASI_EVENTTYPE_CLOCK): "; - } else if (type == constants_1.WASI_EVENTTYPE_FD_READ) { - name = "poll_oneoff (type=WASI_EVENTTYPE_FD_READ): "; - } else { - name = "poll_oneoff (type=WASI_EVENTTYPE_FD_WRITE): "; - } - log(name); - } switch (type) { case constants_1.WASI_EVENTTYPE_CLOCK: { const clockid = this.view.getUint32(sin, true); @@ -1747,9 +1520,6 @@ var require_wasi = __commonJS({ sin += 2; sin += 6; const absolute = subclockflags === 1; - if (log.enabled) { - log(name, { clockid, timeout, absolute }); - } if (!absolute) { fd_timeout_ms = timeout / BigInt(1e6); } @@ -1780,7 +1550,6 @@ var require_wasi = __commonJS({ fd = this.view.getUint32(sin, true); fd_type = type == constants_1.WASI_EVENTTYPE_FD_READ ? "read" : "write"; sin += 4; - log(name, "fd =", fd); sin += 28; this.view.setBigUint64(sout, userdata, true); sout += 8; @@ -1872,22 +1641,6 @@ var require_wasi = __commonJS({ return constants_1.WASI_ENOSYS; }, }; - if (log.enabled) { - Object.keys(this.wasiImport).forEach(key => { - const prevImport = this.wasiImport[key]; - this.wasiImport[key] = function (...args2) { - log(key, args2); - try { - let result = prevImport(...args2); - log("result", result); - return result; - } catch (e) { - log("error: ", e); - throw e; - } - }; - }); - } } getState() { return { env: this.env, FD_MAP: this.FD_MAP, bindings: bindings }; @@ -2002,39 +1755,6 @@ var require_wasi = __commonJS({ } } } - initWasiFdInfo() { - const env = this.env; - if (env["WASI_FD_INFO"] != null) { - const fdInfo = JSON.parse(env["WASI_FD_INFO"]); - for (const wasi_fd in fdInfo) { - console.log(wasi_fd); - const fd = parseInt(wasi_fd); - if (this.FD_MAP.has(fd)) { - continue; - } - const real = fdInfo[wasi_fd]; - try { - this.fstatSync(real); - } catch { - console.log("discarding ", { wasi_fd, real }); - continue; - } - const file = { - real, - filetype: constants_1.WASI_FILETYPE_SOCKET_STREAM, - rights: { - base: STDIN_DEFAULT_RIGHTS, - inheriting: BigInt(0), - }, - }; - this.FD_MAP.set(fd, file); - } - console.log("after initWasiFdInfo: ", this.FD_MAP); - console.log("fdInfo = ", fdInfo); - } else { - console.log("no WASI_FD_INFO"); - } - } }; exports.default = WASI; }, diff --git a/src/js/thirdparty/ws.js b/src/js/thirdparty/ws.js index 84064ff76161..172374670561 100644 --- a/src/js/thirdparty/ws.js +++ b/src/js/thirdparty/ws.js @@ -1615,27 +1615,8 @@ class WebSocketServer extends EventEmitter { // TODO: add perMessageDeflate options - // const secWebSocketExtensions = req.headers["sec-websocket-extensions"]; const extensions = {}; - // if (secWebSocketExtensions !== undefined) { - // console.log(secWebSocketExtensions); - // const perMessageDeflate = new PerMessageDeflate(this.options.perMessageDeflate, true, this.options.maxPayload); - - // try { - // const offers = extension.parse(secWebSocketExtensions); - - // if (offers[PerMessageDeflate.extensionName]) { - // perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]); - // extensions[PerMessageDeflate.extensionName] = perMessageDeflate; - // } - // } catch (err) { - // const message = "Invalid or unacceptable Sec-WebSocket-Extensions header"; - // abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, message); - // return; - // } - // } - // // Optionally call external client verification handler. // diff --git a/src/jsc/bindings/webcore/AbortSignal.cpp b/src/jsc/bindings/webcore/AbortSignal.cpp index cedc5efe5f47..1d16234adbe2 100644 --- a/src/jsc/bindings/webcore/AbortSignal.cpp +++ b/src/jsc/bindings/webcore/AbortSignal.cpp @@ -285,25 +285,6 @@ void AbortSignal::cleanNativeBindings(void* ref) this->eventListenersDidChange(); } -// https://dom.spec.whatwg.org/#abortsignal-follow -void AbortSignal::signalFollow(AbortSignal& signal) -{ - if (aborted()) - return; - - if (signal.aborted()) { - signalAbort(signal.jsReason(*scriptExecutionContext()->jsGlobalObject())); - return; - } - - ASSERT(!m_followingSignal); - m_followingSignal = signal; - signal.addAlgorithm([weakThis = WeakPtr { *this }](JSC::JSValue reason) { - if (RefPtr signal = weakThis.get()) - signal->signalAbort(reason); - }); -} - void AbortSignal::eventListenersDidChange() { bool hadListeners = hasAbortEventListener(); diff --git a/src/jsc/bindings/webcore/AbortSignal.h b/src/jsc/bindings/webcore/AbortSignal.h index 829a0e70532e..51aa13b3a9d9 100644 --- a/src/jsc/bindings/webcore/AbortSignal.h +++ b/src/jsc/bindings/webcore/AbortSignal.h @@ -85,7 +85,6 @@ class AbortSignal final : public RefCounted, public EventTargetWith void signalAbort(JSC::JSGlobalObject* globalObject, CommonAbortReason reason); void signalAbort(JSC::JSValue reason); - void signalFollow(AbortSignal&); bool aborted() const { return m_flags & static_cast(AbortSignalFlags::Aborted); } void markAborted(JSC::JSValue reason); @@ -115,8 +114,6 @@ class AbortSignal final : public RefCounted, public EventTargetWith template void visitAbortAlgorithms(Visitor&); - bool isFollowingSignal() const { return !!m_followingSignal; } - void throwIfAborted(JSC::JSGlobalObject&); using AbortSignalSet = WeakListHashSet; @@ -215,7 +212,6 @@ class AbortSignal final : public RefCounted, public EventTargetWith // Strong-ref cycle leak. Vector>> m_abortAlgorithms WTF_GUARDED_BY_LOCK(m_abortAlgorithmsLock); Lock m_abortAlgorithmsLock; - WeakPtr m_followingSignal; AbortSignalSet m_sourceSignals; AbortSignalSet m_dependentSignals; JSValueInWrappedObject m_reason; diff --git a/src/jsc/bindings/webcore/EventListenerMap.cpp b/src/jsc/bindings/webcore/EventListenerMap.cpp index 7e8af8c0d072..023f3c39ce82 100644 --- a/src/jsc/bindings/webcore/EventListenerMap.cpp +++ b/src/jsc/bindings/webcore/EventListenerMap.cpp @@ -45,19 +45,6 @@ namespace WebCore { EventListenerMap::EventListenerMap() = default; -bool EventListenerMap::containsCapturing(const AtomString& eventType) const -{ - auto* listeners = find(eventType); - if (!listeners) - return false; - - for (auto& eventListener : *listeners) { - if (eventListener->useCapture()) - return true; - } - return false; -} - bool EventListenerMap::containsActive(const AtomString& eventType) const { auto* listeners = find(eventType); diff --git a/src/jsc/bindings/webcore/EventListenerMap.h b/src/jsc/bindings/webcore/EventListenerMap.h index af32801205e6..c92a366c364a 100644 --- a/src/jsc/bindings/webcore/EventListenerMap.h +++ b/src/jsc/bindings/webcore/EventListenerMap.h @@ -53,7 +53,6 @@ class EventListenerMap { bool isEmpty() const { return m_entries.isEmpty(); } bool contains(const AtomString& eventType) const { return find(eventType); } - bool containsCapturing(const AtomString& eventType) const; bool containsActive(const AtomString& eventType) const; void clear(); diff --git a/src/jsc/bindings/webcore/EventTarget.cpp b/src/jsc/bindings/webcore/EventTarget.cpp index e3d74425215e..96be8f73f7d6 100644 --- a/src/jsc/bindings/webcore/EventTarget.cpp +++ b/src/jsc/bindings/webcore/EventTarget.cpp @@ -84,11 +84,6 @@ bool EventTarget::isContextStopped() const return !scriptExecutionContext(); } -bool EventTarget::isPaymentRequest() const -{ - return false; -} - bool EventTarget::addEventListener(const AtomString& eventType, Ref&& listener, const AddEventListenerOptions& options) { #if ASSERT_ENABLED @@ -253,12 +248,6 @@ void EventTarget::uncaughtExceptionInEventHandler() { } -static const AtomString& legacyType(const Event& event) -{ - - return nullAtom(); -} - // https://dom.spec.whatwg.org/#concept-event-listener-invoke void EventTarget::fireEventListeners(Event& event, EventInvokePhase phase) { @@ -270,24 +259,8 @@ void EventTarget::fireEventListeners(Event& event, EventInvokePhase phase) SetForScope firingEventListenersScope(data->isFiringEventListeners, true); - if (auto* listenersVector = data->eventListenerMap.find(event.type())) { + if (auto* listenersVector = data->eventListenerMap.find(event.type())) innerInvokeEventListeners(event, *listenersVector, phase); - return; - } - - // Only fall back to legacy types for trusted events. - if (!event.isTrusted()) - return; - - const AtomString& legacyTypeName = legacyType(event); - if (!legacyTypeName.isNull()) { - if (auto* legacyListenersVector = data->eventListenerMap.find(legacyTypeName)) { - AtomString typeName = event.type(); - event.setType(legacyTypeName); - innerInvokeEventListeners(event, *legacyListenersVector, phase); - event.setType(typeName); - } - } } // Intentionally creates a copy of the listeners vector to avoid event listeners added after this point from being run. diff --git a/src/jsc/bindings/webcore/EventTarget.h b/src/jsc/bindings/webcore/EventTarget.h index 52b34ad09b54..b8b861721e4e 100644 --- a/src/jsc/bindings/webcore/EventTarget.h +++ b/src/jsc/bindings/webcore/EventTarget.h @@ -100,7 +100,6 @@ class EventTarget : public ScriptWrappable, public CanMakeWeakPtrWithBitField eventTypes(); @@ -136,7 +134,6 @@ class EventTarget : public ScriptWrappable, public CanMakeWeakPtrWithBitField void visitJSEventListeners(Visitor&); - void invalidateJSEventListeners(JSC::JSObject*); const EventTargetData* eventTargetData() const; @@ -233,12 +230,6 @@ inline bool EventTarget::hasEventListeners(const AtomString& eventType) const return data && data->eventListenerMap.contains(eventType); } -inline bool EventTarget::hasCapturingEventListeners(const AtomString& eventType) -{ - auto* data = eventTargetData(); - return data && data->eventListenerMap.containsCapturing(eventType); -} - template void EventTarget::visitJSEventListeners(Visitor& visitor) { diff --git a/src/jsc/bindings/webcore/JSAbortSignalCustom.cpp b/src/jsc/bindings/webcore/JSAbortSignalCustom.cpp index 9ff395116051..58f96718bb0b 100644 --- a/src/jsc/bindings/webcore/JSAbortSignalCustom.cpp +++ b/src/jsc/bindings/webcore/JSAbortSignalCustom.cpp @@ -40,12 +40,6 @@ bool JSAbortSignalOwner::isReachableFromOpaqueRoots(JSC::Handle ha } if (!abortSignal.aborted()) { - if (abortSignal.isFollowingSignal()) { - if (reason) [[unlikely]] - *reason = "Is Following Signal"_s; - return true; - } - if (abortSignal.hasActiveTimeoutTimer() && abortSignal.hasTimeoutObserver()) { if (reason) [[unlikely]] *reason = "Has Observed Timeout"_s; diff --git a/src/jsc/bindings/webcore/JSDOMConvertRecord.h b/src/jsc/bindings/webcore/JSDOMConvertRecord.h index f002d1775442..371f590ccf32 100644 --- a/src/jsc/bindings/webcore/JSDOMConvertRecord.h +++ b/src/jsc/bindings/webcore/JSDOMConvertRecord.h @@ -251,35 +251,4 @@ template struct Converter> : DefaultConv } }; -template struct JSConverter> { - static constexpr bool needsState = true; - static constexpr bool needsGlobalObject = true; - - template - static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const MapType& map) - { - auto& vm = JSC::getVM(&lexicalGlobalObject); - - // 1. Let result be ! ObjectCreate(%ObjectPrototype%). - auto result = constructEmptyObject(&lexicalGlobalObject, globalObject.objectPrototype()); - - // 2. Repeat, for each mapping (key, value) in D: - for (const auto& keyValuePair : map) { - // 1. Let esKey be key converted to an ECMAScript value. - // Note, this step is not required, as we need the key to be - // an Identifier, not a JSValue. - - // 2. Let esValue be value converted to an ECMAScript value. - auto esValue = toJS(lexicalGlobalObject, globalObject, keyValuePair.value); - - // 3. Let created be ! CreateDataProperty(result, esKey, esValue). - // putDirect() crashes for numeric-index keys; use createDataProperty. - result->createDataProperty(&lexicalGlobalObject, JSC::Identifier::fromString(vm, keyValuePair.key), esValue, false); - } - - // 3. Return result. - return result; - } -}; - } // namespace WebCore diff --git a/src/jsc/bindings/webcore/JSDOMConvertSequences.h b/src/jsc/bindings/webcore/JSDOMConvertSequences.h index 035e593ecd37..519b819609ea 100644 --- a/src/jsc/bindings/webcore/JSDOMConvertSequences.h +++ b/src/jsc/bindings/webcore/JSDOMConvertSequences.h @@ -246,126 +246,6 @@ struct GenericSequenceConverter { } }; -// Specialization for numeric types -// FIXME: This is only implemented for the IDLFloatingPointTypes and IDLLong. To add -// support for more numeric types, add an overload of Converter::convert that -// takes a JSGlobalObject, ThrowScope and double as its arguments. -template> -struct NumericSequenceConverter { - using Traits = SequenceTraits; - using GenericConverter = GenericSequenceConverter; - using ReturnType = typename GenericConverter::ReturnType; - - static ReturnType convertArray(JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope, JSC::JSArray* array, unsigned length, JSC::IndexingType indexingType, ReturnType&& result) - { - if (indexingType == JSC::Int32Shape) { - for (unsigned i = 0; i < length; i++) { - auto indexValue = array->butterfly()->contiguousInt32().at(array, i).get(); - ASSERT(!indexValue || indexValue.isInt32()); - if (!indexValue) - Traits::append(lexicalGlobalObject, result, i, 0); - else - Traits::append(lexicalGlobalObject, result, i, indexValue.asInt32()); - RETURN_IF_EXCEPTION(scope, {}); - } - return WTF::move(result); - } - - ASSERT(indexingType == JSC::DoubleShape); - ASSERT(JSC::Options::allowDoubleShape()); - for (unsigned i = 0; i < length; i++) { - double doubleValue = array->butterfly()->contiguousDouble().at(array, i); - if (std::isnan(doubleValue)) - Traits::append(lexicalGlobalObject, result, i, 0); - else { - auto convertedValue = Converter::convert(lexicalGlobalObject, scope, doubleValue); - RETURN_IF_EXCEPTION(scope, {}); - - Traits::append(lexicalGlobalObject, result, i, convertedValue); - RETURN_IF_EXCEPTION(scope, {}); - } - } - return WTF::move(result); - } - - static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) - { - auto& vm = JSC::getVM(&lexicalGlobalObject); - auto scope = DECLARE_THROW_SCOPE(vm); - - if (!value.isObject()) { - throwSequenceTypeError(lexicalGlobalObject, scope); - return {}; - } - - JSC::JSObject* object = JSC::asObject(value); - if (!JSC::isJSArray(object)) - RELEASE_AND_RETURN(scope, GenericConverter::convert(lexicalGlobalObject, object)); - - JSC::JSArray* array = JSC::asArray(object); - if (!array->isIteratorProtocolFastAndNonObservable()) - RELEASE_AND_RETURN(scope, GenericConverter::convert(lexicalGlobalObject, object)); - - unsigned length = array->length(); - ReturnType result; - - // If we're not an int32/double array, it's possible that converting a - // JSValue to a number could cause the iterator protocol to change, hence, - // we may need more capacity, or less. In such cases, we use the length - // as a proxy for the capacity we will most likely need (it's unlikely that - // a program is written with a valueOf that will augment the iterator protocol). - // If we are an int32/double array, then length is precisely the capacity we need. - JSC::IndexingType indexingType = array->indexingType() & JSC::IndexingShapeMask; - bool isLengthExact = indexingType == JSC::Int32Shape || indexingType == JSC::DoubleShape; - if (isLengthExact) { - Traits::reserveExact(lexicalGlobalObject, result, length); - } else { - Traits::reserveEstimated(lexicalGlobalObject, result, length); - } - RETURN_IF_EXCEPTION(scope, {}); - - if (!isLengthExact) - RELEASE_AND_RETURN(scope, GenericConverter::convert(lexicalGlobalObject, object, WTF::move(result))); - - return convertArray(lexicalGlobalObject, scope, array, length, indexingType, WTF::move(result)); - } - - static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject* object, JSC::JSValue method) - { - auto& vm = JSC::getVM(&lexicalGlobalObject); - auto scope = DECLARE_THROW_SCOPE(vm); - - if (!JSC::isJSArray(object)) - RELEASE_AND_RETURN(scope, GenericConverter::convert(lexicalGlobalObject, object, method)); - - JSC::JSArray* array = JSC::asArray(object); - if (!array->isIteratorProtocolFastAndNonObservable()) - RELEASE_AND_RETURN(scope, GenericConverter::convert(lexicalGlobalObject, object, method)); - - unsigned length = array->length(); - ReturnType result; - // If we're not an int32/double array, it's possible that converting a - // JSValue to a number could cause the iterator protocol to change, hence, - // we may need more capacity, or less. In such cases, we use the length - // as a proxy for the capacity we will most likely need (it's unlikely that - // a program is written with a valueOf that will augment the iterator protocol). - // If we are an int32/double array, then length is precisely the capacity we need. - JSC::IndexingType indexingType = array->indexingType() & JSC::IndexingShapeMask; - bool isLengthExact = indexingType == JSC::Int32Shape || indexingType == JSC::DoubleShape; - if (isLengthExact) { - Traits::reserveExact(lexicalGlobalObject, result, length); - } else { - Traits::reserveEstimated(lexicalGlobalObject, result, length); - } - RETURN_IF_EXCEPTION(scope, {}); - - if (!isLengthExact) - RELEASE_AND_RETURN(scope, GenericConverter::convert(lexicalGlobalObject, object, method, WTF::move(result))); - - return convertArray(lexicalGlobalObject, scope, array, length, indexingType, WTF::move(result)); - } -}; - template> struct SequenceConverter { using Traits = SequenceTraits; @@ -554,81 +434,6 @@ struct SequenceConverter { } }; -template<> -struct SequenceConverter { - using ReturnType = typename GenericSequenceConverter::ReturnType; - - static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) - { - return NumericSequenceConverter::convert(lexicalGlobalObject, value); - } - - static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject* object, JSC::JSValue method) - { - return NumericSequenceConverter::convert(lexicalGlobalObject, object, method); - } -}; - -template<> -struct SequenceConverter { - using ReturnType = typename GenericSequenceConverter::ReturnType; - - static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) - { - return NumericSequenceConverter::convert(lexicalGlobalObject, value); - } - - static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject* object, JSC::JSValue method) - { - return NumericSequenceConverter::convert(lexicalGlobalObject, object, method); - } -}; - -template<> -struct SequenceConverter { - using ReturnType = typename GenericSequenceConverter::ReturnType; - - static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) - { - return NumericSequenceConverter::convert(lexicalGlobalObject, value); - } - - static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject* object, JSC::JSValue method) - { - return NumericSequenceConverter::convert(lexicalGlobalObject, object, method); - } -}; - -template<> -struct SequenceConverter { - using ReturnType = typename GenericSequenceConverter::ReturnType; - - static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) - { - return NumericSequenceConverter::convert(lexicalGlobalObject, value); - } - - static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject* object, JSC::JSValue method) - { - return NumericSequenceConverter::convert(lexicalGlobalObject, object, method); - } -}; - -template<> -struct SequenceConverter { - using ReturnType = typename GenericSequenceConverter::ReturnType; - - static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) - { - return NumericSequenceConverter::convert(lexicalGlobalObject, value); - } - - static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject* object, JSC::JSValue method) - { - return NumericSequenceConverter::convert(lexicalGlobalObject, object, method); - } -}; - } template @@ -685,20 +490,6 @@ template struct JSConverter> { } }; -template struct Converter> : DefaultConverter> { - using ReturnType = typename Detail::SequenceConverter::ReturnType; - - static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) - { - return Detail::SequenceConverter::convert(lexicalGlobalObject, value); - } - - static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject* object, JSC::JSValue method) - { - return Detail::SequenceConverter::convert(lexicalGlobalObject, object, method); - } -}; - template struct JSConverter> { static constexpr bool needsState = true; static constexpr bool needsGlobalObject = true; diff --git a/src/jsc/bindings/webcore/JSDOMConvertStrings.cpp b/src/jsc/bindings/webcore/JSDOMConvertStrings.cpp index 16c52e6bddd6..af8536c0d697 100644 --- a/src/jsc/bindings/webcore/JSDOMConvertStrings.cpp +++ b/src/jsc/bindings/webcore/JSDOMConvertStrings.cpp @@ -76,20 +76,6 @@ String valueToByteString(JSGlobalObject& lexicalGlobalObject, JSValue value) return string; } -AtomString valueToByteAtomString(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) -{ - VM& vm = lexicalGlobalObject.vm(); - auto scope = DECLARE_THROW_SCOPE(vm); - - AtomString string = value.toString(&lexicalGlobalObject)->toAtomString(&lexicalGlobalObject).data; - RETURN_IF_EXCEPTION(scope, {}); - - if (throwIfInvalidByteString(lexicalGlobalObject, scope, string.string())) [[unlikely]] - return nullAtom(); - - return string; -} - String identifierToUSVString(JSGlobalObject& lexicalGlobalObject, const Identifier& identifier) { return replaceUnpairedSurrogatesWithReplacementCharacter(identifierToString(lexicalGlobalObject, identifier)); @@ -106,15 +92,4 @@ String valueToUSVString(JSGlobalObject& lexicalGlobalObject, JSValue value) return replaceUnpairedSurrogatesWithReplacementCharacter(WTF::move(string)); } -AtomString valueToUSVAtomString(JSGlobalObject& lexicalGlobalObject, JSValue value) -{ - VM& vm = lexicalGlobalObject.vm(); - auto scope = DECLARE_THROW_SCOPE(vm); - - auto string = value.toString(&lexicalGlobalObject)->toAtomString(&lexicalGlobalObject); - RETURN_IF_EXCEPTION(scope, {}); - - return replaceUnpairedSurrogatesWithReplacementCharacter(AtomString(string)); -} - } // namespace WebCore diff --git a/src/jsc/bindings/webcore/JSDOMConvertStrings.h b/src/jsc/bindings/webcore/JSDOMConvertStrings.h index 38fc9eccacdf..c88644031eb9 100644 --- a/src/jsc/bindings/webcore/JSDOMConvertStrings.h +++ b/src/jsc/bindings/webcore/JSDOMConvertStrings.h @@ -34,21 +34,8 @@ namespace WebCore { WEBCORE_EXPORT String identifierToString(JSC::JSGlobalObject&, const JSC::Identifier&); WEBCORE_EXPORT String identifierToByteString(JSC::JSGlobalObject&, const JSC::Identifier&); WEBCORE_EXPORT String valueToByteString(JSC::JSGlobalObject&, JSC::JSValue); -WEBCORE_EXPORT AtomString valueToByteAtomString(JSC::JSGlobalObject&, JSC::JSValue); WEBCORE_EXPORT String identifierToUSVString(JSC::JSGlobalObject&, const JSC::Identifier&); WEBCORE_EXPORT String valueToUSVString(JSC::JSGlobalObject&, JSC::JSValue); -WEBCORE_EXPORT AtomString valueToUSVAtomString(JSC::JSGlobalObject&, JSC::JSValue); - -inline AtomString propertyNameToString(JSC::PropertyName propertyName) -{ - ASSERT(!propertyName.isSymbol()); - return propertyName.uid() ? propertyName.uid() : propertyName.publicName(); -} - -inline AtomString propertyNameToAtomString(JSC::PropertyName propertyName) -{ - return AtomString(propertyName.uid() ? propertyName.uid() : propertyName.publicName()); -} // MARK: - // MARK: String types @@ -151,44 +138,6 @@ template<> struct JSConverter { // MARK: - // MARK: String type adaptors -template struct Converter> : DefaultConverter> { - static String convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) - { - if (value.isNull()) - return emptyString(); - return Converter::convert(lexicalGlobalObject, value); - } -}; - -template struct JSConverter> { - static constexpr bool needsState = true; - static constexpr bool needsGlobalObject = false; - - static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const String& value) - { - return JSConverter::convert(lexicalGlobalObject, value); - } -}; - -template struct Converter> : DefaultConverter> { - static AtomString convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) - { - if (value.isNull()) - return emptyAtom(); - return Converter>::convert(lexicalGlobalObject, value); - } -}; - -template struct JSConverter> { - static constexpr bool needsState = true; - static constexpr bool needsGlobalObject = false; - - static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const AtomString& value) - { - return JSConverter::convert(lexicalGlobalObject, value); - } -}; - template struct Converter> : DefaultConverter> { static AtomString convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) { @@ -198,20 +147,6 @@ template struct Converter> : DefaultConverte } }; -template<> struct Converter> : DefaultConverter> { - static AtomString convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) - { - return valueToUSVAtomString(lexicalGlobalObject, value); - } -}; - -template<> struct Converter> : DefaultConverter> { - static AtomString convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) - { - return valueToByteAtomString(lexicalGlobalObject, value); - } -}; - template struct JSConverter> { static constexpr bool needsState = true; static constexpr bool needsGlobalObject = false; @@ -232,36 +167,6 @@ template struct JSConverter> { } }; -template<> struct JSConverter> { - static constexpr bool needsState = true; - static constexpr bool needsGlobalObject = false; - - static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const AtomString& value) - { - return JSConverter::convert(lexicalGlobalObject, value.string()); - } - - static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const String& value) - { - return JSConverter::convert(lexicalGlobalObject, value); - } - - static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const URL& value) - { - return JSConverter::convert(lexicalGlobalObject, value.string()); - } -}; - -template<> struct JSConverter> { - static constexpr bool needsState = true; - static constexpr bool needsGlobalObject = false; - - static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const AtomString& value) - { - return JSConverter::convert(lexicalGlobalObject, value.string()); - } -}; - template struct Converter> : DefaultConverter> { static AtomString convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) { diff --git a/src/jsc/bindings/webcore/JSDOMConvertUnion.h b/src/jsc/bindings/webcore/JSDOMConvertUnion.h index 1ef5d2cd6ede..02c54e0ccb9e 100644 --- a/src/jsc/bindings/webcore/JSDOMConvertUnion.h +++ b/src/jsc/bindings/webcore/JSDOMConvertUnion.h @@ -413,25 +413,4 @@ template struct JSConverter> { } }; -// BufferSource specialization. In WebKit, BufferSource is defined as IDLUnion as a hack, and it is not compatible to -// annotation described in WebIDL. -template<> struct Converter>> : DefaultConverter> { - static auto convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) -> decltype(auto) - { - return Converter, IDLAllowSharedAdaptor>>::convert(lexicalGlobalObject, value); - } -}; - -template<> -struct JSConverter>> { - static constexpr bool needsState = true; - static constexpr bool needsGlobalObject = true; - - template - static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const U& value) - { - return JSConverter>::convert(lexicalGlobalObject, globalObject, value); - } -}; - } // namespace WebCore diff --git a/src/jsc/bindings/webcore/Performance.cpp b/src/jsc/bindings/webcore/Performance.cpp index f5250082177e..f61144a4190e 100644 --- a/src/jsc/bindings/webcore/Performance.cpp +++ b/src/jsc/bindings/webcore/Performance.cpp @@ -58,12 +58,10 @@ namespace WebCore { WTF_MAKE_TZONE_ALLOCATED_IMPL(Performance); -constexpr Seconds highTimePrecision { 20_us }; static Seconds timePrecision { 1_ms }; Performance::Performance(ScriptExecutionContext* context, MonotonicTime timeOrigin) : ContextDestructionObserver(context) - // , m_resourceTimingBufferFullTimer(*this, &Performance::resourceTimingBufferFullTimerFired) // FIXME: Migrate this to the event loop as well. https://bugs.webkit.org/show_bug.cgi?id=229044 , m_timeOrigin(timeOrigin) { ASSERT(m_timeOrigin); @@ -73,7 +71,6 @@ Performance::~Performance() = default; void Performance::contextDestroyed() { - // m_resourceTimingBufferFullTimer.stop(); ContextDestructionObserver::contextDestroyed(); } @@ -102,38 +99,11 @@ Seconds Performance::reduceTimeResolution(Seconds seconds) return Seconds(reduced); } -void Performance::allowHighPrecisionTime() -{ - timePrecision = highTimePrecision; -} - -Seconds Performance::timeResolution() -{ - return timePrecision; -} - -DOMHighResTimeStamp Performance::relativeTimeFromTimeOriginInReducedResolution(MonotonicTime timestamp) const -{ - Seconds seconds = timestamp - m_timeOrigin; - return reduceTimeResolution(seconds).milliseconds(); -} - MonotonicTime Performance::monotonicTimeFromRelativeTime(DOMHighResTimeStamp relativeTime) const { return m_timeOrigin + Seconds::fromMilliseconds(relativeTime); } -// PerformanceNavigation* Performance::navigation() -// { -// if (!is(scriptExecutionContext())) -// return nullptr; - -// ASSERT(isMainThread()); -// if (!m_navigation) -// m_navigation = PerformanceNavigation::create(downcast(*scriptExecutionContext()).domWindow()); -// return m_navigation.get(); -// } - PerformanceTiming* Performance::timing() { // if (!is(scriptExecutionContext())) @@ -262,110 +232,6 @@ void Performance::setResourceTimingBufferSize(unsigned size) m_resourceTimingBufferFullFlag = false; } -// void Performance::reportFirstContentfulPaint() -// { -// ASSERT(!m_firstContentfulPaint); -// m_firstContentfulPaint = PerformancePaintTiming::createFirstContentfulPaint(now()); -// queueEntry(*m_firstContentfulPaint); -// } - -// void Performance::addNavigationTiming(DocumentLoader& documentLoader, Document& document, CachedResource& resource, const DocumentLoadTiming& timing, const NetworkLoadMetrics& metrics) -// { -// ASSERT(document.settings().performanceNavigationTimingAPIEnabled()); -// m_navigationTiming = PerformanceNavigationTiming::create(m_timeOrigin, resource, timing, metrics, document.eventTiming(), document.securityOrigin(), documentLoader.triggeringAction().type()); -// } - -// void Performance::navigationFinished(const NetworkLoadMetrics& metrics) -// { -// if (!m_navigationTiming) -// return; -// m_navigationTiming->navigationFinished(metrics); - -// queueEntry(*m_navigationTiming); -// } - -void Performance::addResourceTiming(ResourceTiming&& resourceTiming) -{ - ASSERT(scriptExecutionContext()); - - auto entry = PerformanceResourceTiming::create(m_timeOrigin, WTF::move(resourceTiming)); - - if (m_waitingForBackupBufferToBeProcessed) { - m_backupResourceTimingBuffer.append(WTF::move(entry)); - return; - } - - if (m_resourceTimingBufferFullFlag) { - // We fired resourcetimingbufferfull event but the author script didn't clear the buffer. - // Notify performance observers but don't add it to the buffer. - queueEntry(entry.get()); - return; - } - - if (isResourceTimingBufferFull()) { - // ASSERT(!m_resourceTimingBufferFullTimer.isActive()); - m_backupResourceTimingBuffer.append(WTF::move(entry)); - m_waitingForBackupBufferToBeProcessed = true; - // m_resourceTimingBufferFullTimer.startOneShot(0_s); - return; - } - - queueEntry(entry.get()); - m_resourceTimingBuffer.append(WTF::move(entry)); -} - -bool Performance::isResourceTimingBufferFull() const -{ - return m_resourceTimingBuffer.size() >= m_resourceTimingBufferSize; -} - -// void Performance::resourceTimingBufferFullTimerFired() -// { -// ASSERT(scriptExecutionContext()); - -// while (!m_backupResourceTimingBuffer.isEmpty()) { -// auto beforeCount = m_backupResourceTimingBuffer.size(); - -// auto backupBuffer = WTF::move(m_backupResourceTimingBuffer); -// ASSERT(m_backupResourceTimingBuffer.isEmpty()); - -// if (isResourceTimingBufferFull()) { -// m_resourceTimingBufferFullFlag = true; -// dispatchEvent(Event::create(eventNames().resourcetimingbufferfullEvent, Event::CanBubble::No, Event::IsCancelable::No)); -// } - -// if (m_resourceTimingBufferFullFlag) { -// for (auto& entry : backupBuffer) -// queueEntry(*entry); -// // Dispatching resourcetimingbufferfull event may have inserted more entries. -// for (auto& entry : m_backupResourceTimingBuffer) -// queueEntry(*entry); -// m_backupResourceTimingBuffer.clear(); -// break; -// } - -// // More entries may have added while dispatching resourcetimingbufferfull event. -// backupBuffer.appendVector(m_backupResourceTimingBuffer); -// m_backupResourceTimingBuffer.clear(); - -// for (auto& entry : backupBuffer) { -// if (!isResourceTimingBufferFull()) { -// m_resourceTimingBuffer.append(entry.copyRef()); -// queueEntry(*entry); -// } else -// m_backupResourceTimingBuffer.append(entry.copyRef()); -// } - -// auto afterCount = m_backupResourceTimingBuffer.size(); - -// if (beforeCount <= afterCount) { -// m_backupResourceTimingBuffer.clear(); -// break; -// } -// } -// m_waitingForBackupBufferToBeProcessed = false; -// } - ExceptionOr> Performance::mark(JSC::JSGlobalObject& globalObject, const String& markName, std::optional&& markOptions) { if (!m_userTiming) diff --git a/src/jsc/bindings/webcore/Performance.h b/src/jsc/bindings/webcore/Performance.h index da4c463554bc..83dea5849f1f 100644 --- a/src/jsc/bindings/webcore/Performance.h +++ b/src/jsc/bindings/webcore/Performance.h @@ -105,23 +105,14 @@ class Performance final : public RefCounted, public ContextDestruct ExceptionOr> measure(JSC::JSGlobalObject&, const String& measureName, std::optional&&, const String& endMark); void clearMeasures(const String& measureName); - // void addNavigationTiming(DocumentLoader&, Document&, CachedResource&, const DocumentLoadTiming&, const NetworkLoadMetrics&); - // void navigationFinished(const NetworkLoadMetrics&); - void addResourceTiming(ResourceTiming&&); - - // void reportFirstContentfulPaint(); - size_t memoryCost() const; void removeAllObservers(); void registerPerformanceObserver(PerformanceObserver&); void unregisterPerformanceObserver(PerformanceObserver&); - static void allowHighPrecisionTime(); - static Seconds timeResolution(); static Seconds reduceTimeResolution(Seconds); - DOMHighResTimeStamp relativeTimeFromTimeOriginInReducedResolution(MonotonicTime) const; MonotonicTime monotonicTimeFromRelativeTime(DOMHighResTimeStamp) const; ScriptExecutionContext* scriptExecutionContext() const final { return ContextDestructionObserver::scriptExecutionContext(); } @@ -147,9 +138,6 @@ class Performance final : public RefCounted, public ContextDestruct void refEventTarget() final { ref(); } void derefEventTarget() final { deref(); } - bool isResourceTimingBufferFull() const; - // void resourceTimingBufferFullTimerFired(); - void queueEntry(PerformanceEntry&); void scheduleTaskIfNeeded(); @@ -160,12 +148,8 @@ class Performance final : public RefCounted, public ContextDestruct Vector> m_resourceTimingBuffer; unsigned m_resourceTimingBufferSize { 150 }; - // Timer m_resourceTimingBufferFullTimer; - Vector> m_backupResourceTimingBuffer; - // https://w3c.github.io/resource-timing/#dfn-resource-timing-buffer-full-flag bool m_resourceTimingBufferFullFlag { false }; - bool m_waitingForBackupBufferToBeProcessed { false }; bool m_hasScheduledTimingBufferDeliveryTask { false }; MonotonicTime m_timeOrigin; diff --git a/src/jsc/bindings/webcore/PerformanceObserver.h b/src/jsc/bindings/webcore/PerformanceObserver.h index 1049dce4de5d..f4f04ac83a73 100644 --- a/src/jsc/bindings/webcore/PerformanceObserver.h +++ b/src/jsc/bindings/webcore/PerformanceObserver.h @@ -61,9 +61,6 @@ class PerformanceObserver : public RefCounted { OptionSet typeFilter() const { return m_typeFilter; } - bool hasNavigationTiming() const { return m_hasNavigationTiming; } - void addedNavigationTiming() { m_hasNavigationTiming = true; } - void queueEntry(PerformanceEntry&); void deliver(); @@ -79,7 +76,6 @@ class PerformanceObserver : public RefCounted { OptionSet m_typeFilter; bool m_registered { false }; bool m_isTypeObserver { false }; - bool m_hasNavigationTiming { false }; }; } // namespace WebCore diff --git a/src/jsc/bindings/webcore/SerializedScriptValue.cpp b/src/jsc/bindings/webcore/SerializedScriptValue.cpp index 2e57510beaee..06d604c26012 100644 --- a/src/jsc/bindings/webcore/SerializedScriptValue.cpp +++ b/src/jsc/bindings/webcore/SerializedScriptValue.cpp @@ -39,38 +39,16 @@ #include "CryptoKeyRSA.h" #include "CryptoKeyRSAComponents.h" #include "CryptoKeyRaw.h" -// #include "IDBValue.h" -// #include "ImageBitmapBacking.h" -// #include "JSAudioWorkletGlobalScope.h" -// #include "JSBlob.h" #include "JSCryptoKey.h" #include "JSDOMBinding.h" #include "JSDOMConvertBufferSource.h" #include "JSDOMException.h" #include "JSDOMGlobalObject.h" -// #include "JSDOMMatrix.h" -// #include "JSDOMPoint.h" -// #include "JSDOMQuad.h" -// #include "JSDOMRect.h" -// #include "JSExecState.h" -// #include "JSFile.h" -// #include "JSFileList.h" -// #include "JSIDBSerializationGlobalObject.h" -// #include "JSImageBitmap.h" -// #include "JSImageData.h" #include "JSMessagePort.h" -// #include "JSNavigator.h" -// #include "JSRTCCertificate.h" -// #include "JSRTCDataChannel.h" -// #include "JSWebCodecsEncodedVideoChunk.h" -// #include "JSWebCodecsVideoFrame.h" #include "ScriptExecutionContext.h" -// #include "WebCodecsEncodedVideoChunk.h" #include "WebCoreJSClientData.h" -#include #include #include -#include #include #include #include @@ -125,19 +103,6 @@ #include #include -#if USE(CG) -#include -#endif - -#if PLATFORM(COCOA) -#include -#endif - -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) -#include "JSOffscreenCanvas.h" -#include "OffscreenCanvas.h" -#endif - #if CPU(BIG_ENDIAN) || CPU(MIDDLE_ENDIAN) || CPU(NEEDS_ALIGNED_ACCESS) #define ASSUME_LITTLE_ENDIAN 0 #else @@ -191,10 +156,6 @@ enum SerializationTag { TrueTag = 9, DoubleTag = 10, DateTag = 11, - FileTag = 12, - FileListTag = 13, - ImageDataTag = 14, - BlobTag = 15, StringTag = 16, EmptyStringTag = 17, RegExpTag = 18, @@ -218,35 +179,13 @@ enum SerializationTag { SharedArrayBufferTag = 34, #if ENABLE(WEBASSEMBLY) WasmModuleTag = 35, -#endif - DOMPointReadOnlyTag = 36, - DOMPointTag = 37, - DOMRectReadOnlyTag = 38, - DOMRectTag = 39, - DOMMatrixReadOnlyTag = 40, - DOMMatrixTag = 41, - DOMQuadTag = 42, - ImageBitmapTransferTag = 43, -#if ENABLE(WEB_RTC) - RTCCertificateTag = 44, -#endif - ImageBitmapTag = 45, -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - OffscreenCanvasTransferTag = 46, #endif BigIntTag = 47, BigIntObjectTag = 48, #if ENABLE(WEBASSEMBLY) WasmMemoryTag = 49, -#endif -#if ENABLE(WEB_RTC) - RTCDataChannelTransferTag = 50, #endif DOMExceptionTag = 51, -#if ENABLE(WEB_CODECS) - WebCodecsEncodedVideoChunkTag = 52, - WebCodecsVideoFrameTag = 53, -#endif ResizableArrayBufferTag = 54, ErrorInstanceTag = 55, @@ -281,95 +220,6 @@ enum ArrayBufferViewSubtag { Float16ArrayTag = 12, }; -// static bool isTypeExposedToGlobalObject(JSC::JSGlobalObject& globalObject, SerializationTag tag) -// { -// #if ENABLE(WEB_AUDIO) -// if (!dynamicDowncast(&globalObject)) -// return true; - -// // Only built-in JS types are exposed to audio worklets. -// switch (tag) { -// case ArrayTag: -// case ObjectTag: -// case UndefinedTag: -// case NullTag: -// case IntTag: -// case ZeroTag: -// case OneTag: -// case FalseTag: -// case TrueTag: -// case DoubleTag: -// case DateTag: -// case StringTag: -// case EmptyStringTag: -// case RegExpTag: -// case ObjectReferenceTag: -// case ArrayBufferTag: -// case ArrayBufferViewTag: -// case ArrayBufferTransferTag: -// case TrueObjectTag: -// case FalseObjectTag: -// case StringObjectTag: -// case EmptyStringObjectTag: -// case NumberObjectTag: -// case SetObjectTag: -// case MapObjectTag: -// case NonMapPropertiesTag: -// case NonSetPropertiesTag: -// case SharedArrayBufferTag: -// #if ENABLE(WEBASSEMBLY) -// case WasmModuleTag: -// #endif -// case BigIntTag: -// case BigIntObjectTag: -// #if ENABLE(WEBASSEMBLY) -// case WasmMemoryTag: -// #endif -// case ResizableArrayBufferTag: -// case ErrorInstanceTag: -// case ErrorTag: -// case MessagePortReferenceTag: -// return true; -// case FileTag: -// case FileListTag: -// case ImageDataTag: -// case BlobTag: -// #if ENABLE(WEB_CRYPTO) -// case CryptoKeyTag: -// #endif -// case DOMPointReadOnlyTag: -// case DOMPointTag: -// case DOMRectReadOnlyTag: -// case DOMRectTag: -// case DOMMatrixReadOnlyTag: -// case DOMMatrixTag: -// case DOMQuadTag: -// case ImageBitmapTransferTag: -// #if ENABLE(WEB_RTC) -// case RTCCertificateTag: -// #endif -// case ImageBitmapTag: -// #if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) -// case OffscreenCanvasTransferTag: -// #endif -// #if ENABLE(WEB_RTC) -// case RTCDataChannelTransferTag: -// #endif -// case DOMExceptionTag: -// #if ENABLE(WEB_CODECS) -// case WebCodecsEncodedVideoChunkTag: -// case WebCodecsVideoFrameTag: -// #endif -// break; -// } -// return false; -// #else -// UNUSED_PARAM(globalObject); -// UNUSED_PARAM(tag); -// return true; -// #endif -// } - static unsigned typedArrayElementSize(ArrayBufferViewSubtag tag) { switch (tag) { @@ -444,28 +294,6 @@ static ErrorType toErrorType(SerializableErrorType value) return ErrorType::Error; } -enum class PredefinedColorSpaceTag : uint8_t { - SRGB = 0 -#if ENABLE(PREDEFINED_COLOR_SPACE_DISPLAY_P3) - , - DisplayP3 = 1 -#endif -}; - -enum DestinationColorSpaceTag { - DestinationColorSpaceSRGBTag = 0, -#if ENABLE(DESTINATION_COLOR_SPACE_LINEAR_SRGB) - DestinationColorSpaceLinearSRGBTag = 1, -#endif -#if ENABLE(DESTINATION_COLOR_SPACE_DISPLAY_P3) - DestinationColorSpaceDisplayP3Tag = 2, -#endif -#if PLATFORM(COCOA) - DestinationColorSpaceCGColorSpaceNameTag = 3, - DestinationColorSpaceCGColorSpacePropertyListTag = 4, -#endif -}; - #if ENABLE(WEBASSEMBLY) static String agentClusterIDFromGlobalObject(JSGlobalObject& globalObject) { @@ -595,7 +423,6 @@ const uint8_t cryptoKeyOKPOpNameTagMaximumValue = 1; [[maybe_unused]] static constexpr unsigned TerminatorTag = 0xFFFFFFFF; [[maybe_unused]] static constexpr unsigned StringPoolTag = 0xFFFFFFFE; [[maybe_unused]] static constexpr unsigned NonIndexPropertiesTag = 0xFFFFFFFD; -[[maybe_unused]] static constexpr uint32_t ImageDataPoolTag = 0xFFFFFFFE; // The high bit of a StringData's length determines the character size. static constexpr unsigned StringDataIs8BitFlag = 0x80000000; @@ -804,20 +631,6 @@ class CloneBase { MarkedArgumentBuffer m_gcBuffer; }; -#if ENABLE(WEB_CRYPTO) -static bool wrapCryptoKey(JSGlobalObject* lexicalGlobalObject, const Vector& key, Vector& wrappedKey) -{ - auto context = executionContext(lexicalGlobalObject); - return context && context->wrapCryptoKey(key, wrappedKey); -} - -static bool unwrapCryptoKey(JSGlobalObject* lexicalGlobalObject, const Vector& wrappedKey, Vector& key) -{ - auto context = executionContext(lexicalGlobalObject); - return context && context->unwrapCryptoKey(wrappedKey, key); -} -#endif - // Vector::append() grows capacity by 1.5x via expandCapacity(). When the buffer is // already large (from serializing a big ArrayBuffer), 1.5x can exceed the ~2GB Vector capacity // limit and CRASH() even though the exact needed size would fit. This helper grows by 1.5x when @@ -902,54 +715,8 @@ class CloneSerializer : public CloneBase { if (!writeLittleEndian(m_buffer, data, length)) [[unlikely]] fail(); } - // static SerializationReturnCode serialize(JSGlobalObject* lexicalGlobalObject, JSValue value, Vector>& messagePorts, Vector>& arrayBuffers, const Vector>& imageBitmaps, - // #if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - // const Vector>& offscreenCanvases, - // #endif - // #if ENABLE(WEB_RTC) - // const Vector>& rtcDataChannels, - // #endif - // #if ENABLE(WEB_CODECS) - // Vector>& serializedVideoChunks, - // Vector>& serializedVideoFrames, - // #endif - // #if ENABLE(WEBASSEMBLY) - // WasmModuleArray& wasmModules, - // WasmMemoryHandleArray& wasmMemoryHandles, - // #endif - // Vector& blobHandles, Vector& out, SerializationContext context, ArrayBufferContentsArray& sharedBuffers, - // SerializationForStorage forStorage) - // { - // CloneSerializer serializer(lexicalGlobalObject, messagePorts, arrayBuffers, imageBitmaps, - // #if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - // offscreenCanvases, - // #endif - // #if ENABLE(WEB_RTC) - // rtcDataChannels, - // #endif - // #if ENABLE(WEB_CODECS) - // serializedVideoChunks, - // serializedVideoFrames, - // #endif - // #if ENABLE(WEBASSEMBLY) - // wasmModules, - // wasmMemoryHandles, - // #endif - // blobHandles, out, context, sharedBuffers, forStorage); - // return serializer.serialize(value); - // } static SerializationReturnCode serialize(JSGlobalObject* lexicalGlobalObject, JSValue value, Vector>& messagePorts, Vector>& arrayBuffers, -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - const Vector>& offscreenCanvases, -#endif -#if ENABLE(WEB_RTC) - const Vector>& rtcDataChannels, -#endif -#if ENABLE(WEB_CODECS) - Vector>& serializedVideoChunks, - Vector>& serializedVideoFrames, -#endif #if ENABLE(WEBASSEMBLY) WasmModuleArray& wasmModules, WasmMemoryHandleArray& wasmMemoryHandles, @@ -959,16 +726,6 @@ class CloneSerializer : public CloneBase { SerializationForStorage forStorage, SerializationForCrossProcessTransfer forTransfer) { CloneSerializer serializer(lexicalGlobalObject, messagePorts, arrayBuffers, -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - offscreenCanvases, -#endif -#if ENABLE(WEB_RTC) - rtcDataChannels, -#endif -#if ENABLE(WEB_CODECS) - serializedVideoChunks, - serializedVideoFrames, -#endif #if ENABLE(WEBASSEMBLY) wasmModules, wasmMemoryHandles, @@ -979,85 +736,10 @@ class CloneSerializer : public CloneBase { return code; } - static bool serialize(StringView string, Vector& out) - { - if (!writeLittleEndian(out, CurrentVersion)) - return false; - if (string.isEmpty()) - return writeLittleEndian(out, EmptyStringTag); - if (!writeLittleEndian(out, StringTag)) - return false; - const auto length = string.length(); - if (string.is8Bit()) { - const auto span = string.span8(); - if (!writeLittleEndian(out, length | StringDataIs8BitFlag)) - return false; - return writeLittleEndian(out, span.data(), length); - } - const auto span = string.span16(); - if (!writeLittleEndian(out, length)) - return false; - return writeLittleEndian(out, span.data(), length); - } - private: typedef HashMap ObjectPool; - // CloneSerializer(JSGlobalObject* lexicalGlobalObject, Vector>& messagePorts, Vector>& arrayBuffers, const Vector>& imageBitmaps, - // #if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - // const Vector>& offscreenCanvases, - // #endif - // #if ENABLE(WEB_RTC) - // const Vector>& rtcDataChannels, - // #endif - // #if ENABLE(WEB_CODECS) - // Vector>& serializedVideoChunks, - // Vector>& serializedVideoFrames, - // #endif - // #if ENABLE(WEBASSEMBLY) - // WasmModuleArray& wasmModules, - // WasmMemoryHandleArray& wasmMemoryHandles, - // #endif - // Vector& blobHandles, Vector& out, SerializationContext context, ArrayBufferContentsArray& sharedBuffers, SerializationForStorage forStorage) - // : CloneBase(lexicalGlobalObject) - // , m_buffer(out) - // , m_blobHandles(blobHandles) - // , m_emptyIdentifier(Identifier::fromString(lexicalGlobalObject->vm(), emptyString())) - // , m_context(context) - // , m_sharedBuffers(sharedBuffers) - // #if ENABLE(WEBASSEMBLY) - // , m_wasmModules(wasmModules) - // , m_wasmMemoryHandles(wasmMemoryHandles) - // #endif - // #if ENABLE(WEB_CODECS) - // , m_serializedVideoChunks(serializedVideoChunks) - // , m_serializedVideoFrames(serializedVideoFrames) - // #endif - // , m_forStorage(forStorage) - // { - // write(CurrentVersion); - // fillTransferMap(messagePorts, m_transferredMessagePorts); - // fillTransferMap(arrayBuffers, m_transferredArrayBuffers); - // fillTransferMap(imageBitmaps, m_transferredImageBitmaps); - // #if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - // fillTransferMap(offscreenCanvases, m_transferredOffscreenCanvases); - // #endif - // #if ENABLE(WEB_RTC) - // fillTransferMap(rtcDataChannels, m_transferredRTCDataChannels); - // #endif - // } - CloneSerializer(JSGlobalObject* lexicalGlobalObject, Vector>& messagePorts, Vector>& arrayBuffers, -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - const Vector>& offscreenCanvases, -#endif -#if ENABLE(WEB_RTC) - const Vector>& rtcDataChannels, -#endif -#if ENABLE(WEB_CODECS) - Vector>& serializedVideoChunks, - Vector>& serializedVideoFrames, -#endif #if ENABLE(WEBASSEMBLY) WasmModuleArray& wasmModules, WasmMemoryHandleArray& wasmMemoryHandles, @@ -1071,10 +753,6 @@ class CloneSerializer : public CloneBase { #if ENABLE(WEBASSEMBLY) , m_wasmModules(wasmModules) , m_wasmMemoryHandles(wasmMemoryHandles) -#endif -#if ENABLE(WEB_CODECS) - , m_serializedVideoChunks(serializedVideoChunks) - , m_serializedVideoFrames(serializedVideoFrames) #endif , m_forStorage(forStorage) , m_forTransfer(forTransfer) @@ -1082,12 +760,6 @@ class CloneSerializer : public CloneBase { write(CurrentVersion); fillTransferMap(messagePorts, m_transferredMessagePorts); fillTransferMap(arrayBuffers, m_transferredArrayBuffers); -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - fillTransferMap(offscreenCanvases, m_transferredOffscreenCanvases); -#endif -#if ENABLE(WEB_RTC) - fillTransferMap(rtcDataChannels, m_transferredRTCDataChannels); -#endif } template @@ -1103,19 +775,6 @@ class CloneSerializer : public CloneBase { result.add(obj, i); } } - template - void fillTransferMap(const Vector>& input, ObjectPool& result) - { - if (input.isEmpty()) - return; - JSDOMGlobalObject* globalObject = uncheckedDowncast(m_lexicalGlobalObject); - for (size_t i = 0; i < input.size(); i++) { - JSC::JSValue value = toJS(m_lexicalGlobalObject, globalObject, input[i].get()); - JSC::JSObject* obj = value.getObject(); - if (obj && !result.contains(obj)) - result.add(obj, i); - } - } SerializationReturnCode serialize(JSValue in); @@ -1417,197 +1076,6 @@ class CloneSerializer : public CloneBase { return dumpIfTerminal(toJSArrayBuffer(*arrayBuffer), code); } - // void dumpDOMPoint(const DOMPointReadOnly& point) - // { - // write(point.x()); - // write(point.y()); - // write(point.z()); - // write(point.w()); - // } - - // void dumpDOMPoint(JSObject* obj) - // { - // if (obj->inherits()) - // write(DOMPointTag); - // else - // write(DOMPointReadOnlyTag); - - // dumpDOMPoint(uncheckedDowncast(obj)->wrapped()); - // } - - // void dumpDOMRect(JSObject* obj) - // { - // if (obj->inherits()) - // write(DOMRectTag); - // else - // write(DOMRectReadOnlyTag); - - // auto& rect = uncheckedDowncast(obj)->wrapped(); - // write(rect.x()); - // write(rect.y()); - // write(rect.width()); - // write(rect.height()); - // } - - // void dumpDOMMatrix(JSObject* obj) - // { - // if (obj->inherits()) - // write(DOMMatrixTag); - // else - // write(DOMMatrixReadOnlyTag); - - // auto& matrix = uncheckedDowncast(obj)->wrapped(); - // bool is2D = matrix.is2D(); - // write(static_cast(is2D)); - // if (is2D) { - // write(matrix.m11()); - // write(matrix.m12()); - // write(matrix.m21()); - // write(matrix.m22()); - // write(matrix.m41()); - // write(matrix.m42()); - // } else { - // write(matrix.m11()); - // write(matrix.m12()); - // write(matrix.m13()); - // write(matrix.m14()); - // write(matrix.m21()); - // write(matrix.m22()); - // write(matrix.m23()); - // write(matrix.m24()); - // write(matrix.m31()); - // write(matrix.m32()); - // write(matrix.m33()); - // write(matrix.m34()); - // write(matrix.m41()); - // write(matrix.m42()); - // write(matrix.m43()); - // write(matrix.m44()); - // } - // } - - // void dumpDOMQuad(JSObject* obj) - // { - // write(DOMQuadTag); - - // auto& quad = uncheckedDowncast(obj)->wrapped(); - // dumpDOMPoint(quad.p1()); - // dumpDOMPoint(quad.p2()); - // dumpDOMPoint(quad.p3()); - // dumpDOMPoint(quad.p4()); - // } - - // void dumpImageBitmap(JSObject* obj, SerializationReturnCode& code) - // { - // auto index = m_transferredImageBitmaps.find(obj); - // if (index != m_transferredImageBitmaps.end()) { - // write(ImageBitmapTransferTag); - // write(index->value); - // return; - // } - - // auto& imageBitmap = uncheckedDowncast(obj)->wrapped(); - // if (!imageBitmap.originClean()) { - // code = SerializationReturnCode::DataCloneError; - // return; - // } - - // auto* buffer = imageBitmap.buffer(); - // if (!buffer) { - // code = SerializationReturnCode::ValidationError; - // return; - // } - - // // FIXME: We should try to avoid converting pixel format. - // PixelBufferFormat format { AlphaPremultiplication::Premultiplied, PixelFormat::RGBA8, buffer->colorSpace() }; - // const IntSize& logicalSize = buffer->truncatedLogicalSize(); - // auto pixelBuffer = buffer->getPixelBuffer(format, { IntPoint::zero(), logicalSize }); - // if (!is(pixelBuffer)) { - // code = SerializationReturnCode::ValidationError; - // return; - // } - - // auto arrayBuffer = downcast(*pixelBuffer).data().possiblySharedBuffer(); - // if (!arrayBuffer) { - // code = SerializationReturnCode::ValidationError; - // return; - // } - - // write(ImageBitmapTag); - // write(static_cast(imageBitmap.serializationState().toRaw())); - // write(static_cast(logicalSize.width())); - // write(static_cast(logicalSize.height())); - // write(static_cast(buffer->resolutionScale())); - // write(buffer->colorSpace()); - - // CheckedUint32 byteLength = arrayBuffer->byteLength(); - // if (byteLength.hasOverflowed()) { - // code = SerializationReturnCode::ValidationError; - // return; - // } - // write(byteLength); - // write(static_cast(arrayBuffer->data()), byteLength); - // } - -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - void dumpOffscreenCanvas(JSObject* obj, SerializationReturnCode& code) - { - auto index = m_transferredOffscreenCanvases.find(obj); - if (index != m_transferredOffscreenCanvases.end()) { - write(OffscreenCanvasTransferTag); - write(index->value); - return; - } - - code = SerializationReturnCode::DataCloneError; - } -#endif - -#if ENABLE(WEB_RTC) - void dumpRTCDataChannel(JSObject* obj, SerializationReturnCode& code) - { - auto index = m_transferredRTCDataChannels.find(obj); - if (index != m_transferredRTCDataChannels.end()) { - write(RTCDataChannelTransferTag); - write(index->value); - return; - } - - code = SerializationReturnCode::DataCloneError; - } -#endif -#if ENABLE(WEB_CODECS) - void dumpWebCodecsEncodedVideoChunk(JSObject* obj) - { - auto& videoChunk = uncheckedDowncast(obj)->wrapped(); - - auto index = m_serializedVideoChunks.find(&videoChunk.storage()); - if (index == notFound) { - index = m_serializedVideoChunks.size(); - m_serializedVideoChunks.append(&videoChunk.storage()); - } - - write(WebCodecsEncodedVideoChunkTag); - write(static_cast(index)); - } - - bool dumpWebCodecsVideoFrame(JSObject* obj) - { - Ref videoFrame = uncheckedDowncast(obj)->wrapped(); - if (videoFrame->isDetached()) - return false; - - auto index = m_serializedVideoFrames.find(videoFrame.ptr()); - if (index == notFound) { - index = m_serializedVideoChunks.size(); - m_serializedVideoFrames.append(WTF::move(videoFrame)); - } - write(WebCodecsVideoFrameTag); - write(static_cast(index)); - return true; - } -#endif - void dumpDOMException(JSObject* obj, SerializationReturnCode& code) { if (auto* exception = JSDOMException::toWrapped(m_lexicalGlobalObject->vm(), obj)) { @@ -1706,51 +1174,6 @@ class CloneSerializer : public CloneBase { dumpBigIntData(bigIntValue); return true; } - // if (auto* file = JSFile::toWrapped(vm, obj)) { - // write(FileTag); - // write(*file); - // return true; - // } - // if (auto* list = JSFileList::toWrapped(vm, obj)) { - // write(FileListTag); - // write(list->length()); - // for (auto& file : list->files()) - // write(file.get()); - // return true; - // } - - // if (auto* blob = JSBlob::toWrapped(vm, obj)) { - // write(BlobTag); - // m_blobHandles.append(blob->handle().isolatedCopy()); - // write(blob->url().string()); - // write(blob->type()); - // static_assert(sizeof(uint64_t) == sizeof(decltype(blob->size()))); - // uint64_t size = blob->size(); - // write(size); - // uint64_t memoryCost = blob->memoryCost(); - // write(memoryCost); - // return true; - // } - // if (auto* data = JSImageData::toWrapped(vm, obj)) { - // write(ImageDataTag); - // auto addResult = m_imageDataPool.add(*data, m_imageDataPool.size()); - // if (!addResult.isNewEntry) { - // write(ImageDataPoolTag); - // writeImageDataIndex(addResult.iterator->value); - // return true; - // } - // write(static_cast(data->width())); - // write(static_cast(data->height())); - // CheckedUint32 dataLength = data->data().length(); - // if (dataLength.hasOverflowed()) { - // code = SerializationReturnCode::DataCloneError; - // return true; - // } - // write(dataLength); - // write(data->data().data(), dataLength); - // write(data->colorSpace()); - // return true; - // } if (auto* regExp = dynamicDowncast(obj)) { if (!startObjectInternal(regExp)) // handle duplicates return true; @@ -1920,82 +1343,24 @@ class CloneSerializer : public CloneBase { return true; write(CryptoKeyTag); Vector serializedKey; - // Vector dummyBlobHandles; Vector> dummyMessagePorts; Vector> dummyArrayBuffers; -#if ENABLE(WEB_CODECS) - Vector> dummyVideoChunks; - Vector> dummyVideoFrames; -#endif #if ENABLE(WEBASSEMBLY) WasmModuleArray dummyModules; WasmMemoryHandleArray dummyMemoryHandles; #endif ArrayBufferContentsArray dummySharedBuffers; - // CloneSerializer rawKeySerializer(m_lexicalGlobalObject, dummyMessagePorts, dummyArrayBuffers, {}, - // #if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - // {}, - // #endif - // #if ENABLE(WEB_RTC) - // {}, - // #endif - // #if ENABLE(WEB_CODECS) - // dummyVideoChunks, - // dummyVideoFrames, - // #endif - // #if ENABLE(WEBASSEMBLY) - // dummyModules, - // dummyMemoryHandles, - // #endif - // dummyBlobHandles, serializedKey, SerializationContext::Default, dummySharedBuffers, m_forStorage); CloneSerializer rawKeySerializer(m_lexicalGlobalObject, dummyMessagePorts, dummyArrayBuffers, -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - {}, -#endif -#if ENABLE(WEB_RTC) - {}, -#endif -#if ENABLE(WEB_CODECS) - dummyVideoChunks, - dummyVideoFrames, -#endif #if ENABLE(WEBASSEMBLY) dummyModules, dummyMemoryHandles, #endif serializedKey, SerializationContext::Default, dummySharedBuffers, m_forStorage, m_forTransfer); rawKeySerializer.write(key); - Vector wrappedKey; - - // Wrapping isn't required - // https://github.com/WebKit/WebKit/blob/c0902fc4dd3abf5d2d5e008eb0b008aeae837953/Source/WebCore/crypto/SerializedCryptoKeyWrap.h#L35-L40 - // - // and doesn't do anything currently, so we skip it. - // https://github.com/WebKit/WebKit/blob/c0902fc4dd3abf5d2d5e008eb0b008aeae837953/Source/WebCore/crypto/gcrypt/SerializedCryptoKeyWrapGCrypt.cpp#L49 - // https://github.com/WebKit/WebKit/blob/c0902fc4dd3abf5d2d5e008eb0b008aeae837953/Source/WebCore/crypto/openssl/SerializedCryptoKeyWrapOpenSSL.cpp#L51 - // - // if (!wrapCryptoKey(m_lexicalGlobalObject, serializedKey, wrappedKey)) - // return false; - write(serializedKey); return true; } #endif -#if ENABLE(WEB_RTC) - if (auto* rtcCertificate = JSRTCCertificate::toWrapped(vm, obj)) { - write(RTCCertificateTag); - write(rtcCertificate->expires()); - write(rtcCertificate->pemCertificate()); - write(rtcCertificate->origin().toString()); - write(rtcCertificate->pemPrivateKey()); - write(static_cast(rtcCertificate->getFingerprints().size())); - for (const auto& fingerprint : rtcCertificate->getFingerprints()) { - write(fingerprint.algorithm); - write(fingerprint.value); - } - return true; - } -#endif #if ENABLE(WEBASSEMBLY) if (JSWebAssemblyModule* module = dynamicDowncast(obj)) { if (m_context != SerializationContext::WorkerPostMessage && m_context != SerializationContext::WindowPostMessage) @@ -2024,56 +1389,11 @@ class CloneSerializer : public CloneBase { write(index); return true; } -#endif - // if (obj->inherits()) { - // dumpDOMPoint(obj); - // return true; - // } - // if (obj->inherits()) { - // dumpDOMRect(obj); - // return true; - // } - // if (obj->inherits()) { - // dumpDOMMatrix(obj); - // return true; - // } - // if (obj->inherits()) { - // dumpDOMQuad(obj); - // return true; - // } - // if (obj->inherits()) { - // dumpImageBitmap(obj, code); - // return true; - // } -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - if (obj->inherits()) { - dumpOffscreenCanvas(obj, code); - return true; - } -#endif -#if ENABLE(WEB_RTC) - if (obj->inherits()) { - dumpRTCDataChannel(obj, code); - return true; - } #endif if (obj->inherits()) { dumpDOMException(obj, code); return true; } -#if ENABLE(WEB_CODECS) - if (obj->inherits()) { - if (m_forStorage == SerializationForStorage::Yes) - return false; - dumpWebCodecsEncodedVideoChunk(obj); - return true; - } - if (obj->inherits()) { - if (m_forStorage == SerializationForStorage::Yes) - return false; - return dumpWebCodecsVideoFrame(obj); - } -#endif // write bun types auto _cloneable = StructuredCloneableSerialize::fromJS(value); @@ -2216,12 +1536,6 @@ class CloneSerializer : public CloneBase { fail(); } - void write(DestinationColorSpaceTag tag) - { - if (!writeLittleEndian(m_buffer, static_cast(tag))) [[unlikely]] - fail(); - } - #if ENABLE(WEB_CRYPTO) void write(CryptoKeyClassSubtag tag) { @@ -2306,11 +1620,6 @@ class CloneSerializer : public CloneBase { writeConstantPoolIndex(m_constantPool, i); } - // void writeImageDataIndex(unsigned i) - // { - // writeConstantPoolIndex(m_imageDataPool, i); - // } - void writeObjectIndex(unsigned i) { writeConstantPoolIndex(m_objectPool, i); @@ -2388,92 +1697,6 @@ class CloneSerializer : public CloneBase { fail(); } - // void write(const File& file) - // { - // m_blobHandles.append(file.handle().isolatedCopy()); - // write(file.path()); - // write(file.url().string()); - // write(file.type()); - // write(file.name()); - // write(static_cast(file.lastModifiedOverride().value_or(-1))); - // } - - // void write(PredefinedColorSpace colorSpace) - // { - // switch (colorSpace) { - // case PredefinedColorSpace::SRGB: - // writeLittleEndian(m_buffer, static_cast(PredefinedColorSpaceTag::SRGB)); - // break; - // #if ENABLE(PREDEFINED_COLOR_SPACE_DISPLAY_P3) - // case PredefinedColorSpace::DisplayP3: - // writeLittleEndian(m_buffer, static_cast(PredefinedColorSpaceTag::DisplayP3)); - // break; - // #endif - // } - // } - -#if PLATFORM(COCOA) - void write(const RetainPtr& data) - { - uint32_t dataLength = CFDataGetLength(data.get()); - write(dataLength); - write(CFDataGetBytePtr(data.get()), dataLength); - } -#endif - - // void write(DestinationColorSpace destinationColorSpace) - // { - // if (destinationColorSpace == DestinationColorSpace::SRGB()) { - // write(DestinationColorSpaceSRGBTag); - // return; - // } - - // #if ENABLE(DESTINATION_COLOR_SPACE_LINEAR_SRGB) - // if (destinationColorSpace == DestinationColorSpace::LinearSRGB()) { - // write(DestinationColorSpaceLinearSRGBTag); - // return; - // } - // #endif - - // #if ENABLE(DESTINATION_COLOR_SPACE_DISPLAY_P3) - // if (destinationColorSpace == DestinationColorSpace::DisplayP3()) { - // write(DestinationColorSpaceDisplayP3Tag); - // return; - // } - // #endif - - // #if PLATFORM(COCOA) - // auto colorSpace = destinationColorSpace.platformColorSpace(); - - // if (auto name = CGColorSpaceGetName(colorSpace)) { - // auto data = adoptCF(CFStringCreateExternalRepresentation(nullptr, name, kCFStringEncodingUTF8, 0)); - // if (!data) { - // write(DestinationColorSpaceSRGBTag); - // return; - // } - - // write(DestinationColorSpaceCGColorSpaceNameTag); - // write(data); - // return; - // } - - // if (auto propertyList = adoptCF(CGColorSpaceCopyPropertyList(colorSpace))) { - // auto data = adoptCF(CFPropertyListCreateData(nullptr, propertyList.get(), kCFPropertyListBinaryFormat_v1_0, 0, nullptr)); - // if (!data) { - // write(DestinationColorSpaceSRGBTag); - // return; - // } - - // write(DestinationColorSpaceCGColorSpacePropertyListTag); - // write(data); - // return; - // } - // #endif - - // ASSERT_NOT_REACHED(); - // write(DestinationColorSpaceSRGBTag); - // } - #if ENABLE(WEB_CRYPTO) void write(CryptoKeyOKP::NamedCurve curve) { @@ -2750,21 +1973,11 @@ class CloneSerializer : public CloneBase { } } #endif - // Vector& m_blobHandles; ObjectPool m_objectPool; ObjectPool m_transferredMessagePorts; ObjectPool m_transferredArrayBuffers; - ObjectPool m_transferredImageBitmaps; -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - ObjectPool m_transferredOffscreenCanvases; -#endif -#if ENABLE(WEB_RTC) - ObjectPool m_transferredRTCDataChannels; -#endif typedef HashMap, uint32_t, IdentifierRepHash> StringConstantPool; StringConstantPool m_constantPool; - // using ImageDataPool = HashMap, uint32_t>; - // ImageDataPool m_imageDataPool; Identifier m_emptyIdentifier; SerializationContext m_context; ArrayBufferContentsArray& m_sharedBuffers; @@ -2772,10 +1985,6 @@ class CloneSerializer : public CloneBase { #if ENABLE(WEBASSEMBLY) WasmModuleArray& m_wasmModules; WasmMemoryHandleArray& m_wasmMemoryHandles; -#endif -#if ENABLE(WEB_CODECS) - Vector>& m_serializedVideoChunks; - Vector>& m_serializedVideoFrames; #endif SerializationForStorage m_forStorage; SerializationForCrossProcessTransfer m_forTransfer; @@ -3049,114 +2258,20 @@ class CloneDeserializer : public CloneBase { WTF_FORBID_HEAP_ALLOCATION; public: - static String deserializeString(const Vector& buffer) - { - if (buffer.isEmpty()) - return String(); - const uint8_t* ptr = buffer.begin(); - const uint8_t* end = buffer.end(); - uint32_t version; - if (!readLittleEndian(ptr, end, version) || version > CurrentVersion) - return String(); - uint8_t tag; - if (!readLittleEndian(ptr, end, tag) || tag != StringTag) - return String(); - uint32_t length; - if (!readLittleEndian(ptr, end, length)) - return String(); - bool is8Bit = length & StringDataIs8BitFlag; - length &= ~StringDataIs8BitFlag; - String str; - if (!readString(ptr, end, str, length, is8Bit)) - return String(); - return str; - } - - // static DeserializationResult deserialize(JSGlobalObject* lexicalGlobalObject, JSGlobalObject* globalObject, const Vector>& messagePorts, Vector>&& backingStores - // #if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - // , - // Vector>&& detachedOffscreenCanvases - // #endif - // #if ENABLE(WEB_RTC) - // , - // Vector>&& detachedRTCDataChannels - // #endif - // , - // ArrayBufferContentsArray* arrayBufferContentsArray, const Vector& buffer, const Vector& blobURLs, const Vector blobFilePaths, ArrayBufferContentsArray* sharedBuffers - // #if ENABLE(WEBASSEMBLY) - // , - // WasmModuleArray* wasmModules, WasmMemoryHandleArray* wasmMemoryHandles - // #endif - // #if ENABLE(WEB_CODECS) - // , - // Vector>&& serializedVideoChunks, Vector&& serializedVideoFrames - // #endif - // ) - // { - // if (!buffer.size()) - // return std::make_pair(jsNull(), SerializationReturnCode::UnspecifiedError); - // CloneDeserializer deserializer(lexicalGlobalObject, globalObject, messagePorts, arrayBufferContentsArray, buffer, blobURLs, blobFilePaths, sharedBuffers, WTF::move(backingStores) - // #if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - // , - // WTF::move(detachedOffscreenCanvases) - // #endif - // #if ENABLE(WEB_RTC) - // , - // WTF::move(detachedRTCDataChannels) - // #endif - // #if ENABLE(WEBASSEMBLY) - // , - // wasmModules, wasmMemoryHandles - // #endif - // #if ENABLE(WEB_CODECS) - // , - // WTF::move(serializedVideoChunks), WTF::move(serializedVideoFrames) - // #endif - // ); - // if (!deserializer.isValid()) - // return std::make_pair(JSValue(), SerializationReturnCode::ValidationError); - // return deserializer.deserialize(); - // } - - static DeserializationResult deserialize(JSGlobalObject* lexicalGlobalObject, JSGlobalObject* globalObject, const Vector>& messagePorts -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - , - Vector>&& detachedOffscreenCanvases -#endif -#if ENABLE(WEB_RTC) - , - Vector>&& detachedRTCDataChannels -#endif - , + static DeserializationResult deserialize(JSGlobalObject* lexicalGlobalObject, JSGlobalObject* globalObject, const Vector>& messagePorts, ArrayBufferContentsArray* arrayBufferContentsArray, const std::span& buffer, const Vector& blobURLs, const Vector blobFilePaths, ArrayBufferContentsArray* sharedBuffers #if ENABLE(WEBASSEMBLY) , WasmModuleArray* wasmModules, WasmMemoryHandleArray* wasmMemoryHandles -#endif -#if ENABLE(WEB_CODECS) - , - Vector>&& serializedVideoChunks, Vector&& serializedVideoFrames #endif ) { if (!buffer.size()) return std::make_pair(jsNull(), SerializationReturnCode::UnspecifiedError); CloneDeserializer deserializer(lexicalGlobalObject, globalObject, messagePorts, arrayBufferContentsArray, std::span { buffer.begin(), buffer.end() }, blobURLs, blobFilePaths, sharedBuffers -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - , - WTF::move(detachedOffscreenCanvases) -#endif -#if ENABLE(WEB_RTC) - , - WTF::move(detachedRTCDataChannels) -#endif #if ENABLE(WEBASSEMBLY) , wasmModules, wasmMemoryHandles -#endif -#if ENABLE(WEB_CODECS) - , - WTF::move(serializedVideoChunks), WTF::move(serializedVideoFrames) #endif ); if (!deserializer.isValid()) @@ -3222,188 +2337,39 @@ class CloneDeserializer : public CloneBase { size_t m_index; }; - // CloneDeserializer(JSGlobalObject* lexicalGlobalObject, JSGlobalObject* globalObject, const Vector>& messagePorts, ArrayBufferContentsArray* arrayBufferContents, Vector>&& backingStores, const Vector& buffer - // #if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - // , - // Vector>&& detachedOffscreenCanvases = {} - // #endif - // #if ENABLE(WEB_RTC) - // , - // Vector>&& detachedRTCDataChannels = {} - // #endif - // #if ENABLE(WEBASSEMBLY) - // , - // WasmModuleArray* wasmModules = nullptr, WasmMemoryHandleArray* wasmMemoryHandles = nullptr - // #endif - // #if ENABLE(WEB_CODECS) - // , - // Vector>&& serializedVideoChunks = {}, Vector&& serializedVideoFrames = {} - // #endif - // ) - // : CloneBase(lexicalGlobalObject) - // , m_globalObject(globalObject) - // , m_isDOMGlobalObject(globalObject->inherits()) - // , m_canCreateDOMObject(m_isDOMGlobalObject && !globalObject->inherits()) - // , m_ptr(buffer.data()) - // , m_end(buffer.data() + buffer.size()) - // , m_version(0xFFFFFFFF) - // , m_messagePorts(messagePorts) - // , m_arrayBufferContents(arrayBufferContents) - // , m_arrayBuffers(arrayBufferContents ? arrayBufferContents->size() : 0) - // , m_backingStores(WTF::move(backingStores)) - // , m_imageBitmaps(m_backingStores.size()) - // #if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - // , m_detachedOffscreenCanvases(WTF::move(detachedOffscreenCanvases)) - // , m_offscreenCanvases(m_detachedOffscreenCanvases.size()) - // #endif - // #if ENABLE(WEB_RTC) - // , m_detachedRTCDataChannels(WTF::move(detachedRTCDataChannels)) - // , m_rtcDataChannels(m_detachedRTCDataChannels.size()) - // #endif - // #if ENABLE(WEBASSEMBLY) - // , m_wasmModules(wasmModules) - // , m_wasmMemoryHandles(wasmMemoryHandles) - // #endif - // #if ENABLE(WEB_CODECS) - // , m_serializedVideoChunks(WTF::move(serializedVideoChunks)) - // , m_videoChunks(m_serializedVideoChunks.size()) - // , m_serializedVideoFrames(WTF::move(serializedVideoFrames)) - // , m_videoFrames(m_serializedVideoFrames.size()) - // #endif - // { - // if (!read(m_version)) - // m_version = 0xFFFFFFFF; - // } - CloneDeserializer(JSGlobalObject* lexicalGlobalObject, JSGlobalObject* globalObject, const Vector>& messagePorts, ArrayBufferContentsArray* arrayBufferContents, const std::span& buffer -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - , - Vector>&& detachedOffscreenCanvases = {} -#endif -#if ENABLE(WEB_RTC) - , - Vector>&& detachedRTCDataChannels = {} -#endif #if ENABLE(WEBASSEMBLY) , WasmModuleArray* wasmModules = nullptr, WasmMemoryHandleArray* wasmMemoryHandles = nullptr -#endif -#if ENABLE(WEB_CODECS) - , - Vector>&& serializedVideoChunks = {}, Vector&& serializedVideoFrames = {} #endif ) : CloneBase(lexicalGlobalObject) , m_globalObject(globalObject) , m_isDOMGlobalObject(globalObject->inherits()) - // , m_canCreateDOMObject(m_isDOMGlobalObject) , m_ptr(buffer.data()) , m_end(buffer.data() + buffer.size()) , m_version(0xFFFFFFFF) , m_messagePorts(messagePorts) , m_arrayBufferContents(arrayBufferContents) , m_arrayBuffers(arrayBufferContents ? arrayBufferContents->size() : 0) -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - , m_detachedOffscreenCanvases(WTF::move(detachedOffscreenCanvases)) - , m_offscreenCanvases(m_detachedOffscreenCanvases.size()) -#endif -#if ENABLE(WEB_RTC) - , m_detachedRTCDataChannels(WTF::move(detachedRTCDataChannels)) - , m_rtcDataChannels(m_detachedRTCDataChannels.size()) -#endif #if ENABLE(WEBASSEMBLY) , m_wasmModules(wasmModules) , m_wasmMemoryHandles(wasmMemoryHandles) -#endif -#if ENABLE(WEB_CODECS) - , m_serializedVideoChunks(WTF::move(serializedVideoChunks)) - , m_videoChunks(m_serializedVideoChunks.size()) - , m_serializedVideoFrames(WTF::move(serializedVideoFrames)) - , m_videoFrames(m_serializedVideoFrames.size()) #endif { if (!read(m_version)) m_version = 0xFFFFFFFF; } - // CloneDeserializer(JSGlobalObject* lexicalGlobalObject, JSGlobalObject* globalObject, const Vector>& messagePorts, ArrayBufferContentsArray* arrayBufferContents, const Vector& buffer, const Vector& blobURLs, const Vector blobFilePaths, ArrayBufferContentsArray* sharedBuffers, Vector>&& backingStores - // #if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - // , - // Vector>&& detachedOffscreenCanvases - // #endif - // #if ENABLE(WEB_RTC) - // , - // Vector>&& detachedRTCDataChannels - // #endif - // #if ENABLE(WEBASSEMBLY) - // , - // WasmModuleArray* wasmModules, WasmMemoryHandleArray* wasmMemoryHandles - // #endif - // #if ENABLE(WEB_CODECS) - // , - // Vector>&& serializedVideoChunks = {}, Vector&& serializedVideoFrames = {} - // #endif - // ) - // : CloneBase(lexicalGlobalObject) - // , m_globalObject(globalObject) - // , m_isDOMGlobalObject(globalObject->inherits()) - // , m_canCreateDOMObject(m_isDOMGlobalObject && !globalObject->inherits()) - // , m_ptr(buffer.data()) - // , m_end(buffer.data() + buffer.size()) - // , m_version(0xFFFFFFFF) - // , m_messagePorts(messagePorts) - // , m_arrayBufferContents(arrayBufferContents) - // , m_arrayBuffers(arrayBufferContents ? arrayBufferContents->size() : 0) - // , m_blobURLs(blobURLs) - // , m_blobFilePaths(blobFilePaths) - // , m_sharedBuffers(sharedBuffers) - // , m_backingStores(WTF::move(backingStores)) - // , m_imageBitmaps(m_backingStores.size()) - // #if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - // , m_detachedOffscreenCanvases(WTF::move(detachedOffscreenCanvases)) - // , m_offscreenCanvases(m_detachedOffscreenCanvases.size()) - // #endif - // #if ENABLE(WEB_RTC) - // , m_detachedRTCDataChannels(WTF::move(detachedRTCDataChannels)) - // , m_rtcDataChannels(m_detachedRTCDataChannels.size()) - // #endif - // #if ENABLE(WEBASSEMBLY) - // , m_wasmModules(wasmModules) - // , m_wasmMemoryHandles(wasmMemoryHandles) - // #endif - // #if ENABLE(WEB_CODECS) - // , m_serializedVideoChunks(WTF::move(serializedVideoChunks)) - // , m_videoChunks(m_serializedVideoChunks.size()) - // , m_serializedVideoFrames(WTF::move(serializedVideoFrames)) - // , m_videoFrames(m_serializedVideoFrames.size()) - // #endif - // { - // if (!read(m_version)) - // m_version = 0xFFFFFFFF; - // } - CloneDeserializer(JSGlobalObject* lexicalGlobalObject, JSGlobalObject* globalObject, const Vector>& messagePorts, ArrayBufferContentsArray* arrayBufferContents, const std::span& buffer, const Vector& blobURLs, const Vector blobFilePaths, ArrayBufferContentsArray* sharedBuffers -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - , - Vector>&& detachedOffscreenCanvases -#endif -#if ENABLE(WEB_RTC) - , - Vector>&& detachedRTCDataChannels -#endif #if ENABLE(WEBASSEMBLY) , WasmModuleArray* wasmModules, WasmMemoryHandleArray* wasmMemoryHandles -#endif -#if ENABLE(WEB_CODECS) - , - Vector>&& serializedVideoChunks = {}, Vector&& serializedVideoFrames = {} #endif ) : CloneBase(lexicalGlobalObject) , m_globalObject(globalObject) , m_isDOMGlobalObject(globalObject->inherits()) - // , m_canCreateDOMObject(m_isDOMGlobalObject) , m_ptr(buffer.data()) , m_end(buffer.data() + buffer.size()) , m_version(0xFFFFFFFF) @@ -3413,23 +2379,9 @@ class CloneDeserializer : public CloneBase { , m_blobURLs(blobURLs) , m_blobFilePaths(blobFilePaths) , m_sharedBuffers(sharedBuffers) -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - , m_detachedOffscreenCanvases(WTF::move(detachedOffscreenCanvases)) - , m_offscreenCanvases(m_detachedOffscreenCanvases.size()) -#endif -#if ENABLE(WEB_RTC) - , m_detachedRTCDataChannels(WTF::move(detachedRTCDataChannels)) - , m_rtcDataChannels(m_detachedRTCDataChannels.size()) -#endif #if ENABLE(WEBASSEMBLY) , m_wasmModules(wasmModules) , m_wasmMemoryHandles(wasmMemoryHandles) -#endif -#if ENABLE(WEB_CODECS) - , m_serializedVideoChunks(WTF::move(serializedVideoChunks)) - , m_videoChunks(m_serializedVideoChunks.size()) - , m_serializedVideoFrames(WTF::move(serializedVideoFrames)) - , m_videoFrames(m_serializedVideoFrames.size()) #endif { if (!read(m_version)) @@ -3530,11 +2482,6 @@ class CloneDeserializer : public CloneBase { return readConstantPoolIndex(m_constantPool); } - // std::optional readImageDataIndex() - // { - // return readConstantPoolIndex(m_imageDataPool); - // } - template std::optional readConstantPoolIndex(const T& constantPool) { if (constantPool.size() <= 0xFF) { @@ -3743,41 +2690,6 @@ class CloneDeserializer : public CloneBase { object->putDirectMayBeIndex(m_lexicalGlobalObject, property, value); } - // bool readFile(RefPtr& file) - // { - // CachedStringRef path; - // if (!readStringData(path)) - // return false; - // CachedStringRef url; - // if (!readStringData(url)) - // return false; - // CachedStringRef type; - // if (!readStringData(type)) - // return false; - // CachedStringRef name; - // if (!readStringData(name)) - // return false; - // std::optional optionalLastModified; - // if (m_version > 6) { - // double lastModified; - // if (!read(lastModified)) - // return false; - // if (lastModified >= 0) - // optionalLastModified = lastModified; - // } - - // // If the blob URL for this file has an associated blob file path, prefer that one over the "built-in" path. - // String filePath = blobFilePathForBlobURL(url->string()); - // if (filePath.isEmpty()) - // filePath = path->string(); - - // if (!m_canCreateDOMObject) - // return true; - - // file = File::deserialize(executionContext(m_lexicalGlobalObject), filePath, URL { url->string() }, type->string(), name->string(), optionalLastModified); - // return true; - // } - template bool readArrayBufferImpl(RefPtr& arrayBuffer) { @@ -3939,110 +2851,6 @@ class CloneDeserializer : public CloneBase { return true; } - // bool read(PredefinedColorSpace& result) - // { - // uint8_t tag; - // if (!read(tag)) - // return false; - - // switch (static_cast(tag)) { - // case PredefinedColorSpaceTag::SRGB: - // result = PredefinedColorSpace::SRGB; - // return true; - // #if ENABLE(PREDEFINED_COLOR_SPACE_DISPLAY_P3) - // case PredefinedColorSpaceTag::DisplayP3: - // result = PredefinedColorSpace::DisplayP3; - // return true; - // #endif - // default: - // return false; - // } - // } - - // bool read(DestinationColorSpaceTag& tag) - // { - // if (m_ptr >= m_end) - // return false; - // tag = static_cast(*m_ptr++); - // return true; - // } - -#if PLATFORM(COCOA) - bool read(RetainPtr& data) - { - uint32_t dataLength; - if (!read(dataLength) || static_cast(m_end - m_ptr) < dataLength) - return false; - - data = adoptCF(CFDataCreateWithBytesNoCopy(nullptr, m_ptr, dataLength, kCFAllocatorNull)); - if (!data) - return false; - - m_ptr += dataLength; - return true; - } -#endif - - // bool read(DestinationColorSpace& destinationColorSpace) - // { - // DestinationColorSpaceTag tag; - // if (!read(tag)) - // return false; - - // switch (tag) { - // case DestinationColorSpaceSRGBTag: - // destinationColorSpace = DestinationColorSpace::SRGB(); - // return true; - // #if ENABLE(DESTINATION_COLOR_SPACE_LINEAR_SRGB) - // case DestinationColorSpaceLinearSRGBTag: - // destinationColorSpace = DestinationColorSpace::LinearSRGB(); - // return true; - // #endif - // #if ENABLE(DESTINATION_COLOR_SPACE_DISPLAY_P3) - // case DestinationColorSpaceDisplayP3Tag: - // destinationColorSpace = DestinationColorSpace::DisplayP3(); - // return true; - // #endif - // #if PLATFORM(COCOA) - // case DestinationColorSpaceCGColorSpaceNameTag: { - // RetainPtr data; - // if (!read(data)) - // return false; - - // auto name = adoptCF(CFStringCreateFromExternalRepresentation(nullptr, data.get(), kCFStringEncodingUTF8)); - // if (!name) - // return false; - - // auto colorSpace = adoptCF(CGColorSpaceCreateWithName(name.get())); - // if (!colorSpace) - // return false; - - // destinationColorSpace = DestinationColorSpace(colorSpace.get()); - // return true; - // } - // case DestinationColorSpaceCGColorSpacePropertyListTag: { - // RetainPtr data; - // if (!read(data)) - // return false; - - // auto propertyList = adoptCF(CFPropertyListCreateWithData(nullptr, data.get(), kCFPropertyListImmutable, nullptr, nullptr)); - // if (!propertyList) - // return false; - - // auto colorSpace = adoptCF(CGColorSpaceCreateWithPropertyList(propertyList.get())); - // if (!colorSpace) - // return false; - - // destinationColorSpace = DestinationColorSpace(colorSpace.get()); - // return true; - // } - // #endif - // } - - // ASSERT_NOT_REACHED(); - // return false; - // } - #if ENABLE(WEB_CRYPTO) bool read(CryptoKeyOKP::NamedCurve& result) { @@ -4549,329 +3357,6 @@ class CloneDeserializer : public CloneBase { return toJS(m_lexicalGlobalObject, uncheckedDowncast(m_globalObject), std::forward(nativeObj)); } - // template - // JSValue readDOMPoint() - // { - // double x; - // if (!read(x)) - // return {}; - // double y; - // if (!read(y)) - // return {}; - // double z; - // if (!read(z)) - // return {}; - // double w; - // if (!read(w)) - // return {}; - - // return toJSNewlyCreated(m_lexicalGlobalObject, uncheckedDowncast(m_globalObject), T::create(x, y, z, w)); - // } - - // template - // JSValue readDOMMatrix() - // { - // uint8_t is2D; - // if (!read(is2D)) - // return {}; - - // if (is2D) { - // double m11; - // if (!read(m11)) - // return {}; - // double m12; - // if (!read(m12)) - // return {}; - // double m21; - // if (!read(m21)) - // return {}; - // double m22; - // if (!read(m22)) - // return {}; - // double m41; - // if (!read(m41)) - // return {}; - // double m42; - // if (!read(m42)) - // return {}; - - // TransformationMatrix matrix(m11, m12, m21, m22, m41, m42); - // return toJSNewlyCreated(m_lexicalGlobalObject, uncheckedDowncast(m_globalObject), T::create(WTF::move(matrix), DOMMatrixReadOnly::Is2D::Yes)); - // } else { - // double m11; - // if (!read(m11)) - // return {}; - // double m12; - // if (!read(m12)) - // return {}; - // double m13; - // if (!read(m13)) - // return {}; - // double m14; - // if (!read(m14)) - // return {}; - // double m21; - // if (!read(m21)) - // return {}; - // double m22; - // if (!read(m22)) - // return {}; - // double m23; - // if (!read(m23)) - // return {}; - // double m24; - // if (!read(m24)) - // return {}; - // double m31; - // if (!read(m31)) - // return {}; - // double m32; - // if (!read(m32)) - // return {}; - // double m33; - // if (!read(m33)) - // return {}; - // double m34; - // if (!read(m34)) - // return {}; - // double m41; - // if (!read(m41)) - // return {}; - // double m42; - // if (!read(m42)) - // return {}; - // double m43; - // if (!read(m43)) - // return {}; - // double m44; - // if (!read(m44)) - // return {}; - - // TransformationMatrix matrix(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44); - // return toJSNewlyCreated(m_lexicalGlobalObject, uncheckedDowncast(m_globalObject), T::create(WTF::move(matrix), DOMMatrixReadOnly::Is2D::No)); - // } - // } - - // template - // JSValue readDOMRect() - // { - // double x; - // if (!read(x)) - // return {}; - // double y; - // if (!read(y)) - // return {}; - // double width; - // if (!read(width)) - // return {}; - // double height; - // if (!read(height)) - // return {}; - - // return toJSNewlyCreated(m_lexicalGlobalObject, uncheckedDowncast(m_globalObject), T::create(x, y, width, height)); - // } - - // std::optional readDOMPointInit() - // { - // DOMPointInit point; - // if (!read(point.x)) - // return std::nullopt; - // if (!read(point.y)) - // return std::nullopt; - // if (!read(point.z)) - // return std::nullopt; - // if (!read(point.w)) - // return std::nullopt; - - // return point; - // } - - // JSValue readDOMQuad() - // { - // auto p1 = readDOMPointInit(); - // if (!p1) - // return JSValue(); - // auto p2 = readDOMPointInit(); - // if (!p2) - // return JSValue(); - // auto p3 = readDOMPointInit(); - // if (!p3) - // return JSValue(); - // auto p4 = readDOMPointInit(); - // if (!p4) - // return JSValue(); - - // return toJSNewlyCreated(m_lexicalGlobalObject, uncheckedDowncast(m_globalObject), DOMQuad::create(p1.value(), p2.value(), p3.value(), p4.value())); - // } - - // JSValue readTransferredImageBitmap() - // { - // uint32_t index; - // bool indexSuccessfullyRead = read(index); - // if (!indexSuccessfullyRead || index >= m_backingStores.size()) { - // fail(); - // return JSValue(); - // } - - // if (!m_imageBitmaps[index]) { - // m_backingStores.at(index)->connect(*executionContext(m_lexicalGlobalObject)); - // m_imageBitmaps[index] = ImageBitmap::create(WTF::move(m_backingStores.at(index))); - // } - - // auto bitmap = m_imageBitmaps[index].get(); - // return getJSValue(bitmap); - // } - -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - JSValue readOffscreenCanvas() - { - uint32_t index; - bool indexSuccessfullyRead = read(index); - if (!indexSuccessfullyRead || index >= m_detachedOffscreenCanvases.size()) { - fail(); - return JSValue(); - } - - if (!m_offscreenCanvases[index]) - m_offscreenCanvases[index] = OffscreenCanvas::create(*executionContext(m_lexicalGlobalObject), WTF::move(m_detachedOffscreenCanvases.at(index))); - - auto offscreenCanvas = m_offscreenCanvases[index].get(); - return getJSValue(offscreenCanvas); - } -#endif - -#if ENABLE(WEB_RTC) - JSValue readRTCCertificate() - { - double expires; - if (!read(expires)) { - fail(); - return JSValue(); - } - CachedStringRef certificate; - if (!readStringData(certificate)) { - fail(); - return JSValue(); - } - CachedStringRef origin; - if (!readStringData(origin)) { - fail(); - return JSValue(); - } - CachedStringRef keyedMaterial; - if (!readStringData(keyedMaterial)) { - fail(); - return JSValue(); - } - unsigned size = 0; - if (!read(size)) - return JSValue(); - - Vector fingerprints; - fingerprints.reserveInitialCapacity(size); - for (unsigned i = 0; i < size; i++) { - CachedStringRef algorithm; - if (!readStringData(algorithm)) - return JSValue(); - CachedStringRef value; - if (!readStringData(value)) - return JSValue(); - fingerprints.unsafeAppendWithoutCapacityCheck(RTCCertificate::DtlsFingerprint { algorithm->string(), value->string() }); - } - - if (!m_canCreateDOMObject) - return constructEmptyObject(m_lexicalGlobalObject, m_globalObject->objectPrototype()); - - auto rtcCertificate = RTCCertificate::create(SecurityOrigin::createFromString(origin->string()), expires, WTF::move(fingerprints), certificate->takeString(), keyedMaterial->takeString()); - return toJSNewlyCreated(m_lexicalGlobalObject, uncheckedDowncast(m_globalObject), WTF::move(rtcCertificate)); - } - - JSValue readRTCDataChannel() - { - uint32_t index; - bool indexSuccessfullyRead = read(index); - if (!indexSuccessfullyRead || index >= m_detachedRTCDataChannels.size()) { - fail(); - return JSValue(); - } - - if (!m_rtcDataChannels[index]) { - auto detachedChannel = WTF::move(m_detachedRTCDataChannels.at(index)); - m_rtcDataChannels[index] = RTCDataChannel::create(*executionContext(m_lexicalGlobalObject), detachedChannel->identifier, WTF::move(detachedChannel->label), WTF::move(detachedChannel->options), detachedChannel->state); - } - - return getJSValue(m_rtcDataChannels[index].get()); - } -#endif - -#if ENABLE(WEB_CODECS) - JSValue readWebCodecsEncodedVideoChunk() - { - uint32_t index; - bool indexSuccessfullyRead = read(index); - if (!indexSuccessfullyRead || index >= m_serializedVideoChunks.size()) { - fail(); - return JSValue(); - } - - if (!m_videoChunks[index]) - m_videoChunks[index] = WebCodecsEncodedVideoChunk::create(m_serializedVideoChunks.at(index).releaseNonNull()); - - return getJSValue(m_videoChunks[index].get()); - } - JSValue readWebCodecsVideoFrame() - { - uint32_t index; - bool indexSuccessfullyRead = read(index); - if (!indexSuccessfullyRead || index >= m_serializedVideoFrames.size()) { - fail(); - return JSValue(); - } - - if (!m_videoFrames[index]) - m_videoFrames[index] = WebCodecsVideoFrame::create(*executionContext(m_lexicalGlobalObject), WTF::move(m_serializedVideoFrames.at(index))); - - return getJSValue(m_videoFrames[index].get()); - } -#endif - - // JSValue readImageBitmap() - // { - // uint8_t serializationState; - // int32_t logicalWidth; - // int32_t logicalHeight; - // double resolutionScale; - // auto colorSpace = DestinationColorSpace::SRGB(); - // RefPtr arrayBuffer; - - // if (!read(serializationState) || !read(logicalWidth) || !read(logicalHeight) || !read(resolutionScale) || (m_version > 8 && !read(colorSpace)) || !readArrayBufferImpl(arrayBuffer)) { - // fail(); - // return JSValue(); - // } - - // auto logicalSize = IntSize(logicalWidth, logicalHeight); - // auto imageDataSize = logicalSize; - // imageDataSize.scale(resolutionScale); - - // auto buffer = ImageBitmap::createImageBuffer(*executionContext(m_lexicalGlobalObject), logicalSize, RenderingMode::Unaccelerated, colorSpace, resolutionScale); - // if (!buffer) { - // fail(); - // return JSValue(); - // } - - // PixelBufferFormat format { AlphaPremultiplication::Premultiplied, PixelFormat::RGBA8, colorSpace }; - // auto pixelBuffer = ByteArrayPixelBuffer::tryCreate(format, imageDataSize, arrayBuffer.releaseNonNull()); - // if (!pixelBuffer) { - // fail(); - // return JSValue(); - // } - - // buffer->putPixelBuffer(*pixelBuffer, { IntPoint::zero(), logicalSize }); - - // auto bitmap = ImageBitmap::create(ImageBitmapBacking(WTF::move(buffer), OptionSet::fromRaw(serializationState))); - // return getJSValue(bitmap); - // } - JSValue readX509Certificate() { Vector buffer; @@ -5156,99 +3641,6 @@ class CloneDeserializer : public CloneBase { addTerminalToObjectPool(obj); return obj; } - // case FileTag: { - // RefPtr file; - // if (!readFile(file)) - // return JSValue(); - // if (!m_canCreateDOMObject) - // return jsNull(); - // return toJS(m_lexicalGlobalObject, uncheckedDowncast(m_globalObject), file.get()); - // } - // case FileListTag: { - // unsigned length = 0; - // if (!read(length)) - // return JSValue(); - // ASSERT(m_globalObject->inherits()); - // Vector> files; - // for (unsigned i = 0; i < length; i++) { - // RefPtr file; - // if (!readFile(file)) - // return JSValue(); - // if (m_canCreateDOMObject) - // files.append(file.releaseNonNull()); - // } - // if (!m_canCreateDOMObject) - // return jsNull(); - // return getJSValue(FileList::create(WTF::move(files)).get()); - // } - // case ImageDataTag: { - // uint32_t width; - // if (!read(width)) - // return JSValue(); - // if (width == ImageDataPoolTag) { - // auto index = readImageDataIndex(); - // if (!index || *index >= m_imageDataPool.size()) { - // fail(); - // return JSValue(); - // } - // return getJSValue(m_imageDataPool[*index]); - // } - // uint32_t height; - // if (!read(height)) - // return JSValue(); - // uint32_t length; - // if (!read(length)) - // return JSValue(); - // if (static_cast(m_end - m_ptr) < length) { - // fail(); - // return JSValue(); - // } - // auto bufferStart = m_ptr; - // m_ptr += length; - - // auto resultColorSpace = PredefinedColorSpace::SRGB; - // if (m_version > 7) { - // if (!read(resultColorSpace)) - // return JSValue(); - // } - - // if (length && (IntSize(width, height).area() * 4) != length) { - // fail(); - // return JSValue(); - // } - - // if (!m_isDOMGlobalObject) - // return jsNull(); - - // auto result = ImageData::createUninitialized(width, height, resultColorSpace); - // if (result.hasException()) { - // fail(); - // return JSValue(); - // } - // if (length) - // memcpy(result.returnValue()->data().data(), bufferStart, length); - // else - // result.returnValue()->data().zeroFill(); - // m_imageDataPool.append(result.returnValue().copyRef()); - // return getJSValue(result.releaseReturnValue()); - // } - // case BlobTag: { - // CachedStringRef url; - // if (!readStringData(url)) - // return JSValue(); - // CachedStringRef type; - // if (!readStringData(type)) - // return JSValue(); - // uint64_t size = 0; - // if (!read(size)) - // return JSValue(); - // uint64_t memoryCost = 0; - // if (m_version >= 11 && !read(memoryCost)) - // return JSValue(); - // if (!m_canCreateDOMObject) - // return jsNull(); - // return getJSValue(Blob::deserialize(executionContext(m_lexicalGlobalObject), URL { url->string() }, type->string(), size, memoryCost, blobFilePathForBlobURL(url->string())).get()); - // } case StringTag: { CachedStringRef cachedString; if (!readStringData(cachedString)) @@ -5492,16 +3884,7 @@ class CloneDeserializer : public CloneBase { return JSValue(); } - // See CryptoKey serialization for why we don't wrap - // - // Vector serializedKey; - // if (!unwrapCryptoKey(m_lexicalGlobalObject, wrappedKey, serializedKey)) { - // fail(); - // return JSValue(); - // } JSValue cryptoKey; - // Vector> dummyMessagePorts; - // CloneDeserializer rawKeyDeserializer(m_lexicalGlobalObject, m_globalObject, dummyMessagePorts, nullptr, {}, serializedKey); CloneDeserializer rawKeyDeserializer(m_lexicalGlobalObject, m_globalObject, {}, nullptr, serializedKey); if (!rawKeyDeserializer.readCryptoKey(cryptoKey)) { fail(); @@ -5511,43 +3894,6 @@ class CloneDeserializer : public CloneBase { addTerminalToObjectPool(cryptoKey); return cryptoKey; } -#endif - // case DOMPointReadOnlyTag: - // return readDOMPoint(); - // case DOMPointTag: - // return readDOMPoint(); - // case DOMRectReadOnlyTag: - // return readDOMRect(); - // case DOMRectTag: - // return readDOMRect(); - // case DOMMatrixReadOnlyTag: - // return readDOMMatrix(); - // case DOMMatrixTag: - // return readDOMMatrix(); - // case DOMQuadTag: - // return readDOMQuad(); - // case ImageBitmapTransferTag: - // return readTransferredImageBitmap(); -#if ENABLE(WEB_RTC) - case RTCCertificateTag: - return readRTCCertificate(); - -#endif - // case ImageBitmapTag: - // return readImageBitmap(); -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - case OffscreenCanvasTransferTag: - return readOffscreenCanvas(); -#endif -#if ENABLE(WEB_RTC) - case RTCDataChannelTransferTag: - return readRTCDataChannel(); -#endif -#if ENABLE(WEB_CODECS) - case WebCodecsEncodedVideoChunkTag: - return readWebCodecsEncodedVideoChunk(); - case WebCodecsVideoFrameTag: - return readWebCodecsVideoFrame(); #endif case DOMExceptionTag: return readDOMException(); @@ -5579,7 +3925,6 @@ class CloneDeserializer : public CloneBase { JSGlobalObject* const m_globalObject; const bool m_isDOMGlobalObject; - // const bool m_canCreateDOMObject; const uint8_t* m_ptr; const uint8_t* const m_end; unsigned m_version; @@ -5588,44 +3933,16 @@ class CloneDeserializer : public CloneBase { // Only values the serializer passed to recordObject() may be appended here (via // addToObjectPool), in the same order, or every later back-reference is wrong. MarkedArgumentBuffer m_objectPool; - // Vector> m_imageDataPool; const Vector>& m_messagePorts; ArrayBufferContentsArray* m_arrayBufferContents; Vector> m_arrayBuffers; Vector m_blobURLs; Vector m_blobFilePaths; ArrayBufferContentsArray* m_sharedBuffers; -// Vector> m_backingStores; -// Vector> m_imageBitmaps; -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - Vector> m_detachedOffscreenCanvases; - Vector> m_offscreenCanvases; -#endif -#if ENABLE(WEB_RTC) - Vector> m_detachedRTCDataChannels; - Vector> m_rtcDataChannels; -#endif #if ENABLE(WEBASSEMBLY) WasmModuleArray* const m_wasmModules; WasmMemoryHandleArray* const m_wasmMemoryHandles; #endif -#if ENABLE(WEB_CODECS) - Vector> m_serializedVideoChunks; - Vector> m_videoChunks; - Vector m_serializedVideoFrames; - Vector> m_videoFrames; -#endif - - String blobFilePathForBlobURL(const String& blobURL) - { - size_t i = 0; - for (; i < m_blobURLs.size(); ++i) { - if (m_blobURLs[i] == blobURL) - break; - } - - return i < m_blobURLs.size() ? m_blobFilePaths[i] : String(); - } }; DeserializationResult CloneDeserializer::deserialize() @@ -5847,105 +4164,26 @@ SerializedScriptValue::~SerializedScriptValue() BlockList__onStructuredCloneDestroy(ptr); } -SerializedScriptValue::SerializedScriptValue(Vector&& buffer, std::unique_ptr&& arrayBufferContentsArray -#if ENABLE(WEB_RTC) - , - Vector>&& detachedRTCDataChannels -#endif -#if ENABLE(WEB_CODECS) - , - Vector>&& serializedVideoChunks, Vector&& serializedVideoFrames -#endif - ) +SerializedScriptValue::SerializedScriptValue(Vector&& buffer, std::unique_ptr&& arrayBufferContentsArray) : m_data(WTF::move(buffer)) , m_arrayBufferContentsArray(WTF::move(arrayBufferContentsArray)) -#if ENABLE(WEB_RTC) - , m_detachedRTCDataChannels(WTF::move(detachedRTCDataChannels)) -#endif -#if ENABLE(WEB_CODECS) - , m_serializedVideoChunks(WTF::move(serializedVideoChunks)) - , m_serializedVideoFrames(WTF::move(serializedVideoFrames)) -#endif { m_memoryCost = computeMemoryCost(); } -// SerializedScriptValue::SerializedScriptValue(Vector&& buffer, Vector&& blobHandles, std::unique_ptr arrayBufferContentsArray, std::unique_ptr sharedBufferContentsArray, Vector>&& backingStores -// #if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) -// , -// Vector>&& detachedOffscreenCanvases -// #endif -// #if ENABLE(WEB_RTC) -// , -// Vector>&& detachedRTCDataChannels -// #endif -// #if ENABLE(WEBASSEMBLY) -// , -// std::unique_ptr wasmModulesArray, std::unique_ptr wasmMemoryHandlesArray -// #endif -// #if ENABLE(WEB_CODECS) -// , -// Vector>&& serializedVideoChunks, Vector&& serializedVideoFrames -// #endif -// ) -// : m_data(WTF::move(buffer)) -// , m_arrayBufferContentsArray(WTF::move(arrayBufferContentsArray)) -// , m_sharedBufferContentsArray(WTF::move(sharedBufferContentsArray)) -// , m_backingStores(WTF::move(backingStores)) -// #if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) -// , m_detachedOffscreenCanvases(WTF::move(detachedOffscreenCanvases)) -// #endif -// #if ENABLE(WEB_RTC) -// , m_detachedRTCDataChannels(WTF::move(detachedRTCDataChannels)) -// #endif -// #if ENABLE(WEBASSEMBLY) -// , m_wasmModulesArray(WTF::move(wasmModulesArray)) -// , m_wasmMemoryHandlesArray(WTF::move(wasmMemoryHandlesArray)) -// #endif -// #if ENABLE(WEB_CODECS) -// , m_serializedVideoChunks(WTF::move(serializedVideoChunks)) -// , m_serializedVideoFrames(WTF::move(serializedVideoFrames)) -// #endif -// , m_blobHandles(crossThreadCopy(WTF::move(blobHandles))) -// { -// m_memoryCost = computeMemoryCost(); -// } - SerializedScriptValue::SerializedScriptValue(Vector&& buffer, std::unique_ptr arrayBufferContentsArray, std::unique_ptr sharedBufferContentsArray -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - , - Vector>&& detachedOffscreenCanvases -#endif -#if ENABLE(WEB_RTC) - , - Vector>&& detachedRTCDataChannels -#endif #if ENABLE(WEBASSEMBLY) , std::unique_ptr wasmModulesArray, std::unique_ptr wasmMemoryHandlesArray -#endif -#if ENABLE(WEB_CODECS) - , - Vector>&& serializedVideoChunks, Vector&& serializedVideoFrames #endif ) : m_data(WTF::move(buffer)) , m_arrayBufferContentsArray(WTF::move(arrayBufferContentsArray)) , m_sharedBufferContentsArray(WTF::move(sharedBufferContentsArray)) -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - , m_detachedOffscreenCanvases(WTF::move(detachedOffscreenCanvases)) -#endif -#if ENABLE(WEB_RTC) - , m_detachedRTCDataChannels(WTF::move(detachedRTCDataChannels)) -#endif #if ENABLE(WEBASSEMBLY) , m_wasmModulesArray(WTF::move(wasmModulesArray)) , m_wasmMemoryHandlesArray(WTF::move(wasmMemoryHandlesArray)) #endif -#if ENABLE(WEB_CODECS) - , m_serializedVideoChunks(WTF::move(serializedVideoChunks)) - , m_serializedVideoFrames(WTF::move(serializedVideoFrames)) -#endif { m_memoryCost = computeMemoryCost(); } @@ -6006,23 +4244,6 @@ size_t SerializedScriptValue::computeMemoryCost() const cost += content.sizeInBytes(); } - // for (auto& backingStore : m_backingStores) { - // if (auto buffer = backingStore ? backingStore->buffer() : nullptr) - // cost += buffer->memoryCost(); - // } - -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - for (auto& canvas : m_detachedOffscreenCanvases) { - if (canvas) - cost += canvas->memoryCost(); - } -#endif -#if ENABLE(WEB_RTC) - for (auto& channel : m_detachedRTCDataChannels) { - if (channel) - cost += channel->memoryCost(); - } -#endif #if ENABLE(WEBASSEMBLY) // We are not supporting WebAssembly Module memory estimation yet. if (m_wasmMemoryHandlesArray) { @@ -6030,17 +4251,6 @@ size_t SerializedScriptValue::computeMemoryCost() const cost += content->sizeInBytes(std::memory_order_relaxed); } #endif -#if ENABLE(WEB_CODECS) - for (auto& chunk : m_serializedVideoChunks) { - if (chunk) - cost += chunk->memoryCost(); - } - for (auto& frame : m_serializedVideoFrames) - cost += frame.memoryCost(); -#endif - - // for (auto& handle : m_blobHandles) - // cost += handle.url().string().sizeInBytes(); // Account for fast path string memory usage switch (m_fastPath) { @@ -6208,67 +4418,21 @@ static bool isObjectFastPathCandidate(Structure* structure) return true; } -// static bool containsDuplicates(const Vector>& imageBitmaps) -// { -// HashSet visited; -// for (auto& imageBitmap : imageBitmaps) { -// if (!visited.add(imageBitmap.get())) -// return true; -// } -// return false; -// } - -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) -static bool canOffscreenCanvasesDetach(const Vector>& offscreenCanvases) -{ - HashSet visited; - for (auto& offscreenCanvas : offscreenCanvases) { - if (!offscreenCanvas->canDetach()) - return false; - // Check the return value of add, we should not encounter duplicates. - if (!visited.add(offscreenCanvas.get())) - return false; - } - return true; -} -#endif - -#if ENABLE(WEB_RTC) -static bool canDetachRTCDataChannels(const Vector>& channels) -{ - HashSet visited; - for (auto& channel : channels) { - if (!channel->canDetach()) - return false; - // Check the return value of add, we should not encounter duplicates. - if (!visited.add(channel.ptr())) - return false; - } - return true; -} -#endif RefPtr SerializedScriptValue::create(JSC::JSGlobalObject& globalObject, JSC::JSValue value, SerializationForStorage forStorage, SerializationErrorMode throwExceptions, SerializationContext serializationContext, SerializationForCrossProcessTransfer forTransfer) { Vector> dummyPorts; auto result = create(globalObject, value, {}, dummyPorts, forStorage, throwExceptions, serializationContext, forTransfer); - // auto result = create(globalObject, value, {}, forStorage, throwExceptions, serializationContext); if (result.hasException()) return nullptr; return result.releaseReturnValue(); } -// ExceptionOr> SerializedScriptValue::create(JSGlobalObject& globalObject, JSValue value, Vector>&& transferList, Vector>& messagePorts, SerializationForStorage forStorage, SerializationContext serializationContext) -// { -// return create(globalObject, value, WTF::move(transferList), messagePorts, forStorage, SerializationErrorMode::NonThrowing, serializationContext); -// } - ExceptionOr> SerializedScriptValue::create(JSGlobalObject& globalObject, JSValue value, Vector>&& transferList, Vector>& messagePorts, SerializationForStorage forStorage, SerializationContext serializationContext, SerializationForCrossProcessTransfer forTransfer) { return create(globalObject, value, WTF::move(transferList), messagePorts, forStorage, SerializationErrorMode::Throwing, serializationContext, forTransfer); } -// ExceptionOr> SerializedScriptValue::create(JSGlobalObject& lexicalGlobalObject, JSValue value, Vector>&& transferList, SerializationForStorage forStorage, SerializationErrorMode throwExceptions, SerializationContext context) ExceptionOr> SerializedScriptValue::create(JSGlobalObject& lexicalGlobalObject, JSValue value, Vector>&& transferList, Vector>& messagePorts, SerializationForStorage forStorage, SerializationErrorMode throwExceptions, SerializationContext context, SerializationForCrossProcessTransfer forTransfer) { VM& vm = lexicalGlobalObject.vm(); @@ -6504,16 +4668,6 @@ ExceptionOr> SerializedScriptValue::create(JSGlobalOb } Vector> arrayBuffers; - // Vector> imageBitmaps; -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - Vector> offscreenCanvases; -#endif -#if ENABLE(WEB_RTC) - Vector> dataChannels; -#endif -#if ENABLE(WEB_CODECS) - Vector> transferredVideoFrames; -#endif HashSet uniqueTransferables; for (auto& transferable : transferList) { // markAsUntransferable marker: a DontEnum JSC private name (see markAsUncloneable). @@ -6552,91 +4706,17 @@ ExceptionOr> SerializedScriptValue::create(JSGlobalOb continue; } - // if (auto imageBitmap = JSImageBitmap::toWrapped(vm, transferable.get())) { - // if (imageBitmap->isDetached()) - // return Exception { DataCloneError }; - // if (!imageBitmap->originClean()) - // return Exception { DataCloneError }; - - // imageBitmaps.append(WTF::move(imageBitmap)); - // continue; - // } - -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - if (auto offscreenCanvas = JSOffscreenCanvas::toWrapped(vm, transferable.get())) { - offscreenCanvases.append(WTF::move(offscreenCanvas)); - continue; - } -#endif - -#if ENABLE(WEB_RTC) - if (auto channel = JSRTCDataChannel::toWrapped(vm, transferable.get())) { - dataChannels.append(*channel); - continue; - } -#endif - -#if ENABLE(WEB_CODECS) - if (auto videoFrame = JSWebCodecsVideoFrame::toWrapped(vm, transferable.get())) { - if (videoFrame->isDetached()) - return Exception { DataCloneError }; - transferredVideoFrames.append(*videoFrame); - continue; - } -#endif return Exception { DataCloneError }; } - // if (containsDuplicates(imageBitmaps)) - // return Exception { DataCloneError }; -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - if (!canOffscreenCanvasesDetach(offscreenCanvases)) - return Exception { InvalidStateError }; -#endif -#if ENABLE(WEB_RTC) - if (!canDetachRTCDataChannels(dataChannels)) - return Exception { DataCloneError }; -#endif - Vector buffer; - // Vector blobHandles; #if ENABLE(WEBASSEMBLY) WasmModuleArray wasmModules; WasmMemoryHandleArray wasmMemoryHandles; #endif std::unique_ptr sharedBuffers = makeUnique(); Vector serializedBlockListRefs; -#if ENABLE(WEB_CODECS) - Vector> serializedVideoChunks; - Vector> serializedVideoFrames; -#endif - // auto code = CloneSerializer::serialize(&lexicalGlobalObject, value, messagePorts, arrayBuffers, imageBitmaps, - // #if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - // offscreenCanvases, - // #endif - // #if ENABLE(WEB_RTC) - // dataChannels, - // #endif - // #if ENABLE(WEB_CODECS) - // serializedVideoChunks, - // serializedVideoFrames, - // #endif - // #if ENABLE(WEBASSEMBLY) - // wasmModules, - // wasmMemoryHandles, - // #endif - // blobHandles, buffer, context, *sharedBuffers, forStorage); auto code = CloneSerializer::serialize(&lexicalGlobalObject, value, messagePorts, arrayBuffers, -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - offscreenCanvases, -#endif -#if ENABLE(WEB_RTC) - dataChannels, -#endif -#if ENABLE(WEB_CODECS) - serializedVideoChunks, - serializedVideoFrames, -#endif #if ENABLE(WEBASSEMBLY) wasmModules, wasmMemoryHandles, @@ -6669,76 +4749,17 @@ ExceptionOr> SerializedScriptValue::create(JSGlobalOb RELEASE_AND_RETURN(scope, arrayBufferContentsArray.releaseException()); } - // auto backingStores = ImageBitmap::detachBitmaps(WTF::move(imageBitmaps)); - -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - Vector> detachedCanvases; - for (auto offscreenCanvas : offscreenCanvases) - detachedCanvases.append(offscreenCanvas->detach()); -#endif -#if ENABLE(WEB_RTC) - Vector> detachedRTCDataChannels; - for (auto& channel : dataChannels) - detachedRTCDataChannels.append(channel->detach()); -#endif - -#if ENABLE(WEB_CODECS) - auto serializedVideoFrameData = map(serializedVideoFrames, [](auto& frame) -> WebCodecsVideoFrameData { return frame->data(); }); -#endif -#if ENABLE(WEB_CODECS) - for (auto& videoFrame : transferredVideoFrames) - videoFrame->close(); -#endif - - // return adoptRef(*new SerializedScriptValue(WTF::move(buffer), WTF::move(blobHandles), arrayBufferContentsArray.releaseReturnValue(), context == SerializationContext::WorkerPostMessage ? WTF::move(sharedBuffers) : nullptr, WTF::move(backingStores) - // #if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - // , - // WTF::move(detachedCanvases) - // #endif - // #if ENABLE(WEB_RTC) - // , - // WTF::move(detachedRTCDataChannels) - // #endif - // #if ENABLE(WEBASSEMBLY) - // , - // makeUnique(wasmModules), context == SerializationContext::WorkerPostMessage ? makeUnique(wasmMemoryHandles) : nullptr - // #endif - // #if ENABLE(WEB_CODECS) - // , - // WTF::move(serializedVideoChunks), WTF::move(serializedVideoFrameData) - // #endif - // )); scope.releaseAssertNoException(); auto result = adoptRef(*new SerializedScriptValue(WTF::move(buffer), arrayBufferContentsArray.releaseReturnValue(), context == SerializationContext::WorkerPostMessage ? WTF::move(sharedBuffers) : nullptr -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - , - WTF::move(detachedCanvases) -#endif -#if ENABLE(WEB_RTC) - , - WTF::move(detachedRTCDataChannels) -#endif #if ENABLE(WEBASSEMBLY) , makeUnique(wasmModules), context == SerializationContext::WorkerPostMessage ? makeUnique(wasmMemoryHandles) : nullptr -#endif -#if ENABLE(WEB_CODECS) - , - WTF::move(serializedVideoChunks), WTF::move(serializedVideoFrameData) #endif )); result->m_serializedBlockListRefs = WTF::move(serializedBlockListRefs); return result; } -RefPtr SerializedScriptValue::create(StringView string) -{ - Vector buffer; - if (!CloneSerializer::serialize(string, buffer)) - return nullptr; - return adoptRef(*new SerializedScriptValue(WTF::move(buffer))); -} - Ref SerializedScriptValue::createStringFastPath(const String& string) { return adoptRef(*new SerializedScriptValue(Bun::toCrossThreadShareable(string))); @@ -6764,30 +4785,6 @@ Ref SerializedScriptValue::createDoubleArrayFastPath(Vect return adoptRef(*new SerializedScriptValue(WTF::move(data), length, FastPath::DoubleArray)); } -RefPtr SerializedScriptValue::create(JSContextRef originContext, JSValueRef apiValue, JSValueRef* exception) -{ - JSGlobalObject* lexicalGlobalObject = toJS(originContext); - auto& vm = JSC::getVM(lexicalGlobalObject); - JSLockHolder locker(vm); - auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); - - JSValue value = toJS(lexicalGlobalObject, apiValue); - auto serializedValue = SerializedScriptValue::create(*lexicalGlobalObject, value); - if (scope.exception()) [[unlikely]] { - if (exception) - *exception = toRef(lexicalGlobalObject, scope.exception()->value()); - (void)scope.tryClearException(); - return nullptr; - } - ASSERT(serializedValue); - return serializedValue; -} - -String SerializedScriptValue::toString() const -{ - return CloneDeserializer::deserializeString(m_data); -} - Ref SerializedScriptValue::toArrayBuffer() { if (this->m_data.size() == 0) { @@ -6836,10 +4833,6 @@ JSC::JSValue SerializedScriptValue::fromArrayBuffer(JSC::JSGlobalObject& domGlob #if ENABLE(WEBASSEMBLY) , nullptr, nullptr -#endif -#if ENABLE(WEB_CODECS) - , - WTF::move(m_serializedVideoChunks), WTF::move(m_serializedVideoFrames) #endif ); @@ -6857,11 +4850,6 @@ JSC::JSValue SerializedScriptValue::fromArrayBuffer(JSC::JSGlobalObject& domGlob return result.first ? result.first : jsNull(); } -// JSValue SerializedScriptValue::deserialize(JSGlobalObject& lexicalGlobalObject, JSGlobalObject* globalObject, SerializationErrorMode throwExceptions, bool* didFail) -// { -// return deserialize(lexicalGlobalObject, globalObject, {}, throwExceptions, didFail); -// } - JSValue SerializedScriptValue::deserialize(JSGlobalObject& lexicalGlobalObject, JSGlobalObject* globalObject, const Vector>& messagePorts, SerializationErrorMode throwExceptions, bool* didFail) { Vector dummyBlobs; @@ -7079,29 +5067,16 @@ JSValue SerializedScriptValue::deserialize(JSGlobalObject& lexicalGlobalObject, } } - DeserializationResult result = CloneDeserializer::deserialize(&lexicalGlobalObject, globalObject, messagePorts -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - , - WTF::move(m_detachedOffscreenCanvases) -#endif -#if ENABLE(WEB_RTC) - , - WTF::move(m_detachedRTCDataChannels) -#endif - , + DeserializationResult result = CloneDeserializer::deserialize(&lexicalGlobalObject, globalObject, messagePorts, m_arrayBufferContentsArray.get(), m_data, blobURLs, blobFilePaths, m_sharedBufferContentsArray.get() #if ENABLE(WEBASSEMBLY) , m_wasmModulesArray.get(), m_wasmMemoryHandlesArray.get() -#endif -#if ENABLE(WEB_CODECS) - , - WTF::move(m_serializedVideoChunks), WTF::move(m_serializedVideoFrames) #endif ); if (didFail) *didFail = result.second != SerializationReturnCode::SuccessfullyCompleted; - // Deserialize may throw an exception. Similar to serialize (~L6240, SerializedScriptValue::create), + // Deserialize may throw an exception. Similar to serialize (SerializedScriptValue::create), // we'll catch and rethrow. if (scope.exception() || throwExceptions == SerializationErrorMode::Throwing) [[unlikely]] maybeThrowExceptionIfSerializationFailed(lexicalGlobalObject, result.second); @@ -7111,129 +5086,5 @@ JSValue SerializedScriptValue::deserialize(JSGlobalObject& lexicalGlobalObject, return result.first; } -// JSValue SerializedScriptValue::deserialize(JSGlobalObject& lexicalGlobalObject, JSGlobalObject* globalObject, const Vector& blobURLs, const Vector& blobFilePaths, SerializationErrorMode throwExceptions, bool* didFail) -// { -// // DeserializationResult result = CloneDeserializer::deserialize(&lexicalGlobalObject, globalObject, messagePorts, WTF::move(m_backingStores) -// // #if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) -// // , -// // WTF::move(m_detachedOffscreenCanvases) -// // #endif -// // #if ENABLE(WEB_RTC) -// // , -// // WTF::move(m_detachedRTCDataChannels) -// // #endif -// // , -// // m_arrayBufferContentsArray.get(), m_data, blobURLs, blobFilePaths, m_sharedBufferContentsArray.get() -// // #if ENABLE(WEBASSEMBLY) -// // , -// // m_wasmModulesArray.get(), m_wasmMemoryHandlesArray.get() -// // #endif -// // #if ENABLE(WEB_CODECS) -// // , -// // WTF::move(m_serializedVideoChunks), WTF::move(m_serializedVideoFrames) -// // #endif -// // ); -// DeserializationResult result = CloneDeserializer::deserialize(&lexicalGlobalObject, globalObject -// #if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) -// , -// WTF::move(m_detachedOffscreenCanvases) -// #endif -// #if ENABLE(WEB_RTC) -// , -// WTF::move(m_detachedRTCDataChannels) -// #endif -// , -// m_arrayBufferContentsArray.get(), m_data, blobURLs, blobFilePaths, m_sharedBufferContentsArray.get() -// #if ENABLE(WEBASSEMBLY) -// , -// m_wasmModulesArray.get(), m_wasmMemoryHandlesArray.get() -// #endif -// #if ENABLE(WEB_CODECS) -// , -// WTF::move(m_serializedVideoChunks), WTF::move(m_serializedVideoFrames) -// #endif -// ); -// if (didFail) -// *didFail = result.second != SerializationReturnCode::SuccessfullyCompleted; -// if (throwExceptions == SerializationErrorMode::Throwing) -// maybeThrowExceptionIfSerializationFailed(lexicalGlobalObject, result.second); -// return result.first ? result.first : jsNull(); -// } - -JSValueRef SerializedScriptValue::deserialize(JSContextRef destinationContext, JSValueRef* exception) -{ - JSGlobalObject* lexicalGlobalObject = toJS(destinationContext); - auto& vm = JSC::getVM(lexicalGlobalObject); - JSLockHolder locker(vm); - auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); - - JSValue value = deserialize(*lexicalGlobalObject, lexicalGlobalObject); - if (scope.exception()) [[unlikely]] { - if (exception) - *exception = toRef(lexicalGlobalObject, scope.exception()->value()); - (void)scope.tryClearException(); - return nullptr; - } - ASSERT(value); - return toRef(lexicalGlobalObject, value); -} - -Ref -SerializedScriptValue::nullValue() -{ - return adoptRef(*new SerializedScriptValue(Vector())); -} - -uint32_t SerializedScriptValue::wireFormatVersion() -{ - return CurrentVersion; -} - -// Vector SerializedScriptValue::blobURLs() const -// { -// return m_blobHandles.map([](auto& handle) { -// return handle.url().string().isolatedCopy(); -// }); -// } - -// void SerializedScriptValue::writeBlobsToDiskForIndexedDB(CompletionHandler&& completionHandler) -// { -// ASSERT(isMainThread()); -// ASSERT(hasBlobURLs()); - -// blobRegistry().writeBlobsToTemporaryFilesForIndexedDB(blobURLs(), [completionHandler = WTF::move(completionHandler), this, protectedThis = Ref { *this }](auto&& blobFilePaths) mutable { -// ASSERT(isMainThread()); - -// if (blobFilePaths.isEmpty()) { -// // We should have successfully written blobs to temporary files. -// // If we failed, then we can't successfully store this record. -// completionHandler({}); -// return; -// } - -// ASSERT(m_blobHandles.size() == blobFilePaths.size()); - -// completionHandler({ *this, blobURLs(), blobFilePaths }); -// }); -// } - -// IDBValue SerializedScriptValue::writeBlobsToDiskForIndexedDBSynchronously() -// { -// ASSERT(!isMainThread()); - -// BinarySemaphore semaphore; -// IDBValue value; -// callOnMainThread([this, &semaphore, &value] { -// writeBlobsToDiskForIndexedDB([&semaphore, &value](IDBValue&& result) { -// ASSERT(isMainThread()); -// value.setAsIsolatedCopy(result); - -// semaphore.signal(); -// }); -// }); -// semaphore.wait(); - -// return value; -// } } // namespace WebCore diff --git a/src/jsc/bindings/webcore/SerializedScriptValue.h b/src/jsc/bindings/webcore/SerializedScriptValue.h index 51e018628742..78347c7980c3 100644 --- a/src/jsc/bindings/webcore/SerializedScriptValue.h +++ b/src/jsc/bindings/webcore/SerializedScriptValue.h @@ -27,8 +27,6 @@ #pragma once #include "root.h" -// #include "Blob.h" -// #include "DetachedRTCDataChannel.h" #include "ExceptionOr.h" #include #include @@ -41,14 +39,6 @@ #include #include "JavaScriptCore/WasmModule.h" -#if ENABLE(WEB_CODECS) -#include "WebCodecsEncodedVideoChunk.h" -#include "WebCodecsVideoFrame.h" -#endif - -typedef const struct OpaqueJSContext* JSContextRef; -typedef const struct OpaqueJSValue* JSValueRef; - #if ENABLE(WEBASSEMBLY) namespace JSC { namespace Wasm { @@ -89,12 +79,7 @@ enum class FastPath : uint8_t { DenseArray, }; -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) -class DetachedOffscreenCanvas; -#endif -// class IDBValue; class MessagePort; -// class ImageBitmapBacking; class CloneSerializer; class FragmentedSharedBuffer; enum class SerializationReturnCode; @@ -124,14 +109,11 @@ class SerializedScriptValue : public ThreadSafeRefCounted static SYSV_ABI bool isTransferable(JSC::JSGlobalObject* globalObject, JSC::JSValue value); WEBCORE_EXPORT static ExceptionOr> create(JSC::JSGlobalObject&, JSC::JSValue, Vector>&& transfer, Vector>&, SerializationForStorage = SerializationForStorage::No, SerializationContext = SerializationContext::Default, SerializationForCrossProcessTransfer = SerializationForCrossProcessTransfer::No); - // WEBCORE_EXPORT static ExceptionOr> create(JSC::JSGlobalObject&, JSC::JSValue, Vector>&& transfer, SerializationForStorage = SerializationForStorage::No, SerializationContext = SerializationContext::Default); WEBCORE_EXPORT static RefPtr create(JSC::JSGlobalObject&, JSC::JSValue, SerializationForStorage = SerializationForStorage::No, SerializationErrorMode = SerializationErrorMode::Throwing, SerializationContext = SerializationContext::Default, SerializationForCrossProcessTransfer = SerializationForCrossProcessTransfer::No); static RefPtr convert(JSC::JSGlobalObject& globalObject, JSC::JSValue value) { return create(globalObject, value, SerializationForStorage::Yes); } - WEBCORE_EXPORT static RefPtr create(StringView); - // Fast path for postMessage with pure strings static Ref createStringFastPath(const String& string); @@ -148,102 +130,32 @@ class SerializedScriptValue : public ThreadSafeRefCounted // Fast path for postMessage with dense arrays containing simple objects static Ref createDenseArrayFastPath(WTF::FixedVector&& elements); - static Ref nullValue(); - WEBCORE_EXPORT JSC::JSValue deserialize(JSC::JSGlobalObject&, JSC::JSGlobalObject*, SerializationErrorMode = SerializationErrorMode::Throwing, bool* didFail = nullptr); WEBCORE_EXPORT JSC::JSValue deserialize(JSC::JSGlobalObject&, JSC::JSGlobalObject*, const Vector>&, SerializationErrorMode = SerializationErrorMode::Throwing, bool* didFail = nullptr); JSC::JSValue deserialize(JSC::JSGlobalObject&, JSC::JSGlobalObject*, const Vector>&, const Vector& blobURLs, const Vector& blobFilePaths, SerializationErrorMode = SerializationErrorMode::Throwing, bool* didFail = nullptr); - // JSC::JSValue deserialize(JSC::JSGlobalObject&, JSC::JSGlobalObject*, const Vector& blobURLs, const Vector& blobFilePaths, SerializationErrorMode = SerializationErrorMode::Throwing, bool* didFail = nullptr); - - static uint32_t wireFormatVersion(); - - WEBCORE_EXPORT String toString() const; WEBCORE_EXPORT Ref toArrayBuffer(); static JSC::JSValue fromArrayBuffer(JSC::JSGlobalObject&, JSC::JSGlobalObject*, JSC::ArrayBuffer* arrayBuffer, size_t byteOffset = 0, size_t maxByteLength = 0, SerializationErrorMode = SerializationErrorMode::Throwing, bool* didFail = nullptr); - // API implementation helpers. These don't expose special behavior for ArrayBuffers or MessagePorts. - WEBCORE_EXPORT static RefPtr create(JSContextRef, JSValueRef, JSValueRef* exception); - WEBCORE_EXPORT JSValueRef deserialize(JSContextRef, JSValueRef* exception); - - // bool hasBlobURLs() const { return !m_blobHandles.isEmpty(); } - - // Vector blobURLs() const; - // Vector blobHandles() const { return crossThreadCopy(m_blobHandles); } - // void writeBlobsToDiskForIndexedDB(CompletionHandler&&); - // IDBValue writeBlobsToDiskForIndexedDBSynchronously(); static Ref createFromWireBytes(Vector&& data) { return adoptRef(*new SerializedScriptValue(WTF::move(data))); } const Vector& wireBytes() const { return m_data; } - template void encode(Encoder&) const; - template static RefPtr decode(Decoder&); - size_t memoryCost() const { return m_memoryCost; } WEBCORE_EXPORT ~SerializedScriptValue(); private: - // static ExceptionOr> create(JSC::JSGlobalObject&, JSC::JSValue, Vector>&& transfer, Vector>&, SerializationForStorage, SerializationErrorMode, SerializationContext); - // WEBCORE_EXPORT SerializedScriptValue(Vector&&, std::unique_ptr&& = nullptr - // #if ENABLE(WEB_RTC) - // , - // Vector>&& = {} - // #endif - // #if ENABLE(WEB_CODECS) - // , - // Vector>&& = {}, Vector&& = {} - // #endif - // ); static ExceptionOr> create(JSC::JSGlobalObject&, JSC::JSValue, Vector>&& transfer, Vector>&, SerializationForStorage, SerializationErrorMode, SerializationContext, SerializationForCrossProcessTransfer); - WEBCORE_EXPORT SerializedScriptValue(Vector&&, std::unique_ptr&& = nullptr -#if ENABLE(WEB_RTC) - , - Vector>&& = {} -#endif -#if ENABLE(WEB_CODECS) - , - Vector>&& = {}, Vector&& = {} -#endif - ); + WEBCORE_EXPORT SerializedScriptValue(Vector&&, std::unique_ptr&& = nullptr); - // SerializedScriptValue(Vector&&, Vector&& blobHandles, std::unique_ptr, std::unique_ptr sharedBuffers, Vector>&& backingStores - // #if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - // , - // Vector>&& = {} - // #endif - // #if ENABLE(WEB_RTC) - // , - // Vector>&& = {} - // #endif - // #if ENABLE(WEBASSEMBLY) - // , - // std::unique_ptr = nullptr, std::unique_ptr = nullptr - // #endif - // #if ENABLE(WEB_CODECS) - // , - // Vector>&& = {}, Vector&& = {} - // #endif - // ); SerializedScriptValue(Vector&&, std::unique_ptr, std::unique_ptr sharedBuffers -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - , - Vector>&& = {} -#endif -#if ENABLE(WEB_RTC) - , - Vector>&& = {} -#endif #if ENABLE(WEBASSEMBLY) , std::unique_ptr = nullptr, std::unique_ptr = nullptr -#endif -#if ENABLE(WEB_CODECS) - , - Vector>&& = {}, Vector&& = {} #endif ); @@ -264,22 +176,10 @@ class SerializedScriptValue : public ThreadSafeRefCounted // Raw `*mut BlockList` pointers whose refcount was bumped at serialize // time so they outlive the wire buffer; released in the destructor. Vector m_serializedBlockListRefs; - // Vector> m_backingStores; -#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS) - Vector> m_detachedOffscreenCanvases; -#endif -#if ENABLE(WEB_RTC) - Vector> m_detachedRTCDataChannels; -#endif #if ENABLE(WEBASSEMBLY) std::unique_ptr m_wasmModulesArray; std::unique_ptr m_wasmMemoryHandlesArray; #endif -#if ENABLE(WEB_CODECS) - Vector> m_serializedVideoChunks; - Vector m_serializedVideoFrames; -#endif - // Vector m_blobHandles; // Fast path for postMessage with pure strings - avoids serialization overhead String m_fastPathString; @@ -299,115 +199,4 @@ class SerializedScriptValue : public ThreadSafeRefCounted FixedVector m_denseArrayElements {}; }; -template -void SerializedScriptValue::encode(Encoder& encoder) const -{ - encoder << m_data; - - auto hasArray = m_arrayBufferContentsArray && m_arrayBufferContentsArray->size(); - encoder << hasArray; - - if (hasArray) { - encoder << static_cast(m_arrayBufferContentsArray->size()); - for (const auto& arrayBufferContents : *m_arrayBufferContentsArray) - encoder << std::span(reinterpret_cast(arrayBufferContents.data()), arrayBufferContents.sizeInBytes()); - } - -#if ENABLE(WEB_RTC) - encoder << static_cast(m_detachedRTCDataChannels.size()); - for (const auto& channel : m_detachedRTCDataChannels) - encoder << *channel; -#endif - -#if ENABLE(WEB_CODECS) - encoder << static_cast(m_serializedVideoChunks.size()); - for (const auto& videoChunk : m_serializedVideoChunks) - encoder << videoChunk->data(); - - // FIXME: encode video frames -#endif -} - -template -RefPtr SerializedScriptValue::decode(Decoder& decoder) -{ - Vector data; - if (!decoder.decode(data)) - return nullptr; - - bool hasArray; - if (!decoder.decode(hasArray)) - return nullptr; - - std::unique_ptr arrayBufferContentsArray; - if (hasArray) { - uint64_t arrayLength; - if (!decoder.decode(arrayLength)) - return nullptr; - ASSERT(arrayLength); - - arrayBufferContentsArray = makeUnique(); - while (arrayLength--) { - std::span data; - if (!decoder.decode(data)) - return nullptr; - - auto buffer = Gigacage::tryMalloc(Gigacage::Primitive, data.size_bytes()); - if (!buffer) - return nullptr; - - static_assert(sizeof(std::span::element_type) == 1); - memcpy(buffer, data.data(), data.size_bytes()); - JSC::ArrayBufferDestructorFunction destructor = ArrayBuffer::primitiveGigacageDestructor(); - arrayBufferContentsArray->append({ buffer, data.size_bytes(), std::nullopt, WTF::move(destructor) }); - } - } - -#if ENABLE(WEB_RTC) - uint64_t detachedRTCDataChannelsSize; - if (!decoder.decode(detachedRTCDataChannelsSize)) - return nullptr; - - Vector> detachedRTCDataChannels; - while (detachedRTCDataChannelsSize--) { - std::optional detachedRTCDataChannel; - decoder >> detachedRTCDataChannel; - if (!detachedRTCDataChannel) - return nullptr; - detachedRTCDataChannels.append(makeUnique(WTF::move(*detachedRTCDataChannel))); - } -#endif -#if ENABLE(WEB_CODECS) - uint64_t serializedVideoChunksSize; - if (!decoder.decode(serializedVideoChunksSize)) - return nullptr; - - Vector> serializedVideoChunks; - while (serializedVideoChunksSize--) { - std::optional videoChunkData; - decoder >> videoChunkData; - if (!videoChunkData) - return nullptr; - serializedVideoChunks.append(WebCodecsEncodedVideoChunkStorage::create(WTF::move(*videoChunkData))); - } - // FIXME: decode video frames - Vector serializedVideoFrames; -#endif - - return adoptRef(*new SerializedScriptValue(WTF::move(data), WTF::move(arrayBufferContentsArray) -#if ENABLE(WEB_RTC) - , - WTF::move(detachedRTCDataChannels) -#endif -#if ENABLE(WEB_CODECS) - , - WTF::move(serializedVideoChunks) -#endif -#if ENABLE(WEB_CODECS) - , - WTF::move(serializedVideoFrames) -#endif - )); -} - } diff --git a/src/jsc/bindings/webcore/WebSocket.cpp b/src/jsc/bindings/webcore/WebSocket.cpp index d4147507fa13..2ac239a801b2 100644 --- a/src/jsc/bindings/webcore/WebSocket.cpp +++ b/src/jsc/bindings/webcore/WebSocket.cpp @@ -38,29 +38,11 @@ #include "ZigGeneratedClasses.h" #include "CloseEvent.h" #include -// #include "ContentSecurityPolicy.h" -// #include "DOMWindow.h" -// #include "Document.h" #include "Event.h" #include "EventListener.h" #include "EventNames.h" -// #include "Frame.h" -// #include "FrameLoader.h" -// #include "FrameLoaderClient.h" -// #include "InspectorInstrumentation.h" -// #include "Logging.h" #include "MessageEvent.h" -// #include "MixedContentChecker.h" -// #include "ResourceLoadObserver.h" -// #include "ScriptController.h" #include "ScriptExecutionContext.h" -// #include "SecurityOrigin.h" -// #include "SocketProvider.h" -// #include "ThreadableWebSocketChannel.h" -// #include "WebSocketChannel.h" -// #include "WorkerGlobalScope.h" -// #include "WorkerLoaderProxy.h" -// #include "WorkerThread.h" #include #include #include @@ -68,7 +50,6 @@ #include #include #include -// #include #include #include #include @@ -78,10 +59,6 @@ #include "ErrorEvent.h" #include "WebSocketDeflate.h" -// #if USE(WEB_THREAD) -// #include "WebCoreThreadRun.h" -// #endif - namespace WebCore { WTF_MAKE_TZONE_ALLOCATED_IMPL(WebSocket); extern "C" int Bun__getTLSRejectUnauthorizedValue(); @@ -228,14 +205,6 @@ WebSocket::~WebSocket() Bun__WebSocketClientTLS__finalize(reinterpret_cast(this->m_connectedWebSocket.clientSSL)); break; } - // case ConnectedWebSocketKind::Server: { - // this->m_connectedWebSocket.server->end(None); - // break; - // } - // case ConnectedWebSocketKind::ServerSSL: { - // this->m_connectedWebSocket.serverSSL->end(None); - // break; - // } default: { break; } @@ -342,23 +311,6 @@ ExceptionOr> WebSocket::create(ScriptExecutionContext& context, c return socket; } -ExceptionOr> WebSocket::create(ScriptExecutionContext& context, const String& url, const Vector& protocols, std::optional&& headers, bool rejectUnauthorized) -{ - if (url.isNull()) - return Exception { SyntaxError }; - - auto socket = adoptRef(*new WebSocket(context)); - socket->setRejectUnauthorized(rejectUnauthorized); - // socket->suspendIfNeeded(); - - auto result = socket->connect(url, protocols, WTF::move(headers)); - // auto result = socket->connect(url, protocols); - - if (result.hasException()) - return result.releaseException(); - - return socket; -} ExceptionOr> WebSocket::create(ScriptExecutionContext& context, const String& url, const Vector& protocols, std::optional&& headers, const String& proxyUrl, std::optional&& proxyHeaders, WebSocketSSLConfigPtr&& sslConfig, bool offerPerMessageDeflate) { @@ -406,16 +358,6 @@ ExceptionOr> WebSocket::create(ScriptExecutionContext& context, c return create(context, url, Vector { protocol }); } -ExceptionOr WebSocket::connect(const String& url) -{ - return connect(url, Vector {}, std::nullopt); -} - -ExceptionOr WebSocket::connect(const String& url, const String& protocol) -{ - return connect(url, Vector { protocol }, std::nullopt); -} - static String resourceName(const URL& url) { auto path = url.path(); @@ -436,11 +378,6 @@ static String hostName(const URL& url, bool secure) return url.host().convertToASCIILowercase(); } -ExceptionOr WebSocket::connect(const String& url, const Vector& protocols) -{ - return connect(url, protocols, std::nullopt); -} - ExceptionOr WebSocket::connect(const String& url, const Vector& protocols, std::optional&& headersInit) { return connect(url, protocols, WTF::move(headersInit), std::nullopt); @@ -503,30 +440,6 @@ ExceptionOr WebSocket::connect(const String& url, const Vector& pr return Exception { SyntaxError, makeString("URL has fragment component "_s, m_url.stringCenterEllipsizedToLength()) }; } - // ASSERT(context.contentSecurityPolicy()); - // auto& contentSecurityPolicy = *context.contentSecurityPolicy(); - - // contentSecurityPolicy.upgradeInsecureRequestIfNeeded(m_url, ContentSecurityPolicy::InsecureRequestType::Load); - - // if (!portAllowed(m_url)) { - // String message; - // if (m_url.port()) - // message = makeString("WebSocket port ", m_url.port().value(), " blocked"); - // else - // message = "WebSocket without port blocked"_s; - // context.addConsoleMessage(MessageSource::JS, MessageLevel::Error, message); - // failAsynchronously(); - // return {}; - // } - - // FIXME: Convert this to check the isolated world's Content Security Policy once webkit.org/b/104520 is solved. - // if (!context.shouldBypassMainWorldContentSecurityPolicy() && !contentSecurityPolicy.allowConnectToSource(m_url)) { - // m_state = CLOSED; - - // // FIXME: Should this be throwing an exception? - // return Exception { SecurityError }; - // } - // FIXME: There is a disagreement about restriction of subprotocols between WebSocket API and hybi-10 protocol // draft. The former simply says "only characters in the range U+0021 to U+007E are allowed," while the latter // imposes a stricter rule: "the elements MUST be non-empty strings with characters as defined in [RFC2616], @@ -552,20 +465,6 @@ ExceptionOr WebSocket::connect(const String& url, const Vector& pr } } - // RunLoop::main().dispatch([targetURL = m_url.isolatedCopy(), mainFrameURL = context.url().isolatedCopy()]() { - // ResourceLoadObserver::shared().logWebSocketLoading(targetURL, mainFrameURL); - // }); - - // if (is(context)) { - // Document& document = downcast(context); - // RefPtr frame = document.frame(); - // // FIXME: make the mixed content check equivalent to the non-document mixed content check currently in WorkerThreadableWebSocketChannel::Bridge::connect() - // if (!frame || !MixedContentChecker::canRunInsecureContent(*frame, document.securityOrigin(), m_url)) { - // failAsynchronously(); - // return { }; - // } - // } - String protocolString; if (!protocols.isEmpty()) protocolString = joinStrings(protocols, subprotocolSeparator()); @@ -776,19 +675,6 @@ ExceptionOr WebSocket::connect(const String& url, const Vector& pr } m_state = CONNECTING; - - // #if ENABLE(INTELLIGENT_TRACKING_PREVENTION) - // auto reportRegistrableDomain = [domain = RegistrableDomain(m_url).isolatedCopy()](auto& context) mutable { - // if (auto* frame = downcast(context).frame()) - // frame->loader().client().didLoadFromRegistrableDomain(WTF::move(domain)); - // }; - // if (is(context)) - // reportRegistrableDomain(context); - // else - // downcast(context).thread().workerLoaderProxy().postTaskToLoader(WTF::move(reportRegistrableDomain)); - // #endif - - // m_pendingActivity = makePendingActivity(*this); updateHasPendingActivity(); return {}; } @@ -888,16 +774,6 @@ void WebSocket::sendWebSocketData(const char* baseAddress, size_t length, const Bun__WebSocketClientTLS__writeBinaryData(this->m_connectedWebSocket.clientSSL, reinterpret_cast(baseAddress), length, static_cast(op)); break; } - // case ConnectedWebSocketKind::Server: { - // this->m_connectedWebSocket.server->send({ baseAddress, length }, opCode); - // this->m_bufferedAmount = this->m_connectedWebSocket.server->getBufferedAmount(); - // break; - // } - // case ConnectedWebSocketKind::ServerSSL: { - // this->m_connectedWebSocket.serverSSL->send({ baseAddress, length }, opCode); - // this->m_bufferedAmount = this->m_connectedWebSocket.serverSSL->getBufferedAmount(); - // break; - // } default: { RELEASE_ASSERT_NOT_REACHED(); } @@ -919,18 +795,6 @@ void WebSocket::sendWebSocketString(const String& message, const Opcode op) Bun__WebSocketClientTLS__writeString(this->m_connectedWebSocket.clientSSL, &zigStr, static_cast(op)); break; } - // case ConnectedWebSocketKind::Server: { - // auto utf8 = message.utf8(StrictConversionReplacingUnpairedSurrogatesWithFFFD); - // this->m_connectedWebSocket.server->send({ utf8.data(), utf8.length() }, uWS::OpCode::TEXT); - // this->m_bufferedAmount = this->m_connectedWebSocket.server->getBufferedAmount(); - // break; - // } - // case ConnectedWebSocketKind::ServerSSL: { - // auto utf8 = message.utf8(StrictConversionReplacingUnpairedSurrogatesWithFFFD); - // this->m_connectedWebSocket.serverSSL->send({ utf8.data(), utf8.length() }, uWS::OpCode::TEXT); - // this->m_bufferedAmount = this->m_connectedWebSocket.serverSSL->getBufferedAmount(); - // break; - // } default: { RELEASE_ASSERT_NOT_REACHED(); } @@ -1027,16 +891,6 @@ ExceptionOr WebSocket::close(std::optional optionalCode, c // this->m_bufferedAmount = this->m_connectedWebSocket.clientSSL->getBufferedAmount(); break; } - // case ConnectedWebSocketKind::Server: { - // this->m_connectedWebSocket.server->end(code, { utf8.data(), utf8.length() }); - // this->m_bufferedAmount = this->m_connectedWebSocket.server->getBufferedAmount(); - // break; - // } - // case ConnectedWebSocketKind::ServerSSL: { - // // this->m_connectedWebSocket.serverSSL->end(code, { utf8.data(), utf8.length() }); - // // this->m_bufferedAmount = this->m_connectedWebSocket.serverSSL->getBufferedAmount(); - // break; - // } default: { break; } @@ -1319,49 +1173,6 @@ ScriptExecutionContext* WebSocket::scriptExecutionContext() const return ContextDestructionObserver::scriptExecutionContext(); } -// void WebSocket::contextDestroyed() -// { -// LOG(Network, "WebSocket %p contextDestroyed()", this); -// ASSERT(!m_channel); -// ASSERT(m_state == CLOSED); -// // ActiveDOMObject::contextDestroyed(); -// } - -// void WebSocket::suspend(ReasonForSuspension reason) -// { -// // if (!m_channel) -// // return; - -// // if (reason == ReasonForSuspension::BackForwardCache) { -// // // This will cause didClose() to be called. -// // m_channel->fail("WebSocket is closed due to suspension."_s); -// // return; -// // } - -// // m_channel->suspend(); -// } - -// void WebSocket::resume() -// { -// // if (m_channel) -// // m_channel->resume(); -// } - -// void WebSocket::stop() -// { -// if (m_channel) -// m_channel->disconnect(); -// m_channel = nullptr; -// m_state = CLOSED; -// // ActiveDOMObject::stop(); -// // m_pendingActivity = nullptr; -// } - -// const char* WebSocket::activeDOMObjectName() const -// { -// return "WebSocket"; -// } - void WebSocket::didConnect() { // from new WebSocket() -> connect() @@ -1639,14 +1450,6 @@ void WebSocket::didReceiveClose(CleanStatus wasClean, unsigned short code, WTF:: } } -void WebSocket::didUpdateBufferedAmount(unsigned bufferedAmount) -{ - // LOG(Network, "WebSocket %p didUpdateBufferedAmount() New bufferedAmount is %u", this, bufferedAmount); - if (m_state == CLOSED) - return; - m_bufferedAmount = bufferedAmount; -} - void WebSocket::didStartClosingHandshake() { // LOG(Network, "WebSocket %p didStartClosingHandshake()", this); diff --git a/src/jsc/bindings/webcore/WebSocket.h b/src/jsc/bindings/webcore/WebSocket.h index c86298ffa0ab..41bebbec9929 100644 --- a/src/jsc/bindings/webcore/WebSocket.h +++ b/src/jsc/bindings/webcore/WebSocket.h @@ -117,7 +117,6 @@ class WebSocket final : public RefCounted, public EventTargetWithInli static ExceptionOr> create(ScriptExecutionContext&, const String& url, const String& protocol); static ExceptionOr> create(ScriptExecutionContext&, const String& url, const Vector& protocols); static ExceptionOr> create(ScriptExecutionContext&, const String& url, const Vector& protocols, std::optional&&); - static ExceptionOr> create(ScriptExecutionContext& context, const String& url, const Vector& protocols, std::optional&& headers, bool rejectUnauthorized); // With proxy support static ExceptionOr> create(ScriptExecutionContext&, const String& url, const Vector& protocols, std::optional&&, const String& proxyUrl, std::optional&& proxyHeaders, WebSocketSSLConfigPtr&& sslConfig, bool offerPerMessageDeflate); static ExceptionOr> create(ScriptExecutionContext& context, const String& url, const Vector& protocols, std::optional&& headers, bool rejectUnauthorized, const String& proxyUrl, std::optional&& proxyHeaders, WebSocketSSLConfigPtr&& sslConfig, bool offerPerMessageDeflate); @@ -153,9 +152,6 @@ class WebSocket final : public RefCounted, public EventTargetWithInli ProxyTLS // ws:// or wss:// through HTTPS proxy (TLS socket to proxy) }; - ExceptionOr connect(const String& url); - ExceptionOr connect(const String& url, const String& protocol); - ExceptionOr connect(const String& url, const Vector& protocols); ExceptionOr connect(const String& url, const Vector& protocols, std::optional&&); // Internal connect with proxy config (used by create() with proxy support) ExceptionOr connect(const String& url, const Vector& protocols, std::optional&&, std::optional&&); @@ -205,7 +201,6 @@ class WebSocket final : public RefCounted, public EventTargetWithInli void didFailWithErrorCode(Bun::WebSocketErrorCode code); void didReceiveMessage(String&& message); - void didReceiveData(const char* data, size_t length); void didReceiveBinaryData(const AtomString& eventName, const std::span binaryData); struct HandshakeRawHeader { const uint8_t* name_ptr; @@ -235,11 +230,6 @@ class WebSocket final : public RefCounted, public EventTargetWithInli m_offerPerMessageDeflate = offer; } - bool offerPerMessageDeflate() const - { - return m_offerPerMessageDeflate; - } - // C++-only callback mode. When set, didConnect/didReceiveMessage/ // didClose call these function pointers directly instead of building // Event objects and going through dispatchEvent. Fires synchronously @@ -309,7 +299,6 @@ class WebSocket final : public RefCounted, public EventTargetWithInli std::atomic m_hasPendingActivity { true }; explicit WebSocket(ScriptExecutionContext&); - explicit WebSocket(ScriptExecutionContext&, const String& url); EventTargetInterface eventTargetInterface() const final; @@ -317,7 +306,6 @@ class WebSocket final : public RefCounted, public EventTargetWithInli void derefEventTarget() final { deref(); } void didReceiveClose(CleanStatus wasClean, unsigned short code, WTF::String reason, bool isConnectionError = false); - void didUpdateBufferedAmount(unsigned bufferedAmount); void failConnectingWebSocket(); void sendWebSocketString(const String& message, const Opcode opcode); @@ -355,10 +343,7 @@ class WebSocket final : public RefCounted, public EventTargetWithInli // upgrade client in connect(); freed by ~WebSocketSSLConfigPtr otherwise). WebSocketSSLConfigPtr m_sslConfig; - bool m_dispatchedErrorEvent { false }; - NativeCallbacks m_native; - // RefPtr> m_pendingActivity; }; } // namespace WebCore diff --git a/src/jsc/bindings/windows/rescle.cpp b/src/jsc/bindings/windows/rescle.cpp index a3171b4eaaa4..99eeeabf2898 100644 --- a/src/jsc/bindings/windows/rescle.cpp +++ b/src/jsc/bindings/windows/rescle.cpp @@ -109,15 +109,6 @@ inline T round(T value, int modula = 4) return value + ((value % modula > 0) ? (modula - value % modula) : 0); } -std::wstring ReadFileToString(const wchar_t* filename) -{ - std::wifstream wif(filename); - wif.imbue(std::locale(std::locale::empty(), new std::codecvt_utf8)); - std::wstringstream wss; - wss << wif.rdbuf(); - return wss.str(); -} - class ScopedFile { public: ScopedFile(const WCHAR* path) @@ -466,34 +457,11 @@ bool ResourceUpdater::Load(const WCHAR* filename) EnumResourceNamesW(module_, RT_VERSION, OnEnumResourceName, reinterpret_cast(this)); EnumResourceNamesW(module_, RT_GROUP_ICON, OnEnumResourceName, reinterpret_cast(this)); EnumResourceNamesW(module_, RT_ICON, OnEnumResourceName, reinterpret_cast(this)); - EnumResourceNamesW(module_, RT_MANIFEST, OnEnumResourceManifest, reinterpret_cast(this)); EnumResourceNamesW(module_, RT_RCDATA, OnEnumResourceName, reinterpret_cast(this)); return true; } -bool ResourceUpdater::SetExecutionLevel(const WCHAR* value) -{ - executionLevel_ = value; - return true; -} - -bool ResourceUpdater::IsExecutionLevelSet() -{ - return !executionLevel_.empty(); -} - -bool ResourceUpdater::SetApplicationManifest(const WCHAR* value) -{ - applicationManifestPath_ = value; - return true; -} - -bool ResourceUpdater::IsApplicationManifestSet() -{ - return !applicationManifestPath_.empty(); -} - bool ResourceUpdater::SetVersionString(WORD languageId, const WCHAR* name, const WCHAR* value) { std::wstring nameStr(name); @@ -523,32 +491,6 @@ bool ResourceUpdater::SetVersionString(const WCHAR* name, const WCHAR* value) return SetVersionString(langId, name, value); } -const WCHAR* ResourceUpdater::GetVersionString(WORD languageId, const WCHAR* name) -{ - std::wstring nameStr(name); - - const auto& stringTables = versionStampMap_[languageId].stringTables; - for (const auto& j : stringTables) { - const auto& stringPairs = j.strings; - for (const auto& k : stringPairs) { - if (k.first == nameStr) { - return k.second.c_str(); - } - } - } - - return NULL; -} - -const WCHAR* ResourceUpdater::GetVersionString(const WCHAR* name) -{ - if (versionStampMap_.empty()) { - return NULL; - } else { - return GetVersionString(versionStampMap_.begin()->first, name); - } -} - bool ResourceUpdater::SetProductVersion(WORD languageId, UINT id, unsigned short v1, unsigned short v2, unsigned short v3, unsigned short v4) { VersionInfo& versionInfo = versionStampMap_[languageId]; @@ -592,95 +534,6 @@ bool ResourceUpdater::SetFileVersion(unsigned short v1, unsigned short v2, unsig return SetFileVersion(langId, 1, v1, v2, v3, v4); } -bool ResourceUpdater::ChangeString(WORD languageId, UINT id, const WCHAR* value) -{ - StringTable& table = stringTableMap_[languageId]; - - UINT blockId = id / 16; - if (table.find(blockId) == table.end()) { - // Fill the table until we reach the block. - for (size_t i = table.size(); i <= blockId; ++i) { - table[i] = std::vector(16); - } - } - - assert(table[blockId].size() == 16); - UINT blockIndex = id % 16; - table[blockId][blockIndex] = value; - - return true; -} - -bool ResourceUpdater::ChangeString(UINT id, const WCHAR* value) -{ - LANGID langId = stringTableMap_.empty() ? kLangEnUs - : stringTableMap_.begin()->first; - return ChangeString(langId, id, value); -} - -bool ResourceUpdater::ChangeRcData(UINT id, const WCHAR* pathToResource) -{ - auto rcDataLngPairIt = std::find_if(rcDataLngMap_.begin(), rcDataLngMap_.end(), [=](const auto& rcDataLngPair) { - return rcDataLngPair.second.find(id) != rcDataLngPair.second.end(); - }); - - if (rcDataLngPairIt == rcDataLngMap_.end()) { - fprintf(stderr, "Cannot find RCDATA with id '%u'\n", id); - return false; - } - - wchar_t abspath[MAX_PATH] = { 0 }; - const auto filePath = _wfullpath(abspath, pathToResource, MAX_PATH) ? abspath : pathToResource; - ScopedFile newRcDataFile(filePath); - if (newRcDataFile == INVALID_HANDLE_VALUE) { - fprintf(stderr, "Cannot open new data file '%ws'\n", filePath); - return false; - } - - const auto dwFileSize = GetFileSize(newRcDataFile, NULL); - if (dwFileSize == INVALID_FILE_SIZE) { - fprintf(stderr, "Cannot get file size for '%ws'\n", filePath); - return false; - } - - auto& rcData = rcDataLngPairIt->second[id]; - rcData.clear(); - rcData.resize(dwFileSize); - - DWORD dwBytesRead { 0 }; - if (!ReadFile(newRcDataFile, rcData.data(), dwFileSize, &dwBytesRead, NULL)) { - fprintf(stderr, "Cannot read file '%ws'\n", filePath); - return false; - } - - return true; -} - -const WCHAR* ResourceUpdater::GetString(WORD languageId, UINT id) -{ - StringTable& table = stringTableMap_[languageId]; - - UINT blockId = id / 16; - if (table.find(blockId) == table.end()) { - // Fill the table until we reach the block. - for (size_t i = table.size(); i <= blockId; ++i) { - table[i] = std::vector(16); - } - } - - assert(table[blockId].size() == 16); - UINT blockIndex = id % 16; - - return table[blockId][blockIndex].c_str(); -} - -const WCHAR* ResourceUpdater::GetString(UINT id) -{ - LANGID langId = stringTableMap_.empty() ? kLangEnUs - : stringTableMap_.begin()->first; - return GetString(langId, id); -} - bool ResourceUpdater::SetIcon(const WCHAR* path, const LANGID& langId, UINT iconBundle) { @@ -786,75 +639,6 @@ bool ResourceUpdater::Commit() } } - // update the execution level - if (applicationManifestPath_.empty() && !executionLevel_.empty()) { - // string replace with requested executionLevel - std::wstring::size_type pos = 0u; - while ((pos = manifestString_.find(originalExecutionLevel_, pos)) != std::string::npos) { - manifestString_.replace(pos, originalExecutionLevel_.length(), executionLevel_); - pos += executionLevel_.length(); - } - - // clean old padding and add new padding, ensuring that the size is a multiple of 4 - std::wstring::size_type padPos = manifestString_.find(L""); - // trim anything after the , 11 being the length of (ie, remove old padding) - std::wstring trimmedStr = manifestString_.substr(0, padPos + 11); - std::wstring padding = L"\n"; - - int offset = (trimmedStr.length() + padding.length()) % 4; - // multiple X by the number in offset - pos = 0u; - for (int posCount = 0; posCount < offset; posCount = posCount + 1) { - if ((pos = padding.find(L"X", pos)) != std::string::npos) { - padding.replace(pos, 1, L"XX"); - pos += executionLevel_.length(); - } - } - - // convert the wchar back into char, so that it encodes correctly for Windows to read the XML. - std::wstring stringSectionW = trimmedStr + padding; - std::wstring_convert, wchar_t> converter; - std::string stringSection = converter.to_bytes(stringSectionW); - - if (!UpdateResourceW(ru.Get(), RT_MANIFEST, MAKEINTRESOURCEW(1), - kLangEnUs, // this is hardcoded at 1033, ie, en-us, as that is what RT_MANIFEST default uses - &stringSection.at(0), sizeof(char) * stringSection.size())) { - return false; - } - } - - // load file contents and replace the manifest - if (!applicationManifestPath_.empty()) { - std::wstring fileContents = ReadFileToString(applicationManifestPath_.c_str()); - - // clean old padding and add new padding, ensuring that the size is a multiple of 4 - std::wstring::size_type padPos = fileContents.find(L""); - // trim anything after the , 11 being the length of (ie, remove old padding) - std::wstring trimmedStr = fileContents.substr(0, padPos + 11); - std::wstring padding = L"\n"; - - int offset = (trimmedStr.length() + padding.length()) % 4; - // multiple X by the number in offset - std::wstring::size_type pos = 0u; - for (int posCount = 0; posCount < offset; posCount = posCount + 1) { - if ((pos = padding.find(L"X", pos)) != std::string::npos) { - padding.replace(pos, 1, L"XX"); - pos += executionLevel_.length(); - } - } - - // convert the wchar back into char, so that it encodes correctly for Windows to read the XML. - std::wstring stringSectionW = fileContents + padding; - std::wstring_convert, wchar_t> converter; - std::string stringSection = converter.to_bytes(stringSectionW); - - if (!UpdateResourceW(ru.Get(), RT_MANIFEST, MAKEINTRESOURCEW(1), - kLangEnUs, // this is hardcoded at 1033, ie, en-us, as that is what RT_MANIFEST default uses - &stringSection.at(0), sizeof(char) * stringSection.size())) { - return false; - } - } - // update string table. for (const auto& i : stringTableMap_) { for (const auto& j : i.second) { @@ -1015,47 +799,6 @@ BOOL CALLBACK ResourceUpdater::OnEnumResourceName(HMODULE hModule, LPCWSTR lpszT return TRUE; } -// static -// courtesy of http://stackoverflow.com/questions/420852/reading-an-applications-manifest-file -BOOL CALLBACK ResourceUpdater::OnEnumResourceManifest(HMODULE hModule, LPCTSTR lpType, LPWSTR lpName, LONG_PTR lParam) -{ - ResourceUpdater* instance = reinterpret_cast(lParam); - HRSRC hResInfo = FindResource(hModule, lpName, lpType); - DWORD cbResource = SizeofResource(hModule, hResInfo); - - HGLOBAL hResData = LoadResource(hModule, hResInfo); - const BYTE* pResource = (const BYTE*)LockResource(hResData); - - // FIXME(zcbenz): Do a real UTF string convertion. - int len = strlen(reinterpret_cast(pResource)); - std::wstring manifestStringLocal(pResource, pResource + len); - - // FIXME(zcbenz): Strip the BOM instead of doing string search. - size_t start = manifestStringLocal.find(L" 0) { - manifestStringLocal = manifestStringLocal.substr(start); - } - - // Support alternative formatting, such as using " vs ' and level="..." on another line - size_t found = manifestStringLocal.find(L"requestedExecutionLevel"); - size_t level = manifestStringLocal.find(L"level=\"", found); - size_t end = manifestStringLocal.find(L"\"", level + 7); - if (level < 0) { - level = manifestStringLocal.find(L"level=\'", found); - end = manifestStringLocal.find(L"\'", level + 7); - } - - instance->originalExecutionLevel_ = manifestStringLocal.substr(level + 7, end - level - 7); - - // also store original manifestString - instance->manifestString_ = manifestStringLocal; - - UnlockResource(hResData); - FreeResource(hResData); - - return TRUE; // Keep going -} - ScopedResourceUpdater::ScopedResourceUpdater(const WCHAR* filename, bool deleteOld) : handle_(BeginUpdateResourceW(filename, deleteOld)) { diff --git a/src/jsc/bindings/windows/rescle.h b/src/jsc/bindings/windows/rescle.h index 417de1dc0ddb..27561bec6777 100644 --- a/src/jsc/bindings/windows/rescle.h +++ b/src/jsc/bindings/windows/rescle.h @@ -49,18 +49,13 @@ #include #include // unique_ptr -#define RU_VS_COMMENTS L"Comments" #define RU_VS_COMPANY_NAME L"CompanyName" #define RU_VS_FILE_DESCRIPTION L"FileDescription" #define RU_VS_FILE_VERSION L"FileVersion" -#define RU_VS_INTERNAL_NAME L"InternalName" #define RU_VS_LEGAL_COPYRIGHT L"LegalCopyright" -#define RU_VS_LEGAL_TRADEMARKS L"LegalTrademarks" #define RU_VS_ORIGINAL_FILENAME L"OriginalFilename" -#define RU_VS_PRIVATE_BUILD L"PrivateBuild" #define RU_VS_PRODUCT_NAME L"ProductName" #define RU_VS_PRODUCT_VERSION L"ProductVersion" -#define RU_VS_SPECIAL_BUILD L"SpecialBuild" namespace rescle { @@ -152,39 +147,23 @@ class ResourceUpdater { bool Load(const WCHAR* filename); bool SetVersionString(WORD languageId, const WCHAR* name, const WCHAR* value); bool SetVersionString(const WCHAR* name, const WCHAR* value); - const WCHAR* GetVersionString(WORD languageId, const WCHAR* name); - const WCHAR* GetVersionString(const WCHAR* name); bool SetProductVersion(WORD languageId, UINT id, unsigned short v1, unsigned short v2, unsigned short v3, unsigned short v4); bool SetProductVersion(unsigned short v1, unsigned short v2, unsigned short v3, unsigned short v4); bool SetFileVersion(WORD languageId, UINT id, unsigned short v1, unsigned short v2, unsigned short v3, unsigned short v4); bool SetFileVersion(unsigned short v1, unsigned short v2, unsigned short v3, unsigned short v4); - bool ChangeString(WORD languageId, UINT id, const WCHAR* value); - bool ChangeString(UINT id, const WCHAR* value); - bool ChangeRcData(UINT id, const WCHAR* pathToResource); - const WCHAR* GetString(WORD languageId, UINT id); - const WCHAR* GetString(UINT id); bool SetIcon(const WCHAR* path, const LANGID& langId, UINT iconBundle); bool SetIcon(const WCHAR* path, const LANGID& langId); bool SetIcon(const WCHAR* path); - bool SetExecutionLevel(const WCHAR* value); - bool IsExecutionLevelSet(); - bool SetApplicationManifest(const WCHAR* value); - bool IsApplicationManifestSet(); bool Commit(); private: bool SerializeStringTable(const StringValues& values, UINT blockId, std::vector* out); static BOOL CALLBACK OnEnumResourceName(HMODULE hModule, LPCWSTR lpszType, LPWSTR lpszName, LONG_PTR lParam); - static BOOL CALLBACK OnEnumResourceManifest(HMODULE hModule, LPCWSTR lpszType, LPWSTR lpszName, LONG_PTR lParam); static BOOL CALLBACK OnEnumResourceLanguage(HANDLE hModule, LPCWSTR lpszType, LPCWSTR lpszName, WORD wIDLanguage, LONG_PTR lParam); HMODULE module_; std::wstring filename_; - std::wstring executionLevel_; - std::wstring originalExecutionLevel_; - std::wstring applicationManifestPath_; - std::wstring manifestString_; VersionStampMap versionStampMap_; StringTableMap stringTableMap_; IconTableMap iconBundleMap_; diff --git a/src/standalone_graph/StandaloneModuleGraph.rs b/src/standalone_graph/StandaloneModuleGraph.rs index 1f9e960d7217..418e51410e92 100644 --- a/src/standalone_graph/StandaloneModuleGraph.rs +++ b/src/standalone_graph/StandaloneModuleGraph.rs @@ -1882,10 +1882,6 @@ pub fn to_executable( "Failed to extract executable for '{}'. The download may be incomplete.", target )), - crate::Error::UnsupportedTarget => CompileResult::fail_fmt(format_args!( - "Target '{}' is not supported", - target - )), _ => CompileResult::fail_fmt(format_args!( "Failed to download '{}': {}", target, diff --git a/src/standalone_graph/error.rs b/src/standalone_graph/error.rs index 58b56b14fa70..14ea8649d2ab 100644 --- a/src/standalone_graph/error.rs +++ b/src/standalone_graph/error.rs @@ -10,8 +10,6 @@ pub enum Error { InvalidResponse, #[error("ExtractionFailed")] ExtractionFailed, - #[error("UnsupportedTarget")] - UnsupportedTarget, #[error("InvalidSourceMap")] InvalidSourceMap, #[error("SourceMapTooLarge")] @@ -45,7 +43,6 @@ impl Error { Self::NetworkError => "NetworkError", Self::InvalidResponse => "InvalidResponse", Self::ExtractionFailed => "ExtractionFailed", - Self::UnsupportedTarget => "UnsupportedTarget", Self::InvalidSourceMap => "InvalidSourceMap", Self::SourceMapTooLarge => "SourceMapTooLarge", Self::Sys(e) => <&'static str>::from(e), diff --git a/src/threading/lib.rs b/src/threading/lib.rs index ee6283c2ed4e..a5fd555c77c9 100644 --- a/src/threading/lib.rs +++ b/src/threading/lib.rs @@ -29,11 +29,10 @@ pub use condition::{Condition, Condvar}; /// `Futex` re-exported as a capitalized module alias so callers can write /// `Futex::wait`, `Futex::wake`, `Futex::Deadline`. pub use futex as Futex; -pub use guarded::RawMutex; -pub use guarded::{Guarded, GuardedBy, GuardedLock}; +pub use guarded::{Guarded, GuardedLock}; pub use mutex::{Mutex, MutexGuard}; pub use reset_event::ResetEvent; -pub use rwlock::{RwLock, RwLockReadGuard, RwLockWriteGuard}; +pub use rwlock::RwLock; pub use semaphore::Semaphore; pub use thread_pool::ThreadPool; pub use unbounded_queue::{Link, Linked, UnboundedQueue}; diff --git a/test/internal/source-lints/dead-symbols-ssv-wasi-webcore.test.ts b/test/internal/source-lints/dead-symbols-ssv-wasi-webcore.test.ts new file mode 100644 index 000000000000..2932e6b3d6e8 --- /dev/null +++ b/test/internal/source-lints/dead-symbols-ssv-wasi-webcore.test.ts @@ -0,0 +1,157 @@ +// Guards against reintroduction of symbols removed as dead code from +// SerializedScriptValue, WebSocket, Performance, EventTarget, AbortSignal, +// the JSDOMConvert* template headers, windows/rescle, node:wasi, and a few +// small Rust crates. Each entry was verified to have zero callers across +// src/ and build/debug/codegen/ before deletion, and a full `bun bd` plus +// `bun run rust:check-all` (all targets) passes without them. This test +// fails if any of them reappear, e.g. via a merge that resurrects a stale +// file or a copy-paste from WebKit upstream. +// +// This is a source-tree lint: it reads files from src/ and does not touch the +// built binary, so it belongs in test/internal/source-lints/ per the README. + +import { expect, test } from "bun:test"; +import { readFileSync } from "node:fs"; +import path from "node:path"; + +const repoRoot = path.resolve(import.meta.dir, "..", "..", ".."); + +function src(p: string): string { + return readFileSync(path.join(repoRoot, p), "utf8"); +} + +function resurrected(checks: Array<[string, RegExp]>): string[] { + return checks.filter(([file, re]) => re.test(src(file))).map(([file, re]) => `${file}: ${re.source}`); +} + +test("dead SerializedScriptValue ENABLE() blocks and unused public methods do not reappear", () => { + // Bun's JSCOnly cmakeconfig.h sets ENABLE_OFFSCREEN_CANVAS_IN_WORKERS, + // ENABLE_WEB_RTC, ENABLE_WEB_CODECS, ENABLE_PREDEFINED_COLOR_SPACE_DISPLAY_P3 + // to 0 on every target; the referenced types (OffscreenCanvas, RTCCertificate, + // WebCodecsVideoFrame) have no headers under src/, so the guarded bodies could + // not compile if the macros flipped. The uncalled public methods were verified + // against src/ and build/debug/codegen/. + const checks: Array<[string, RegExp]> = [ + ["src/jsc/bindings/webcore/SerializedScriptValue.cpp", /ENABLE\(OFFSCREEN_CANVAS_IN_WORKERS\)/], + ["src/jsc/bindings/webcore/SerializedScriptValue.cpp", /ENABLE\(WEB_RTC\)/], + ["src/jsc/bindings/webcore/SerializedScriptValue.cpp", /ENABLE\(WEB_CODECS\)/], + ["src/jsc/bindings/webcore/SerializedScriptValue.cpp", /readRTCCertificate/], + ["src/jsc/bindings/webcore/SerializedScriptValue.cpp", /readOffscreenCanvas/], + ["src/jsc/bindings/webcore/SerializedScriptValue.cpp", /readWebCodecsVideoFrame/], + ["src/jsc/bindings/webcore/SerializedScriptValue.cpp", /SerializedScriptValue::nullValue/], + ["src/jsc/bindings/webcore/SerializedScriptValue.cpp", /SerializedScriptValue::toString/], + ["src/jsc/bindings/webcore/SerializedScriptValue.cpp", /SerializedScriptValue::wireFormatVersion/], + ["src/jsc/bindings/webcore/SerializedScriptValue.cpp", /CloneDeserializer::deserializeString/], + ["src/jsc/bindings/webcore/SerializedScriptValue.cpp", /blobFilePathForBlobURL/], + ["src/jsc/bindings/webcore/SerializedScriptValue.h", /ENABLE\(WEB_RTC\)/], + ["src/jsc/bindings/webcore/SerializedScriptValue.h", /static Ref nullValue\(\)/], + ["src/jsc/bindings/webcore/SerializedScriptValue.h", /static uint32_t wireFormatVersion\(\)/], + ["src/jsc/bindings/webcore/SerializedScriptValue.h", /void encode\(Encoder&\) const/], + ["src/jsc/bindings/webcore/SerializedScriptValue.h", /static RefPtr decode\(Decoder&/], + ]; + expect(resurrected(checks)).toEqual([]); +}); + +test("dead WebSocket create/connect overloads and commented-out WebKit blocks do not reappear", () => { + const checks: Array<[string, RegExp]> = [ + ["src/jsc/bindings/webcore/WebSocket.cpp", /ENABLE\(INTELLIGENT_TRACKING_PREVENTION\)/], + ["src/jsc/bindings/webcore/WebSocket.cpp", /MixedContentChecker/], + ["src/jsc/bindings/webcore/WebSocket.cpp", /WebSocket::didUpdateBufferedAmount/], + ["src/jsc/bindings/webcore/WebSocket.cpp", /ConnectedWebSocketKind::Server:/], + ["src/jsc/bindings/webcore/WebSocket.h", /void didReceiveData\(const char\*, size_t\);/], + ["src/jsc/bindings/webcore/WebSocket.h", /void didUpdateBufferedAmount\(unsigned/], + ["src/jsc/bindings/webcore/WebSocket.h", /WebSocket\(ScriptExecutionContext&, const String& url\);/], + ["src/jsc/bindings/webcore/WebSocket.h", /void connect\(const String& url\);/], + ["src/jsc/bindings/webcore/WebSocket.h", /void connect\(const String& url, const String& protocol\);/], + ]; + expect(resurrected(checks)).toEqual([]); +}); + +test("dead Performance/PerformanceObserver/EventTarget/AbortSignal members do not reappear", () => { + const checks: Array<[string, RegExp]> = [ + // addResourceTiming had no callers; Bun's fetch produces PerformanceResourceTiming + // via Performance::appendBufferedEntry / queueEntry directly. + ["src/jsc/bindings/webcore/Performance.cpp", /Performance::addResourceTiming/], + ["src/jsc/bindings/webcore/Performance.cpp", /Performance::isResourceTimingBufferFull/], + ["src/jsc/bindings/webcore/Performance.cpp", /Performance::allowHighPrecisionTime/], + ["src/jsc/bindings/webcore/Performance.cpp", /Performance::timeResolution/], + ["src/jsc/bindings/webcore/Performance.cpp", /relativeTimeFromTimeOriginInReducedResolution/], + ["src/jsc/bindings/webcore/Performance.cpp", /resourceTimingBufferFullTimerFired/], + ["src/jsc/bindings/webcore/Performance.h", /m_backupResourceTimingBuffer/], + ["src/jsc/bindings/webcore/Performance.h", /m_waitingForBackupBufferToBeProcessed/], + ["src/jsc/bindings/webcore/PerformanceObserver.h", /m_hasNavigationTiming/], + ["src/jsc/bindings/webcore/EventTarget.cpp", /static const AtomString& legacyType/], + ["src/jsc/bindings/webcore/EventTarget.cpp", /EventTarget::isPaymentRequest/], + ["src/jsc/bindings/webcore/EventTarget.h", /hasCapturingEventListeners/], + ["src/jsc/bindings/webcore/EventTarget.h", /void invalidateJSEventListeners\(JSC::JSObject\*\)/], + // signalFollow was unreferenced and the only writer of m_followingSignal; + // JSAbortSignalCustom's isFollowingSignal() check was therefore always false. + ["src/jsc/bindings/webcore/AbortSignal.cpp", /AbortSignal::signalFollow/], + ["src/jsc/bindings/webcore/AbortSignal.h", /m_followingSignal/], + ]; + expect(resurrected(checks)).toEqual([]); +}); + +test("dead JSDOMConvert* template specializations do not reappear", () => { + // IDLSequence is only instantiated with string/enum/interface/dictionary + // element types in Bun; none of the numeric specializations (nor the + // NumericSequenceConverter they dispatch to) are reachable. + const checks: Array<[string, RegExp]> = [ + ["src/jsc/bindings/webcore/JSDOMConvertSequences.h", /struct NumericSequenceConverter/], + ["src/jsc/bindings/webcore/JSDOMConvertSequences.h", /SequenceConverter/], + ["src/jsc/bindings/webcore/JSDOMConvertSequences.h", /SequenceConverter/], + ["src/jsc/bindings/webcore/JSDOMConvertSequences.h", /struct Converter>/], + ["src/jsc/bindings/webcore/JSDOMConvertStrings.h", /propertyNameToAtomString/], + ["src/jsc/bindings/webcore/JSDOMConvertStrings.h", /IDLLegacyNullToEmptyStringAdaptor/], + ["src/jsc/bindings/webcore/JSDOMConvertStrings.h", /IDLAtomStringAdaptor/], + ["src/jsc/bindings/webcore/JSDOMConvertStrings.h", /IDLAtomStringAdaptor/], + ["src/jsc/bindings/webcore/JSDOMConvertStrings.cpp", /valueToByteAtomString/], + ["src/jsc/bindings/webcore/JSDOMConvertStrings.cpp", /valueToUSVAtomString/], + ["src/jsc/bindings/webcore/JSDOMConvertRecord.h", /struct JSConverter>/], + ["src/jsc/bindings/webcore/JSDOMConvertUnion.h", /IDLAllowSharedAdaptor { + // The only Rust entry point (rescle__setWindowsMetadata) uses Load, SetIcon, + // SetVersionString, SetFileVersion, SetProductVersion, and Commit. All other + // ResourceUpdater public methods were unreachable. + const checks: Array<[string, RegExp]> = [ + ["src/jsc/bindings/windows/rescle.cpp", /ResourceUpdater::SetExecutionLevel/], + ["src/jsc/bindings/windows/rescle.cpp", /ResourceUpdater::SetApplicationManifest/], + ["src/jsc/bindings/windows/rescle.cpp", /ResourceUpdater::GetVersionString/], + ["src/jsc/bindings/windows/rescle.cpp", /ResourceUpdater::ChangeString/], + ["src/jsc/bindings/windows/rescle.cpp", /ResourceUpdater::ChangeRcData/], + ["src/jsc/bindings/windows/rescle.cpp", /ResourceUpdater::GetString/], + ["src/jsc/bindings/windows/rescle.cpp", /OnEnumResourceManifest/], + ["src/jsc/bindings/windows/rescle.h", /RU_VS_LEGAL_TRADEMARKS/], + ]; + expect(resurrected(checks)).toEqual([]); +}); + +test("dead wasi.ts bundle artifacts and debug scaffolding do not reappear", () => { + // The `= void 0` chains are esbuild/tsc emit artifacts from the original + // wasi-js npm bundle; every property is immediately re-assigned to its real + // value. initWasiFdInfo() was unreferenced debug code with console.log calls. + const checks: Array<[string, RegExp]> = [ + ["src/js/node/wasi.ts", /exports\.WASI_ENOMSG =\n/], + ["src/js/node/wasi.ts", /class extends Error \{\n\s+constructor\(signal\)/], + ["src/js/node/wasi.ts", /WASIKillError/], + ["src/js/node/wasi.ts", /SOCKET_DEFAULT_RIGHTS/], + ["src/js/node/wasi.ts", /initWasiFdInfo/], + ["src/js/node/wasi.ts", /if \(log\.enabled\)/], + ["src/js/thirdparty/ws.js", /secWebSocketExtensions/], + ]; + expect(resurrected(checks)).toEqual([]); +}); + +test("dead Rust http/threading/standalone_graph/bunfig items do not reappear", () => { + const checks: Array<[string, RegExp]> = [ + ["src/http/lib.rs", /const PRINT_EVERY: usize/], + ["src/threading/lib.rs", /RwLockReadGuard, RwLockWriteGuard/], + ["src/standalone_graph/error.rs", /UnsupportedTarget/], + ["src/bunfig/bunfig.rs", /pub use bun_options_types::offline_mode::OfflineMode/], + ]; + expect(resurrected(checks)).toEqual([]); +}); From b0031a6ab1e780b6565a02ce873f0be8d391c61c Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 30 Jul 2026 16:14:20 +0000 Subject: [PATCH 02/10] [autofix.ci] apply automated fixes --- src/jsc/bindings/webcore/SerializedScriptValue.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/jsc/bindings/webcore/SerializedScriptValue.cpp b/src/jsc/bindings/webcore/SerializedScriptValue.cpp index 06d604c26012..bebe18a93545 100644 --- a/src/jsc/bindings/webcore/SerializedScriptValue.cpp +++ b/src/jsc/bindings/webcore/SerializedScriptValue.cpp @@ -2270,7 +2270,7 @@ class CloneDeserializer : public CloneBase { return std::make_pair(jsNull(), SerializationReturnCode::UnspecifiedError); CloneDeserializer deserializer(lexicalGlobalObject, globalObject, messagePorts, arrayBufferContentsArray, std::span { buffer.begin(), buffer.end() }, blobURLs, blobFilePaths, sharedBuffers #if ENABLE(WEBASSEMBLY) - , + , wasmModules, wasmMemoryHandles #endif ); @@ -4752,10 +4752,10 @@ ExceptionOr> SerializedScriptValue::create(JSGlobalOb scope.releaseAssertNoException(); auto result = adoptRef(*new SerializedScriptValue(WTF::move(buffer), arrayBufferContentsArray.releaseReturnValue(), context == SerializationContext::WorkerPostMessage ? WTF::move(sharedBuffers) : nullptr #if ENABLE(WEBASSEMBLY) - , + , makeUnique(wasmModules), context == SerializationContext::WorkerPostMessage ? makeUnique(wasmMemoryHandles) : nullptr #endif - )); + )); result->m_serializedBlockListRefs = WTF::move(serializedBlockListRefs); return result; } From ae218828213a436a8f88efd7a5f876cd9f6cb0b8 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Thu, 30 Jul 2026 16:34:20 +0000 Subject: [PATCH 03/10] Address review: fix vacuous test regexes and finish transitive cascade Source-lint test: three WebSocket.h regexes did not match the pre-PR signatures (didReceiveData takes named params; connect returns ExceptionOr), so they were vacuous. Fixed to match the actual removed declarations; verified all 71 checks now match main and none match this branch. Finish the one-hop cascade for code this PR made dead: - Event.h: delete setType() (only callers were the removed legacyType fallback in fireEventListeners). - Performance.cpp: make timePrecision constexpr (only writer allowHighPrecisionTime() was removed); delete two commented-out hasNavigationTiming/addedNavigationTiming blocks that now referenced methods removed from PerformanceObserver.h; drop the now-unused PerformanceObserver& param from appendBufferedEntriesByType and update its one caller. - rescle.cpp: drop , , , includes whose only consumers were the removed ReadFileToString / ChangeString / GetString / ChangeRcData / manifest branches. --- src/jsc/bindings/webcore/Event.h | 1 - src/jsc/bindings/webcore/Performance.cpp | 22 ++----------------- src/jsc/bindings/webcore/Performance.h | 2 +- .../bindings/webcore/PerformanceObserver.cpp | 2 +- src/jsc/bindings/windows/rescle.cpp | 4 ---- .../dead-symbols-ssv-wasi-webcore.test.ts | 6 ++--- 6 files changed, 7 insertions(+), 30 deletions(-) diff --git a/src/jsc/bindings/webcore/Event.h b/src/jsc/bindings/webcore/Event.h index 346a59edd313..973c81bb9f23 100644 --- a/src/jsc/bindings/webcore/Event.h +++ b/src/jsc/bindings/webcore/Event.h @@ -72,7 +72,6 @@ class Event : public ScriptWrappable, public RefCounted { bool isInitialized() const { return m_isInitialized; } const AtomString& type() const { return m_type; } - void setType(const AtomString& type) { m_type = type; } EventTarget* target() const { return m_target.get(); } void setTarget(RefPtr&&); diff --git a/src/jsc/bindings/webcore/Performance.cpp b/src/jsc/bindings/webcore/Performance.cpp index f61144a4190e..4d91f0b5402b 100644 --- a/src/jsc/bindings/webcore/Performance.cpp +++ b/src/jsc/bindings/webcore/Performance.cpp @@ -58,7 +58,7 @@ namespace WebCore { WTF_MAKE_TZONE_ALLOCATED_IMPL(Performance); -static Seconds timePrecision { 1_ms }; +static constexpr Seconds timePrecision { 1_ms }; Performance::Performance(ScriptExecutionContext* context, MonotonicTime timeOrigin) : ContextDestructionObserver(context) @@ -197,21 +197,10 @@ Vector> Performance::getEntriesByName(const String& nam return entries; } -void Performance::appendBufferedEntriesByType(const String& entryType, Vector>& entries, PerformanceObserver& observer) const +void Performance::appendBufferedEntriesByType(const String& entryType, Vector>& entries) const { - // if (m_navigationTiming - // && entryType == "navigation"_s - // && !observer.hasNavigationTiming()) { - // entries.append(m_navigationTiming); - // observer.addedNavigationTiming(); - // } - if (entryType == "resource"_s) entries.appendVector(m_resourceTimingBuffer); - - // if (entryType == "paint"_s && m_firstContentfulPaint) - // entries.append(m_firstContentfulPaint); - if (m_userTiming) { if (entryType.isNull() || entryType == "mark"_s) entries.appendVector(m_userTiming->getMarks()); @@ -282,13 +271,6 @@ void Performance::removeAllObservers() void Performance::registerPerformanceObserver(PerformanceObserver& observer) { m_observers.add(&observer); - - // if (m_navigationTiming - // && observer.typeFilter().contains(PerformanceEntry::Type::Navigation) - // && !observer.hasNavigationTiming()) { - // observer.queueEntry(*m_navigationTiming); - // observer.addedNavigationTiming(); - // } } void Performance::unregisterPerformanceObserver(PerformanceObserver& observer) diff --git a/src/jsc/bindings/webcore/Performance.h b/src/jsc/bindings/webcore/Performance.h index 83dea5849f1f..6b44e874066a 100644 --- a/src/jsc/bindings/webcore/Performance.h +++ b/src/jsc/bindings/webcore/Performance.h @@ -93,7 +93,7 @@ class Performance final : public RefCounted, public ContextDestruct Vector> getEntries() const; Vector> getEntriesByType(const String& entryType) const; Vector> getEntriesByName(const String& name, const String& entryType) const; - void appendBufferedEntriesByType(const String& entryType, Vector>&, PerformanceObserver&) const; + void appendBufferedEntriesByType(const String& entryType, Vector>&) const; void clearResourceTimings(); void setResourceTimingBufferSize(unsigned); diff --git a/src/jsc/bindings/webcore/PerformanceObserver.cpp b/src/jsc/bindings/webcore/PerformanceObserver.cpp index 38aab5a09589..ae2acdf10c14 100644 --- a/src/jsc/bindings/webcore/PerformanceObserver.cpp +++ b/src/jsc/bindings/webcore/PerformanceObserver.cpp @@ -88,7 +88,7 @@ ExceptionOr PerformanceObserver::observe(Init&& init) if (init.buffered) { isBuffered = true; auto oldSize = m_entriesToDeliver.size(); - m_performance->appendBufferedEntriesByType(*init.type, m_entriesToDeliver, *this); + m_performance->appendBufferedEntriesByType(*init.type, m_entriesToDeliver); auto begin = m_entriesToDeliver.begin(); auto oldEnd = begin + oldSize; auto end = m_entriesToDeliver.end(); diff --git a/src/jsc/bindings/windows/rescle.cpp b/src/jsc/bindings/windows/rescle.cpp index 99eeeabf2898..fb2e88bdbb7e 100644 --- a/src/jsc/bindings/windows/rescle.cpp +++ b/src/jsc/bindings/windows/rescle.cpp @@ -32,13 +32,9 @@ // http://code.google.com/p/rescle/ #include "rescle.h" -#include #include #include // wstringstream #include // setw, setfill -#include -#include -#include namespace rescle { diff --git a/test/internal/source-lints/dead-symbols-ssv-wasi-webcore.test.ts b/test/internal/source-lints/dead-symbols-ssv-wasi-webcore.test.ts index 2932e6b3d6e8..ca506e20b791 100644 --- a/test/internal/source-lints/dead-symbols-ssv-wasi-webcore.test.ts +++ b/test/internal/source-lints/dead-symbols-ssv-wasi-webcore.test.ts @@ -58,11 +58,11 @@ test("dead WebSocket create/connect overloads and commented-out WebKit blocks do ["src/jsc/bindings/webcore/WebSocket.cpp", /MixedContentChecker/], ["src/jsc/bindings/webcore/WebSocket.cpp", /WebSocket::didUpdateBufferedAmount/], ["src/jsc/bindings/webcore/WebSocket.cpp", /ConnectedWebSocketKind::Server:/], - ["src/jsc/bindings/webcore/WebSocket.h", /void didReceiveData\(const char\*, size_t\);/], + ["src/jsc/bindings/webcore/WebSocket.h", /void didReceiveData\(const char\* data, size_t length\);/], ["src/jsc/bindings/webcore/WebSocket.h", /void didUpdateBufferedAmount\(unsigned/], ["src/jsc/bindings/webcore/WebSocket.h", /WebSocket\(ScriptExecutionContext&, const String& url\);/], - ["src/jsc/bindings/webcore/WebSocket.h", /void connect\(const String& url\);/], - ["src/jsc/bindings/webcore/WebSocket.h", /void connect\(const String& url, const String& protocol\);/], + ["src/jsc/bindings/webcore/WebSocket.h", /ExceptionOr connect\(const String& url\);/], + ["src/jsc/bindings/webcore/WebSocket.h", /ExceptionOr connect\(const String& url, const String& protocol\);/], ]; expect(resurrected(checks)).toEqual([]); }); From bfd38c61000ca01dc36f4ff322e167068723574e Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Thu, 30 Jul 2026 16:56:49 +0000 Subject: [PATCH 04/10] Performance: remove cascade orphans from addResourceTiming/isResourceTimingBufferFull removal m_resourceTimingBufferSize and m_resourceTimingBufferFullFlag became write-only once their sole readers were removed; drop the fields and their dead stores in clearResourceTimings/setResourceTimingBufferSize. Drop the ResourceTiming/ResourceResponse/PerformancePaintTiming forward-decls and the commented-out includes and member decls that were their only remaining references. --- src/jsc/bindings/webcore/Performance.cpp | 9 +-------- src/jsc/bindings/webcore/Performance.h | 9 --------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/src/jsc/bindings/webcore/Performance.cpp b/src/jsc/bindings/webcore/Performance.cpp index 4d91f0b5402b..2fa0abb1dbd0 100644 --- a/src/jsc/bindings/webcore/Performance.cpp +++ b/src/jsc/bindings/webcore/Performance.cpp @@ -42,14 +42,10 @@ #include "PerformanceEntry.h" #include "PerformanceMarkOptions.h" #include "PerformanceMeasureOptions.h" -// #include "PerformanceNavigation.h" -// #include "PerformanceNavigationTiming.h" #include "PerformanceObserver.h" -// #include "PerformancePaintTiming.h" #include "PerformanceResourceTiming.h" #include "PerformanceTiming.h" #include "PerformanceUserTiming.h" -// #include "ResourceResponse.h" #include "ScriptExecutionContext.h" #include #include "BunClientData.h" @@ -212,13 +208,10 @@ void Performance::appendBufferedEntriesByType(const String& entryType, Vector> Performance::mark(JSC::JSGlobalObject& globalObject, const String& markName, std::optional&& markOptions) diff --git a/src/jsc/bindings/webcore/Performance.h b/src/jsc/bindings/webcore/Performance.h index 6b44e874066a..3a0b069e8e10 100644 --- a/src/jsc/bindings/webcore/Performance.h +++ b/src/jsc/bindings/webcore/Performance.h @@ -68,10 +68,7 @@ class PerformanceMeasure; class PerformanceNavigation; class PerformanceNavigationTiming; class PerformanceObserver; -class PerformancePaintTiming; class PerformanceTiming; -class ResourceResponse; -class ResourceTiming; class ScriptExecutionContext; struct PerformanceMarkOptions; struct PerformanceMeasureOptions; @@ -144,18 +141,12 @@ class Performance final : public RefCounted, public ContextDestruct // mutable RefPtr m_navigation; mutable RefPtr m_timing; - // https://w3c.github.io/resource-timing/#extensions-performance-interface recommends size of 150. Vector> m_resourceTimingBuffer; - unsigned m_resourceTimingBufferSize { 150 }; - // https://w3c.github.io/resource-timing/#dfn-resource-timing-buffer-full-flag - bool m_resourceTimingBufferFullFlag { false }; bool m_hasScheduledTimingBufferDeliveryTask { false }; MonotonicTime m_timeOrigin; - // RefPtr m_navigationTiming; - // RefPtr m_firstContentfulPaint; std::unique_ptr m_userTiming; ListHashSet> m_observers; From ba206e3668623b99d869de9cdccfd1c949c84372 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Thu, 30 Jul 2026 17:07:29 +0000 Subject: [PATCH 05/10] source-lints: guard removed .h declarations for AbortSignal and rescle Add header-file checks alongside the .cpp checks so a reintroduced declaration (without the definition) still trips the lint. --- .../source-lints/dead-symbols-ssv-wasi-webcore.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/internal/source-lints/dead-symbols-ssv-wasi-webcore.test.ts b/test/internal/source-lints/dead-symbols-ssv-wasi-webcore.test.ts index ca506e20b791..856d6ff414cb 100644 --- a/test/internal/source-lints/dead-symbols-ssv-wasi-webcore.test.ts +++ b/test/internal/source-lints/dead-symbols-ssv-wasi-webcore.test.ts @@ -87,6 +87,7 @@ test("dead Performance/PerformanceObserver/EventTarget/AbortSignal members do no // signalFollow was unreferenced and the only writer of m_followingSignal; // JSAbortSignalCustom's isFollowingSignal() check was therefore always false. ["src/jsc/bindings/webcore/AbortSignal.cpp", /AbortSignal::signalFollow/], + ["src/jsc/bindings/webcore/AbortSignal.h", /void signalFollow\(AbortSignal&\)/], ["src/jsc/bindings/webcore/AbortSignal.h", /m_followingSignal/], ]; expect(resurrected(checks)).toEqual([]); @@ -126,6 +127,13 @@ test("dead windows/rescle.cpp resource-editing methods do not reappear", () => { ["src/jsc/bindings/windows/rescle.cpp", /ResourceUpdater::GetString/], ["src/jsc/bindings/windows/rescle.cpp", /OnEnumResourceManifest/], ["src/jsc/bindings/windows/rescle.h", /RU_VS_LEGAL_TRADEMARKS/], + ["src/jsc/bindings/windows/rescle.h", /bool SetExecutionLevel\(/], + ["src/jsc/bindings/windows/rescle.h", /bool SetApplicationManifest\(/], + ["src/jsc/bindings/windows/rescle.h", /GetVersionString\(/], + ["src/jsc/bindings/windows/rescle.h", /bool ChangeString\(/], + ["src/jsc/bindings/windows/rescle.h", /bool ChangeRcData\(/], + ["src/jsc/bindings/windows/rescle.h", /GetString\(/], + ["src/jsc/bindings/windows/rescle.h", /OnEnumResourceManifest/], ]; expect(resurrected(checks)).toEqual([]); }); From 071f23d7fa7a13cf09cde5b1ab5c0d617942e331 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Thu, 30 Jul 2026 17:28:14 +0000 Subject: [PATCH 06/10] JSDOMConvertNumbers/IDLTypes: remove cascade orphans from NumericSequenceConverter/LegacyNullToEmpty removal The five Converter convert(JSGlobalObject&, ThrowScope&, double) overloads existed only for the removed NumericSequenceConverter::convertArray (the removed FIXME above it documented that contract); the sibling convert(JSGlobalObject&, JSValue) overloads inline their own logic. IDLLegacyNullToEmpty{,Atom}StringAdaptor type tags in IDLTypes.h had no remaining references after their Converter<>/JSConverter<> specializations were removed from JSDOMConvertStrings.h. --- src/jsc/bindings/IDLTypes.h | 8 ----- .../bindings/webcore/JSDOMConvertNumbers.h | 30 ------------------- 2 files changed, 38 deletions(-) diff --git a/src/jsc/bindings/IDLTypes.h b/src/jsc/bindings/IDLTypes.h index ae6def884888..d73b46c47e2e 100644 --- a/src/jsc/bindings/IDLTypes.h +++ b/src/jsc/bindings/IDLTypes.h @@ -186,14 +186,6 @@ struct IDLByteString : IDLString { struct IDLUSVString : IDLString { }; -template struct IDLLegacyNullToEmptyStringAdaptor : IDLString { - using InnerType = T; -}; - -template struct IDLLegacyNullToEmptyAtomStringAdaptor : IDLString { - using InnerType = T; -}; - template struct IDLAtomStringAdaptor : IDLString { using InnerType = T; }; diff --git a/src/jsc/bindings/webcore/JSDOMConvertNumbers.h b/src/jsc/bindings/webcore/JSDOMConvertNumbers.h index ed279b251ee4..b91243ad896c 100644 --- a/src/jsc/bindings/webcore/JSDOMConvertNumbers.h +++ b/src/jsc/bindings/webcore/JSDOMConvertNumbers.h @@ -147,11 +147,6 @@ template<> struct JSConverter { }; template<> struct Converter : DefaultConverter { - static inline int32_t convert(JSC::JSGlobalObject&, JSC::ThrowScope&, double number) - { - return JSC::toInt32(number); - } - static int32_t convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) { return convertToInteger(lexicalGlobalObject, value); @@ -276,14 +271,6 @@ template struct JSConverter> { // MARK: Floating point types template<> struct Converter : DefaultConverter { - - static inline float convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope, double number) - { - if (!std::isfinite(number)) [[unlikely]] - throwNonFiniteTypeError(lexicalGlobalObject, scope); - return static_cast(number); - } - static float convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) { auto& vm = JSC::getVM(&lexicalGlobalObject); @@ -311,11 +298,6 @@ template<> struct JSConverter { }; template<> struct Converter : DefaultConverter { - static inline float convert(JSC::JSGlobalObject&, JSC::ThrowScope&, double number) - { - return static_cast(number); - } - static float convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) { auto& vm = JSC::getVM(&lexicalGlobalObject); @@ -344,13 +326,6 @@ template<> struct JSConverter { }; template<> struct Converter : DefaultConverter { - static inline double convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope, double number) - { - if (!std::isfinite(number)) [[unlikely]] - throwNonFiniteTypeError(lexicalGlobalObject, scope); - return number; - } - static double convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) { auto& vm = JSC::getVM(&lexicalGlobalObject); @@ -377,11 +352,6 @@ template<> struct JSConverter { }; template<> struct Converter : DefaultConverter { - static inline double convert(JSC::JSGlobalObject&, JSC::ThrowScope&, double number) - { - return number; - } - static double convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) { return value.toNumber(&lexicalGlobalObject); From 63bfbb24a6fb316fc426037a790e38f9c04a1ce4 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Fri, 31 Jul 2026 10:18:03 +0000 Subject: [PATCH 07/10] Restore AbortSignal::signalFollow and m_followingSignal Per review, this will be needed soon. Reverts the AbortSignal.cpp/.h and JSAbortSignalCustom.cpp changes and drops the corresponding source-lint checks. --- Cargo.lock | 19 ------------------- src/jsc/bindings/webcore/AbortSignal.cpp | 19 +++++++++++++++++++ src/jsc/bindings/webcore/AbortSignal.h | 4 ++++ .../bindings/webcore/JSAbortSignalCustom.cpp | 6 ++++++ .../dead-symbols-ssv-wasi-webcore.test.ts | 9 ++------- 5 files changed, 31 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7774603536fb..b0581dd43592 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -289,18 +289,9 @@ dependencies = [ name = "bun_brotli" version = "0.0.0" dependencies = [ - "bitflags", - "bstr", "bun_alloc", "bun_brotli_sys", "bun_core", - "bun_io", - "const_format", - "enum-map", - "enumset", - "libc", - "scopeguard", - "strum", "thiserror", ] @@ -1721,17 +1712,7 @@ dependencies = [ name = "bun_safety" version = "0.0.0" dependencies = [ - "bitflags", - "bstr", - "bun_alloc", "bun_core", - "const_format", - "enum-map", - "enumset", - "libc", - "scopeguard", - "strum", - "thiserror", ] [[package]] diff --git a/src/jsc/bindings/webcore/AbortSignal.cpp b/src/jsc/bindings/webcore/AbortSignal.cpp index 1d16234adbe2..cedc5efe5f47 100644 --- a/src/jsc/bindings/webcore/AbortSignal.cpp +++ b/src/jsc/bindings/webcore/AbortSignal.cpp @@ -285,6 +285,25 @@ void AbortSignal::cleanNativeBindings(void* ref) this->eventListenersDidChange(); } +// https://dom.spec.whatwg.org/#abortsignal-follow +void AbortSignal::signalFollow(AbortSignal& signal) +{ + if (aborted()) + return; + + if (signal.aborted()) { + signalAbort(signal.jsReason(*scriptExecutionContext()->jsGlobalObject())); + return; + } + + ASSERT(!m_followingSignal); + m_followingSignal = signal; + signal.addAlgorithm([weakThis = WeakPtr { *this }](JSC::JSValue reason) { + if (RefPtr signal = weakThis.get()) + signal->signalAbort(reason); + }); +} + void AbortSignal::eventListenersDidChange() { bool hadListeners = hasAbortEventListener(); diff --git a/src/jsc/bindings/webcore/AbortSignal.h b/src/jsc/bindings/webcore/AbortSignal.h index 51aa13b3a9d9..829a0e70532e 100644 --- a/src/jsc/bindings/webcore/AbortSignal.h +++ b/src/jsc/bindings/webcore/AbortSignal.h @@ -85,6 +85,7 @@ class AbortSignal final : public RefCounted, public EventTargetWith void signalAbort(JSC::JSGlobalObject* globalObject, CommonAbortReason reason); void signalAbort(JSC::JSValue reason); + void signalFollow(AbortSignal&); bool aborted() const { return m_flags & static_cast(AbortSignalFlags::Aborted); } void markAborted(JSC::JSValue reason); @@ -114,6 +115,8 @@ class AbortSignal final : public RefCounted, public EventTargetWith template void visitAbortAlgorithms(Visitor&); + bool isFollowingSignal() const { return !!m_followingSignal; } + void throwIfAborted(JSC::JSGlobalObject&); using AbortSignalSet = WeakListHashSet; @@ -212,6 +215,7 @@ class AbortSignal final : public RefCounted, public EventTargetWith // Strong-ref cycle leak. Vector>> m_abortAlgorithms WTF_GUARDED_BY_LOCK(m_abortAlgorithmsLock); Lock m_abortAlgorithmsLock; + WeakPtr m_followingSignal; AbortSignalSet m_sourceSignals; AbortSignalSet m_dependentSignals; JSValueInWrappedObject m_reason; diff --git a/src/jsc/bindings/webcore/JSAbortSignalCustom.cpp b/src/jsc/bindings/webcore/JSAbortSignalCustom.cpp index 58f96718bb0b..9ff395116051 100644 --- a/src/jsc/bindings/webcore/JSAbortSignalCustom.cpp +++ b/src/jsc/bindings/webcore/JSAbortSignalCustom.cpp @@ -40,6 +40,12 @@ bool JSAbortSignalOwner::isReachableFromOpaqueRoots(JSC::Handle ha } if (!abortSignal.aborted()) { + if (abortSignal.isFollowingSignal()) { + if (reason) [[unlikely]] + *reason = "Is Following Signal"_s; + return true; + } + if (abortSignal.hasActiveTimeoutTimer() && abortSignal.hasTimeoutObserver()) { if (reason) [[unlikely]] *reason = "Has Observed Timeout"_s; diff --git a/test/internal/source-lints/dead-symbols-ssv-wasi-webcore.test.ts b/test/internal/source-lints/dead-symbols-ssv-wasi-webcore.test.ts index 856d6ff414cb..a34a2585bcf7 100644 --- a/test/internal/source-lints/dead-symbols-ssv-wasi-webcore.test.ts +++ b/test/internal/source-lints/dead-symbols-ssv-wasi-webcore.test.ts @@ -1,5 +1,5 @@ // Guards against reintroduction of symbols removed as dead code from -// SerializedScriptValue, WebSocket, Performance, EventTarget, AbortSignal, +// SerializedScriptValue, WebSocket, Performance, EventTarget, // the JSDOMConvert* template headers, windows/rescle, node:wasi, and a few // small Rust crates. Each entry was verified to have zero callers across // src/ and build/debug/codegen/ before deletion, and a full `bun bd` plus @@ -67,7 +67,7 @@ test("dead WebSocket create/connect overloads and commented-out WebKit blocks do expect(resurrected(checks)).toEqual([]); }); -test("dead Performance/PerformanceObserver/EventTarget/AbortSignal members do not reappear", () => { +test("dead Performance/PerformanceObserver/EventTarget members do not reappear", () => { const checks: Array<[string, RegExp]> = [ // addResourceTiming had no callers; Bun's fetch produces PerformanceResourceTiming // via Performance::appendBufferedEntry / queueEntry directly. @@ -84,11 +84,6 @@ test("dead Performance/PerformanceObserver/EventTarget/AbortSignal members do no ["src/jsc/bindings/webcore/EventTarget.cpp", /EventTarget::isPaymentRequest/], ["src/jsc/bindings/webcore/EventTarget.h", /hasCapturingEventListeners/], ["src/jsc/bindings/webcore/EventTarget.h", /void invalidateJSEventListeners\(JSC::JSObject\*\)/], - // signalFollow was unreferenced and the only writer of m_followingSignal; - // JSAbortSignalCustom's isFollowingSignal() check was therefore always false. - ["src/jsc/bindings/webcore/AbortSignal.cpp", /AbortSignal::signalFollow/], - ["src/jsc/bindings/webcore/AbortSignal.h", /void signalFollow\(AbortSignal&\)/], - ["src/jsc/bindings/webcore/AbortSignal.h", /m_followingSignal/], ]; expect(resurrected(checks)).toEqual([]); }); From 754b4fe22d5b07388174b10909bcbb3c05cf58f3 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Fri, 31 Jul 2026 10:19:05 +0000 Subject: [PATCH 08/10] Drop stray Cargo.lock diff picked up from a newer main --- Cargo.lock | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index b0581dd43592..7774603536fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -289,9 +289,18 @@ dependencies = [ name = "bun_brotli" version = "0.0.0" dependencies = [ + "bitflags", + "bstr", "bun_alloc", "bun_brotli_sys", "bun_core", + "bun_io", + "const_format", + "enum-map", + "enumset", + "libc", + "scopeguard", + "strum", "thiserror", ] @@ -1712,7 +1721,17 @@ dependencies = [ name = "bun_safety" version = "0.0.0" dependencies = [ + "bitflags", + "bstr", + "bun_alloc", "bun_core", + "const_format", + "enum-map", + "enumset", + "libc", + "scopeguard", + "strum", + "thiserror", ] [[package]] From e0122fcf03498870f9f7f7482d332ce5408569c5 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Fri, 31 Jul 2026 12:06:26 +0000 Subject: [PATCH 09/10] ci: retrigger From 11bdeca32351a3cfc67e815910bccbc14e78dc05 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Fri, 31 Jul 2026 18:26:45 -0700 Subject: [PATCH 10/10] Delete test/internal/source-lints/dead-symbols-ssv-wasi-webcore.test.ts --- .../dead-symbols-ssv-wasi-webcore.test.ts | 160 ------------------ 1 file changed, 160 deletions(-) delete mode 100644 test/internal/source-lints/dead-symbols-ssv-wasi-webcore.test.ts diff --git a/test/internal/source-lints/dead-symbols-ssv-wasi-webcore.test.ts b/test/internal/source-lints/dead-symbols-ssv-wasi-webcore.test.ts deleted file mode 100644 index a34a2585bcf7..000000000000 --- a/test/internal/source-lints/dead-symbols-ssv-wasi-webcore.test.ts +++ /dev/null @@ -1,160 +0,0 @@ -// Guards against reintroduction of symbols removed as dead code from -// SerializedScriptValue, WebSocket, Performance, EventTarget, -// the JSDOMConvert* template headers, windows/rescle, node:wasi, and a few -// small Rust crates. Each entry was verified to have zero callers across -// src/ and build/debug/codegen/ before deletion, and a full `bun bd` plus -// `bun run rust:check-all` (all targets) passes without them. This test -// fails if any of them reappear, e.g. via a merge that resurrects a stale -// file or a copy-paste from WebKit upstream. -// -// This is a source-tree lint: it reads files from src/ and does not touch the -// built binary, so it belongs in test/internal/source-lints/ per the README. - -import { expect, test } from "bun:test"; -import { readFileSync } from "node:fs"; -import path from "node:path"; - -const repoRoot = path.resolve(import.meta.dir, "..", "..", ".."); - -function src(p: string): string { - return readFileSync(path.join(repoRoot, p), "utf8"); -} - -function resurrected(checks: Array<[string, RegExp]>): string[] { - return checks.filter(([file, re]) => re.test(src(file))).map(([file, re]) => `${file}: ${re.source}`); -} - -test("dead SerializedScriptValue ENABLE() blocks and unused public methods do not reappear", () => { - // Bun's JSCOnly cmakeconfig.h sets ENABLE_OFFSCREEN_CANVAS_IN_WORKERS, - // ENABLE_WEB_RTC, ENABLE_WEB_CODECS, ENABLE_PREDEFINED_COLOR_SPACE_DISPLAY_P3 - // to 0 on every target; the referenced types (OffscreenCanvas, RTCCertificate, - // WebCodecsVideoFrame) have no headers under src/, so the guarded bodies could - // not compile if the macros flipped. The uncalled public methods were verified - // against src/ and build/debug/codegen/. - const checks: Array<[string, RegExp]> = [ - ["src/jsc/bindings/webcore/SerializedScriptValue.cpp", /ENABLE\(OFFSCREEN_CANVAS_IN_WORKERS\)/], - ["src/jsc/bindings/webcore/SerializedScriptValue.cpp", /ENABLE\(WEB_RTC\)/], - ["src/jsc/bindings/webcore/SerializedScriptValue.cpp", /ENABLE\(WEB_CODECS\)/], - ["src/jsc/bindings/webcore/SerializedScriptValue.cpp", /readRTCCertificate/], - ["src/jsc/bindings/webcore/SerializedScriptValue.cpp", /readOffscreenCanvas/], - ["src/jsc/bindings/webcore/SerializedScriptValue.cpp", /readWebCodecsVideoFrame/], - ["src/jsc/bindings/webcore/SerializedScriptValue.cpp", /SerializedScriptValue::nullValue/], - ["src/jsc/bindings/webcore/SerializedScriptValue.cpp", /SerializedScriptValue::toString/], - ["src/jsc/bindings/webcore/SerializedScriptValue.cpp", /SerializedScriptValue::wireFormatVersion/], - ["src/jsc/bindings/webcore/SerializedScriptValue.cpp", /CloneDeserializer::deserializeString/], - ["src/jsc/bindings/webcore/SerializedScriptValue.cpp", /blobFilePathForBlobURL/], - ["src/jsc/bindings/webcore/SerializedScriptValue.h", /ENABLE\(WEB_RTC\)/], - ["src/jsc/bindings/webcore/SerializedScriptValue.h", /static Ref nullValue\(\)/], - ["src/jsc/bindings/webcore/SerializedScriptValue.h", /static uint32_t wireFormatVersion\(\)/], - ["src/jsc/bindings/webcore/SerializedScriptValue.h", /void encode\(Encoder&\) const/], - ["src/jsc/bindings/webcore/SerializedScriptValue.h", /static RefPtr decode\(Decoder&/], - ]; - expect(resurrected(checks)).toEqual([]); -}); - -test("dead WebSocket create/connect overloads and commented-out WebKit blocks do not reappear", () => { - const checks: Array<[string, RegExp]> = [ - ["src/jsc/bindings/webcore/WebSocket.cpp", /ENABLE\(INTELLIGENT_TRACKING_PREVENTION\)/], - ["src/jsc/bindings/webcore/WebSocket.cpp", /MixedContentChecker/], - ["src/jsc/bindings/webcore/WebSocket.cpp", /WebSocket::didUpdateBufferedAmount/], - ["src/jsc/bindings/webcore/WebSocket.cpp", /ConnectedWebSocketKind::Server:/], - ["src/jsc/bindings/webcore/WebSocket.h", /void didReceiveData\(const char\* data, size_t length\);/], - ["src/jsc/bindings/webcore/WebSocket.h", /void didUpdateBufferedAmount\(unsigned/], - ["src/jsc/bindings/webcore/WebSocket.h", /WebSocket\(ScriptExecutionContext&, const String& url\);/], - ["src/jsc/bindings/webcore/WebSocket.h", /ExceptionOr connect\(const String& url\);/], - ["src/jsc/bindings/webcore/WebSocket.h", /ExceptionOr connect\(const String& url, const String& protocol\);/], - ]; - expect(resurrected(checks)).toEqual([]); -}); - -test("dead Performance/PerformanceObserver/EventTarget members do not reappear", () => { - const checks: Array<[string, RegExp]> = [ - // addResourceTiming had no callers; Bun's fetch produces PerformanceResourceTiming - // via Performance::appendBufferedEntry / queueEntry directly. - ["src/jsc/bindings/webcore/Performance.cpp", /Performance::addResourceTiming/], - ["src/jsc/bindings/webcore/Performance.cpp", /Performance::isResourceTimingBufferFull/], - ["src/jsc/bindings/webcore/Performance.cpp", /Performance::allowHighPrecisionTime/], - ["src/jsc/bindings/webcore/Performance.cpp", /Performance::timeResolution/], - ["src/jsc/bindings/webcore/Performance.cpp", /relativeTimeFromTimeOriginInReducedResolution/], - ["src/jsc/bindings/webcore/Performance.cpp", /resourceTimingBufferFullTimerFired/], - ["src/jsc/bindings/webcore/Performance.h", /m_backupResourceTimingBuffer/], - ["src/jsc/bindings/webcore/Performance.h", /m_waitingForBackupBufferToBeProcessed/], - ["src/jsc/bindings/webcore/PerformanceObserver.h", /m_hasNavigationTiming/], - ["src/jsc/bindings/webcore/EventTarget.cpp", /static const AtomString& legacyType/], - ["src/jsc/bindings/webcore/EventTarget.cpp", /EventTarget::isPaymentRequest/], - ["src/jsc/bindings/webcore/EventTarget.h", /hasCapturingEventListeners/], - ["src/jsc/bindings/webcore/EventTarget.h", /void invalidateJSEventListeners\(JSC::JSObject\*\)/], - ]; - expect(resurrected(checks)).toEqual([]); -}); - -test("dead JSDOMConvert* template specializations do not reappear", () => { - // IDLSequence is only instantiated with string/enum/interface/dictionary - // element types in Bun; none of the numeric specializations (nor the - // NumericSequenceConverter they dispatch to) are reachable. - const checks: Array<[string, RegExp]> = [ - ["src/jsc/bindings/webcore/JSDOMConvertSequences.h", /struct NumericSequenceConverter/], - ["src/jsc/bindings/webcore/JSDOMConvertSequences.h", /SequenceConverter/], - ["src/jsc/bindings/webcore/JSDOMConvertSequences.h", /SequenceConverter/], - ["src/jsc/bindings/webcore/JSDOMConvertSequences.h", /struct Converter>/], - ["src/jsc/bindings/webcore/JSDOMConvertStrings.h", /propertyNameToAtomString/], - ["src/jsc/bindings/webcore/JSDOMConvertStrings.h", /IDLLegacyNullToEmptyStringAdaptor/], - ["src/jsc/bindings/webcore/JSDOMConvertStrings.h", /IDLAtomStringAdaptor/], - ["src/jsc/bindings/webcore/JSDOMConvertStrings.h", /IDLAtomStringAdaptor/], - ["src/jsc/bindings/webcore/JSDOMConvertStrings.cpp", /valueToByteAtomString/], - ["src/jsc/bindings/webcore/JSDOMConvertStrings.cpp", /valueToUSVAtomString/], - ["src/jsc/bindings/webcore/JSDOMConvertRecord.h", /struct JSConverter>/], - ["src/jsc/bindings/webcore/JSDOMConvertUnion.h", /IDLAllowSharedAdaptor { - // The only Rust entry point (rescle__setWindowsMetadata) uses Load, SetIcon, - // SetVersionString, SetFileVersion, SetProductVersion, and Commit. All other - // ResourceUpdater public methods were unreachable. - const checks: Array<[string, RegExp]> = [ - ["src/jsc/bindings/windows/rescle.cpp", /ResourceUpdater::SetExecutionLevel/], - ["src/jsc/bindings/windows/rescle.cpp", /ResourceUpdater::SetApplicationManifest/], - ["src/jsc/bindings/windows/rescle.cpp", /ResourceUpdater::GetVersionString/], - ["src/jsc/bindings/windows/rescle.cpp", /ResourceUpdater::ChangeString/], - ["src/jsc/bindings/windows/rescle.cpp", /ResourceUpdater::ChangeRcData/], - ["src/jsc/bindings/windows/rescle.cpp", /ResourceUpdater::GetString/], - ["src/jsc/bindings/windows/rescle.cpp", /OnEnumResourceManifest/], - ["src/jsc/bindings/windows/rescle.h", /RU_VS_LEGAL_TRADEMARKS/], - ["src/jsc/bindings/windows/rescle.h", /bool SetExecutionLevel\(/], - ["src/jsc/bindings/windows/rescle.h", /bool SetApplicationManifest\(/], - ["src/jsc/bindings/windows/rescle.h", /GetVersionString\(/], - ["src/jsc/bindings/windows/rescle.h", /bool ChangeString\(/], - ["src/jsc/bindings/windows/rescle.h", /bool ChangeRcData\(/], - ["src/jsc/bindings/windows/rescle.h", /GetString\(/], - ["src/jsc/bindings/windows/rescle.h", /OnEnumResourceManifest/], - ]; - expect(resurrected(checks)).toEqual([]); -}); - -test("dead wasi.ts bundle artifacts and debug scaffolding do not reappear", () => { - // The `= void 0` chains are esbuild/tsc emit artifacts from the original - // wasi-js npm bundle; every property is immediately re-assigned to its real - // value. initWasiFdInfo() was unreferenced debug code with console.log calls. - const checks: Array<[string, RegExp]> = [ - ["src/js/node/wasi.ts", /exports\.WASI_ENOMSG =\n/], - ["src/js/node/wasi.ts", /class extends Error \{\n\s+constructor\(signal\)/], - ["src/js/node/wasi.ts", /WASIKillError/], - ["src/js/node/wasi.ts", /SOCKET_DEFAULT_RIGHTS/], - ["src/js/node/wasi.ts", /initWasiFdInfo/], - ["src/js/node/wasi.ts", /if \(log\.enabled\)/], - ["src/js/thirdparty/ws.js", /secWebSocketExtensions/], - ]; - expect(resurrected(checks)).toEqual([]); -}); - -test("dead Rust http/threading/standalone_graph/bunfig items do not reappear", () => { - const checks: Array<[string, RegExp]> = [ - ["src/http/lib.rs", /const PRINT_EVERY: usize/], - ["src/threading/lib.rs", /RwLockReadGuard, RwLockWriteGuard/], - ["src/standalone_graph/error.rs", /UnsupportedTarget/], - ["src/bunfig/bunfig.rs", /pub use bun_options_types::offline_mode::OfflineMode/], - ]; - expect(resurrected(checks)).toEqual([]); -});