Enable -Wexit-time-destructors for all in-tree library targets and update process-lifetime library statics so they no longer register exit-time destructors. Long-lived caches, lookup tables, singleton registries, and generated constants now use NeverDestroyed or leaked references where the data is intended to live until process exit. Update LibWeb, LibLine, and the binding generators so regenerated sources follow the same rule instead of reintroducing destructed statics.
77 lines
2.8 KiB
C++
77 lines
2.8 KiB
C++
/*
|
|
* Copyright (c) 2022, Andrew Kaster <akaster@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/ByteString.h>
|
|
#include <AK/NeverDestroyed.h>
|
|
#include <AK/Vector.h>
|
|
#include <LibIDL/ExposedTo.h>
|
|
|
|
static auto& error_string()
|
|
{
|
|
static NeverDestroyed<ByteString> string;
|
|
return *string;
|
|
}
|
|
|
|
namespace IDL {
|
|
|
|
ErrorOr<ExposedTo> parse_exposure_set(StringView interface_name, StringView exposed)
|
|
{
|
|
// NOTE: This roughly follows the definitions of https://webidl.spec.whatwg.org/#Exposed
|
|
// It does not remotely interpret all the abstract operations therein though.
|
|
|
|
auto exposed_trimmed = exposed.trim_whitespace();
|
|
if (exposed_trimmed == "*"sv)
|
|
return ExposedTo::All;
|
|
if (exposed_trimmed == "Nobody"sv)
|
|
return ExposedTo::Nobody;
|
|
|
|
auto exposed_from_string = [](auto& string) -> Optional<ExposedTo> {
|
|
if (string == "Window"sv)
|
|
return ExposedTo::Window;
|
|
if (string == "Worker"sv)
|
|
return ExposedTo::AllWorkers;
|
|
if (string == "DedicatedWorker"sv)
|
|
return ExposedTo::DedicatedWorker;
|
|
if (string == "SharedWorker"sv)
|
|
return ExposedTo::SharedWorker;
|
|
if (string == "ServiceWorker"sv)
|
|
return ExposedTo::ServiceWorker;
|
|
if (string == "AudioWorklet"sv)
|
|
return ExposedTo::AudioWorklet;
|
|
if (string == "LayoutWorklet"sv)
|
|
return ExposedTo::LayoutWorklet;
|
|
if (string == "PaintWorklet"sv)
|
|
return ExposedTo::PaintWorklet;
|
|
if (string == "Worklet"sv)
|
|
return ExposedTo::Worklet;
|
|
return {};
|
|
};
|
|
if (auto parsed_exposed = exposed_from_string(exposed_trimmed); parsed_exposed.has_value())
|
|
return parsed_exposed.value();
|
|
|
|
if (exposed_trimmed[0] == '(') {
|
|
ExposedTo whom = ExposedTo::Nobody;
|
|
for (StringView candidate : exposed_trimmed.substring_view(1, exposed_trimmed.length() - 1).split_view(',')) {
|
|
candidate = candidate.trim_whitespace();
|
|
if (auto parsed_exposed = exposed_from_string(candidate); parsed_exposed.has_value()) {
|
|
whom |= parsed_exposed.value();
|
|
} else {
|
|
error_string() = ByteString::formatted("Unknown Exposed attribute candidate {} in {} in {}", candidate, exposed_trimmed, interface_name);
|
|
return Error::from_string_view(error_string().view());
|
|
}
|
|
}
|
|
if (whom == ExposedTo::Nobody) {
|
|
error_string() = ByteString::formatted("Unknown Exposed attribute {} in {}", exposed_trimmed, interface_name);
|
|
return Error::from_string_view(error_string().view());
|
|
}
|
|
return whom;
|
|
}
|
|
|
|
error_string() = ByteString::formatted("Unknown Exposed attribute {} in {}", exposed_trimmed, interface_name);
|
|
return Error::from_string_view(error_string().view());
|
|
}
|
|
|
|
}
|