Преглед изворни кода

- New method Behavior >> lookupSelector:
- Fixed the debugger selectorlookup

Nicolas Petton пре 11 година
родитељ
комит
d30c822249
6 измењених фајлова са 133 додато и 27 уклоњено
  1. 3 7
      js/IDE.deploy.js
  2. 11 15
      js/IDE.js
  3. 42 0
      js/Kernel-Classes.deploy.js
  4. 52 0
      js/Kernel-Classes.js
  5. 5 5
      st/IDE.st
  6. 20 0
      st/Kernel-Classes.st

+ 3 - 7
js/IDE.deploy.js

@@ -325,14 +325,9 @@ selector: "handleError:",
 fn: function (anError){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
var $1,$2;
-_st((function(){
-return smalltalk.withContext(function($ctx2) { 
$1=_st((smalltalk.Debugger || Debugger))._new();
+$1=_st((smalltalk.Debugger || Debugger))._new();
 _st($1)._error_(anError);
 $2=_st($1)._open();
-return $2;
-})}))._on_do_((smalltalk.Error || Error),(function(error){
-return smalltalk.withContext(function($ctx2) { 
return _st(_st((smalltalk.ErrorHandler || ErrorHandler))._new())._handleError_(error);
-})}));
 return self}, self, "handleError:", [anError], smalltalk.DebugErrorHandler)}
 }),
 smalltalk.DebugErrorHandler);
@@ -2947,7 +2942,7 @@ selector: "method",
 fn: function (){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
var $1;
-$1=_st(_st(_st(self["@selectedContext"])._receiver())._class())._methodAt_(_st(self["@selectedContext"])._selector());
+$1=_st(_st(_st(self["@selectedContext"])._receiver())._class())._lookupSelector_(_st(self["@selectedContext"])._selector());
 return $1;
 }, self, "method", [], smalltalk.Debugger)}
 }),
@@ -3021,6 +3016,7 @@ selector: "renderButtonsOn:",
 fn: function (html){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
var $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15;
+_st(self)._inspect();
 $1=_st(html)._button();
 _st($1)._with_("Save");
 $2=_st($1)._onClick_((function(){

+ 11 - 15
js/IDE.js

@@ -426,19 +426,14 @@ category: 'error handling',
 fn: function (anError){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
var $1,$2;
-_st((function(){
-return smalltalk.withContext(function($ctx2) { 
$1=_st((smalltalk.Debugger || Debugger))._new();
+$1=_st((smalltalk.Debugger || Debugger))._new();
 _st($1)._error_(anError);
 $2=_st($1)._open();
-return $2;
-})}))._on_do_((smalltalk.Error || Error),(function(error){
-return smalltalk.withContext(function($ctx2) { 
return _st(_st((smalltalk.ErrorHandler || ErrorHandler))._new())._handleError_(error);
-})}));
 return self}, self, "handleError:", [anError], smalltalk.DebugErrorHandler)},
 args: ["anError"],
-source: "handleError: anError\x0a\x09[Debugger new\x0a\x09\x09error: anError;\x0a\x09\x09open] on: Error do: [:error |\x0a\x09\x09\x09ErrorHandler new handleError: error]",
-messageSends: ["on:do:", "handleError:", "new", "error:", "open"],
-referencedClasses: ["Error", "ErrorHandler", "Debugger"]
+source: "handleError: anError\x0a\x09Debugger new\x0a\x09\x09error: anError;\x0a\x09\x09open",
+messageSends: ["error:", "new", "open"],
+referencedClasses: ["Debugger"]
 }),
 smalltalk.DebugErrorHandler);
 
@@ -3743,12 +3738,12 @@ category: 'accessing',
 fn: function (){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
var $1;
-$1=_st(_st(_st(self["@selectedContext"])._receiver())._class())._methodAt_(_st(self["@selectedContext"])._selector());
+$1=_st(_st(_st(self["@selectedContext"])._receiver())._class())._lookupSelector_(_st(self["@selectedContext"])._selector());
 return $1;
 }, self, "method", [], smalltalk.Debugger)},
 args: [],
-source: "method\x0a\x09^selectedContext receiver class methodAt: selectedContext selector",
-messageSends: ["methodAt:", "selector", "class", "receiver"],
+source: "method\x0a\x09^selectedContext receiver class lookupSelector: selectedContext selector",
+messageSends: ["lookupSelector:", "selector", "class", "receiver"],
 referencedClasses: []
 }),
 smalltalk.Debugger);
@@ -3828,7 +3823,7 @@ _st(self)._renderTopPanelOn_(html);
 $1=_st(self)._renderBottomPanelOn_(html);
 return self}, self, "renderBoxOn:", [html], smalltalk.Debugger)},
 args: ["html"],
-source: "renderBoxOn: html\x0a    self \x0a\x09renderTopPanelOn: html;\x0a\x09renderBottomPanelOn: html",
+source: "renderBoxOn: html\x0a   self \x0a\x09renderTopPanelOn: html;\x0a\x09renderBottomPanelOn: html",
 messageSends: ["renderTopPanelOn:", "renderBottomPanelOn:"],
 referencedClasses: []
 }),
@@ -3842,6 +3837,7 @@ category: 'rendering',
 fn: function (html){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
var $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15;
+_st(self)._inspect();
 $1=_st(html)._button();
 _st($1)._with_("Save");
 $2=_st($1)._onClick_((function(){
@@ -3886,8 +3882,8 @@ _st(self)._updateVariablesList();
 $15=_st(self)._updateInspector();
 return self}, self, "renderButtonsOn:", [html], smalltalk.Debugger)},
 args: ["html"],
-source: "renderButtonsOn: html\x0a\x09saveButton := html button\x0a\x09\x09with: 'Save';\x0a\x09\x09onClick: [self save].\x0a\x09html button\x0a\x09\x09with: 'DoIt';\x0a\x09\x09onClick: [sourceArea doIt].\x0a\x09html button\x0a\x09\x09with: 'PrintIt';\x0a\x09\x09onClick: [sourceArea printIt].\x0a\x09html button\x0a\x09\x09with: 'InspectIt';\x0a\x09\x09onClick: [sourceArea inspectIt].\x0a\x09html button \x0a\x09\x09with: 'Proceed';\x0a\x09\x09onClick: [self proceed].\x0a\x09html button\x0a\x09\x09with: 'Abandon';\x0a\x09\x09onClick: [self close].\x0a\x09inspectButton := html button\x0a\x09\x09class: 'amber_button debugger inspect';\x0a\x09\x09with: 'Inspect';\x0a\x09\x09onClick: [self inspectSelectedVariable].\x0a\x09 self \x0a\x09\x09updateSourceArea;\x0a\x09\x09updateStatus;\x0a\x09\x09updateVariablesList;\x0a\x09\x09updateInspector",
-messageSends: ["with:", "button", "onClick:", "save", "doIt", "printIt", "inspectIt", "proceed", "close", "class:", "inspectSelectedVariable", "updateSourceArea", "updateStatus", "updateVariablesList", "updateInspector"],
+source: "renderButtonsOn: html\x0a\x09self inspect.\x0a\x09saveButton := html button\x0a\x09\x09with: 'Save';\x0a\x09\x09onClick: [self save].\x0a\x09html button\x0a\x09\x09with: 'DoIt';\x0a\x09\x09onClick: [sourceArea doIt].\x0a\x09html button\x0a\x09\x09with: 'PrintIt';\x0a\x09\x09onClick: [sourceArea printIt].\x0a\x09html button\x0a\x09\x09with: 'InspectIt';\x0a\x09\x09onClick: [sourceArea inspectIt].\x0a\x09html button \x0a\x09\x09with: 'Proceed';\x0a\x09\x09onClick: [self proceed].\x0a\x09html button\x0a\x09\x09with: 'Abandon';\x0a\x09\x09onClick: [self close].\x0a\x09inspectButton := html button\x0a\x09\x09class: 'amber_button debugger inspect';\x0a\x09\x09with: 'Inspect';\x0a\x09\x09onClick: [self inspectSelectedVariable].\x0a\x09 self \x0a\x09\x09updateSourceArea;\x0a\x09\x09updateStatus;\x0a\x09\x09updateVariablesList;\x0a\x09\x09updateInspector",
+messageSends: ["inspect", "with:", "button", "onClick:", "save", "doIt", "printIt", "inspectIt", "proceed", "close", "class:", "inspectSelectedVariable", "updateSourceArea", "updateStatus", "updateVariablesList", "updateInspector"],
 referencedClasses: []
 }),
 smalltalk.Debugger);

+ 42 - 0
js/Kernel-Classes.deploy.js

@@ -201,6 +201,19 @@ return smalltalk.withContext(function($ctx1) { 
return "";
 }),
 smalltalk.Behavior);
 
+smalltalk.addMethod(
+"_includesSelector_",
+smalltalk.method({
+selector: "includesSelector:",
+fn: function (aSymbol){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
var $1;
+$1=_st(_st(self)._methodDictionary())._includesKey_(_st(aSymbol)._asString());
+return $1;
+}, self, "includesSelector:", [aSymbol], smalltalk.Behavior)}
+}),
+smalltalk.Behavior);
+
 smalltalk.addMethod(
 "_inheritsFrom_",
 smalltalk.method({
@@ -226,6 +239,35 @@ return self}, self, "instanceVariableNames", [], smalltalk.Behavior)}
 }),
 smalltalk.Behavior);
 
+smalltalk.addMethod(
+"_lookupSelector_",
+smalltalk.method({
+selector: "lookupSelector:",
+fn: function (selector){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
var $1,$2;
+var $early={};
+try {
+$ctx1.locals.lookupClass=nil;
+$ctx1.locals.lookupClass=self;
+_st((function(){
+return smalltalk.withContext(function($ctx2) { 
return _st($ctx1.locals.lookupClass).__eq(nil);
+})}))._whileFalse_((function(){
+return smalltalk.withContext(function($ctx2) { 
$1=_st($ctx1.locals.lookupClass)._includesSelector_(selector);
+if(smalltalk.assert($1)){
+$2=_st($ctx1.locals.lookupClass)._methodAt_(selector);
+throw $early=[$2];
+};
+$ctx1.locals.lookupClass=_st($ctx1.locals.lookupClass)._superclass();
+return $ctx1.locals.lookupClass;
+})}));
+return nil;
+}
+catch(e) {if(e===$early)return e[0]; throw e}
+}, self, "lookupSelector:", [selector], smalltalk.Behavior)}
+}),
+smalltalk.Behavior);
+
 smalltalk.addMethod(
 "_methodAt_",
 smalltalk.method({

+ 52 - 0
js/Kernel-Classes.js

@@ -267,6 +267,24 @@ referencedClasses: []
 }),
 smalltalk.Behavior);
 
+smalltalk.addMethod(
+"_includesSelector_",
+smalltalk.method({
+selector: "includesSelector:",
+category: 'testing',
+fn: function (aSymbol){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
var $1;
+$1=_st(_st(self)._methodDictionary())._includesKey_(_st(aSymbol)._asString());
+return $1;
+}, self, "includesSelector:", [aSymbol], smalltalk.Behavior)},
+args: ["aSymbol"],
+source: "includesSelector: aSymbol\x0a\x09^ self methodDictionary includesKey: aSymbol asString",
+messageSends: ["includesKey:", "asString", "methodDictionary"],
+referencedClasses: []
+}),
+smalltalk.Behavior);
+
 smalltalk.addMethod(
 "_inheritsFrom_",
 smalltalk.method({
@@ -302,6 +320,40 @@ referencedClasses: []
 }),
 smalltalk.Behavior);
 
+smalltalk.addMethod(
+"_lookupSelector_",
+smalltalk.method({
+selector: "lookupSelector:",
+category: 'accessing',
+fn: function (selector){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
var $1,$2;
+var $early={};
+try {
+$ctx1.locals.lookupClass=nil;
+$ctx1.locals.lookupClass=self;
+_st((function(){
+return smalltalk.withContext(function($ctx2) { 
return _st($ctx1.locals.lookupClass).__eq(nil);
+})}))._whileFalse_((function(){
+return smalltalk.withContext(function($ctx2) { 
$1=_st($ctx1.locals.lookupClass)._includesSelector_(selector);
+if(smalltalk.assert($1)){
+$2=_st($ctx1.locals.lookupClass)._methodAt_(selector);
+throw $early=[$2];
+};
+$ctx1.locals.lookupClass=_st($ctx1.locals.lookupClass)._superclass();
+return $ctx1.locals.lookupClass;
+})}));
+return nil;
+}
+catch(e) {if(e===$early)return e[0]; throw e}
+}, self, "lookupSelector:", [selector], smalltalk.Behavior)},
+args: ["selector"],
+source: "lookupSelector: selector\x0a\x09\x22Look up the given selector in my methodDictionary.\x0a\x09Return the corresponding method if found.\x0a\x09Otherwise chase the superclass chain and try again.\x0a\x09Return nil if no method is found.\x22\x0a    \x0a\x09| lookupClass |\x0a    \x0a\x09lookupClass := self.\x0a\x09[ lookupClass = nil ] whileFalse: [\x0a      \x09(lookupClass includesSelector: selector)\x0a\x09\x09\x09\x09ifTrue: [ ^ lookupClass methodAt: selector ].\x0a\x09\x09\x09lookupClass := lookupClass superclass ].\x0a\x09^ nil",
+messageSends: ["whileFalse:", "ifTrue:", "methodAt:", "includesSelector:", "superclass", "="],
+referencedClasses: []
+}),
+smalltalk.Behavior);
+
 smalltalk.addMethod(
 "_methodAt_",
 smalltalk.method({

+ 5 - 5
st/IDE.st

@@ -156,10 +156,9 @@ ErrorHandler subclass: #DebugErrorHandler
 !DebugErrorHandler methodsFor: 'error handling'!
 
 handleError: anError
-	[Debugger new
+	Debugger new
 		error: anError;
-		open] on: Error do: [:error |
-			ErrorHandler new handleError: error]
+		open
 ! !
 
 !DebugErrorHandler class methodsFor: 'initialization'!
@@ -1340,7 +1339,7 @@ label
 !
 
 method
-	^selectedContext receiver class methodAt: selectedContext selector
+	^selectedContext receiver class lookupSelector: selectedContext selector
 !
 
 receiver
@@ -1412,12 +1411,13 @@ renderBottomPanelOn: html
 !
 
 renderBoxOn: html
-    self 
+   self 
 	renderTopPanelOn: html;
 	renderBottomPanelOn: html
 !
 
 renderButtonsOn: html
+	self inspect.
 	saveButton := html button
 		with: 'Save';
 		onClick: [self save].

+ 20 - 0
st/Kernel-Classes.st

@@ -68,6 +68,22 @@ instanceVariableNames
 	<return self.iVarNames>
 !
 
+lookupSelector: selector
+	"Look up the given selector in my methodDictionary.
+	Return the corresponding method if found.
+	Otherwise chase the superclass chain and try again.
+	Return nil if no method is found."
+    
+	| lookupClass |
+    
+	lookupClass := self.
+	[ lookupClass = nil ] whileFalse: [
+      	(lookupClass includesSelector: selector)
+				ifTrue: [ ^ lookupClass methodAt: selector ].
+			lookupClass := lookupClass superclass ].
+	^ nil
+!
+
 methodAt: aSymbol
 	^ self methodDictionary at: aSymbol asString
 !
@@ -208,6 +224,10 @@ canUnderstand: aSelector
 		self superclass notNil and: [self superclass canUnderstand: aSelector]]
 !
 
+includesSelector: aSymbol
+	^ self methodDictionary includesKey: aSymbol asString
+!
+
 inheritsFrom: aClass
 	^aClass allSubclasses includes: self
 ! !