Browse Source

Fix treatment of message sends to JS objects.

Herby Vojčík 5 years ago
parent
commit
6ef647daec
2 changed files with 15 additions and 6 deletions
  1. 6 0
      CHANGELOG
  2. 9 6
      lang/base/kernel-runtime.js

+ 6 - 0
CHANGELOG

@@ -5,6 +5,12 @@
 * `imports:` loaded lazily using isReady promise
   * you can have circular `import:` clauses
   * you cannot presume your `import:` dependency is initialized in your own class-level `initialize`
+* `aJsObject Uppercase: foo and: bar` is called as `aJsObject.Uppercase(foo, bar)`
+  * only the unary `aJsObject Uppercase` is special and returns `aJsObject.Uppercase`
+  * so far all uppercase selectors made an exception, even ones with args
+* `aJsObject selector: foo withMoreArguments: bar` fails if `aJsObject.selector` is not a function
+  * only the single-arg `aJsObject selector: foo` sets the value `aJsObject selector = foo`
+  * so far even more-than-one-arg ones did set the value denoted by first keyword
 
 Commits: https://lolg.it/amber/amber/commits/0.23.0
 

+ 9 - 6
lang/base/kernel-runtime.js

@@ -376,13 +376,16 @@ define(function () {
          */
         st.accessJavaScript = function (self, propertyName, args) {
             var propertyValue = self[propertyName];
-            if (typeof propertyValue === "function" && !/^[A-Z]/.test(propertyName)) {
+            if (typeof propertyValue === "function" && !(args.length === 0 && /^[A-Z]/.test(propertyName)))
                 return propertyValue.apply(self, args);
-            } else if (args.length === 0) {
-                return propertyValue;
-            } else {
-                self[propertyName] = args[0];
-                return self;
+            switch (args.length) {
+                case 0:
+                    return propertyValue;
+                case 1:
+                    self[propertyName] = args[0];
+                    return self;
+                default:
+                    throw new Error("Cannot interpret " + propertyName + " with " + args.length + " arguments; field is a " + typeof propertyValue + ", not a function")
             }
         };
     }