Browse Source

Compiler class >> eval:

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

+ 2 - 0
API-CHANGES.txt

@@ -8,6 +8,8 @@
 + AmberBootstrapInitialization class >>
   + run
   + initializeClasses
++ Compiler class >>
+  + eval:
 + JavaScriptException >>
   + shouldBeStubbed
   + wrap

+ 23 - 0
src/Compiler-Core.js

@@ -937,6 +937,29 @@ messageSends: []
 $globals.Compiler);
 
 
+$core.addMethod(
+$core.method({
+selector: "eval:",
+protocol: "evaluating",
+fn: function (aString){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return $recv($self._new())._eval_(aString);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"eval:",{aString:aString},$globals.Compiler.a$cls)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aString"],
+source: "eval: aString\x0a\x09^ self new eval: aString",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["eval:", "new"]
+}),
+$globals.Compiler.a$cls);
+
 $core.addMethod(
 $core.method({
 selector: "recompile:",

+ 6 - 0
src/Compiler-Core.st

@@ -245,6 +245,12 @@ recompileAll
 		self recompile: each ]
 ! !
 
+!Compiler class methodsFor: 'evaluating'!
+
+eval: aString
+	^ self new eval: aString
+! !
+
 Error subclass: #CompilerError
 	instanceVariableNames: ''
 	package: 'Compiler-Core'!

+ 3 - 3
src/Compiler-Interpreter.js

@@ -2409,7 +2409,7 @@ return $recv(str)._nextPutAll_("})()})");
 }, function($ctx2) {$ctx2.fillBlock({str:str},$ctx1,1)});
 //>>excludeEnd("ctx");
 }));
-function_=$recv($recv($globals.Compiler)._new())._eval_(source);
+function_=$recv($globals.Compiler)._eval_(source);
 return $recv(function_)._valueWithPossibleArguments_($recv($recv($self._context())._locals())._values());
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"eval:",{aString:aString,source:source,function_:function_},$globals.ASTInterpreter)});
@@ -2417,10 +2417,10 @@ return $recv(function_)._valueWithPossibleArguments_($recv($recv($self._context(
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aString"],
-source: "eval: aString\x0a\x09\x22Evaluate aString as JS source inside an JS function.\x0a\x09aString is not sandboxed.\x22\x0a\x09\x0a\x09| source function |\x0a\x09\x0a\x09source := String streamContents: [ :str |\x0a\x09\x09str nextPutAll: '0,(function('.\x0a\x09\x09self context locals keys\x0a\x09\x09\x09do: [ :each | str nextPutAll: each ]\x0a\x09\x09\x09separatedBy: [ str nextPutAll: ',' ].\x0a\x09\x09str\x0a\x09\x09\x09nextPutAll: '){ return (function() {';\x0a\x09\x09\x09nextPutAll: aString;\x0a\x09\x09\x09nextPutAll: '})()})' ].\x0a\x09\x09\x09\x0a\x09function := Compiler new eval: source.\x0a\x09\x0a\x09^ function valueWithPossibleArguments: self context locals values",
+source: "eval: aString\x0a\x09\x22Evaluate aString as JS source inside an JS function.\x0a\x09aString is not sandboxed.\x22\x0a\x09\x0a\x09| source function |\x0a\x09\x0a\x09source := String streamContents: [ :str |\x0a\x09\x09str nextPutAll: '0,(function('.\x0a\x09\x09self context locals keys\x0a\x09\x09\x09do: [ :each | str nextPutAll: each ]\x0a\x09\x09\x09separatedBy: [ str nextPutAll: ',' ].\x0a\x09\x09str\x0a\x09\x09\x09nextPutAll: '){ return (function() {';\x0a\x09\x09\x09nextPutAll: aString;\x0a\x09\x09\x09nextPutAll: '})()})' ].\x0a\x09\x09\x09\x0a\x09function := Compiler eval: source.\x0a\x09\x0a\x09^ function valueWithPossibleArguments: self context locals values",
 referencedClasses: ["String", "Compiler"],
 //>>excludeEnd("ide");
-messageSends: ["streamContents:", "nextPutAll:", "do:separatedBy:", "keys", "locals", "context", "eval:", "new", "valueWithPossibleArguments:", "values"]
+messageSends: ["streamContents:", "nextPutAll:", "do:separatedBy:", "keys", "locals", "context", "eval:", "valueWithPossibleArguments:", "values"]
 }),
 $globals.ASTInterpreter);
 

+ 1 - 1
src/Compiler-Interpreter.st

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

+ 5 - 6
src/Compiler-Semantic.js

@@ -1919,7 +1919,7 @@ var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1,$2,$3,$receiver;
+var $1,$2,$receiver;
 if(($receiver = aPackage) == null || $receiver.a$nil){
 aPackage;
 } else {
@@ -1931,22 +1931,21 @@ if($core.assert($1)){
 return false;
 }
 }
-$2=$recv($globals.Compiler)._new();
-$3=$recv("typeof ".__comma(aString)).__comma(" == \x22undefined\x22");
+$2=$recv("typeof ".__comma(aString)).__comma(" === \x22undefined\x22");
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.sendIdx[","]=1;
 //>>excludeEnd("ctx");
-return $recv($2)._eval_($3);
+return $recv($globals.Compiler)._eval_($2);
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"isVariableUndefined:inPackage:",{aString:aString,aPackage:aPackage},$globals.SemanticAnalyzer)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aString", "aPackage"],
-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'",
+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'",
 referencedClasses: ["Compiler"],
 //>>excludeEnd("ide");
-messageSends: ["ifNotNil:", "collect:", "reject:", "imports", "ifTrue:", "includes:", "eval:", "new", ","]
+messageSends: ["ifNotNil:", "collect:", "reject:", "imports", "ifTrue:", "includes:", "eval:", ","]
 }),
 $globals.SemanticAnalyzer);
 

+ 1 - 2
src/Compiler-Semantic.st

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