Browse Source

kernel: st.addMethod guards for only fresh methods.

Herbert Vojčík 7 years ago
parent
commit
52b944a072
1 changed files with 4 additions and 1 deletions
  1. 4 1
      support/kernel-fundamentals.js

+ 4 - 1
support/kernel-fundamentals.js

@@ -298,9 +298,12 @@ define(['./compatibility'], function () {
         /* Add/remove a method to/from a class */
 
         st.addMethod = function (method, behaviorBody) {
-            behaviorBody.localMethods[method.selector] = method;
+            if (method.methodClass != null) {
+                throw new Error("addMethod: Method " + method.selector + " already bound to " + method.methodClass);
+            }
             method.methodClass = behaviorBody;
             registerNewSelectors(method);
+            behaviorBody.localMethods[method.selector] = method;
             updateMethod(method.selector, behaviorBody);
         };