Browse Source

SequenceableCollection >> numericallyIndexable

Herbert Vojčík 11 years ago
parent
commit
fe07735adb
2 changed files with 72 additions and 0 deletions
  1. 48 0
      js/Kernel-Collections.js
  2. 24 0
      st/Kernel-Collections.st

+ 48 - 0
js/Kernel-Collections.js

@@ -2754,6 +2754,22 @@ referencedClasses: []
 }),
 smalltalk.SequenceableCollection);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "numericallyIndexable",
+category: 'protected',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+self._subclassResponsibility();
+return self}, function($ctx1) {$ctx1.fill(self,"numericallyIndexable",{},smalltalk.SequenceableCollection)})},
+args: [],
+source: "numericallyIndexable\x0a\x09\x22This is internal converting message.\x0a\x09It returns such representation of self\x0a\x09that can use foo[i] in JavaScript code.\x0a\x09It fixes IE8, where boxed String is unable\x0a\x09to numerically index its characters,\x0a\x09but primitive string can.\x22\x0a\x09self subclassResponsibility",
+messageSends: ["subclassResponsibility"],
+referencedClasses: []
+}),
+smalltalk.SequenceableCollection);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "readStream",
@@ -3131,6 +3147,22 @@ referencedClasses: []
 }),
 smalltalk.Array);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "numericallyIndexable",
+category: 'protected',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+return self;
+}, function($ctx1) {$ctx1.fill(self,"numericallyIndexable",{},smalltalk.Array)})},
+args: [],
+source: "numericallyIndexable\x0a\x09^ self",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.Array);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "printOn:",
@@ -4533,6 +4565,22 @@ referencedClasses: []
 }),
 smalltalk.String);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "numericallyIndexable",
+category: 'protected',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+return String(self);
+return self}, function($ctx1) {$ctx1.fill(self,"numericallyIndexable",{},smalltalk.String)})},
+args: [],
+source: "numericallyIndexable\x0a\x09<return String(self)>",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.String);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "printNl",

+ 24 - 0
st/Kernel-Collections.st

@@ -945,6 +945,18 @@ withIndexDo: aBlock
 	<for(var i=0;i<self.length;i++){aBlock._value_value_(self[i], i+1);}>
 ! !
 
+!SequenceableCollection methodsFor: 'protected'!
+
+numericallyIndexable
+	"This is internal converting message.
+	It returns such representation of self
+	that can use foo[i] in JavaScript code.
+	It fixes IE8, where boxed String is unable
+	to numerically index its characters,
+	but primitive string can."
+	self subclassResponsibility
+! !
+
 !SequenceableCollection methodsFor: 'streaming'!
 
 newStream
@@ -1128,6 +1140,12 @@ printOn: aStream
 	aStream nextPutAll: ')'
 ! !
 
+!Array methodsFor: 'protected'!
+
+numericallyIndexable
+	^ self
+! !
+
 !Array class methodsFor: 'instance creation'!
 
 new: anInteger
@@ -1439,6 +1457,12 @@ printOn: aStream
 		nextPutAll: ''''
 ! !
 
+!String methodsFor: 'protected'!
+
+numericallyIndexable
+	<return String(self)>
+! !
+
 !String methodsFor: 'regular expressions'!
 
 match: aRegexp