浏览代码

JSObjectProxy: add >>at:ifAbsent:

Manfred Kroehnert 11 年之前
父节点
当前提交
c0b0e6d897
共有 3 个文件被更改,包括 44 次插入0 次删除
  1. 15 0
      js/Kernel-Objects.deploy.js
  2. 20 0
      js/Kernel-Objects.js
  3. 9 0
      st/Kernel-Objects.st

+ 15 - 0
js/Kernel-Objects.deploy.js

@@ -1467,6 +1467,21 @@ return self}, function($ctx1) {$ctx1.fill(self,"at:",{aSymbol:aSymbol}, smalltal
 }),
 smalltalk.JSObjectProxy);
 
+smalltalk.addMethod(
+"_at_ifAbsent_",
+smalltalk.method({
+selector: "at:ifAbsent:",
+fn: function (aSymbol,aBlock){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+    	var value = self['@jsObject'][aSymbol._asString()];
+        if (undefined === value) return aBlock();
+        return value;
+	;
+return self}, function($ctx1) {$ctx1.fill(self,"at:ifAbsent:",{aSymbol:aSymbol,aBlock:aBlock}, smalltalk.JSObjectProxy)})}
+}),
+smalltalk.JSObjectProxy);
+
 smalltalk.addMethod(
 "_at_put_",
 smalltalk.method({

+ 20 - 0
js/Kernel-Objects.js

@@ -2056,6 +2056,26 @@ referencedClasses: []
 }),
 smalltalk.JSObjectProxy);
 
+smalltalk.addMethod(
+"_at_ifAbsent_",
+smalltalk.method({
+selector: "at:ifAbsent:",
+category: 'accessing',
+fn: function (aSymbol,aBlock){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+    	var value = self['@jsObject'][aSymbol._asString()];
+        if (undefined === value) return aBlock();
+        return value;
+	;
+return self}, function($ctx1) {$ctx1.fill(self,"at:ifAbsent:",{aSymbol:aSymbol,aBlock:aBlock}, smalltalk.JSObjectProxy)})},
+args: ["aSymbol", "aBlock"],
+source: "at: aSymbol ifAbsent: aBlock\x0a\x09\x22return the aSymbol property or evaluate aBlock if the property is undefined\x22\x0a\x09<\x0a    \x09var value = self['@jsObject'][aSymbol._asString()];\x0a        if (undefined === value) return aBlock();\x0a        return value;\x0a\x09>",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.JSObjectProxy);
+
 smalltalk.addMethod(
 "_at_put_",
 smalltalk.method({

+ 9 - 0
st/Kernel-Objects.st

@@ -672,6 +672,15 @@ at: aSymbol
 	<return self['@jsObject'][aSymbol._asString()]>
 !
 
+at: aSymbol ifAbsent: aBlock
+	"return the aSymbol property or evaluate aBlock if the property is undefined"
+	<
+    	var value = self['@jsObject'][aSymbol._asString()];
+        if (undefined === value) return aBlock();
+        return value;
+	>
+!
+
 at: aSymbol put: anObject
 	<self['@jsObject'][aSymbol._asString()] = anObject>
 !