Browse Source

Move part of MNU handling to Smalltalk side.

Herbert Vojčík 7 years ago
parent
commit
972c0406ad
3 changed files with 42 additions and 19 deletions
  1. 23 0
      src/Kernel-Methods.js
  2. 9 0
      src/Kernel-Methods.st
  3. 10 19
      support/kernel-runtime.js

+ 23 - 0
src/Kernel-Methods.js

@@ -1693,6 +1693,29 @@ messageSends: ["selector:", "new", "arguments:", "yourself"]
 }),
 $globals.Message.a$cls);
 
+$core.addMethod(
+$core.method({
+selector: "selector:arguments:notUnderstoodBy:",
+protocol: "dnu handling",
+fn: function (aString,anArray,anObject){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return $recv(anObject)._doesNotUnderstand_($self._selector_arguments_(aString,anArray));
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"selector:arguments:notUnderstoodBy:",{aString:aString,anArray:anArray,anObject:anObject},$globals.Message.a$cls)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aString", "anArray", "anObject"],
+source: "selector: aString arguments: anArray notUnderstoodBy: anObject\x0a\x09\x22Creates the message and passes it to #doesNotUnderstand:.\x0a\x09Used by kernel to handle MNU.\x22\x0a\x09^ anObject doesNotUnderstand:\x0a\x09\x09(self selector: aString arguments: anArray)",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["doesNotUnderstand:", "selector:arguments:"]
+}),
+$globals.Message.a$cls);
+
 
 $core.addClass("MessageSend", $globals.Object, ["receiver", "message"], "Kernel-Methods");
 //>>excludeStart("ide", pragmas.excludeIdeData);

+ 9 - 0
src/Kernel-Methods.st

@@ -454,6 +454,15 @@ printOn: aStream
 		nextPutAll: ')'
 ! !
 
+!Message class methodsFor: 'dnu handling'!
+
+selector: aString arguments: anArray notUnderstoodBy: anObject
+	"Creates the message and passes it to #doesNotUnderstand:.
+	Used by kernel to handle MNU."
+	^ anObject doesNotUnderstand:
+		(self selector: aString arguments: anArray)
+! !
+
 !Message class methodsFor: 'instance creation'!
 
 selector: aString arguments: anArray

+ 10 - 19
support/kernel-runtime.js

@@ -13,10 +13,10 @@ define(function () {
     function noop () {
     }
 
-    DNUBrik.deps = ["selectors", "messageSend", "manipulation", "classes"];
+    DNUBrik.deps = ["selectors", "smalltalkGlobals", "manipulation", "classes"];
     function DNUBrik (brikz, st) {
         var selectorsBrik = brikz.selectors;
-        var messageNotUnderstood = brikz.messageSend.messageNotUnderstood;
+        var globals = brikz.smalltalkGlobals.globals;
         var installJSMethod = brikz.manipulation.installJSMethod;
         var nilAsClass = brikz.classes.nilAsClass;
 
@@ -37,7 +37,9 @@ define(function () {
 
         function createHandler (stSelector) {
             return function () {
-                return messageNotUnderstood(this, stSelector, arguments);
+                return globals.Message._selector_arguments_notUnderstoodBy_(
+                    stSelector, [].slice.call(arguments), this
+                );
             };
         }
 
@@ -383,11 +385,11 @@ define(function () {
                 self = nilAsReceiver;
             }
             var method = klass ? klass.fn.prototype[st.st2js(selector)] : self.a$cls && self[st.st2js(selector)];
-            if (method) {
-                return method.apply(self, args || []);
-            } else {
-                return messageNotUnderstood(self.a$cls ? self : wrapJavaScript(self), selector, args);
-            }
+            return method ?
+                method.apply(self, args || []) :
+                globals.Message._selector_arguments_notUnderstoodBy_(
+                    selector, [].slice.call(args), self.a$cls ? self : wrapJavaScript(self)
+                );
         };
 
         function wrapJavaScript (o) {
@@ -396,15 +398,6 @@ define(function () {
 
         st.wrapJavaScript = wrapJavaScript;
 
-        /* Handles #dnu:. Calls #doesNotUnderstand:. */
-        function messageNotUnderstood (receiver, stSelector, args) {
-            return receiver._doesNotUnderstand_(
-                globals.Message._new()
-                    ._selector_(stSelector)
-                    ._arguments_([].slice.call(args))
-            );
-        }
-
         /* If the object property is a function, then call it, except if it starts with
          an uppercase character (we probably want to answer the function itself in this
          case and send it #new from Amber).
@@ -420,8 +413,6 @@ define(function () {
                 return propertyValue;
             }
         };
-
-        this.messageNotUnderstood = messageNotUnderstood;
     }
 
     /* Making smalltalk that can run */