Browse Source

Forbids creating new instances of Smalltalk

Nicolas Petton 10 years ago
parent
commit
579e894d78
2 changed files with 25 additions and 5 deletions
  1. 19 3
      js/Kernel-Infrastructure.js
  2. 6 2
      st/Kernel-Infrastructure.st

+ 19 - 3
js/Kernel-Infrastructure.js

@@ -2607,14 +2607,14 @@ smalltalk.Smalltalk.klass.iVarNames = ['current'];
 smalltalk.addMethod(
 smalltalk.method({
 selector: "current",
-protocol: 'accessing',
+protocol: 'instance creation',
 fn: function (){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
 var $2,$1;
 $2=self["@current"];
 if(($receiver = $2) == nil || $receiver == null){
-self["@current"]=self._new();
+self["@current"]=smalltalk.Smalltalk.klass.superclass.fn.prototype._new.apply(_st(self), []);
 $1=self["@current"];
 } else {
 $1=$2;
@@ -2622,12 +2622,28 @@ $1=$2;
 return $1;
 }, function($ctx1) {$ctx1.fill(self,"current",{},smalltalk.Smalltalk.klass)})},
 args: [],
-source: "current\x0a\x09^ current ifNil: [ current := self new ]",
+source: "current\x0a\x09^ current ifNil: [ current := super new ]",
 messageSends: ["ifNil:", "new"],
 referencedClasses: []
 }),
 smalltalk.Smalltalk.klass);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "new",
+protocol: 'instance creation',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+self._shouldNotImplement();
+return self}, function($ctx1) {$ctx1.fill(self,"new",{},smalltalk.Smalltalk.klass)})},
+args: [],
+source: "new\x0a\x09self shouldNotImplement",
+messageSends: ["shouldNotImplement"],
+referencedClasses: []
+}),
+smalltalk.Smalltalk.klass);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "do:displayingProgress:",

+ 6 - 2
st/Kernel-Infrastructure.st

@@ -985,10 +985,14 @@ isSmalltalkObject: anObject
 
 Smalltalk class instanceVariableNames: 'current'!
 
-!Smalltalk class methodsFor: 'accessing'!
+!Smalltalk class methodsFor: 'instance creation'!
 
 current
-	^ current ifNil: [ current := self new ]
+	^ current ifNil: [ current := super new ]
+!
+
+new
+	self shouldNotImplement
 ! !
 
 !SequenceableCollection methodsFor: '*Kernel-Infrastructure'!