Parcourir la source

Make ConsoleTranscript actually print

ConsoleTranscript used to try and print an undefined variable (string)
to the browser's console, instead of the object sent via the 'show:'
message.
Kenneth Pullen il y a 11 ans
Parent
commit
82964f57bd

+ 24 - 0
js/Kernel-Tests.deploy.js

@@ -1874,6 +1874,30 @@ messageSends: []}),
 smalltalk.StringTest.klass);
 
 
+smalltalk.addClass('ConsoleTranscriptTest', smalltalk.TestCase, [], 'Kernel-Tests');
+smalltalk.addMethod(
+smalltalk.method({
+selector: "testShow",
+fn: function (){
+var self=this;
+var originalTranscript;
+function $Transcript(){return smalltalk.Transcript||(typeof Transcript=="undefined"?nil:Transcript)}
+function $ConsoleTranscript(){return smalltalk.ConsoleTranscript||(typeof ConsoleTranscript=="undefined"?nil:ConsoleTranscript)}
+function $Error(){return smalltalk.Error||(typeof Error=="undefined"?nil:Error)}
+return smalltalk.withContext(function($ctx1) { 
+originalTranscript=_st($Transcript())._current();
+_st($Transcript())._register_(_st($ConsoleTranscript())._new());
+_st(self)._shouldnt_raise_((function(){
+return smalltalk.withContext(function($ctx2) {
+return _st($Transcript())._show_("Hello console!");
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),$Error());
+_st($Transcript())._register_(originalTranscript);
+return self}, function($ctx1) {$ctx1.fill(self,"testShow",{originalTranscript:originalTranscript},smalltalk.ConsoleTranscriptTest)})},
+messageSends: ["current", "register:", "new", "shouldnt:raise:", "show:"]}),
+smalltalk.ConsoleTranscriptTest);
+
+
+
 smalltalk.addClass('JSObjectProxyTest', smalltalk.TestCase, [], 'Kernel-Tests');
 smalltalk.addMethod(
 smalltalk.method({

+ 30 - 0
js/Kernel-Tests.js

@@ -2344,6 +2344,36 @@ referencedClasses: ["String"]
 smalltalk.StringTest.klass);
 
 
+smalltalk.addClass('ConsoleTranscriptTest', smalltalk.TestCase, [], 'Kernel-Tests');
+smalltalk.ConsoleTranscriptTest.comment="I will try to ensure that you can print to a browser's console."
+smalltalk.addMethod(
+smalltalk.method({
+selector: "testShow",
+category: 'tests',
+fn: function (){
+var self=this;
+var originalTranscript;
+function $Transcript(){return smalltalk.Transcript||(typeof Transcript=="undefined"?nil:Transcript)}
+function $ConsoleTranscript(){return smalltalk.ConsoleTranscript||(typeof ConsoleTranscript=="undefined"?nil:ConsoleTranscript)}
+function $Error(){return smalltalk.Error||(typeof Error=="undefined"?nil:Error)}
+return smalltalk.withContext(function($ctx1) { 
+originalTranscript=_st($Transcript())._current();
+_st($Transcript())._register_(_st($ConsoleTranscript())._new());
+_st(self)._shouldnt_raise_((function(){
+return smalltalk.withContext(function($ctx2) {
+return _st($Transcript())._show_("Hello console!");
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),$Error());
+_st($Transcript())._register_(originalTranscript);
+return self}, function($ctx1) {$ctx1.fill(self,"testShow",{originalTranscript:originalTranscript},smalltalk.ConsoleTranscriptTest)})},
+args: [],
+source: "testShow\x0a| originalTranscript |\x0aoriginalTranscript := Transcript current.\x0aTranscript register: ConsoleTranscript new.\x0aself shouldnt: [ Transcript show: 'Hello console!' ] raise: Error.\x0aTranscript register: originalTranscript.",
+messageSends: ["current", "register:", "new", "shouldnt:raise:", "show:"],
+referencedClasses: ["Transcript", "ConsoleTranscript", "Error"]
+}),
+smalltalk.ConsoleTranscriptTest);
+
+
+
 smalltalk.addClass('JSObjectProxyTest', smalltalk.TestCase, [], 'Kernel-Tests');
 smalltalk.addMethod(
 smalltalk.method({

+ 1 - 1
js/Kernel-Transcript.deploy.js

@@ -36,7 +36,7 @@ selector: "show:",
 fn: function (anObject){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
-console.log(String(string._asString()));
+console.log(String(anObject._asString()));
 return self}, function($ctx1) {$ctx1.fill(self,"show:",{anObject:anObject},smalltalk.ConsoleTranscript)})},
 messageSends: []}),
 smalltalk.ConsoleTranscript);

+ 2 - 2
js/Kernel-Transcript.js

@@ -53,10 +53,10 @@ category: 'printing',
 fn: function (anObject){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
-console.log(String(string._asString()));
+console.log(String(anObject._asString()));
 return self}, function($ctx1) {$ctx1.fill(self,"show:",{anObject:anObject},smalltalk.ConsoleTranscript)})},
 args: ["anObject"],
-source: "show: anObject\x0a\x09<console.log(String(string._asString()))>",
+source: "show: anObject\x0a\x09<console.log(String(anObject._asString()))>",
 messageSends: [],
 referencedClasses: []
 }),

+ 16 - 0
st/Kernel-Tests.st

@@ -890,6 +890,22 @@ collectionClass
 	^ String
 ! !
 
+TestCase subclass: #ConsoleTranscriptTest
+	instanceVariableNames: ''
+	package: 'Kernel-Tests'!
+!ConsoleTranscriptTest commentStamp!
+I will try to ensure that you can print to a browser's console.!
+
+!ConsoleTranscriptTest methodsFor: 'tests'!
+
+testShow
+| originalTranscript |
+originalTranscript := Transcript current.
+Transcript register: ConsoleTranscript new.
+self shouldnt: [ Transcript show: 'Hello console!!' ] raise: Error.
+Transcript register: originalTranscript.
+! !
+
 TestCase subclass: #JSObjectProxyTest
 	instanceVariableNames: ''
 	package: 'Kernel-Tests'!

+ 1 - 1
st/Kernel-Transcript.st

@@ -23,7 +23,7 @@ cr
 !
 
 show: anObject
-	<console.log(String(string._asString()))>
+	<console.log(String(anObject._asString()))>
 ! !
 
 !ConsoleTranscript class methodsFor: 'initialization'!