- Revision
- 208481
- Author
- [email protected]
- Date
- 2016-11-09 13:33:23 -0800 (Wed, 09 Nov 2016)
Log Message
[DOMJIT] Implement Node::ownerDocument
https://bugs.webkit.org/show_bug.cgi?id=164004
Reviewed by Darin Adler.
Source/WebCore:
Test: js/dom/domjit-accessor-owner-document.html
Still I cannot reproduce this crash in x64 environment, according to the crash log, it accesses 0x8 address.
This can happen if document() accidentally returns nullptr. In the C++ ownerDocument implementation,
if document() returns nullptr, it just returns nullptr. But in the DOMJIT implementation, we assume that
document() won't return nullptr and access the member of it.
This patch aligns the DOMJIT implementation strictly to the C++ one.
* dom/Node.idl:
* domjit/JSNodeDOMJIT.cpp:
(WebCore::NodeOwnerDocumentDOMJIT::checkDOM):
(WebCore::NodeOwnerDocumentDOMJIT::callDOMGetter):
LayoutTests:
* js/dom/domjit-accessor-owner-document-expected.txt: Added.
* js/dom/domjit-accessor-owner-document.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (208480 => 208481)
--- trunk/LayoutTests/ChangeLog 2016-11-09 21:30:41 UTC (rev 208480)
+++ trunk/LayoutTests/ChangeLog 2016-11-09 21:33:23 UTC (rev 208481)
@@ -1,3 +1,13 @@
+2016-11-09 Yusuke Suzuki <[email protected]>
+
+ [DOMJIT] Implement Node::ownerDocument
+ https://bugs.webkit.org/show_bug.cgi?id=164004
+
+ Reviewed by Darin Adler.
+
+ * js/dom/domjit-accessor-owner-document-expected.txt: Added.
+ * js/dom/domjit-accessor-owner-document.html: Added.
+
2016-11-09 Dave Hyatt <[email protected]>
[CSS Parser] Fix grid layout parsing
Added: trunk/LayoutTests/js/dom/domjit-accessor-owner-document-expected.txt (0 => 208481)
--- trunk/LayoutTests/js/dom/domjit-accessor-owner-document-expected.txt (rev 0)
+++ trunk/LayoutTests/js/dom/domjit-accessor-owner-document-expected.txt 2016-11-09 21:33:23 UTC (rev 208481)
@@ -0,0 +1,109 @@
+Test DOMJIT nodeType accessor works.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS (
+ function testElement(element, result)
+ {
+ for (var i = 0; i < 1e4; ++i) {
+ if (element.ownerDocument !== result)
+ return false;
+ }
+ return true;
+ }
+ )(target, result) is true
+PASS (
+ function testAttr(element, result)
+ {
+ for (var i = 0; i < 1e4; ++i) {
+ if (element.ownerDocument !== result)
+ return false;
+ }
+ return true;
+ }
+ )(target, result) is true
+PASS (
+ function testText(element, result)
+ {
+ for (var i = 0; i < 1e4; ++i) {
+ if (element.ownerDocument !== result)
+ return false;
+ }
+ return true;
+ }
+ )(target, result) is true
+PASS (
+ function testCDATA(element, result)
+ {
+ for (var i = 0; i < 1e4; ++i) {
+ if (element.ownerDocument !== result)
+ return false;
+ }
+ return true;
+ }
+ )(target, result) is true
+PASS (
+ function testProcessingInstruction(element, result)
+ {
+ for (var i = 0; i < 1e4; ++i) {
+ if (element.ownerDocument !== result)
+ return false;
+ }
+ return true;
+ }
+ )(target, result) is true
+PASS (
+ function testComment(element, result)
+ {
+ for (var i = 0; i < 1e4; ++i) {
+ if (element.ownerDocument !== result)
+ return false;
+ }
+ return true;
+ }
+ )(target, result) is true
+PASS (
+ function testDocument(element, result)
+ {
+ for (var i = 0; i < 1e4; ++i) {
+ if (element.ownerDocument !== result)
+ return false;
+ }
+ return true;
+ }
+ )(target, result) is true
+PASS (
+ function testXMLDocument(element, result)
+ {
+ for (var i = 0; i < 1e4; ++i) {
+ if (element.ownerDocument !== result)
+ return false;
+ }
+ return true;
+ }
+ )(target, result) is true
+PASS (
+ function testDocumentType(element, result)
+ {
+ for (var i = 0; i < 1e4; ++i) {
+ if (element.ownerDocument !== result)
+ return false;
+ }
+ return true;
+ }
+ )(target, result) is true
+PASS (
+ function testDocumentFragment(element, result)
+ {
+ for (var i = 0; i < 1e4; ++i) {
+ if (element.ownerDocument !== result)
+ return false;
+ }
+ return true;
+ }
+ )(target, result) is true
+
Added: trunk/LayoutTests/js/dom/domjit-accessor-owner-document.html (0 => 208481)
--- trunk/LayoutTests/js/dom/domjit-accessor-owner-document.html (rev 0)
+++ trunk/LayoutTests/js/dom/domjit-accessor-owner-document.html 2016-11-09 21:33:23 UTC (rev 208481)
@@ -0,0 +1,56 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<iframe id="xmlframe" _onload_="frameLoaded()" style="height:0px" src="" version='1.0' encoding='UTF-8'?><body/>"></iframe>
+<script>
+description('Test DOMJIT nodeType accessor works.');
+
+if (window.testRunner)
+ testRunner.waitUntilDone();
+
+var target = null;
+var result = null;
+function runTest()
+{
+ var xmlDocument = document.getElementById('xmlframe').contentDocument;
+ var targets = [
+ ['Element', document.body, document],
+ ['Attr', document.createAttribute('Cocoa'), document],
+ ['Text', document.createTextNode('Cocoa'), document],
+ ['CDATA', xmlDocument.createCDATASection('test'), xmlDocument],
+ ['ProcessingInstruction', xmlDocument.createProcessingInstruction('target', 'test'), xmlDocument],
+ ['Comment', document.createComment('Cocoa'), document],
+ ['Document', document, null],
+ ['XMLDocument', xmlDocument, null],
+ ['DocumentType', document.doctype, document],
+ ['DocumentFragment', document.createDocumentFragment(), document],
+ ];
+
+ for ([name, target, result] of targets) {
+ var text = `
+ function test${name}(element, result)
+ {
+ for (var i = 0; i < 1e4; ++i) {
+ if (element.ownerDocument !== result)
+ return false;
+ }
+ return true;
+ }
+ `;
+ shouldBeTrue(`(${text})(target, result)`);
+ }
+
+ if (window.testRunner)
+ testRunner.notifyDone();
+}
+function frameLoaded()
+{
+ runTest();
+}
+</script>
+<script src=""
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (208480 => 208481)
--- trunk/Source/WebCore/ChangeLog 2016-11-09 21:30:41 UTC (rev 208480)
+++ trunk/Source/WebCore/ChangeLog 2016-11-09 21:33:23 UTC (rev 208481)
@@ -1,3 +1,24 @@
+2016-11-09 Yusuke Suzuki <[email protected]>
+
+ [DOMJIT] Implement Node::ownerDocument
+ https://bugs.webkit.org/show_bug.cgi?id=164004
+
+ Reviewed by Darin Adler.
+
+ Test: js/dom/domjit-accessor-owner-document.html
+
+ Still I cannot reproduce this crash in x64 environment, according to the crash log, it accesses 0x8 address.
+ This can happen if document() accidentally returns nullptr. In the C++ ownerDocument implementation,
+ if document() returns nullptr, it just returns nullptr. But in the DOMJIT implementation, we assume that
+ document() won't return nullptr and access the member of it.
+
+ This patch aligns the DOMJIT implementation strictly to the C++ one.
+
+ * dom/Node.idl:
+ * domjit/JSNodeDOMJIT.cpp:
+ (WebCore::NodeOwnerDocumentDOMJIT::checkDOM):
+ (WebCore::NodeOwnerDocumentDOMJIT::callDOMGetter):
+
2016-11-09 Sam Weinig <[email protected]>
[SVG] Start moving special casing of SVG out of the bindings - SVGAngle
Modified: trunk/Source/WebCore/dom/Node.idl (208480 => 208481)
--- trunk/Source/WebCore/dom/Node.idl 2016-11-09 21:30:41 UTC (rev 208480)
+++ trunk/Source/WebCore/dom/Node.idl 2016-11-09 21:33:23 UTC (rev 208481)
@@ -53,7 +53,7 @@
[DOMJIT] readonly attribute Node? lastChild;
[DOMJIT] readonly attribute Node? previousSibling;
[DOMJIT] readonly attribute Node? nextSibling;
- readonly attribute Document? ownerDocument;
+ [DOMJIT] readonly attribute Document? ownerDocument;
[CEReactions, Custom, MayThrowLegacyException] Node insertBefore(Node newChild, Node? refChild);
[CEReactions, Custom, MayThrowLegacyException] Node replaceChild(Node newChild, Node oldChild);
Modified: trunk/Source/WebCore/domjit/JSNodeDOMJIT.cpp (208480 => 208481)
--- trunk/Source/WebCore/domjit/JSNodeDOMJIT.cpp 2016-11-09 21:30:41 UTC (rev 208480)
+++ trunk/Source/WebCore/domjit/JSNodeDOMJIT.cpp 2016-11-09 21:33:23 UTC (rev 208481)
@@ -157,6 +157,43 @@
return patchpoint;
}
+Ref<JSC::DOMJIT::Patchpoint> NodeOwnerDocumentDOMJIT::checkDOM()
+{
+ return DOMJIT::checkDOM<Node>();
}
+Ref<JSC::DOMJIT::CallDOMGetterPatchpoint> NodeOwnerDocumentDOMJIT::callDOMGetter()
+{
+ Ref<JSC::DOMJIT::CallDOMGetterPatchpoint> patchpoint = JSC::DOMJIT::CallDOMGetterPatchpoint::create();
+ patchpoint->numGPScratchRegisters = 2;
+ patchpoint->setGenerator([=](CCallHelpers& jit, JSC::DOMJIT::PatchpointParams& params) {
+ JSValueRegs result = params[0].jsValueRegs();
+ GPRReg node = params[1].gpr();
+ GPRReg globalObject = params[2].gpr();
+ JSValue globalObjectValue = params[2].value();
+ GPRReg wrapped = params.gpScratch(0);
+ GPRReg document = params.gpScratch(1);
+
+ jit.loadPtr(CCallHelpers::Address(node, JSNode::offsetOfWrapped()), wrapped);
+ DOMJIT::loadDocument(jit, wrapped, document);
+ RELEASE_ASSERT(!CAST_OFFSET(EventTarget*, Node*));
+ RELEASE_ASSERT(!CAST_OFFSET(Node*, Document*));
+
+ CCallHelpers::JumpList nullCases;
+ // If the |this| is the document itself, ownerDocument will return null.
+ nullCases.append(jit.branchPtr(CCallHelpers::Equal, wrapped, document));
+ DOMJIT::toWrapper<Document>(jit, params, document, globalObject, result, DOMJIT::toWrapperSlow<Document>, globalObjectValue);
+ auto done = jit.jump();
+
+ nullCases.link(&jit);
+ jit.moveValue(jsNull(), result);
+ done.link(&jit);
+ return CCallHelpers::JumpList();
+ });
+ patchpoint->effect = JSC::DOMJIT::Effect::forDef(DOMJIT::AbstractHeapRepository::Node_ownerDocument);
+ return patchpoint;
+}
+
+}
+
#endif