Skip to content

Commit 41eb725

Browse files
gmtatrflynn89
authored andcommitted
LibWeb: Convert Ladybird notes in spec steps to // NB: ...
We have a couple of ways to designate spec notes and (our) developer notes in comments, but we never really settled on a single approach. As a result, we have a bit of a mixed bag of note comments on our hands. To the extent that I could find them, I changed developer notes to `// NB: ...` and changed spec notes to `// NOTE: ...`. The rationale for this is that in most web specs, notes are prefixed by `NOTE: ...` so this makes it easier to copy paste verbatim. The choice for `NB: ...` is pretty arbitrary, but it makes it stand out from the regular spec notes and it was already in wide use in our codebase.
1 parent 9394c9a commit 41eb725

File tree

11 files changed

+52
-44
lines changed

11 files changed

+52
-44
lines changed

Libraries/LibWeb/Bindings/MainThreadVM.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -535,12 +535,12 @@ void initialize_main_thread_vm(AgentType type)
535535
return;
536536
}
537537

538-
// Spec-Note: This step is essentially validating all of the requested module specifiers and type attributes
539-
// when the first call to HostLoadImportedModule for a static module dependency list is made, to
540-
// avoid further loading operations in the case any one of the dependencies has a static error.
541-
// We treat a module with unresolvable module specifiers or unsupported type attributes the same
542-
// as one that cannot be parsed; in both cases, a syntactic issue makes it impossible to ever
543-
// contemplate linking the module later.
538+
// NOTE: This step is essentially validating all of the requested module specifiers and type attributes
539+
// when the first call to HostLoadImportedModule for a static module dependency list is made, to
540+
// avoid further loading operations in the case any one of the dependencies has a static error. We
541+
// treat a module with unresolvable module specifiers or unsupported type attributes the same as
542+
// one that cannot be parsed; in both cases, a syntactic issue makes it impossible to ever
543+
// contemplate linking the module later.
544544
}
545545
}
546546

Libraries/LibWeb/DOM/EventTarget.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -734,16 +734,18 @@ JS::ThrowCompletionOr<void> EventTarget::process_event_handler_for_event(FlyStri
734734
if (special_error_event_handling) {
735735
// -> If special error event handling is true
736736
// If return value is true, then set event's canceled flag.
737-
// NOTE: the return type of EventHandler is `any`, so no coercion happens, meaning we have to check if it's a boolean first.
737+
// NB: the return type of EventHandler is `any`, so no coercion happens, meaning we have to check if it's a
738+
// boolean first.
738739
if (return_value.is_boolean() && return_value.as_bool())
739740
event.set_cancelled(true);
740741
} else {
741742
// -> Otherwise
742743
// If return value is false, then set event's canceled flag.
743-
// NOTE: the return type of EventHandler is `any`, so no coercion happens, meaning we have to check if it's a boolean first.
744-
// Spec-Note: If we've gotten to this "Otherwise" clause because event's type is "beforeunload" but event is
745-
// not a BeforeUnloadEvent object, then return value will never be false, since in such cases
746-
// return value will have been coerced into either null or a DOMString.
744+
// NB: the return type of EventHandler is `any`, so no coercion happens, meaning we have to check if it's a
745+
// boolean first.
746+
// NOTE: If we've gotten to this "Otherwise" clause because event's type is "beforeunload" but event is not a
747+
// BeforeUnloadEvent object, then return value will never be false, since in such cases return value will
748+
// have been coerced into either null or a DOMString.
747749
if (return_value.is_boolean() && !return_value.as_bool() && !is_beforeunload)
748750
event.set_cancelled(true);
749751
}

Libraries/LibWeb/DOM/Node.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -786,10 +786,10 @@ void Node::insert_before(GC::Ref<Node> node, GC::Ptr<Node> child, bool suppress_
786786
children_changed(&metadata);
787787

788788
// 10. Let staticNodeList be a list of nodes, initially « ».
789-
// Spec-Note: We collect all nodes before calling the post-connection steps on any one of them, instead of calling
790-
// the post-connection steps while we’re traversing the node tree. This is because the post-connection
791-
// steps can modify the tree’s structure, making live traversal unsafe, possibly leading to the
792-
// post-connection steps being called multiple times on the same node.
789+
// NOTE: We collect all nodes before calling the post-connection steps on any one of them, instead of calling the
790+
// post-connection steps while we’re traversing the node tree. This is because the post-connection steps can
791+
// modify the tree’s structure, making live traversal unsafe, possibly leading to the post-connection steps
792+
// being called multiple times on the same node.
793793
GC::RootVector<GC::Ref<Node>> static_node_list(heap());
794794

795795
// 11. For each node of nodes, in tree order:

Libraries/LibWeb/FileAPI/FileReader.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ WebIDL::ExceptionOr<void> FileReader::read_operation(Blob& blob, Type type, Opti
258258
if (m_state != State::Loading)
259259
dispatch_event(DOM::Event::create(realm, HTML::EventNames::loadend));
260260

261-
// Spec-Note: Event handler for the load or error events could have started another load, if that happens the loadend event for this load is not fired.
261+
// NOTE: Event handler for the load or error events could have started another load, if that happens
262+
// the loadend event for this load is not fired.
262263
}));
263264

264265
return;
@@ -278,7 +279,8 @@ WebIDL::ExceptionOr<void> FileReader::read_operation(Blob& blob, Type type, Opti
278279
if (m_state != State::Loading)
279280
dispatch_event(DOM::Event::create(realm, HTML::EventNames::loadend));
280281

281-
// Spec-Note: Event handler for the error event could have started another load, if that happens the loadend event for this load is not fired.
282+
// NOTE: Event handler for the error event could have started another load, if that happens the
283+
// loadend event for this load is not fired.
282284
}));
283285

284286
return;

Libraries/LibWeb/HTML/HTMLButtonElement.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ bool HTMLButtonElement::has_activation_behavior() const
154154
return true;
155155
}
156156

157+
// https://html.spec.whatwg.org/multipage/form-elements.html#the-button-element:activation-behaviour
157158
void HTMLButtonElement::activation_behavior(DOM::Event const& event)
158159
{
159-
// https://html.spec.whatwg.org/multipage/form-elements.html#the-button-element:activation-behaviour
160160
// 1. If element is disabled, then return.
161161
if (!enabled())
162162
return;
@@ -223,8 +223,12 @@ void HTMLButtonElement::activation_behavior(DOM::Event const& event)
223223
return;
224224
}
225225

226-
// 5. Let continue be the result of firing an event named command at target, using CommandEvent, with its command attribute initialized to command, its source attribute initialized to element, and its cancelable and composed attributes initialized to true.
227-
// SPEC-NOTE: DOM standard issue #1328 tracks how to better standardize associated event data in a way which makes sense on Events. Currently an event attribute initialized to a value cannot also have a getter, and so an internal slot (or map of additional fields) is required to properly specify this.
226+
// 5. Let continue be the result of firing an event named command at target, using CommandEvent, with its
227+
// command attribute initialized to command, its source attribute initialized to element, and its cancelable
228+
// and composed attributes initialized to true.
229+
// NOTE: DOM standard issue #1328 tracks how to better standardize associated event data in a way which makes
230+
// sense on Events. Currently an event attribute initialized to a value cannot also have a getter, and so
231+
// an internal slot (or map of additional fields) is required to properly specify this.
228232
CommandEventInit event_init {};
229233
event_init.command = command;
230234
event_init.source = this;

Libraries/LibWeb/HTML/Navigation.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,10 @@ WebIDL::ExceptionOr<NavigationResult> Navigation::navigate(String url, Navigatio
244244
// 4. Let state be options["state"], if it exists; otherwise, undefined.
245245
auto state = options.state.value_or(JS::js_undefined());
246246

247-
// 5. Let serializedState be StructuredSerializeForStorage(state).
248-
// If this throws an exception, then return an early error result for that exception.
249-
// Spec-Note: It is important to perform this step early, since serialization can invoke web developer code,
250-
// which in turn might change various things we check in later steps.
247+
// 5. Let serializedState be StructuredSerializeForStorage(state). If this throws an exception, then return an early
248+
// error result for that exception.
249+
// NOTE: It is important to perform this step early, since serialization can invoke web developer code, which in
250+
// turn might change various things we check in later steps.
251251
auto serialized_state_or_error = structured_serialize_for_storage(vm, state);
252252
if (serialized_state_or_error.is_error()) {
253253
return early_error_result(serialized_state_or_error.release_error());
@@ -307,10 +307,10 @@ WebIDL::ExceptionOr<NavigationResult> Navigation::reload(NavigationReloadOptions
307307
// 2. Let serializedState be StructuredSerializeForStorage(undefined).
308308
auto serialized_state = MUST(structured_serialize_for_storage(vm, JS::js_undefined()));
309309

310-
// 3. If options["state"] exists, then set serializedState to StructuredSerializeForStorage(options["state"]).
311-
// If this throws an exception, then return an early error result for that exception.
312-
// Spec-Note: It is important to perform this step early, since serialization can invoke web developer
313-
// code, which in turn might change various things we check in later steps.
310+
// 3. If options["state"] exists, then set serializedState to StructuredSerializeForStorage(options["state"]). If
311+
// this throws an exception, then return an early error result for that exception.
312+
// NOTE: It is important to perform this step early, since serialization can invoke web developer code, which in
313+
// turn might change various things we check in later steps.
314314
if (options.state.has_value()) {
315315
auto serialized_state_or_error = structured_serialize_for_storage(vm, options.state.value());
316316
if (serialized_state_or_error.is_error())

Libraries/LibWeb/HTML/Scripting/Fetching.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ WebIDL::ExceptionOr<URL::URL> resolve_module_specifier(Optional<Script&> referri
157157
result = TRY(resolve_imports_match(normalized_specifier.to_byte_string(), as_url, import_map.imports()));
158158

159159
// 12. If result is null, set it to asURL.
160-
// Spec-Note: By this point, if result was null, specifier wasn't remapped to anything by importMap, but it might have been able to be turned into a URL.
160+
// NOTE: By this point, if result was null, specifier wasn't remapped to anything by importMap, but it might have
161+
// been able to be turned into a URL.
161162
if (!result.has_value())
162163
result = as_url;
163164

Libraries/LibWeb/HTML/Scripting/ImportMap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ void merge_existing_and_new_import_maps(Window& global, ImportMap& new_import_ma
300300
// 1. Let newImportMapScopes be a deep copy of newImportMap's scopes.
301301
auto new_import_map_scopes = new_import_map.scopes();
302302

303-
// Spec-Note: We're mutating these copies and removing items from them when they are used to ignore scope-specific
304-
// rules. This is true for newImportMapScopes, as well as to newImportMapImports below.
303+
// NOTE: We're mutating these copies and removing items from them when they are used to ignore scope-specific rules.
304+
// This is true for newImportMapScopes, as well as to newImportMapImports below.
305305

306306
// 2. Let oldImportMap be global's import map.
307307
auto& old_import_map = global.import_map();

Libraries/LibWeb/HTML/Window.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ struct SpecifierResolution {
5858
// A specifier as a URL
5959
// A URL-or-null that represents the URL in case of a URL-like module specifier.
6060
//
61-
// Spec-Note: Implementations can replace specifier as a URL with a boolean that indicates
62-
// that the specifier is either bare or URL-like that is special.
61+
// NOTE: Implementations can replace specifier as a URL with a boolean that indicates that the specifier is either
62+
// bare or URL-like that is special.
6363
bool specifier_is_null_or_url_like_that_is_special { false };
6464
};
6565

@@ -300,10 +300,10 @@ class WEB_API Window final
300300
// https://html.spec.whatwg.org/multipage/webappapis.html#resolved-module-set
301301
// A global object has a resolved module set, a set of specifier resolution records, initially empty.
302302
//
303-
// Spec-Note: The resolved module set ensures that module specifier resolution returns the same result when called
304-
// multiple times with the same (referrer, specifier) pair. It does that by ensuring that import map rules
305-
// that impact the specifier in its referrer's scope cannot be defined after its initial resolution. For
306-
// now, only Window global objects have their module set data structures modified from the initial empty one.
303+
// NOTE: The resolved module set ensures that module specifier resolution returns the same result when called
304+
// multiple times with the same (referrer, specifier) pair. It does that by ensuring that import map rules
305+
// that impact the specifier in its referrer's scope cannot be defined after its initial resolution. For now,
306+
// only Window global objects have their module set data structures modified from the initial empty one.
307307
Vector<SpecifierResolution> m_resolved_module_set;
308308

309309
GC::Ptr<CSS::Screen> m_screen;

Libraries/LibWeb/SVG/SVGAnimatedNumber.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ void SVGAnimatedNumber::set_base_val(float new_value)
6363

6464
// 3. Let second be the second number in current if it has been explicitly specified, and if not, the implicit
6565
// value as described in the definition of the attribute.
66-
// LB-NOTE: All known usages of <number-optional-number> specify that a missing second number defaults to the
67-
// value of the first number.
66+
// NB: All known usages of <number-optional-number> specify that a missing second number defaults to the value
67+
// of the first number.
6868
auto second = current_values.size() > 1 && !current_values[1].is_empty()
6969
? parse_value_or_initial(current_values[1])
7070
: first;
@@ -130,8 +130,8 @@ float SVGAnimatedNumber::get_base_or_anim_value() const
130130
// 2. Otherwise, this SVGAnimatedNumber object reflects the second number. Return the second value in value if
131131
// it has been explicitly specified, and if not, return the implicit value as described in the definition of
132132
// the attribute.
133-
// LB-NOTE: All known usages of <number-optional-number> specify that a missing second number defaults to the
134-
// value of the first number.
133+
// NB: All known usages of <number-optional-number> specify that a missing second number defaults to the value
134+
// of the first number.
135135
VERIFY(m_value_represented == ValueRepresented::Second);
136136
if (values.size() > 1 && !values[1].is_empty())
137137
return parse_value_or_initial(values[1]);

0 commit comments

Comments
 (0)