Browse Source

Merge pull request #337 from xekoukou/master

Native Function ecapsulation
Nicolas Petton 12 years ago
parent
commit
cd0abb9a9b
3 changed files with 174 additions and 4 deletions
  1. 59 1
      js/Kernel-Methods.deploy.js
  2. 85 2
      js/Kernel-Methods.js
  3. 30 1
      st/Kernel-Methods.st

+ 59 - 1
js/Kernel-Methods.deploy.js

@@ -83,7 +83,7 @@ smalltalk.method({
 selector: "newValue:value:value:",
 fn: function (anObject,anObject2,anObject3){
 var self=this;
-return smalltalk.withContext(function($ctx1) { 
return new self(anObject, anObject2);
+return smalltalk.withContext(function($ctx1) { 
return new self(anObject, anObject2,anObject3);
 return self}, function($ctx1) {$ctx1.fill(self,"newValue:value:value:",{anObject:anObject,anObject2:anObject2,anObject3:anObject3}, smalltalk.BlockClosure)})}
 }),
 smalltalk.BlockClosure);
@@ -877,3 +877,61 @@ smalltalk.MethodContext);
 
 
 
+smalltalk.addClass('NativeFunction', smalltalk.Object, [], 'Kernel-Methods');
+
+smalltalk.addMethod(
+"_class_",
+smalltalk.method({
+selector: "class:",
+fn: function (aString){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
var a=eval(aString); return new a();;
+return self}, function($ctx1) {$ctx1.fill(self,"class:",{aString:aString}, smalltalk.NativeFunction.klass)})}
+}),
+smalltalk.NativeFunction.klass);
+
+smalltalk.addMethod(
+"_class_value_",
+smalltalk.method({
+selector: "class:value:",
+fn: function (aString,anObject){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
var a=eval(aString); return new a(anObject);;
+return self}, function($ctx1) {$ctx1.fill(self,"class:value:",{aString:aString,anObject:anObject}, smalltalk.NativeFunction.klass)})}
+}),
+smalltalk.NativeFunction.klass);
+
+smalltalk.addMethod(
+"_class_value_value_",
+smalltalk.method({
+selector: "class:value:value:",
+fn: function (aString,anObject,anObject2){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
var a=eval(aString); return new a(anObject,anObject2);;
+return self}, function($ctx1) {$ctx1.fill(self,"class:value:value:",{aString:aString,anObject:anObject,anObject2:anObject2}, smalltalk.NativeFunction.klass)})}
+}),
+smalltalk.NativeFunction.klass);
+
+smalltalk.addMethod(
+"_class_value_value_value_",
+smalltalk.method({
+selector: "class:value:value:value:",
+fn: function (aString,anObject,anObject2,anObject3){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
var a=eval(aString); return new a(anObject,anObject2, anObject3);;
+return self}, function($ctx1) {$ctx1.fill(self,"class:value:value:value:",{aString:aString,anObject:anObject,anObject2:anObject2,anObject3:anObject3}, smalltalk.NativeFunction.klass)})}
+}),
+smalltalk.NativeFunction.klass);
+
+smalltalk.addMethod(
+"_exists_",
+smalltalk.method({
+selector: "exists:",
+fn: function (aString){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
if(aString in window){return true}else{return false};
+return self}, function($ctx1) {$ctx1.fill(self,"exists:",{aString:aString}, smalltalk.NativeFunction.klass)})}
+}),
+smalltalk.NativeFunction.klass);
+
+

+ 85 - 2
js/Kernel-Methods.js

@@ -120,10 +120,10 @@ selector: "newValue:value:value:",
 category: 'evaluating',
 fn: function (anObject,anObject2,anObject3){
 var self=this;
-return smalltalk.withContext(function($ctx1) { 
return new self(anObject, anObject2);
+return smalltalk.withContext(function($ctx1) { 
return new self(anObject, anObject2,anObject3);
 return self}, function($ctx1) {$ctx1.fill(self,"newValue:value:value:",{anObject:anObject,anObject2:anObject2,anObject3:anObject3}, smalltalk.BlockClosure)})},
 args: ["anObject", "anObject2", "anObject3"],
-source: "newValue:  anObject value: anObject2 value: anObject3\x0a\x09\x22Use the receiver as a JS constructor. \x0a\x09*Do not* use this method to instanciate Smalltalk objects!\x22\x0a\x09<return new self(anObject, anObject2)>",
+source: "newValue:  anObject value: anObject2 value: anObject3\x0a\x09\x22Use the receiver as a JS constructor. \x0a\x09*Do not* use this method to instanciate Smalltalk objects!\x22\x0a\x09<return new self(anObject, anObject2,anObject3)>",
 messageSends: [],
 referencedClasses: []
 }),
@@ -1202,3 +1202,86 @@ smalltalk.MethodContext);
 
 
 
+smalltalk.addClass('NativeFunction', smalltalk.Object, [], 'Kernel-Methods');
+
+smalltalk.addMethod(
+"_class_",
+smalltalk.method({
+selector: "class:",
+category: 'not yet classified',
+fn: function (aString){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
var a=eval(aString); return new a();;
+return self}, function($ctx1) {$ctx1.fill(self,"class:",{aString:aString}, smalltalk.NativeFunction.klass)})},
+args: ["aString"],
+source: "class: aString\x0a<var a=eval(aString); return new a();>\x0a",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.NativeFunction.klass);
+
+smalltalk.addMethod(
+"_class_value_",
+smalltalk.method({
+selector: "class:value:",
+category: 'not yet classified',
+fn: function (aString,anObject){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
var a=eval(aString); return new a(anObject);;
+return self}, function($ctx1) {$ctx1.fill(self,"class:value:",{aString:aString,anObject:anObject}, smalltalk.NativeFunction.klass)})},
+args: ["aString", "anObject"],
+source: "class: aString value:anObject\x0a\x0a<var a=eval(aString); return new a(anObject);>\x0a",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.NativeFunction.klass);
+
+smalltalk.addMethod(
+"_class_value_value_",
+smalltalk.method({
+selector: "class:value:value:",
+category: 'not yet classified',
+fn: function (aString,anObject,anObject2){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
var a=eval(aString); return new a(anObject,anObject2);;
+return self}, function($ctx1) {$ctx1.fill(self,"class:value:value:",{aString:aString,anObject:anObject,anObject2:anObject2}, smalltalk.NativeFunction.klass)})},
+args: ["aString", "anObject", "anObject2"],
+source: "class: aString value:anObject value: anObject2\x0a\x0a<var a=eval(aString); return new a(anObject,anObject2);>\x0a",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.NativeFunction.klass);
+
+smalltalk.addMethod(
+"_class_value_value_value_",
+smalltalk.method({
+selector: "class:value:value:value:",
+category: 'not yet classified',
+fn: function (aString,anObject,anObject2,anObject3){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
var a=eval(aString); return new a(anObject,anObject2, anObject3);;
+return self}, function($ctx1) {$ctx1.fill(self,"class:value:value:value:",{aString:aString,anObject:anObject,anObject2:anObject2,anObject3:anObject3}, smalltalk.NativeFunction.klass)})},
+args: ["aString", "anObject", "anObject2", "anObject3"],
+source: "class: aString value:anObject value: anObject2 value:anObject3\x0a\x0a<var a=eval(aString); return new a(anObject,anObject2, anObject3);>\x0a",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.NativeFunction.klass);
+
+smalltalk.addMethod(
+"_exists_",
+smalltalk.method({
+selector: "exists:",
+category: 'not yet classified',
+fn: function (aString){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
if(aString in window){return true}else{return false};
+return self}, function($ctx1) {$ctx1.fill(self,"exists:",{aString:aString}, smalltalk.NativeFunction.klass)})},
+args: ["aString"],
+source: "exists: aString\x0a<if(aString in window){return true}else{return false}>\x0a",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.NativeFunction.klass);
+
+

+ 30 - 1
st/Kernel-Methods.st

@@ -80,7 +80,7 @@ newValue:  anObject value: anObject2
 newValue:  anObject value: anObject2 value: anObject3
 	"Use the receiver as a JS constructor. 
 	*Do not* use this method to instanciate Smalltalk objects!!"
-	<return new self(anObject, anObject2)>
+	<return new self(anObject, anObject2,anObject3)>
 !
 
 timeToRun
@@ -419,3 +419,32 @@ isBlockContext
 	^ self selector isNil
 ! !
 
+Object subclass: #NativeFunction
+	instanceVariableNames: ''
+	package: 'Kernel-Methods'!
+
+!NativeFunction class methodsFor: 'not yet classified'!
+
+class: aString
+<var a=eval(aString); return new a();>
+!
+
+class: aString value:anObject
+
+<var a=eval(aString); return new a(anObject);>
+!
+
+class: aString value:anObject value: anObject2
+
+<var a=eval(aString); return new a(anObject,anObject2);>
+!
+
+class: aString value:anObject value: anObject2 value:anObject3
+
+<var a=eval(aString); return new a(anObject,anObject2, anObject3);>
+!
+
+exists: aString
+<if(aString in window){return true}else{return false}>
+! !
+