Browse Source

Compiler class >> eval:

Convenience not to `Compiler new eval: ...`.
Herbert Vojčík 5 months ago
parent
commit
6edba6242a

+ 2 - 0
API-CHANGES.txt

@@ -8,6 +8,8 @@
8 8
 + AmberBootstrapInitialization class >>
9 9
   + run
10 10
   + initializeClasses
11
++ Compiler class >>
12
+  + eval:
11 13
 + JavaScriptException >>
12 14
   + shouldBeStubbed
13 15
   + wrap

+ 23 - 0
src/Compiler-Core.js

@@ -939,6 +939,29 @@ $globals.Compiler);
939 939
 
940 940
 $core.addMethod(
941 941
 $core.method({
942
+selector: "eval:",
943
+protocol: "evaluating",
944
+fn: function (aString){
945
+var self=this,$self=this;
946
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
947
+return $core.withContext(function($ctx1) {
948
+//>>excludeEnd("ctx");
949
+return $recv($self._new())._eval_(aString);
950
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
951
+}, function($ctx1) {$ctx1.fill(self,"eval:",{aString:aString},$globals.Compiler.a$cls)});
952
+//>>excludeEnd("ctx");
953
+},
954
+//>>excludeStart("ide", pragmas.excludeIdeData);
955
+args: ["aString"],
956
+source: "eval: aString\x0a\x09^ self new eval: aString",
957
+referencedClasses: [],
958
+//>>excludeEnd("ide");
959
+messageSends: ["eval:", "new"]
960
+}),
961
+$globals.Compiler.a$cls);
962
+
963
+$core.addMethod(
964
+$core.method({
942 965
 selector: "recompile:",
943 966
 protocol: "compiling",
944 967
 fn: function (aClass){

+ 6 - 0
src/Compiler-Core.st

@@ -245,6 +245,12 @@ recompileAll
245 245
 		self recompile: each ]
246 246
 ! !
247 247
 
248
+!Compiler class methodsFor: 'evaluating'!
249
+
250
+eval: aString
251
+	^ self new eval: aString
252
+! !
253
+
248 254
 Error subclass: #CompilerError
249 255
 	instanceVariableNames: ''
250 256
 	package: 'Compiler-Core'!

File diff suppressed because it is too large
+ 3 - 3
src/Compiler-Interpreter.js


+ 1 - 1
src/Compiler-Interpreter.st

@@ -723,7 +723,7 @@ eval: aString
723 723
 			nextPutAll: aString;
724 724
 			nextPutAll: '})()})' ].
725 725
 			
726
-	function := Compiler new eval: source.
726
+	function := Compiler eval: source.
727 727
 	
728 728
 	^ function valueWithPossibleArguments: self context locals values
729 729
 !

+ 5 - 6
src/Compiler-Semantic.js

@@ -1919,7 +1919,7 @@ var self=this,$self=this;
1919 1919
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
1920 1920
 return $core.withContext(function($ctx1) {
1921 1921
 //>>excludeEnd("ctx");
1922
-var $1,$2,$3,$receiver;
1922
+var $1,$2,$receiver;
1923 1923
 if(($receiver = aPackage) == null || $receiver.a$nil){
1924 1924
 aPackage;
1925 1925
 } else {
@@ -1931,22 +1931,21 @@ if($core.assert($1)){
1931 1931
 return false;
1932 1932
 }
1933 1933
 }
1934
-$2=$recv($globals.Compiler)._new();
1935
-$3=$recv("typeof ".__comma(aString)).__comma(" == \x22undefined\x22");
1934
+$2=$recv("typeof ".__comma(aString)).__comma(" === \x22undefined\x22");
1936 1935
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
1937 1936
 $ctx1.sendIdx[","]=1;
1938 1937
 //>>excludeEnd("ctx");
1939
-return $recv($2)._eval_($3);
1938
+return $recv($globals.Compiler)._eval_($2);
1940 1939
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
1941 1940
 }, function($ctx1) {$ctx1.fill(self,"isVariableUndefined:inPackage:",{aString:aString,aPackage:aPackage},$globals.SemanticAnalyzer)});
1942 1941
 //>>excludeEnd("ctx");
1943 1942
 },
1944 1943
 //>>excludeStart("ide", pragmas.excludeIdeData);
1945 1944
 args: ["aString", "aPackage"],
1946
-source: "isVariableUndefined: aString inPackage: aPackage\x0a\x09aPackage ifNotNil: [\x0a\x09\x09| packageKnownVars |\x0a\x09\x09packageKnownVars := (aPackage imports\x0a\x09\x09\x09reject: #isString)\x0a\x09\x09\x09collect: #key.\x0a\x09\x09(packageKnownVars includes: aString) ifTrue: [ ^ false ]].\x0a\x09^ Compiler new\x0a\x09\x09eval: 'typeof ', aString, ' == \x22undefined\x22'",
1945
+source: "isVariableUndefined: aString inPackage: aPackage\x0a\x09aPackage ifNotNil: [\x0a\x09\x09| packageKnownVars |\x0a\x09\x09packageKnownVars := (aPackage imports\x0a\x09\x09\x09reject: #isString)\x0a\x09\x09\x09collect: #key.\x0a\x09\x09(packageKnownVars includes: aString) ifTrue: [ ^ false ]].\x0a\x09^ Compiler eval: 'typeof ', aString, ' === \x22undefined\x22'",
1947 1946
 referencedClasses: ["Compiler"],
1948 1947
 //>>excludeEnd("ide");
1949
-messageSends: ["ifNotNil:", "collect:", "reject:", "imports", "ifTrue:", "includes:", "eval:", "new", ","]
1948
+messageSends: ["ifNotNil:", "collect:", "reject:", "imports", "ifTrue:", "includes:", "eval:", ","]
1950 1949
 }),
1951 1950
 $globals.SemanticAnalyzer);
1952 1951
 

+ 1 - 2
src/Compiler-Semantic.st

@@ -540,8 +540,7 @@ isVariableUndefined: aString inPackage: aPackage
540 540
 			reject: #isString)
541 541
 			collect: #key.
542 542
 		(packageKnownVars includes: aString) ifTrue: [ ^ false ]].
543
-	^ Compiler new
544
-		eval: 'typeof ', aString, ' == "undefined"'
543
+	^ Compiler eval: 'typeof ', aString, ' === "undefined"'
545 544
 ! !
546 545
 
547 546
 !SemanticAnalyzer methodsFor: 'visiting'!