Skip to content

Commit

Permalink
Merge branch 'LadybirdBrowser:master' into fix-mouse-events
Browse files Browse the repository at this point in the history
  • Loading branch information
Psychpsyo authored Nov 15, 2024
2 parents f1a42ff + 6319ded commit f4cdddf
Show file tree
Hide file tree
Showing 23 changed files with 936 additions and 36 deletions.
7 changes: 7 additions & 0 deletions AK/AK+Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,11 @@ extension AK.StringView: ExpressibleByStringLiteral {
public init(stringLiteral value: StringLiteralType) {
self.init(value.utf8Start, value.utf8CodeUnitCount)
}

public func endsWith(_ suffix: AK.StringView) -> Bool {
if suffix.length() == 1 {
return self.ends_with(suffix[0])
}
return self.ends_with(suffix, AK.CaseSensitivity.sensitive)
}
}
2 changes: 1 addition & 1 deletion Libraries/LibCore/MimeData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static Array const s_registered_mime_type = {
MimeType { .name = "application/x-blender"sv, .common_extensions = { ".blend"sv, ".blended"sv }, .description = "Blender project file"sv, .magic_bytes = Vector<u8> { 'B', 'L', 'E', 'N', 'D', 'E', 'R' } },
MimeType { .name = "application/x-bzip2"sv, .common_extensions = { ".bz2"sv }, .description = "BZIP2 compressed data"sv, .magic_bytes = Vector<u8> { 'B', 'Z', 'h' } },
MimeType { .name = "application/x-sheets+json"sv, .common_extensions = { ".sheets"sv }, .description = "Serenity Spreadsheet document"sv },
MimeType { .name = "application/xhtml+xml"sv, .common_extensions = { ".xhtml"sv }, .description = "XHTML document"sv },
MimeType { .name = "application/xhtml+xml"sv, .common_extensions = { ".xhtml"sv, ".xht"sv }, .description = "XHTML document"sv },
MimeType { .name = "application/zip"sv, .common_extensions = { ".zip"sv }, .description = "ZIP archive"sv, .magic_bytes = Vector<u8> { 0x50, 0x4B } },

MimeType { .name = "audio/flac"sv, .common_extensions = { ".flac"sv }, .description = "FLAC audio"sv, .magic_bytes = Vector<u8> { 'f', 'L', 'a', 'C' } },
Expand Down
7 changes: 6 additions & 1 deletion Libraries/LibGfx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ set(SOURCES
SkiaBackendContext.cpp
)

set(SWIFT_EXCLUDE_HEADERS
MetalContext.h
VulkanContext.h
)

if (APPLE)
list(APPEND SOURCES MetalContext.mm)
endif()
Expand Down Expand Up @@ -130,7 +135,7 @@ else()
endif()

if (ENABLE_SWIFT)
generate_clang_module_map(LibGfx GENERATED_FILES ${generated_headers})
generate_clang_module_map(LibGfx GENERATED_FILES ${generated_headers} EXCLUDE_FILES ${SWIFT_EXCLUDE_HEADERS})
target_sources(LibGfx PRIVATE
Color.swift
)
Expand Down
10 changes: 6 additions & 4 deletions Libraries/LibJS/SourceTextModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,10 @@ ThrowCompletionOr<void> SourceTextModule::execute_module(VM& vm, GC::Ptr<Promise
// the top-level module code.
// FIXME: Improve this situation, so we can match the spec better.

// AD-HOC: We push/pop the moduleContext around the function construction to ensure that the async execution context
// captures the module execution context.
vm.push_execution_context(*module_context);

FunctionParsingInsights parsing_insights;
parsing_insights.uses_this_from_environment = true;
parsing_insights.uses_this = true;
Expand All @@ -768,12 +772,10 @@ ThrowCompletionOr<void> SourceTextModule::execute_module(VM& vm, GC::Ptr<Promise
{}, 0, {}, environment(), nullptr, FunctionKind::Async, true, parsing_insights);
module_wrapper_function->set_is_module_wrapper(true);

// AD-HOC: We push/pop the moduleContext around the call to ensure that the async execution context
// captures the module execution context.
vm.push_execution_context(*module_context);
auto result = call(vm, Value { module_wrapper_function }, js_undefined(), ReadonlySpan<Value> {});
vm.pop_execution_context();

auto result = call(vm, Value { module_wrapper_function }, js_undefined(), ReadonlySpan<Value> {});

// AD-HOC: This is basically analogous to what AsyncBlockStart would do.
if (result.is_throw_completion()) {
MUST(call(vm, *capability->reject(), js_undefined(), result.throw_completion().value().value()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,33 @@ describe("normal behavior", () => {

expect(value).not.toHaveProperty("default", null);
expect(value).not.toHaveProperty("bar", null);
expect(value).not.toHaveProperty("baz", null);
expect(value).not.toHaveProperty("qux", null);
passed = true;
})
.catch(value => {
error = value;
});
runQueuedPromiseJobs();
expect(error).toBeNull();
expect(passed).toBeTrue();
});

test("value from async module from top-level awaited function", () => {
const shadowRealm = new ShadowRealm();
const promise = shadowRealm.importValue("./async-module.mjs", "qux");
expect(promise).toBeInstanceOf(Promise);
let error = null;
let passed = false;
promise
.then(value => {
expect(value).toBe("'qux' export");
expect(typeof value).toBe("string");

expect(value).not.toHaveProperty("default", null);
expect(value).not.toHaveProperty("foo", null);
expect(value).not.toHaveProperty("bar", null);
expect(value).not.toHaveProperty("baz", null);
passed = true;
})
.catch(value => {
Expand Down
6 changes: 6 additions & 0 deletions Libraries/LibJS/Tests/builtins/ShadowRealm/async-module.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ export default "Default export";
await Promise.resolve(2);

export const bar = "'bar' export";

async function baz() {
return "'qux' export";
}

export const qux = await baz();
27 changes: 15 additions & 12 deletions Libraries/LibWeb/Crypto/SubtleCrypto.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2023-2024, stelar7 <dudedbz@gmail.com>
* Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <AK/QuickSort.h>
#include <LibCrypto/Hash/HashManager.h>
#include <LibJS/Runtime/ArrayBuffer.h>
#include <LibJS/Runtime/Promise.h>
#include <LibWeb/Bindings/ExceptionOrUtils.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/SubtleCryptoPrototype.h>
Expand Down Expand Up @@ -664,7 +664,7 @@ JS::ThrowCompletionOr<GC::Ref<WebIDL::Promise>> SubtleCrypto::derive_key(Algorit
auto promise = WebIDL::create_promise(realm);

// 9. Return promise and perform the remaining steps in parallel.
Platform::EventLoopPlugin::the().deferred_invoke(GC::create_function(realm.heap(), [&realm, &vm, normalized_algorithm = normalized_algorithm.release_value(), promise, normalized_derived_key_algorithm_import = normalized_derived_key_algorithm_import.release_value(), normalized_derived_key_algorithm_length = normalized_derived_key_algorithm_length.release_value(), base_key = move(base_key), extractable, key_usages = move(key_usages)]() -> void {
Platform::EventLoopPlugin::the().deferred_invoke(GC::create_function(realm.heap(), [&realm, &vm, normalized_algorithm = normalized_algorithm.release_value(), promise, normalized_derived_key_algorithm_import = normalized_derived_key_algorithm_import.release_value(), normalized_derived_key_algorithm_length = normalized_derived_key_algorithm_length.release_value(), base_key = move(base_key), extractable, key_usages = move(key_usages)]() mutable -> void {
HTML::TemporaryExecutionContext context(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes);
// 10. If the following steps or referenced procedures say to throw an error, reject promise with the returned error and then terminate the algorithm.

Expand Down Expand Up @@ -707,25 +707,28 @@ JS::ThrowCompletionOr<GC::Ref<WebIDL::Promise>> SubtleCrypto::derive_key(Algorit
}

// 15. Let result be the result of performing the import key operation specified by normalizedDerivedKeyAlgorithmImport using "raw" as format, secret as keyData, derivedKeyType as algorithm and using extractable and usages.
auto result = normalized_derived_key_algorithm_import.methods->import_key(*normalized_derived_key_algorithm_import.parameter, Bindings::KeyFormat::Raw, secret.release_value()->buffer(), extractable, key_usages);
if (result.is_error()) {
WebIDL::reject_promise(realm, promise, Bindings::dom_exception_to_throw_completion(realm.vm(), result.release_error()).release_value().value());
auto result_or_error = normalized_derived_key_algorithm_import.methods->import_key(*normalized_derived_key_algorithm_import.parameter, Bindings::KeyFormat::Raw, secret.release_value()->buffer(), extractable, key_usages);
if (result_or_error.is_error()) {
WebIDL::reject_promise(realm, promise, Bindings::dom_exception_to_throw_completion(realm.vm(), result_or_error.release_error()).release_value().value());
return;
}
auto result = result_or_error.release_value();

// 16. If the [[type]] internal slot of result is "secret" or "private" and usages is empty, then throw a SyntaxError.
if ((result.release_value()->type() == Bindings::KeyType::Secret || result.release_value()->type() == Bindings::KeyType::Private) && key_usages.is_empty()) {
if ((result->type() == Bindings::KeyType::Secret || result->type() == Bindings::KeyType::Private) && key_usages.is_empty()) {
WebIDL::reject_promise(realm, promise, WebIDL::SyntaxError::create(realm, "usages must not be empty"_string));
return;
}

// AD-HOC: Set the [[extractable]] internal slot of key to be extractable.
// See: https://github.com/w3c/webcrypto/issues/383
auto key = result.release_value();
key->set_extractable(extractable);
// 17. Set the [[extractable]] internal slot of result to extractable.
result->set_extractable(extractable);

// 17. Resolve promise with result.
WebIDL::resolve_promise(realm, promise, key);
// 18. Set the [[usages]] internal slot of result to the normalized value of usages.
normalize_key_usages(key_usages);
result->set_usages(key_usages);

// 19. Resolve promise with result.
WebIDL::resolve_promise(realm, promise, result);
}));

return promise;
Expand Down
4 changes: 3 additions & 1 deletion Libraries/LibWeb/HTML/MessagePort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,9 @@ void MessagePort::post_message_task_steps(SerializedTransferRecord& serialize_wi
MessageEventInit event_init {};
event_init.data = message_clone;
event_init.ports = move(new_ports);
message_event_target->dispatch_event(MessageEvent::create(target_realm, HTML::EventNames::message, event_init));
auto event = MessageEvent::create(target_realm, HTML::EventNames::message, event_init);
event->set_is_trusted(true);
message_event_target->dispatch_event(event);
}

// https://html.spec.whatwg.org/multipage/web-messaging.html#dom-messageport-start
Expand Down
75 changes: 75 additions & 0 deletions Libraries/LibWeb/HTML/Parser/HTMLToken.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,81 @@ public class HTMLToken {
}
}
}
public var name: Swift.String? {
get {
switch self.type {
case .DOCTYPE(let name, _, _, _):
return name
default:
preconditionFailure("doctypeName called on non-doctype token")
}
}
set {
switch self.type {
case .DOCTYPE(_, let publicIdentifier, let systemIdentifier, let forceQuirksMode):
self.type = .DOCTYPE(name: newValue, publicIdentifier: publicIdentifier, systemIdentifier: systemIdentifier, forceQuirksMode: forceQuirksMode)
default:
preconditionFailure("doctypeName= called on non-doctype token")
}
}
}

public var forceQuirks: Bool {
get {
switch self.type {
case .DOCTYPE(_, _, _, let forceQuirksMode):
return forceQuirksMode
default:
preconditionFailure("forceQuirks called on non-doctype token")
}
}
set {
switch self.type {
case .DOCTYPE(let name, let publicIdentifier, let systemIdentifier, _):
self.type = .DOCTYPE(name: name, publicIdentifier: publicIdentifier, systemIdentifier: systemIdentifier, forceQuirksMode: newValue)
default:
preconditionFailure("forceQuirks= called on non-doctype token")
}
}
}

public var publicIdentifier: Swift.String? {
get {
switch self.type {
case .DOCTYPE(_, let publicIdentifier, _, _):
return publicIdentifier
default:
preconditionFailure("publicIdentifier called on non-doctype token")
}
}
set {
switch self.type {
case .DOCTYPE(let name, _, let systemIdentifier, let forceQuirksMode):
self.type = .DOCTYPE(name: name, publicIdentifier: newValue, systemIdentifier: systemIdentifier, forceQuirksMode: forceQuirksMode)
default:
preconditionFailure("publicIdentifier= called on non-doctype token")
}
}
}

public var systemIdentifier: Swift.String? {
get {
switch self.type {
case .DOCTYPE(_, _, let systemIdentifier, _):
return systemIdentifier
default:
preconditionFailure("systemIdentifier called on non-doctype token")
}
}
set {
switch self.type {
case .DOCTYPE(let name, let publicIdentifier, _, let forceQuirksMode):
self.type = .DOCTYPE(name: name, publicIdentifier: publicIdentifier, systemIdentifier: newValue, forceQuirksMode: forceQuirksMode)
default:
preconditionFailure("systemIdentifier= called on non-doctype token")
}
}
}

public init() {}
public init(type: TokenType) {
Expand Down
Loading

0 comments on commit f4cdddf

Please sign in to comment.