This is an automated email from the ASF dual-hosted git repository. gregdove pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
commit 783718ab6167569ee8f18415e35e86a811e88071 Author: greg-dove <[email protected]> AuthorDate: Tue Apr 19 11:27:51 2022 +1200 In JS (at least) provide a warning in debug builds (only) when cloning an Event subclass that does not override the cloneEvent method. --- .../projects/Core/src/main/royale/CoreClasses.as | 1 + .../org/apache/royale/debugging/alreadyRecorded.as | 58 ++++++++++++++++++++++ .../org/apache/royale/events/EventDispatcher.as | 17 +++++++ 3 files changed, 76 insertions(+) diff --git a/frameworks/projects/Core/src/main/royale/CoreClasses.as b/frameworks/projects/Core/src/main/royale/CoreClasses.as index 8dc1095798..69847ef491 100644 --- a/frameworks/projects/Core/src/main/royale/CoreClasses.as +++ b/frameworks/projects/Core/src/main/royale/CoreClasses.as @@ -327,6 +327,7 @@ internal class CoreClasses // import org.apache.royale.debugging.conditionalBreak; conditionalBreak; import org.apache.royale.debugging.notNull; notNull; import org.apache.royale.debugging.throwError; throwError; + import org.apache.royale.debugging.alreadyRecorded; alreadyRecorded; import org.apache.royale.utils.measureComponent; measureComponent; import org.apache.royale.utils.loadBeadFromValuesManager; loadBeadFromValuesManager; diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/debugging/alreadyRecorded.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/debugging/alreadyRecorded.as new file mode 100644 index 0000000000..7362657d2a --- /dev/null +++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/debugging/alreadyRecorded.as @@ -0,0 +1,58 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.royale.debugging +{ + + /** + * If this method has been called with forObject previously, this method returns true, otherwise if this is the first time, + * it returns false + */ + public function alreadyRecorded(forObject:Object):Boolean + { + var recorded:Boolean = true; + COMPILE::SWF + { + if (!map[forObject]) { + map[forObject] = true; + recorded = false; + } + } + COMPILE::JS + { + if (!map.has(forObject)) { + map.set(forObject, true); + recorded = false; + } + } + + return recorded; + } +} + +COMPILE::SWF{ + import flash.utils.Dictionary; +} + + +COMPILE::JS +var map:WeakMap = new WeakMap(); + + +COMPILE::SWF +var map:Dictionary = new Dictionary(true) diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/events/EventDispatcher.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/events/EventDispatcher.as index 3a19f12f78..d77255758e 100644 --- a/frameworks/projects/Core/src/main/royale/org/apache/royale/events/EventDispatcher.as +++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/events/EventDispatcher.as @@ -24,6 +24,9 @@ package org.apache.royale.events import goog.events.Listener; import goog.events.EventTarget; import org.apache.royale.events.Event; + + import org.apache.royale.debugging.alreadyRecorded; + import goog.DEBUG; } COMPILE::SWF @@ -101,7 +104,21 @@ package org.apache.royale.events else if ("target" in event1) { if (event1.target && event1 is IRoyaleEvent) { //we are re-dispatching, we need to clone the original: + if(goog.DEBUG) + { + var original:Object = event1; + } event1 = IRoyaleEvent(event1).cloneEvent(); + if(goog.DEBUG) + { + if (event1.constructor != original.constructor) { + var notAlreadyRecorded:Boolean = !alreadyRecorded(original.constructor); + if (notAlreadyRecorded) { + //this should help identify missing cloneEvent requirements: + console.warn(original.constructor.prototype.ROYALE_CLASS_INFO.names[0].qName + ' is missing a cloneEvent method override, this should be implemented, otherwise it is being cloned as :' + event1.constructor.prototype.ROYALE_CLASS_INFO.names[0].qName); + } + } + } } event1.target = _dispatcher; //console.log("assigned target to event ",event);
