Shaka Player Embedded
Public Types | Public Member Functions | List of all members
shaka::js::dom::Node Class Referenceabstract

#include <node.h>

Inheritance diagram for shaka::js::dom::Node:
shaka::js::events::EventTarget shaka::BackingObject shaka::memory::Traceable shaka::js::dom::Attr shaka::js::dom::CharacterData shaka::js::dom::ContainerNode shaka::js::dom::Comment shaka::js::dom::Text shaka::js::dom::Document shaka::js::dom::Element shaka::js::mse::HTMLMediaElement shaka::js::mse::HTMLVideoElement

Public Types

enum  NodeType {
  ELEMENT_NODE = 1, ATTRIBUTE_NODE = 2, TEXT_NODE = 3, CDATA_SECTION_NODE = 4,
  ENTITY_REFERENCE_NODE = 5, ENTITY_NODE = 6, PROCESSING_INSTRUCTION_NODE = 7, COMMENT_NODE = 8,
  DOCUMENT_NODE = 9, DOCUMENT_TYPE_NODE = 10, DOCUMENT_FRAGMENT_NODE = 11, NOTATION_NODE = 12
}
 
enum  DocumentPosition {
  DOCUMENT_POSITION_DISCONNECTED = 0x01, DOCUMENT_POSITION_PRECEDING = 0x02, DOCUMENT_POSITION_FOLLOWING = 0x04, DOCUMENT_POSITION_CONTAINS = 0x08,
  DOCUMENT_POSITION_CONTAINED_BY = 0x10, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20
}
 
- Public Types inherited from shaka::js::events::EventTarget
using Listener = optional< Callback >
 

Public Member Functions

 Node (NodeType type, RefPtr< Document > document)
 
void Trace (memory::HeapTracer *tracer) const override
 
bool IsShortLived () const override
 
RefPtr< Documentdocument () const
 
RefPtr< Nodeparent_node () const
 
std::vector< RefPtr< Node > > child_nodes () const
 
NodeType node_type () const
 
virtual std::string node_name () const =0
 
virtual optional< std::string > NodeValue () const =0
 
virtual optional< std::string > TextContent () const =0
 
RefPtr< Nodefirst_child () const
 
RefPtr< Nodelast_child () const
 
RefPtr< NodeAppendChild (RefPtr< Node > new_child)
 
RefPtr< NodeRemoveChild (RefPtr< Node > to_remove)
 
bool is_document () const
 
bool is_element () const
 
bool is_char_data () const
 
- Public Member Functions inherited from shaka::js::events::EventTarget
 EventTarget ()
 
void Trace (memory::HeapTracer *tracer) const override
 
void AddEventListener (const std::string &type, Listener callback)
 
void SetCppEventListener (EventType type, std::function< void()> callback)
 
void RemoveEventListener (const std::string &type, Listener callback)
 
void UnsetCppEventListener (EventType type)
 
ExceptionOr< bool > DispatchEvent (RefPtr< Event > event)
 
ExceptionOr< bool > DispatchEventInternal (RefPtr< Event > event, bool *did_listeners_throw)
 
template<typename EventType , typename... Args>
std::shared_ptr< ThreadEvent< bool > > ScheduleEvent (Args &&... args)
 
template<typename EventType , typename... Args>
ExceptionOr< bool > RaiseEvent (Args... args)
 
- Public Member Functions inherited from shaka::BackingObject
 BackingObject ()
 
void Trace (memory::HeapTracer *tracer) const override
 
bool IsRootedAlive () const override
 
std::string name () const
 
virtual BackingObjectFactoryBasefactory () const =0
 
bool DerivedFrom (const std::string &base)
 
ReturnVal< JsValue > JsThis () const
 
void SetJsThis (Handle< JsObject > this_)
 
- Public Member Functions inherited from shaka::memory::Traceable
virtual ~Traceable ()
 

Additional Inherited Members

- Static Public Member Functions inherited from shaka::BackingObject
static void * operator new[] (size_t size)=delete
 
static void operator delete[] (void *)=delete
 
- Static Public Attributes inherited from shaka::BackingObject
static constexpr const size_t kInternalFieldCount = 2
 
- Static Public Attributes inherited from shaka::memory::Traceable
static constexpr const uint64_t kShortLiveDurationMs = 5000
 
- Protected Member Functions inherited from shaka::js::events::EventTarget
void AddListenerField (EventType type, Listener *on_field)
 
- Protected Member Functions inherited from shaka::BackingObject
 ~BackingObject () override
 

Detailed Description

Implements the Node interface for DOM. https://dom.spec.whatwg.org/#interface-node

IMPORTANT: This does not implement any event firing. Because the player only uses XML parsing, it does not need it. Meaning that altering the DOM tree will not result in any mutation events.

This also does not implement shadow-DOM.

The DOM spec says that Nodes should return the same objects, namely that adding a field to a node should persist. However, here we do not persist backing objects if they are not used.

// JavaScript
var x = document.getElementById('abc');
x.firstChild.foobar = 'xyz';
gc();
console.log(x.firstChild.foobar);

The above should work, but may not because the GC will collect the firstCild wrapper (JavaScript) object since it has no references.

Definition at line 59 of file node.h.

Member Enumeration Documentation

§ DocumentPosition

Enumerator
DOCUMENT_POSITION_DISCONNECTED 
DOCUMENT_POSITION_PRECEDING 
DOCUMENT_POSITION_FOLLOWING 
DOCUMENT_POSITION_CONTAINS 
DOCUMENT_POSITION_CONTAINED_BY 
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC 

Definition at line 77 of file node.h.

§ NodeType

Enumerator
ELEMENT_NODE 
ATTRIBUTE_NODE 
TEXT_NODE 
CDATA_SECTION_NODE 
ENTITY_REFERENCE_NODE 
ENTITY_NODE 
PROCESSING_INSTRUCTION_NODE 
COMMENT_NODE 
DOCUMENT_NODE 
DOCUMENT_TYPE_NODE 
DOCUMENT_FRAGMENT_NODE 
NOTATION_NODE 

Definition at line 63 of file node.h.

Constructor & Destructor Documentation

§ Node()

shaka::js::dom::Node::Node ( NodeType  type,
RefPtr< Document document 
)

Definition at line 26 of file node.cc.

Member Function Documentation

§ AppendChild()

RefPtr< Node > shaka::js::dom::Node::AppendChild ( RefPtr< Node new_child)

Definition at line 67 of file node.cc.

§ child_nodes()

std::vector< RefPtr< Node > > shaka::js::dom::Node::child_nodes ( ) const

Definition at line 55 of file node.cc.

§ document()

RefPtr< Document > shaka::js::dom::Node::document ( ) const

Definition at line 47 of file node.cc.

§ first_child()

RefPtr< Node > shaka::js::dom::Node::first_child ( ) const

Definition at line 59 of file node.cc.

§ is_char_data()

bool shaka::js::dom::Node::is_char_data ( ) const
inline

Definition at line 116 of file node.h.

§ is_document()

bool shaka::js::dom::Node::is_document ( ) const
inline

Definition at line 110 of file node.h.

§ is_element()

bool shaka::js::dom::Node::is_element ( ) const
inline

Definition at line 113 of file node.h.

§ IsShortLived()

bool shaka::js::dom::Node::IsShortLived ( ) const
overridevirtual

Gets whether the object is considered short-lived. This means that once the C++ ref-count is zero, the object won't remain alive for long. It is important to only set this if the JavaScript object won't be used for long.

This exists for JSC which doesn't offer a way for us to track whether a JavaScript object is still alive. If the JavaScript object is used after the backing object is destroyed, then a JavaScript exception will be thrown.

Reimplemented from shaka::memory::Traceable.

Definition at line 43 of file node.cc.

§ last_child()

RefPtr< Node > shaka::js::dom::Node::last_child ( ) const

Definition at line 63 of file node.cc.

§ node_name()

virtual std::string shaka::js::dom::Node::node_name ( ) const
pure virtual

§ node_type()

NodeType shaka::js::dom::Node::node_type ( ) const
inline

Definition at line 95 of file node.h.

§ NodeValue()

virtual optional<std::string> shaka::js::dom::Node::NodeValue ( ) const
pure virtual

§ parent_node()

RefPtr< Node > shaka::js::dom::Node::parent_node ( ) const

Definition at line 51 of file node.cc.

§ RemoveChild()

RefPtr< Node > shaka::js::dom::Node::RemoveChild ( RefPtr< Node to_remove)

Definition at line 80 of file node.cc.

§ TextContent()

virtual optional<std::string> shaka::js::dom::Node::TextContent ( ) const
pure virtual

§ Trace()

Doxygen_Skip void shaka::js::dom::Node::Trace ( memory::HeapTracer tracer) const
overridevirtual

Called during a GC run. This should call HeapTracer::Trace on all Traceable members. Be sure to call the base method when overriding.

Implements shaka::memory::Traceable.

Reimplemented in shaka::js::mse::HTMLMediaElement.

Definition at line 35 of file node.cc.


The documentation for this class was generated from the following files: