Skip to content
10 changes: 5 additions & 5 deletions bridge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ if(CMAKE_SYSTEM_NAME MATCHES "MSYS" OR MINGW)
# set(CMAKE_LINKER lld)
# set(CMAKE_AR llvm-ar)
# set(CMAKE_RANLIB llvm-ranlib)

# Set C++20 standard for MSYS2 with libc++
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
add_compile_options(-stdlib=libc++)
add_link_options(-stdlib=libc++)

# Define math constants that are not in standard C++
add_compile_definitions(_USE_MATH_DEFINES)

Expand Down Expand Up @@ -108,14 +108,14 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -static-libgcc")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -stdlib=libc++ -static-libgcc")

# Ensure we're using clang/clang++ for libc++ support
if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message(WARNING "Using libc++ requires Clang compiler. Current compiler: ${CMAKE_CXX_COMPILER_ID}")
endif()

message(STATUS "Using static libc++ for Linux build")

# STATIC_QUICKJS is set via build script (-DSTATIC_QUICKJS=true)
endif ()

Expand Down
6 changes: 6 additions & 0 deletions bridge/bindings/qjs/binding_initializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
#include "qjs_image.h"
#include "qjs_input_event.h"
#include "qjs_intersection_change_event.h"
#include "qjs_intersection_observer.h"
#include "qjs_intersection_observer_entry.h"
#include "qjs_keyboard_event.h"
#include "qjs_computed_css_style_declaration.h"
#include "qjs_css_style_declaration.h"
Expand Down Expand Up @@ -315,6 +317,10 @@ void InstallBindings(ExecutingContext* context) {
QJSSVGLineElement::Install(context);
QJSNativeLoader::Install(context);

// IntersectionObserver
QJSIntersectionObserver::Install(context);
QJSIntersectionObserverEntry::Install(context);

// Legacy bindings, not standard.
QJSElementAttributes::Install(context);
QJSLegacyCssStyleDeclaration::Install(context);
Expand Down
1 change: 1 addition & 0 deletions bridge/bindings/qjs/generated_code_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
#include "bindings/qjs/dictionary_base.h"
#include "bindings/qjs/qjs_interface_bridge.h"
#include "script_value.h"
#include "qjs_union_double_sequencedouble.h"

#endif
4 changes: 4 additions & 0 deletions bridge/bindings/qjs/wrapper_type_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ enum {
JS_CLASS_FORM_DATA,
JS_CLASS_FILE,

// IntersectionObserver
JS_CLASS_INTERSECTION_OBSERVER,
JS_CLASS_INTERSECTION_OBSERVER_ENTRY,

JS_CLASS_CUSTOM_CLASS_INIT_COUNT /* last entry for predefined classes */
};

Expand Down
5 changes: 5 additions & 0 deletions bridge/bridge_sources.json5
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@
"core/dom/dom_token_list.cc",
"core/dom/dom_string_map.cc",
"core/dom/names_map.cc",
"core/dom/intersection_observer.cc",
"core/dom/intersection_observer_entry.cc",
"core/dom/element_rare_data_vector.cc",
"core/dom/space_split_string.cc",
"core/dom/scripted_animation_controller.cc",
Expand Down Expand Up @@ -739,6 +741,9 @@
"code_gen/qjs_dom_point_init.cc",
"code_gen/qjs_dom_point.cc",
"code_gen/qjs_dom_point_read_only.cc",
"code_gen/qjs_intersection_observer.cc",
"code_gen/qjs_intersection_observer_entry.cc",
"code_gen/qjs_intersection_observer_init.cc",
"code_gen/qjs_union_double_sequencedouble.cc",
"code_gen/qjs_unionhtml_image_elementhtml_canvas_element.cc",
"code_gen/qjs_union_dom_stringcanvas_gradientcanvas_pattern.cc",
Expand Down
2 changes: 1 addition & 1 deletion bridge/core/binding_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void NativeBindingObject::HandleCallFromDartSide(const DartIsolateContext* dart_
return;

const AtomicString method =
AtomicString(std::unique_ptr<AutoFreeNativeString>(static_cast<AutoFreeNativeString*>(native_method->u.ptr)));
native_method != nullptr ? AtomicString(std::unique_ptr<AutoFreeNativeString>(static_cast<AutoFreeNativeString*>(native_method->u.ptr))) : AtomicString::Empty();
const NativeValue result = binding_object->binding_target_->HandleCallFromDartSide(method, argc, argv, dart_object);

auto* return_value = new NativeValue();
Expand Down
3 changes: 2 additions & 1 deletion bridge/core/binding_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ enum CreateBindingObjectType {
kCreateDOMMatrix = 0,
kCreatePath2D = 1,
kCreateDOMPoint = 2,
kCreateFormData = 3
kCreateFormData = 3,
kCreateIntersectionObserver = 4,
};

struct BindingObjectPromiseContext : public DartReadable {
Expand Down
21 changes: 21 additions & 0 deletions bridge/core/dom/document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "core/dom/comment.h"
#include "core/dom/document_fragment.h"
#include "core/dom/element.h"
#include "core/dom/intersection_observer.h"
#include "core/dom/events/event_target.h"
#include "core/dom/text.h"
#include "core/frame/window.h"
Expand Down Expand Up @@ -556,9 +557,29 @@ std::shared_ptr<EventListener> Document::GetWindowAttributeEventListener(const A
return window->GetAttributeEventListener(event_type);
}

void Document::RegisterIntersectionObserver(IntersectionObserver* observer) {
if (observer == nullptr)
return;
intersection_observers_.insert(observer);
}

void Document::UnregisterIntersectionObserver(IntersectionObserver* observer) {
if (observer == nullptr)
return;
for (auto it = intersection_observers_.begin(); it != intersection_observers_.end(); ++it) {
if (it->Get() == observer) {
intersection_observers_.erase(it);
break;
}
}
}

void Document::Trace(GCVisitor* visitor) const {
script_animation_controller_.Trace(visitor);
visitor->TraceMember(current_script_);
for (auto& observer : intersection_observers_) {
visitor->TraceMember(observer);
}
if (style_engine_ != nullptr) {
style_engine_->Trace(visitor);
}
Expand Down
9 changes: 9 additions & 0 deletions bridge/core/dom/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef BRIDGE_DOCUMENT_H
#define BRIDGE_DOCUMENT_H

#include <unordered_set>

#include "bindings/qjs/cppgc/local_handle.h"
#include "container_node.h"
#include "core/platform/url/kurl.h"
Expand All @@ -30,6 +32,7 @@ class Text;
class Comment;
class HTMLElement;
class LiveNodeListBase;
class IntersectionObserver;

enum NodeListInvalidationType : int {
kDoNotInvalidateOnAttributeChanges = 0,
Expand Down Expand Up @@ -174,6 +177,10 @@ class Document : public ContainerNode, public TreeScope {
ExceptionState& exception_state);
std::shared_ptr<EventListener> GetWindowAttributeEventListener(const AtomicString& event_type);

// Keep JS IntersectionObserver instances alive while observing targets.
void RegisterIntersectionObserver(IntersectionObserver* observer);
void UnregisterIntersectionObserver(IntersectionObserver* observer);

void Trace(GCVisitor* visitor) const override;
const DocumentPublicMethods* documentPublicMethods();
StyleEngine& EnsureStyleEngine();
Expand Down Expand Up @@ -236,6 +243,8 @@ class Document : public ContainerNode, public TreeScope {
KURL base_element_url_; // The URL set by the <base> element.
KURL cookie_url_; // The URL to use for cookie access.
Member<HTMLScriptElement> current_script_{nullptr};

std::unordered_set<Member<IntersectionObserver>, Member<IntersectionObserver>::KeyHasher> intersection_observers_;
};

template <>
Expand Down
Loading
Loading