Ver código fonte

Merge pull request #767 from herby/ie8

IE8 fixes
Nicolas Petton 10 anos atrás
pai
commit
e3b39d12d6

+ 3 - 3
js/Kernel-Classes.js

@@ -637,15 +637,15 @@ var self=this;
 return smalltalk.withContext(function($ctx1) { 
 var dict = smalltalk.HashedCollection._new();
 	var methods = self.methods;
-	for(var i in methods) {
+	Object.keys(methods).forEach(function(i) {
 		if(methods[i].selector) {
 			dict._at_put_(methods[i].selector, methods[i]);
 		}
-	};
+	});
 	return dict;
 return self}, function($ctx1) {$ctx1.fill(self,"methodDictionary",{},smalltalk.Behavior)})},
 args: [],
-source: "methodDictionary\x0a\x09<var dict = smalltalk.HashedCollection._new();\x0a\x09var methods = self.methods;\x0a\x09for(var i in methods) {\x0a\x09\x09if(methods[i].selector) {\x0a\x09\x09\x09dict._at_put_(methods[i].selector, methods[i]);\x0a\x09\x09}\x0a\x09};\x0a\x09return dict>",
+source: "methodDictionary\x0a\x09<var dict = smalltalk.HashedCollection._new();\x0a\x09var methods = self.methods;\x0a\x09Object.keys(methods).forEach(function(i) {\x0a\x09\x09if(methods[i].selector) {\x0a\x09\x09\x09dict._at_put_(methods[i].selector, methods[i]);\x0a\x09\x09}\x0a\x09});\x0a\x09return dict>",
 messageSends: [],
 referencedClasses: []
 }),

+ 66 - 41
js/Kernel-Collections.js

@@ -2551,6 +2551,7 @@ fn: function (aBlock,anotherBlock){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
 
+		self = self._numericallyIndexable();
 		for(var i = 0; i < self.length; i++)
 			if(aBlock._value_(self[i]))
 				return self[i];
@@ -2558,7 +2559,7 @@ return smalltalk.withContext(function($ctx1) {
 	;
 return self}, function($ctx1) {$ctx1.fill(self,"detect:ifNone:",{aBlock:aBlock,anotherBlock:anotherBlock},smalltalk.SequenceableCollection)})},
 args: ["aBlock", "anotherBlock"],
-source: "detect: aBlock ifNone: anotherBlock\x0a\x09<\x0a\x09\x09for(var i = 0; i < self.length; i++)\x0a\x09\x09\x09if(aBlock._value_(self[i]))\x0a\x09\x09\x09\x09return self[i];\x0a\x09\x09return anotherBlock._value();\x0a\x09>",
+source: "detect: aBlock ifNone: anotherBlock\x0a\x09<\x0a\x09\x09self = self._numericallyIndexable();\x0a\x09\x09for(var i = 0; i < self.length; i++)\x0a\x09\x09\x09if(aBlock._value_(self[i]))\x0a\x09\x09\x09\x09return self[i];\x0a\x09\x09return anotherBlock._value();\x0a\x09>",
 messageSends: [],
 referencedClasses: []
 }),
@@ -2571,10 +2572,10 @@ category: 'enumerating',
 fn: function (aBlock){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
-for(var i=0;i<self.length;i++){aBlock._value_(self[i]);};
+self=self._numericallyIndexable();for(var i=0;i<self.length;i++){aBlock._value_(self[i]);};
 return self}, function($ctx1) {$ctx1.fill(self,"do:",{aBlock:aBlock},smalltalk.SequenceableCollection)})},
 args: ["aBlock"],
-source: "do: aBlock\x0a\x09<for(var i=0;i<self.length;i++){aBlock._value_(self[i]);}>",
+source: "do: aBlock\x0a\x09<self=self._numericallyIndexable();for(var i=0;i<self.length;i++){aBlock._value_(self[i]);}>",
 messageSends: [],
 referencedClasses: []
 }),
@@ -2663,6 +2664,7 @@ fn: function (anObject,aBlock){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
 
+		self = self._numericallyIndexable();
 		for(var i=0;i<self.length;i++) {
 			if(self[i].__eq(anObject)) {return i+1}
 		};
@@ -2670,7 +2672,7 @@ return smalltalk.withContext(function($ctx1) {
 	;
 return self}, function($ctx1) {$ctx1.fill(self,"indexOf:ifAbsent:",{anObject:anObject,aBlock:aBlock},smalltalk.SequenceableCollection)})},
 args: ["anObject", "aBlock"],
-source: "indexOf: anObject ifAbsent: aBlock\x0a\x09<\x0a\x09\x09for(var i=0;i<self.length;i++) {\x0a\x09\x09\x09if(self[i].__eq(anObject)) {return i+1}\x0a\x09\x09};\x0a\x09\x09return aBlock._value();\x0a\x09>",
+source: "indexOf: anObject ifAbsent: aBlock\x0a\x09<\x0a\x09\x09self = self._numericallyIndexable();\x0a\x09\x09for(var i=0;i<self.length;i++) {\x0a\x09\x09\x09if(self[i].__eq(anObject)) {return i+1}\x0a\x09\x09};\x0a\x09\x09return aBlock._value();\x0a\x09>",
 messageSends: [],
 referencedClasses: []
 }),
@@ -2705,6 +2707,7 @@ fn: function (anObject,start,aBlock){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
 
+		self = self._numericallyIndexable();
 		for(var i=start-1;i<self.length;i++){
 			if(self[i].__eq(anObject)) {return i+1}
 		}
@@ -2712,7 +2715,7 @@ return smalltalk.withContext(function($ctx1) {
 	;
 return self}, function($ctx1) {$ctx1.fill(self,"indexOf:startingAt:ifAbsent:",{anObject:anObject,start:start,aBlock:aBlock},smalltalk.SequenceableCollection)})},
 args: ["anObject", "start", "aBlock"],
-source: "indexOf: anObject startingAt: start ifAbsent: aBlock\x0a\x09<\x0a\x09\x09for(var i=start-1;i<self.length;i++){\x0a\x09\x09\x09if(self[i].__eq(anObject)) {return i+1}\x0a\x09\x09}\x0a\x09\x09return aBlock._value();\x0a\x09>",
+source: "indexOf: anObject startingAt: start ifAbsent: aBlock\x0a\x09<\x0a\x09\x09self = self._numericallyIndexable();\x0a\x09\x09for(var i=start-1;i<self.length;i++){\x0a\x09\x09\x09if(self[i].__eq(anObject)) {return i+1}\x0a\x09\x09}\x0a\x09\x09return aBlock._value();\x0a\x09>",
 messageSends: [],
 referencedClasses: []
 }),
@@ -2754,6 +2757,22 @@ referencedClasses: []
 }),
 smalltalk.SequenceableCollection);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "numericallyIndexable",
+category: 'private',
+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",
@@ -2909,10 +2928,16 @@ category: 'enumerating',
 fn: function (anotherCollection,aBlock){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
-for(var i=0;i<self.length;i++){aBlock._value_value_(self[i], anotherCollection[i]);};
+
+		self = self._numericallyIndexable();
+		anotherCollection = anotherCollection._numericallyIndexable();
+		for(var i=0; i<self.length; i++) {
+			aBlock._value_value_(self[i], anotherCollection[i]);
+		}
+	;
 return self}, function($ctx1) {$ctx1.fill(self,"with:do:",{anotherCollection:anotherCollection,aBlock:aBlock},smalltalk.SequenceableCollection)})},
 args: ["anotherCollection", "aBlock"],
-source: "with: anotherCollection do: aBlock\x0a\x09<for(var i=0;i<self.length;i++){aBlock._value_value_(self[i], anotherCollection[i]);}>",
+source: "with: anotherCollection do: aBlock\x0a\x09<\x0a\x09\x09self = self._numericallyIndexable();\x0a\x09\x09anotherCollection = anotherCollection._numericallyIndexable();\x0a\x09\x09for(var i=0; i<self.length; i++) {\x0a\x09\x09\x09aBlock._value_value_(self[i], anotherCollection[i]);\x0a\x09\x09}\x0a\x09>",
 messageSends: [],
 referencedClasses: []
 }),
@@ -2925,10 +2950,10 @@ category: 'enumerating',
 fn: function (aBlock){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
-for(var i=0;i<self.length;i++){aBlock._value_value_(self[i], i+1);};
+self=self._numericallyIndexable();for(var i=0;i<self.length;i++){aBlock._value_value_(self[i], i+1);};
 return self}, function($ctx1) {$ctx1.fill(self,"withIndexDo:",{aBlock:aBlock},smalltalk.SequenceableCollection)})},
 args: ["aBlock"],
-source: "withIndexDo: aBlock\x0a\x09<for(var i=0;i<self.length;i++){aBlock._value_value_(self[i], i+1);}>",
+source: "withIndexDo: aBlock\x0a\x09<self=self._numericallyIndexable();for(var i=0;i<self.length;i++){aBlock._value_value_(self[i], i+1);}>",
 messageSends: [],
 referencedClasses: []
 }),
@@ -3131,6 +3156,22 @@ referencedClasses: []
 }),
 smalltalk.Array);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "numericallyIndexable",
+category: 'private',
+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:",
@@ -4156,22 +4197,6 @@ referencedClasses: []
 }),
 smalltalk.String);
 
-smalltalk.addMethod(
-smalltalk.method({
-selector: "do:",
-category: 'enumerating',
-fn: function (aBlock){
-var self=this;
-return smalltalk.withContext(function($ctx1) { 
-for(var i=0;i<self.length;i++){aBlock._value_(self.charAt(i));};
-return self}, function($ctx1) {$ctx1.fill(self,"do:",{aBlock:aBlock},smalltalk.String)})},
-args: ["aBlock"],
-source: "do: aBlock\x0a\x09<for(var i=0;i<self.length;i++){aBlock._value_(self.charAt(i));}>",
-messageSends: [],
-referencedClasses: []
-}),
-smalltalk.String);
-
 smalltalk.addMethod(
 smalltalk.method({
 selector: "escaped",
@@ -4533,6 +4558,22 @@ referencedClasses: []
 }),
 smalltalk.String);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "numericallyIndexable",
+category: 'private',
+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",
@@ -4885,22 +4926,6 @@ referencedClasses: []
 }),
 smalltalk.String);
 
-smalltalk.addMethod(
-smalltalk.method({
-selector: "withIndexDo:",
-category: 'enumerating',
-fn: function (aBlock){
-var self=this;
-return smalltalk.withContext(function($ctx1) { 
-for(var i=0;i<self.length;i++){aBlock._value_value_(self.charAt(i), i+1);};
-return self}, function($ctx1) {$ctx1.fill(self,"withIndexDo:",{aBlock:aBlock},smalltalk.String)})},
-args: ["aBlock"],
-source: "withIndexDo: aBlock\x0a\x09<for(var i=0;i<self.length;i++){aBlock._value_value_(self.charAt(i), i+1);}>",
-messageSends: [],
-referencedClasses: []
-}),
-smalltalk.String);
-
 
 smalltalk.addMethod(
 smalltalk.method({

+ 4 - 6
js/Kernel-Infrastructure.js

@@ -2378,15 +2378,13 @@ fn: function (){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
 
-		var packages = [];
-		for(var key in self.packages) {
-			packages.push(self.packages[key]);
-		}
-		return packages;
+		return Object.keys(self.packages).map(function(k) {
+			return self.packages[k];
+		})
 	;
 return self}, function($ctx1) {$ctx1.fill(self,"packages",{},smalltalk.Smalltalk)})},
 args: [],
-source: "packages\x0a\x09\x22Return all Package instances in the system.\x22\x0a\x0a\x09<\x0a\x09\x09var packages = [];\x0a\x09\x09for(var key in self.packages) {\x0a\x09\x09\x09packages.push(self.packages[key]);\x0a\x09\x09}\x0a\x09\x09return packages;\x0a\x09>",
+source: "packages\x0a\x09\x22Return all Package instances in the system.\x22\x0a\x0a\x09<\x0a\x09\x09return Object.keys(self.packages).map(function(k) {\x0a\x09\x09\x09return self.packages[k];\x0a\x09\x09})\x0a\x09>",
 messageSends: [],
 referencedClasses: []
 }),

+ 6 - 6
js/Kernel-Objects.js

@@ -525,16 +525,16 @@ var self=this;
 return smalltalk.withContext(function($ctx1) { 
 
 		var copy = self.klass._new();
-		for(var i in self) {
+		Object.keys(self).forEach(function (i) {
 		if(/^@.+/.test(i)) {
 			copy[i] = self[i]._deepCopy();
 		}
-		}
+		});
 		return copy;
 	;
 return self}, function($ctx1) {$ctx1.fill(self,"deepCopy",{},smalltalk.Object)})},
 args: [],
-source: "deepCopy\x0a\x09<\x0a\x09\x09var copy = self.klass._new();\x0a\x09\x09for(var i in self) {\x0a\x09\x09if(/^@.+/.test(i)) {\x0a\x09\x09\x09copy[i] = self[i]._deepCopy();\x0a\x09\x09}\x0a\x09\x09}\x0a\x09\x09return copy;\x0a\x09>",
+source: "deepCopy\x0a\x09<\x0a\x09\x09var copy = self.klass._new();\x0a\x09\x09Object.keys(self).forEach(function (i) {\x0a\x09\x09if(/^@.+/.test(i)) {\x0a\x09\x09\x09copy[i] = self[i]._deepCopy();\x0a\x09\x09}\x0a\x09\x09});\x0a\x09\x09return copy;\x0a\x09>",
 messageSends: [],
 referencedClasses: []
 }),
@@ -1009,16 +1009,16 @@ var self=this;
 return smalltalk.withContext(function($ctx1) { 
 
 		var copy = self.klass._new();
-		for(var i in self) {
+		Object.keys(self).forEach(function(i) {
 		if(/^@.+/.test(i)) {
 			copy[i] = self[i];
 		}
-		}
+		});
 		return copy;
 	;
 return self}, function($ctx1) {$ctx1.fill(self,"shallowCopy",{},smalltalk.Object)})},
 args: [],
-source: "shallowCopy\x0a\x09<\x0a\x09\x09var copy = self.klass._new();\x0a\x09\x09for(var i in self) {\x0a\x09\x09if(/^@.+/.test(i)) {\x0a\x09\x09\x09copy[i] = self[i];\x0a\x09\x09}\x0a\x09\x09}\x0a\x09\x09return copy;\x0a\x09>",
+source: "shallowCopy\x0a\x09<\x0a\x09\x09var copy = self.klass._new();\x0a\x09\x09Object.keys(self).forEach(function(i) {\x0a\x09\x09if(/^@.+/.test(i)) {\x0a\x09\x09\x09copy[i] = self[i];\x0a\x09\x09}\x0a\x09\x09});\x0a\x09\x09return copy;\x0a\x09>",
 messageSends: [],
 referencedClasses: []
 }),

+ 2 - 2
st/Kernel-Classes.st

@@ -121,11 +121,11 @@ methodAt: aString
 methodDictionary
 	<var dict = smalltalk.HashedCollection._new();
 	var methods = self.methods;
-	for(var i in methods) {
+	Object.keys(methods).forEach(function(i) {
 		if(methods[i].selector) {
 			dict._at_put_(methods[i].selector, methods[i]);
 		}
-	};
+	});
 	return dict>
 !
 

+ 36 - 13
st/Kernel-Collections.st

@@ -834,6 +834,7 @@ fourth
 
 indexOf: anObject ifAbsent: aBlock
 	<
+		self = self._numericallyIndexable();
 		for(var i=0;i<self.length;i++) {
 			if(self[i].__eq(anObject)) {return i+1}
 		};
@@ -850,6 +851,7 @@ indexOf: anObject startingAt: start
 
 indexOf: anObject startingAt: start ifAbsent: aBlock
 	<
+		self = self._numericallyIndexable();
 		for(var i=start-1;i<self.length;i++){
 			if(self[i].__eq(anObject)) {return i+1}
 		}
@@ -926,6 +928,7 @@ shallowCopy
 
 detect: aBlock ifNone: anotherBlock
 	<
+		self = self._numericallyIndexable();
 		for(var i = 0; i < self.length; i++)
 			if(aBlock._value_(self[i]))
 				return self[i];
@@ -934,15 +937,33 @@ detect: aBlock ifNone: anotherBlock
 !
 
 do: aBlock
-	<for(var i=0;i<self.length;i++){aBlock._value_(self[i]);}>
+	<self=self._numericallyIndexable();for(var i=0;i<self.length;i++){aBlock._value_(self[i]);}>
 !
 
 with: anotherCollection do: aBlock
-	<for(var i=0;i<self.length;i++){aBlock._value_value_(self[i], anotherCollection[i]);}>
+	<
+		self = self._numericallyIndexable();
+		anotherCollection = anotherCollection._numericallyIndexable();
+		for(var i=0; i<self.length; i++) {
+			aBlock._value_value_(self[i], anotherCollection[i]);
+		}
+	>
 !
 
 withIndexDo: aBlock
-	<for(var i=0;i<self.length;i++){aBlock._value_value_(self[i], i+1);}>
+	<self=self._numericallyIndexable();for(var i=0;i<self.length;i++){aBlock._value_value_(self[i], i+1);}>
+! !
+
+!SequenceableCollection methodsFor: 'private'!
+
+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'!
@@ -1128,6 +1149,12 @@ printOn: aStream
 	aStream nextPutAll: ')'
 ! !
 
+!Array methodsFor: 'private'!
+
+numericallyIndexable
+	^ self
+! !
+
 !Array class methodsFor: 'instance creation'!
 
 new: anInteger
@@ -1416,16 +1443,6 @@ shallowCopy
 	^ self class fromString: self
 ! !
 
-!String methodsFor: 'enumerating'!
-
-do: aBlock
-	<for(var i=0;i<self.length;i++){aBlock._value_(self.charAt(i));}>
-!
-
-withIndexDo: aBlock
-	<for(var i=0;i<self.length;i++){aBlock._value_value_(self.charAt(i), i+1);}>
-! !
-
 !String methodsFor: 'printing'!
 
 printNl
@@ -1439,6 +1456,12 @@ printOn: aStream
 		nextPutAll: ''''
 ! !
 
+!String methodsFor: 'private'!
+
+numericallyIndexable
+	<return String(self)>
+! !
+
 !String methodsFor: 'regular expressions'!
 
 match: aRegexp

+ 3 - 5
st/Kernel-Infrastructure.st

@@ -915,11 +915,9 @@ packages
 	"Return all Package instances in the system."
 
 	<
-		var packages = [];
-		for(var key in self.packages) {
-			packages.push(self.packages[key]);
-		}
-		return packages;
+		return Object.keys(self.packages).map(function(k) {
+			return self.packages[k];
+		})
 	>
 !
 

+ 4 - 4
st/Kernel-Objects.st

@@ -213,11 +213,11 @@ copy
 deepCopy
 	<
 		var copy = self.klass._new();
-		for(var i in self) {
+		Object.keys(self).forEach(function (i) {
 		if(/^@.+/.test(i)) {
 			copy[i] = self[i]._deepCopy();
 		}
-		}
+		});
 		return copy;
 	>
 !
@@ -228,11 +228,11 @@ postCopy
 shallowCopy
 	<
 		var copy = self.klass._new();
-		for(var i in self) {
+		Object.keys(self).forEach(function(i) {
 		if(/^@.+/.test(i)) {
 			copy[i] = self[i];
 		}
-		}
+		});
 		return copy;
 	>
 ! !