Skip to content

Commit b81057c

Browse files
committed
Complete breakup of Introduction.md
1 parent d98ea02 commit b81057c

File tree

11 files changed

+1068
-1062
lines changed

11 files changed

+1068
-1062
lines changed

Sources/WebKit/WebKit.docc/Build&Debug/Build.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,18 @@ run-minibrowser --debug --wpe
124124

125125
Pass one of `--gtk`, `--jsc-only`, or `--wpe` to indicate the port to use.
126126

127+
## Fixing mysterious build or runtime errors after Xcode upgrades
128+
129+
If you see mysterious build failures or if you’ve switched to a new version of
130+
macOS or Xcode, delete the `WebKitBuild` directory.
131+
`make clean` may not delete all the relevant files,
132+
and building after doing that without deleting the `WebKitBuild` directory may result in mysterious build or dyld errors.
133+
134+
## Building with Address Sanitizer to investigate memory corruption bugs
135+
136+
To build [Address Sanitizer](https://en.wikipedia.org/wiki/AddressSanitizer) or ASan builds to analyze security bugs,
137+
run `Tools/Scripts/set-webkit-configuration --asan --release`.
138+
This will enable ASan build. If want to attach a debugger, you can also specify `--debug` instead of `--release`.
139+
Once you don’t need to build or run ASan anymore, you can specify `--no-asan` in place of `--asan` to disable ASan.
140+
Note that this configuration is saved by creating a file called Asan in the WebKitBuild directory,
141+
so if you are trying to do a clean Asan build by deleting the build directory you need to rerun this command.

Sources/WebKit/WebKit.docc/Build&Debug/DebuggingWithXcode.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,35 @@
22

33
Debugging with the Xcode IDE
44

5+
## Overview
6+
7+
You can also use Xcode to build & debug WebKit. Open `WebKit.xcworkspace` at the top level directory.
8+
9+
In order to make Xcode use build files built by `make` command above,
10+
go to File > Workspace Settings... > Advanced... > Custom > Relative to Workspace
11+
and adjust the relative paths of Products and Intermediates to point to `WebKitBuild` directory.
12+
![Screenshot of Xcode Workspace Settings](xcode-workspace-settings.png)
13+
![Screenshot of Xcode Workspace Settings - Advanced Build Location](xcode-workspace-build-location.png)
14+
Note that debugging WebCore code typically requires attaching to the relevant WebContent process,
15+
not the application process, which is mostly running code in [Source/WebKit/UIProcess](https://github.com/WebKit/WebKit/tree/main/Source/WebKit/UIProcess).
16+
Depending on what you’re debugging, you’d have to attach & debug different processes in the coalition.
17+
18+
You may find it useful to use the debug helpers under `Tools/lldb/lldb_webkit.py`.
19+
This can be added to `~/.lldbinit` for automatic loading into LLDB on launch by adding the line `command script import {Path to WebKit}/Tools/lldb/lldb_webkit.py`.
20+
For more details, see the Wiki article on [lldb formatters](https://trac.webkit.org/wiki/lldb%20formatters).
21+
22+
When debugging a debug build in LLDB, there are also a few functions that can be called on objects that will dump debugging info.
23+
24+
* RenderObject
25+
* showNodeTree()
26+
* showLineTree()
27+
* showRenderTree()
28+
* Node
29+
* showTree()
30+
* showNodePath()
31+
* showTreeForThis()
32+
* showNodePathForThis()
33+
534
## Debugging Layout Tests
635

736
The easiest way to debug a layout test is with WebKitTestRunner or DumpRenderTree.

Sources/WebKit/WebKit.docc/Build&Debug/Tests.md

Lines changed: 537 additions & 0 deletions
Large diffs are not rendered by default.

Sources/WebKit/WebKit.docc/GettingStarted/Introduction.md

Lines changed: 0 additions & 1061 deletions
Large diffs are not rendered by default.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Adding JS APIs
2+
3+
## Overview
4+
5+
To introduce a new JavaScript API in [WebCore](https://github.com/WebKit/WebKit/blob/main/Source/WebCore/),
6+
first identify the directory under which to implement this new API, and introduce corresponding Web IDL files (e.g., "dom/SomeAPI.idl").
7+
8+
New IDL files should be listed in [Source/WebCore/DerivedSources.make](https://github.com/WebKit/WebKit/blob/main/Source/WebCore/DerivedSources.make)
9+
so that the aforementioned perl script can generate corresponding JS*.cpp and JS*.h files.
10+
Add these newly generated JS*.cpp files to [Source/WebCore/Sources.txt](https://github.com/WebKit/WebKit/blob/main/Source/WebCore/Sources.txt)
11+
in order for them to be compiled.
12+
13+
Also, add the new IDL file(s) to [Source/WebCore/CMakeLists.txt](https://github.com/WebKit/WebKit/blob/main/Source/WebCore/CMakeLists.txt).
14+
15+
Remember to add these files to [WebCore's Xcode project](https://github.com/WebKit/WebKit/tree/main/Source/WebCore/WebCore.xcodeproj) as well.
16+
17+
For example, [this commit](https://github.com/WebKit/WebKit/commit/cbda68a29beb3da90d19855882c5340ce06f1546)
18+
introduced [`IdleDeadline.idl`](https://github.com/WebKit/WebKit/blob/main/Source/WebCore/dom/IdleDeadline.idl)
19+
and added `JSIdleDeadline.cpp` to the list of derived sources to be compiled.

Sources/WebKit/WebKit.docc/InDepth/JSWrappers.md

Lines changed: 342 additions & 0 deletions
Large diffs are not rendered by default.

Sources/WebKit/WebKit.docc/InDepth/MemoryManagement.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,88 @@ Because `WeakHashMap` does not get notified when the referenced object is delete
265265
the users / owners of `WeakHashMap` are still responsible for deleting the relevant entries from the map.
266266
Otherwise, the memory space used by `WeakPtrImpl` and its value will not be free'ed up until
267267
next rehash or amortized cleanup cycle arrives (based on the total number of read or write operations).
268+
269+
## Reference Counting of DOM Nodes
270+
271+
[`Node`](https://github.com/WebKit/WebKit/blob/main/Source/WebCore/dom/Node.h) is a reference counted object but with a twist.
272+
It has a [separate boolean flag](https://github.com/WebKit/WebKit/blob/297c01a143f649b34544f0cb7a555decf6ecbbfd/Source/WebCore/dom/Node.h#L832)
273+
indicating whether it has a [parent](https://dom.spec.whatwg.org/#concept-tree-parent) node or not.
274+
A `Node` object is [not deleted](https://github.com/WebKit/WebKit/blob/297c01a143f649b34544f0cb7a555decf6ecbbfd/Source/WebCore/dom/Node.h#L801)
275+
so long as it has a reference count above 0 or this boolean flag is set.
276+
The boolean flag effectively functions as a `RefPtr` from a parent `Node`
277+
to each one of its [child](https://dom.spec.whatwg.org/#concept-tree-child) `Node`.
278+
We do this because `Node` only knows its [first child](https://dom.spec.whatwg.org/#concept-tree-first-child)
279+
and its [last child](https://dom.spec.whatwg.org/#concept-tree-last-child)
280+
and each [sibling](https://dom.spec.whatwg.org/#concept-tree-sibling) nodes are implemented
281+
as a [doubly linked list](https://en.wikipedia.org/wiki/Doubly_linked_list) to allow
282+
efficient [insertion](https://dom.spec.whatwg.org/#concept-node-insert)
283+
and [removal](https://dom.spec.whatwg.org/#concept-node-remove) and traversal of sibling nodes.
284+
285+
Conceptually, each `Node` is kept alive by its root node and external references to it,
286+
and we use the root node as an opaque root of each `Node`'s JS wrapper.
287+
Therefore the JS wrapper of each `Node` is kept alive as long as either the node itself
288+
or any other node which shares the same root node is visited by the garbage collector.
289+
290+
On the other hand, a `Node` does not keep its parent or any of its
291+
[shadow-including ancestor](https://dom.spec.whatwg.org/#concept-shadow-including-ancestor) `Node` alive
292+
either by reference counting or via the boolean flag even though the JavaScript API requires this to be the case.
293+
In order to implement this DOM API behavior,
294+
WebKit [will create](https://github.com/WebKit/WebKit/blob/297c01a143f649b34544f0cb7a555decf6ecbbfd/Source/WebCore/bindings/js/JSNodeCustom.cpp#L174)
295+
a JS wrapper for each `Node` which is being removed from its parent if there isn't already one.
296+
A `Node` which is a root node (of the newly removed [subtree](https://dom.spec.whatwg.org/#concept-tree)) is an opaque root of its JS wrapper,
297+
and the garbage collector will visit this opaque root if there is any JS wrapper in the removed subtree that needs to be kept alive.
298+
In effect, this keeps the new root node and all its [descendant](https://dom.spec.whatwg.org/#concept-tree-descendant) nodes alive
299+
if the newly removed subtree contains any node with a live JS wrapper, preserving the API contract.
300+
301+
It's important to recognize that storing a `Ref` or a `RefPtr` to another `Node` in a `Node` subclass
302+
or an object directly owned by the Node can create a [reference cycle](https://en.wikipedia.org/wiki/Reference_counting#Dealing_with_reference_cycles),
303+
or a reference that never gets cleared.
304+
It's not guaranteed that every node is [disconnected](https://dom.spec.whatwg.org/#connected)
305+
from a [`Document`](https://github.com/WebKit/WebKit/blob/main/Source/WebCore/dom/Document.h) at some point in the future,
306+
and some `Node` may always have a parent node or a child node so long as it exists.
307+
Only permissible circumstances in which a `Ref` or a `RefPtr` to another `Node` can be stored
308+
in a `Node` subclass or other data structures owned by it is if it's temporally limited.
309+
For example, it's okay to store a `Ref` or a `RefPtr` in
310+
an enqueued [event loop task](https://github.com/WebKit/WebKit/blob/main/Source/WebCore/dom/EventLoop.h#L69).
311+
In all other circumstances, `WeakPtr` should be used to reference another `Node`,
312+
and JS wrapper relationships such as opaque roots should be used to preserve the lifecycle ties between `Node` objects.
313+
314+
It's equally crucial to observe that keeping C++ Node object alive by storing `Ref` or `RefPtr`
315+
in an enqueued [event loop task](https://github.com/WebKit/WebKit/blob/main/Source/WebCore/dom/EventLoop.h#L69)
316+
does not keep its JS wrapper alive, and can result in the JS wrapper of a conceptually live object to be erroneously garbage collected.
317+
To avoid this problem, use [`GCReachableRef`](https://github.com/WebKit/WebKit/blob/main/Source/WebCore/dom/GCReachableRef.h) instead
318+
to temporarily hold a strong reference to a node over a period of time.
319+
For example, [`HTMLTextFormControlElement::scheduleSelectEvent()`](https://github.com/WebKit/WebKit/blob/297c01a143f649b34544f0cb7a555decf6ecbbfd/Source/WebCore/html/HTMLTextFormControlElement.cpp#L547)
320+
uses `GCReachableRef` to fire an event in an event loop task:
321+
```cpp
322+
void HTMLTextFormControlElement::scheduleSelectEvent()
323+
{
324+
document().eventLoop().queueTask(TaskSource::UserInteraction, [protectedThis = GCReachableRef { *this }] {
325+
protectedThis->dispatchEvent(Event::create(eventNames().selectEvent, Event::CanBubble::Yes, Event::IsCancelable::No));
326+
});
327+
}
328+
```
329+
330+
Alternatively, we can make it inherit from an [active DOM object](https://github.com/WebKit/WebKit/blob/main/Source/WebCore/dom/ActiveDOMObject.h),
331+
and use one of the following functions to enqueue a task or an event:
332+
- [`queueTaskKeepingObjectAlive`](https://github.com/WebKit/WebKit/blob/297c01a143f649b34544f0cb7a555decf6ecbbfd/Source/WebCore/dom/ActiveDOMObject.h#L107)
333+
- [`queueCancellableTaskKeepingObjectAlive`](https://github.com/WebKit/WebKit/blob/297c01a143f649b34544f0cb7a555decf6ecbbfd/Source/WebCore/dom/ActiveDOMObject.h#L115)
334+
- [`queueTaskToDispatchEvent`](https://github.com/WebKit/WebKit/blob/297c01a143f649b34544f0cb7a555decf6ecbbfd/Source/WebCore/dom/ActiveDOMObject.h#L124)
335+
- [`queueCancellableTaskToDispatchEvent`](https://github.com/WebKit/WebKit/blob/297c01a143f649b34544f0cb7a555decf6ecbbfd/Source/WebCore/dom/ActiveDOMObject.h#L130)
336+
337+
[`Document`](https://github.com/WebKit/WebKit/blob/main/Source/WebCore/dom/Document.h) node has one more special quirk
338+
because every [`Node`](https://github.com/WebKit/WebKit/blob/main/Source/WebCore/dom/Node.h) can have access to a document
339+
via [`ownerDocument` property](https://developer.mozilla.org/en-US/docs/Web/API/Node/ownerDocument)
340+
whether Node is [connected](https://dom.spec.whatwg.org/#connected) to the document or not.
341+
Every document has a regular reference count used by external clients and
342+
[referencing node count](https://github.com/WebKit/WebKit/blob/297c01a143f649b34544f0cb7a555decf6ecbbfd/Source/WebCore/dom/Document.h#L2093).
343+
The referencing node count of a document is the total number of nodes whose `ownerDocument` is the document.
344+
A document is [kept alive](https://github.com/WebKit/WebKit/blob/297c01a143f649b34544f0cb7a555decf6ecbbfd/Source/WebCore/dom/Document.cpp#L749)
345+
so long as its reference count and node referencing count is above 0.
346+
In addition, when the regular reference count is to become 0,
347+
it clears various states including its internal references to owning Nodes to sever any reference cycles with them.
348+
A document is special in that sense that it can store `RefPtr` to other nodes.
349+
Note that whilst the referencing node count acts like `Ref` from each `Node` to its owner `Document`,
350+
storing a `Ref` or a `RefPtr` to the same document or any other document will create
351+
a [reference cycle](https://en.wikipedia.org/wiki/Reference_counting#Dealing_with_reference_cycles)
352+
and should be avoided unless it's temporally limited as noted above.

Sources/WebKit/WebKit.docc/InDepth/WebKitBuildSystem.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# WebKit's Build System
1+
# Build System
22

33
An overview of how the WebKit build system is structured.
44

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Continuous Integration
2+
3+
## Overview
4+
5+
WebKit’s CI ([continuous integration](https://en.wikipedia.org/wiki/Continuous_integration)) infrastructure is located at [build.webkit.org](https://build.webkit.org/)).
6+
7+
[build.webkit.org](https://build.webkit.org/) will build and test commits from WebKit in the chronological order
8+
and report test results to [results.webkit.org](https://results.webkit.org/).
9+
Due to the chronological ordering, results could be a few hours behind during the work week.
10+
11+
12+
We also have a dashboard to monitor the health of [build.webkit.org](https://build.webkit.org/)
13+
at [build.webkit.org/dashboard](https://build.webkit.org/dashboard/).
14+
If you observe that some bots are offline, or otherwise not processing your patch,
15+
please notify [[email protected]](mailto:[email protected]).
16+
17+
This dashboard isn't great for investigating individual test failures,
18+
[results.webkit.org](https://results.webkit.org/) is a better tool for such investigations.
19+
It keeps track of individual test status by configuration over time.
20+
You can search individual tests by name or look at the historical results of entire test suites.
21+
These results will link back to the test runs in Buildbot which are associated with a specific failure.
22+
See layout tests section for more details on how to use these tools to investigate test failures observed on bots.
23+
24+
FIXME: Add a section about downloading build products from build.webkit.org.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Todo
2+
3+
Articles that need to be written.
4+
5+
## Overview
6+
7+
| Topic | Description |
8+
| ----- | ----------- |
9+
| Inserting or Removing DOM Nodes | FIXME: Talk about how a node insertion or removal works. |
10+
| Understanding Style and Render Tree | FIXME: Describe rendering/layers/compositing |
11+
| Security Model of Web | For starters, refer to https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy. FIXME: Write this section. |

0 commit comments

Comments
 (0)