fix(lite): every Node constant is on Node and on each node (owner: "continue with other parity tests; before that you'd better have a complete parity test plan or QA plan for the Lite.")

Readest's dialogs keep Tab inside them by asking
compareDocumentPosition(el) & Node.DOCUMENT_POSITION_FOLLOWING. Lite
defined 7 of the 18 Node constants; DOCUMENT_POSITION_FOLLOWING and
PRECEDING were undefined, so `x & undefined` was 0, no control was ever
ahead, and Tab went back to the dialog's first control. That path is
reached once Tab in a dialog stops throwing, later in this series.

All 12 node types and 6 document positions are now on Node and on
Node.prototype, as in Chromium.

Verified:
- dom_basics.rs node_constants_are_on_node_and_every_node. Without the
  change it fails with "1/1 undefined/undefined 3/3 undefined/undefined
  ..."; with it, it prints Chromium's 18 values.
- The suites and the parity sweep ran on this commit together with the
  next three (tabIndex, focus events, elementFromPoint); the results are
  in the elementFromPoint commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Huang Xin 2026-11-28 17:52:59 +08:00
parent 572e49ac51
commit 6eeec7736b
No known key found for this signature in database
GPG key ID: FEB86D637D085E7D
2 changed files with 39 additions and 10 deletions

View file

@ -667,22 +667,29 @@
return o === this;
}
}
define(Node, {
// Node's constants, on Node and on every node.
const NODE_CONSTANTS = {
ELEMENT_NODE: 1,
ATTRIBUTE_NODE: 2,
TEXT_NODE: 3,
CDATA_SECTION_NODE: 4,
ENTITY_REFERENCE_NODE: 5,
ENTITY_NODE: 6,
PROCESSING_INSTRUCTION_NODE: 7,
COMMENT_NODE: 8,
DOCUMENT_NODE: 9,
DOCUMENT_TYPE_NODE: 10,
DOCUMENT_FRAGMENT_NODE: 11,
DOCUMENT_POSITION_CONTAINED_BY: 16,
NOTATION_NODE: 12,
DOCUMENT_POSITION_DISCONNECTED: 1,
DOCUMENT_POSITION_PRECEDING: 2,
DOCUMENT_POSITION_FOLLOWING: 4,
DOCUMENT_POSITION_CONTAINS: 8,
});
Object.assign(Node.prototype, {
ELEMENT_NODE: 1,
TEXT_NODE: 3,
COMMENT_NODE: 8,
DOCUMENT_NODE: 9,
DOCUMENT_FRAGMENT_NODE: 11,
});
DOCUMENT_POSITION_CONTAINED_BY: 16,
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: 32,
};
define(Node, NODE_CONSTANTS);
Object.assign(Node.prototype, NODE_CONSTANTS);
class CharacterData extends Node {
get data() {

View file

@ -463,3 +463,25 @@ fn documents_are_in_standards_mode() {
assert_eq!(doc.take_js_errors(), Vec::<String>::new());
assert_eq!(doc.take_messages(), ["log: CSS1Compat CSS1Compat"]);
}
#[test]
fn node_constants_are_on_node_and_every_node() {
// Readest's dialogs keep Tab inside with `compareDocumentPosition(el) &
// Node.DOCUMENT_POSITION_FOLLOWING`; Lite had no such constant, so nothing was ever ahead and
// Tab went back to the dialog's first control.
let mut doc = QjsDocument::from_html("<!DOCTYPE html><body></body>", DocumentConfig::default());
doc.eval(
"console.log(['ELEMENT_NODE', 'ATTRIBUTE_NODE', 'TEXT_NODE', 'CDATA_SECTION_NODE', 'ENTITY_REFERENCE_NODE',
'ENTITY_NODE', 'PROCESSING_INSTRUCTION_NODE', 'COMMENT_NODE', 'DOCUMENT_NODE', 'DOCUMENT_TYPE_NODE',
'DOCUMENT_FRAGMENT_NODE', 'NOTATION_NODE', 'DOCUMENT_POSITION_DISCONNECTED', 'DOCUMENT_POSITION_PRECEDING',
'DOCUMENT_POSITION_FOLLOWING', 'DOCUMENT_POSITION_CONTAINS', 'DOCUMENT_POSITION_CONTAINED_BY',
'DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC'].map((k) => `${Node[k]}/${document.body[k]}`).join(' '));",
"test",
);
assert_eq!(doc.take_js_errors(), Vec::<String>::new());
// Chromium's
assert_eq!(
doc.take_messages(),
["log: 1/1 2/2 3/3 4/4 5/5 6/6 7/7 8/8 9/9 10/10 11/11 12/12 1/1 2/2 4/4 8/8 16/16 32/32"]
);
}