From c1c01616c92f991df86622743bcb2263f9c6bb96 Mon Sep 17 00:00:00 2001 From: reuk Date: Tue, 9 Jul 2024 16:28:32 +0100 Subject: [PATCH] DynamicObject: Make virtual functions non-virtual --- BREAKING_CHANGES.md | 34 +++++++++++++++++++ .../juce_core/containers/juce_DynamicObject.h | 14 ++++---- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index ee5c7ea438..71dfa397e8 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -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. diff --git a/modules/juce_core/containers/juce_DynamicObject.h b/modules/juce_core/containers/juce_DynamicObject.h index 97ec7dc7e9..fc093456cd 100644 --- a/modules/juce_core/containers/juce_DynamicObject.h +++ b/modules/juce_core/containers/juce_DynamicObject.h @@ -62,18 +62,18 @@ public: /** 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. @@ -82,7 +82,7 @@ public: 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. @@ -92,8 +92,8 @@ public: 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.