Browse Source

setClassConstructor: reproto subclasses. Fix #1240.

Herby Vojčík 4 years ago
parent
commit
e7c2cda1c6
2 changed files with 15 additions and 0 deletions
  1. 7 0
      lang/base/kernel-checks.js
  2. 8 0
      lang/base/kernel-runtime.js

+ 7 - 0
lang/base/kernel-checks.js

@@ -22,6 +22,13 @@ define(function () {
         var p = {};
         return Object.getPrototypeOf(Object.create(p)) === p;
     });
+    assert(function () {
+        var p = {x: 4, y: 5}, q = {x: 6};
+        var r = Object.setPrototypeOf(q, p);
+        return r === q &&
+            q.x === 6 &&
+            q.y === 5;
+    });
     // assert(function () {
     //     return new Function("return this")().Object === Object;
     // });

+ 8 - 0
lang/base/kernel-runtime.js

@@ -154,7 +154,15 @@ define(function () {
             klass.fn = constructor;
             installIvarCompat(klass);
             initClass(klass);
+            klass.subclasses.forEach(reprotoFn(constructor));
         };
+
+        function reprotoFn (constructor) {
+            var prototype = constructor.prototype;
+            return function (subclass) {
+                Object.setPrototypeOf(subclass.fn.prototype, prototype);
+            };
+        }
     }
 
     FrameBindingBrik.deps = ["smalltalkGlobals", "runtimeClasses"];