Browse Source

Smalltalk asSmalltalkException: nil is ok now.

Fixes #1255.
Herby Vojčík 3 years ago
parent
commit
a2aa067f52
2 changed files with 24 additions and 6 deletions
  1. 18 3
      lang/src/Kernel-Infrastructure.js
  2. 6 3
      lang/src/Kernel-Infrastructure.st

+ 18 - 3
lang/src/Kernel-Infrastructure.js

@@ -3089,21 +3089,36 @@ selector: "asSmalltalkException:",
 protocol: "error handling",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["anObject"],
-source: "asSmalltalkException: anObject\x0a\x09\x22A JavaScript exception may be thrown.\x0a\x09We then need to convert it back to a Smalltalk object\x22\x0a\x09\x0a\x09^ (self isError: anObject)\x0a\x09\x09ifTrue: [ anObject ]\x0a\x09\x09ifFalse: [ JavaScriptException on: anObject ]",
-referencedClasses: ["JavaScriptException"],
+source: "asSmalltalkException: anObject\x0a\x09\x22A JavaScript exception may be thrown.\x0a\x09We then need to convert it back to a Smalltalk object\x22\x0a\x09\x0a\x09^ anObject\x0a\x09\x09ifNil: [ [ self error: 'Error: nil' ] on: Error do: [ :e | e ] ]\x0a\x09\x09ifNotNil: [\x0a\x09\x09\x09(self isError: anObject)\x0a\x09\x09\x09\x09ifTrue: [ anObject ]\x0a\x09\x09\x09\x09ifFalse: [ JavaScriptException on: anObject ] ]",
+referencedClasses: ["Error", "JavaScriptException"],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["ifTrue:ifFalse:", "isError:", "on:"]
+messageSends: ["ifNil:ifNotNil:", "on:do:", "error:", "ifTrue:ifFalse:", "isError:", "on:"]
 }, function ($methodClass){ return function (anObject){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
+if(anObject == null || anObject.a$nil){
+return $recv((function(){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+return $self._error_("Error: nil");
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
+//>>excludeEnd("ctx");
+}))._on_do_($globals.Error,(function(e){
+return e;
+
+}));
+} else {
 if($core.assert($self._isError_(anObject))){
 return anObject;
 } else {
 return $recv($globals.JavaScriptException)._on_(anObject);
 }
+}
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"asSmalltalkException:",{anObject:anObject})});
 //>>excludeEnd("ctx");

+ 6 - 3
lang/src/Kernel-Infrastructure.st

@@ -937,9 +937,12 @@ asSmalltalkException: anObject
 	"A JavaScript exception may be thrown.
 	We then need to convert it back to a Smalltalk object"
 	
-	^ (self isError: anObject)
-		ifTrue: [ anObject ]
-		ifFalse: [ JavaScriptException on: anObject ]
+	^ anObject
+		ifNil: [ [ self error: 'Error: nil' ] on: Error do: [ :e | e ] ]
+		ifNotNil: [
+			(self isError: anObject)
+				ifTrue: [ anObject ]
+				ifFalse: [ JavaScriptException on: anObject ] ]
 !
 
 try: actionBlock ifTrue: aBlock catch: anotherBlock