From 774a22ebd2e92cee2a96bd790105ba6b679e1efc Mon Sep 17 00:00:00 2001 From: ldm0 Date: Wed, 21 Oct 2026 11:12:02 +0800 Subject: [PATCH] fix(dom): expose immutable MutationRecord prototype attributes Keep record values in private slots and expose the nine readonly attributes through branded prototype getters. Preserve snapshot identity across realms, shadow properties, registered native Proxies, and retained records. Create delivery arguments in the callback function's relevant realm so MutationRecord wrappers and arrays use the correct prototypes. --- moli-renderer-v8/src/observer_runtime/mod.rs | 2 ++ .../tests/fixtures/mutation-record-attributes.js | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/moli-renderer-v8/src/observer_runtime/mod.rs b/moli-renderer-v8/src/observer_runtime/mod.rs index 3dcb34c64d5..56dcf9bc18e 100644 --- a/moli-renderer-v8/src/observer_runtime/mod.rs +++ b/moli-renderer-v8/src/observer_runtime/mod.rs @@ -722,6 +722,8 @@ fn invoke_mutation_deliveries<'s>( if !delivery.callback.is_current(scope) { continue; } + // Convert callback arguments in the callback function's Realm, which + // can differ from the observer's construction Realm. let callback_context = delivery.callback.relevant_context(scope); let records_array = { let scope = &mut v8::ContextScope::new(scope, callback_context); diff --git a/moli-renderer-v8/tests/fixtures/mutation-record-attributes.js b/moli-renderer-v8/tests/fixtures/mutation-record-attributes.js index d214e0026e7..159535bef8f 100644 --- a/moli-renderer-v8/tests/fixtures/mutation-record-attributes.js +++ b/moli-renderer-v8/tests/fixtures/mutation-record-attributes.js @@ -42,9 +42,9 @@ function produce(owner, doc) { const host = doc.createElement('item'); const left = doc.createTextNode('left'), right = doc.createTextNode('right'); - const text = doc.createTextNode('old text\u00e9'), middle = doc.createElement('middle'); + const text = doc.createTextNode('old text\udfff'), middle = doc.createElement('middle'); host.append(left, right, text); - host.setAttributeNS('urn:record', 'p:keep', 'old attr\u{1D306}'); + host.setAttributeNS('urn:record', 'p:keep', 'old attr\ud800'); const observer = new owner.MutationObserver(() => {}); observer.observe(host, {attributes: true, attributeOldValue: true, characterData: true, characterDataOldValue: true, childList: true, subtree: true}); @@ -58,8 +58,8 @@ attributeName: null, attributeNamespace: null, oldValue: null}; const expected = [ {...empty, type: 'attributes', target: host, attributeName: 'keep', - attributeNamespace: 'urn:record', oldValue: 'old attr\u{1D306}'}, - {...empty, type: 'characterData', target: text, oldValue: 'old text\u00e9'}, + attributeNamespace: 'urn:record', oldValue: 'old attr\ud800'}, + {...empty, type: 'characterData', target: text, oldValue: 'old text\udfff'}, {...empty, type: 'childList', target: host, addedNodes: [middle], previousSibling: left, nextSibling: right}, ]; return {records, expected, host, text, middle};