Skip to content

Commit

Permalink
DynamicObject: Make virtual functions non-virtual
Browse files Browse the repository at this point in the history
  • Loading branch information
reuk authored and tpoole committed Sep 26, 2024
1 parent 46c2a95 commit c1c0161
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
34 changes: 34 additions & 0 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,40 @@

# Version 8.0.1

## Change

All member functions of DynamicObject other than clone() and writeAsJSON() have
been made non-virtual.

**Possible Issues**

Classes that override these functions will fail to compile.

**Workaround**

Instead of overriding hasMethod() and invokeMethod(), call setMethod() to
add new member functions.

Instead of overriding getProperty() to return a custom property, add that
property using setProperty().

**Rationale**

Allowing the implementations of these functions to be changed may cause derived
types to accidentally break the invariants of the DynamicObject type.
Specifically, the results of hasMethod() and hasProperty() must be consistent
with the result of getProperties(). Additiionally, calling getProperty() should
return the same var as fetching the property through getProperties(), and
calling invokeMethod() should behave the same way as retrieving and invoking a
NativeFunction via getProperties().

More concretely, the new QuickJS-based Javascript engine requires that all
methods/properties are declared explicitly, which cannot be mapped to the more
open-ended invokeMethod() API taking an arbitrary method name. Making
invokeMethod() non-virtual forces users to add methods with setMethod() instead
of overriding invokeMethod(), which is more compatible with QuickJS.


## Change

The LowLevelGraphicsPostscriptRenderer has been removed.
Expand Down
14 changes: 7 additions & 7 deletions modules/juce_core/containers/juce_DynamicObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ class JUCE_API DynamicObject : public ReferenceCountedObject
/** Returns true if the object has a property with this name.
Note that if the property is actually a method, this will return false.
*/
virtual bool hasProperty (const Identifier& propertyName) const;
bool hasProperty (const Identifier& propertyName) const;

/** Returns a named property.
This returns var() if no such property exists.
*/
virtual const var& getProperty (const Identifier& propertyName) const;
const var& getProperty (const Identifier& propertyName) const;

/** Sets a named property. */
virtual void setProperty (const Identifier& propertyName, const var& newValue);
void setProperty (const Identifier& propertyName, const var& newValue);

/** Removes a named property. */
virtual void removeProperty (const Identifier& propertyName);
void removeProperty (const Identifier& propertyName);

//==============================================================================
/** Checks whether this object has the specified method.
Expand All @@ -82,7 +82,7 @@ class JUCE_API DynamicObject : public ReferenceCountedObject
with this name that's actually a method, but this can be overridden for
building objects with dynamic invocation.
*/
virtual bool hasMethod (const Identifier& methodName) const;
bool hasMethod (const Identifier& methodName) const;

/** Invokes a named method on this object.
Expand All @@ -92,8 +92,8 @@ class JUCE_API DynamicObject : public ReferenceCountedObject
This method is virtual to allow more dynamic invocation to used for objects
where the methods may not already be set as properties.
*/
virtual var invokeMethod (Identifier methodName,
const var::NativeFunctionArgs& args);
var invokeMethod (Identifier methodName,
const var::NativeFunctionArgs& args);

/** Adds a method to the class.
Expand Down

0 comments on commit c1c0161

Please sign in to comment.