Explorar el Código

Move ivars from `obj["@x"]` to `obj.x`.

Step 1: Actual move of placement,
compat layer,
minimal necessary fixes for tests to pass.
Herby Vojčík hace 5 años
padre
commit
0da5b56581

+ 20 - 0
lang/base/kernel-language.js

@@ -310,6 +310,25 @@ define(function () {
             emit.behaviorMethodRemoved(method, this);
         });
 
+        // TODO remove, ["@foo"] backward compatibility
+        function installIvarCompat (klass) {
+            var ivars = klass.instanceVariableNames;
+            ivars.forEach(function (ivar) {
+                Object.defineProperty(klass.fn.prototype, "@" + ivar, {
+                    get: function () {
+                        return this[ivar];
+                    },
+                    set: function (value) {
+                        return this[ivar] = value;
+                    },
+                    enumerable: false,
+                    configurable: true
+                });
+            });
+        }
+
+        this.installIvarCompat = installIvarCompat;
+
         function setInstanceVariables (klass, instanceVariableNames) {
             instanceVariableNames.forEach(function (name) {
                 if (!name.match(/^[a-zA-Z][a-zA-Z0-9]*$/))
@@ -317,6 +336,7 @@ define(function () {
             });
 
             klass.instanceVariableNames = instanceVariableNames;
+            installIvarCompat(klass);
         }
 
         st.setInstanceVariables = setInstanceVariables;

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

@@ -63,6 +63,7 @@ define(function () {
         var installMethod = brikz.runtimeMethods.installMethod;
         var traitsOrClasses = brikz.behaviors.traitsOrClasses;
         var wireKlass = brikz.classes.wireKlass;
+        var installIvarCompat = brikz.classes.installIvarCompat;
         var emit = brikz.event.emit;
 
         var detachedRootClasses = [];
@@ -143,6 +144,7 @@ define(function () {
         st.setClassConstructor = this.setClassConstructor = function (klass, constructor) {
             markClassDetachedRoot(klass);
             klass.fn = constructor;
+            installIvarCompat(klass);
             initClass(klass);
         };
     }

+ 6 - 6
lang/src/Kernel-Objects.js

@@ -945,9 +945,9 @@ return $core.withContext(function($ctx1) {
 
 		var copy = self.a$cls._new();
 		Object.keys(self).forEach(function (i) {
-		if(/^@.+/.test(i)) {
+		// if(/^@.+/.test(i)) {
 			copy[i] = $recv(self[i])._deepCopy();
-		}
+		// }
 		});
 		return copy;
 	;
@@ -958,7 +958,7 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "deepCopy\x0a\x09<inlineJS: '\x0a\x09\x09var copy = self.a$cls._new();\x0a\x09\x09Object.keys(self).forEach(function (i) {\x0a\x09\x09if(/^@.+/.test(i)) {\x0a\x09\x09\x09copy[i] = $recv(self[i])._deepCopy();\x0a\x09\x09}\x0a\x09\x09});\x0a\x09\x09return copy;\x0a\x09'>",
+source: "deepCopy\x0a\x09<inlineJS: '\x0a\x09\x09var copy = self.a$cls._new();\x0a\x09\x09Object.keys(self).forEach(function (i) {\x0a\x09\x09// if(/^@.+/.test(i)) {\x0a\x09\x09\x09copy[i] = $recv(self[i])._deepCopy();\x0a\x09\x09// }\x0a\x09\x09});\x0a\x09\x09return copy;\x0a\x09'>",
 referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: []
@@ -1434,9 +1434,9 @@ return $core.withContext(function($ctx1) {
 
 		var copy = self.a$cls._new();
 		Object.keys(self).forEach(function(i) {
-		if(/^@.+/.test(i)) {
+		// if(/^@.+/.test(i)) {
 			copy[i] = self[i];
-		}
+		// }
 		});
 		return copy;
 	;
@@ -1447,7 +1447,7 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "shallowCopy\x0a\x09<inlineJS: '\x0a\x09\x09var copy = self.a$cls._new();\x0a\x09\x09Object.keys(self).forEach(function(i) {\x0a\x09\x09if(/^@.+/.test(i)) {\x0a\x09\x09\x09copy[i] = self[i];\x0a\x09\x09}\x0a\x09\x09});\x0a\x09\x09return copy;\x0a\x09'>",
+source: "shallowCopy\x0a\x09<inlineJS: '\x0a\x09\x09var copy = self.a$cls._new();\x0a\x09\x09Object.keys(self).forEach(function(i) {\x0a\x09\x09// if(/^@.+/.test(i)) {\x0a\x09\x09\x09copy[i] = self[i];\x0a\x09\x09// }\x0a\x09\x09});\x0a\x09\x09return copy;\x0a\x09'>",
 referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: []

+ 4 - 4
lang/src/Kernel-Objects.st

@@ -250,9 +250,9 @@ deepCopy
 	<inlineJS: '
 		var copy = self.a$cls._new();
 		Object.keys(self).forEach(function (i) {
-		if(/^@.+/.test(i)) {
+		// if(/^@.+/.test(i)) {
 			copy[i] = $recv(self[i])._deepCopy();
-		}
+		// }
 		});
 		return copy;
 	'>
@@ -265,9 +265,9 @@ shallowCopy
 	<inlineJS: '
 		var copy = self.a$cls._new();
 		Object.keys(self).forEach(function(i) {
-		if(/^@.+/.test(i)) {
+		// if(/^@.+/.test(i)) {
 			copy[i] = self[i];
-		}
+		// }
 		});
 		return copy;
 	'>