Browse Source

Platform service

Herbert Vojčík 9 years ago
parent
commit
3977971ce6

+ 4 - 4
API-CHANGES.txt

@@ -1,15 +1,15 @@
 0.14.14:
 
 * InterfacingObject >> ajax: deprecated
-* PlatformInterface class >> ajax: deprecated
-* PlatformInterface class >> alert:/confirm:/prompt:[default:] deprecated
-* PlatformInterface class >> existsGlobal: deprecated
+* PlatformInterface class deprecated
 * Class BrowserInterface removed
 * Class Terminal, BrowserTerminal added
+* Class Platform, BrowserPlatform added
 
 + Environment >>
   + renamePackage:to:
-+ PlatformInterface class >>
++ Platform class >>
+  + globals
   + newXhr
 + Terminal class >>
   + alert:

+ 5 - 5
src/Compiler-Interpreter.js

@@ -3390,7 +3390,7 @@ selector: "visitVariableNode:",
 protocol: 'visiting',
 fn: function (aNode){
 var self=this;
-function $PlatformInterface(){return $globals.PlatformInterface||(typeof PlatformInterface=="undefined"?nil:PlatformInterface)}
+function $Platform(){return $globals.Platform||(typeof Platform=="undefined"?nil:Platform)}
 function $Smalltalk(){return $globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
@@ -3402,7 +3402,7 @@ $ctx1.sendIdx["binding"]=1;
 //>>excludeEnd("ctx");
 $1=$recv($2)._isUnknownVar();
 if($core.assert($1)){
-$5=$recv($PlatformInterface())._globals();
+$5=$recv($Platform())._globals();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.sendIdx["globals"]=1;
 //>>excludeEnd("ctx");
@@ -3468,7 +3468,7 @@ return $recv($16)._at_ifAbsent_($17,(function(){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx3) {
 //>>excludeEnd("ctx");
-return $recv($recv($PlatformInterface())._globals())._at_($recv(aNode)._value());
+return $recv($recv($Platform())._globals())._at_($recv(aNode)._value());
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx3) {$ctx3.fillBlock({},$ctx2,7)});
 //>>excludeEnd("ctx");
@@ -3487,8 +3487,8 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aNode"],
-source: "visitVariableNode: aNode\x0a\x09aNode binding isUnknownVar ifTrue: [\x0a\x09\x09^ self push: (PlatformInterface globals at: aNode value ifAbsent: [ self error: 'Unknown variable' ]) ].\x0a\x09\x09\x0a\x09self push: (aNode binding isInstanceVar\x0a\x09\x09ifTrue: [ self context receiver instVarAt: aNode value ]\x0a\x09\x09ifFalse: [ self context \x0a\x09\x09\x09localAt: aNode value\x0a\x09\x09\x09ifAbsent: [\x0a\x09\x09\x09\x09aNode value isCapitalized\x0a\x09\x09\x09\x09\x09ifTrue: [\x0a\x09\x09\x09\x09\x09\x09Smalltalk globals \x0a\x09\x09\x09\x09\x09\x09\x09at: aNode value \x0a\x09\x09\x09\x09\x09\x09\x09ifAbsent: [ PlatformInterface globals at: aNode value ] ] ] ])",
-referencedClasses: ["PlatformInterface", "Smalltalk"],
+source: "visitVariableNode: aNode\x0a\x09aNode binding isUnknownVar ifTrue: [\x0a\x09\x09^ self push: (Platform globals at: aNode value ifAbsent: [ self error: 'Unknown variable' ]) ].\x0a\x09\x09\x0a\x09self push: (aNode binding isInstanceVar\x0a\x09\x09ifTrue: [ self context receiver instVarAt: aNode value ]\x0a\x09\x09ifFalse: [ self context \x0a\x09\x09\x09localAt: aNode value\x0a\x09\x09\x09ifAbsent: [\x0a\x09\x09\x09\x09aNode value isCapitalized\x0a\x09\x09\x09\x09\x09ifTrue: [\x0a\x09\x09\x09\x09\x09\x09Smalltalk globals \x0a\x09\x09\x09\x09\x09\x09\x09at: aNode value \x0a\x09\x09\x09\x09\x09\x09\x09ifAbsent: [ Platform globals at: aNode value ] ] ] ])",
+referencedClasses: ["Platform", "Smalltalk"],
 //>>excludeEnd("ide");
 messageSends: ["ifTrue:", "isUnknownVar", "binding", "push:", "at:ifAbsent:", "globals", "value", "error:", "ifTrue:ifFalse:", "isInstanceVar", "instVarAt:", "receiver", "context", "localAt:ifAbsent:", "isCapitalized", "at:"]
 }),

+ 2 - 2
src/Compiler-Interpreter.st

@@ -849,7 +849,7 @@ visitValueNode: aNode
 
 visitVariableNode: aNode
 	aNode binding isUnknownVar ifTrue: [
-		^ self push: (PlatformInterface globals at: aNode value ifAbsent: [ self error: 'Unknown variable' ]) ].
+		^ self push: (Platform globals at: aNode value ifAbsent: [ self error: 'Unknown variable' ]) ].
 		
 	self push: (aNode binding isInstanceVar
 		ifTrue: [ self context receiver instVarAt: aNode value ]
@@ -860,7 +860,7 @@ visitVariableNode: aNode
 					ifTrue: [
 						Smalltalk globals 
 							at: aNode value 
-							ifAbsent: [ PlatformInterface globals at: aNode value ] ] ] ])
+							ifAbsent: [ Platform globals at: aNode value ] ] ] ])
 ! !
 
 Error subclass: #ASTInterpreterError

+ 4 - 4
src/Kernel-Infrastructure.js

@@ -2885,12 +2885,12 @@ selector: "existsJsGlobal:",
 protocol: 'testing',
 fn: function (aString){
 var self=this;
-function $PlatformInterface(){return $globals.PlatformInterface||(typeof PlatformInterface=="undefined"?nil:PlatformInterface)}
+function $Platform(){return $globals.Platform||(typeof Platform=="undefined"?nil:Platform)}
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
 var $1;
-$1=$recv($recv($PlatformInterface())._globals())._at_ifPresent_ifAbsent_(aString,(function(){
+$1=$recv($recv($Platform())._globals())._at_ifPresent_ifAbsent_(aString,(function(){
 return true;
 
 }),(function(){
@@ -2904,8 +2904,8 @@ return $1;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aString"],
-source: "existsJsGlobal: aString\x0a\x09^ PlatformInterface globals \x0a\x09\x09at: aString \x0a\x09\x09ifPresent: [ true ] \x0a\x09\x09ifAbsent: [ false ]",
-referencedClasses: ["PlatformInterface"],
+source: "existsJsGlobal: aString\x0a\x09^ Platform globals \x0a\x09\x09at: aString \x0a\x09\x09ifPresent: [ true ] \x0a\x09\x09ifAbsent: [ false ]",
+referencedClasses: ["Platform"],
 //>>excludeEnd("ide");
 messageSends: ["at:ifPresent:ifAbsent:", "globals"]
 }),

+ 1 - 1
src/Kernel-Infrastructure.st

@@ -901,7 +901,7 @@ deletePackage: packageName
 !SmalltalkImage methodsFor: 'testing'!
 
 existsJsGlobal: aString
-	^ PlatformInterface globals 
+	^ Platform globals 
 		at: aString 
 		ifPresent: [ true ] 
 		ifAbsent: [ false ]

+ 110 - 0
src/Platform-Browser.js

@@ -4,6 +4,116 @@ $core.addPackage('Platform-Browser');
 $core.packages["Platform-Browser"].innerEval = function (expr) { return eval(expr); };
 $core.packages["Platform-Browser"].transport = {"type":"amd","amdNamespace":"amber_core"};
 
+$core.addClass('BrowserPlatform', $globals.Object, [], 'Platform-Browser');
+//>>excludeStart("ide", pragmas.excludeIdeData);
+$globals.BrowserPlatform.comment="I am `Platform` service implementation for browser.";
+//>>excludeEnd("ide");
+$core.addMethod(
+$core.method({
+selector: "globals",
+protocol: 'accessing',
+fn: function (){
+var self=this;
+var $1;
+$1=window;
+return $1;
+
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "globals\x0a\x09^ window",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.BrowserPlatform);
+
+$core.addMethod(
+$core.method({
+selector: "newXhr",
+protocol: 'accessing',
+fn: function (){
+var self=this;
+function $XMLHttpRequest(){return $globals.XMLHttpRequest||(typeof XMLHttpRequest=="undefined"?nil:XMLHttpRequest)}
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $1,$receiver;
+if(($receiver = $XMLHttpRequest()) == null || $receiver.isNil){
+self._error_("XMLHttpRequest not available.");
+} else {
+$1=$recv($XMLHttpRequest())._new();
+return $1;
+};
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"newXhr",{},$globals.BrowserPlatform)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "newXhr\x0a\x09XMLHttpRequest\x0a\x09\x09ifNotNil: [ ^ XMLHttpRequest new ]\x0a\x09\x09ifNil: [ self error: 'XMLHttpRequest not available.' ]",
+referencedClasses: ["XMLHttpRequest"],
+//>>excludeEnd("ide");
+messageSends: ["ifNotNil:ifNil:", "new", "error:"]
+}),
+$globals.BrowserPlatform);
+
+
+$core.addMethod(
+$core.method({
+selector: "initialize",
+protocol: 'testing',
+fn: function (){
+var self=this;
+function $Platform(){return $globals.Platform||(typeof Platform=="undefined"?nil:Platform)}
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $1;
+$1=self._isFeasible();
+if($core.assert($1)){
+$recv($Platform())._registerIfNone_(self._new());
+};
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.BrowserPlatform.klass)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "initialize\x0a\x09self isFeasible ifTrue: [ Platform registerIfNone: self new ]",
+referencedClasses: ["Platform"],
+//>>excludeEnd("ide");
+messageSends: ["ifTrue:", "isFeasible", "registerIfNone:", "new"]
+}),
+$globals.BrowserPlatform.klass);
+
+$core.addMethod(
+$core.method({
+selector: "isFeasible",
+protocol: 'testing',
+fn: function (){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return typeof window !== "undefined";
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"isFeasible",{},$globals.BrowserPlatform.klass)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "isFeasible\x0a<return typeof window !== \x22undefined\x22>",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.BrowserPlatform.klass);
+
+
 $core.addClass('BrowserTerminal', $globals.Object, [], 'Platform-Browser');
 //>>excludeStart("ide", pragmas.excludeIdeData);
 $globals.BrowserTerminal.comment="I am `Terminal` service implementation for browser.";

+ 28 - 0
src/Platform-Browser.st

@@ -1,4 +1,32 @@
 Smalltalk createPackage: 'Platform-Browser'!
+Object subclass: #BrowserPlatform
+	instanceVariableNames: ''
+	package: 'Platform-Browser'!
+!BrowserPlatform commentStamp!
+I am `Platform` service implementation for browser.!
+
+!BrowserPlatform methodsFor: 'accessing'!
+
+globals
+	^ window
+!
+
+newXhr
+	XMLHttpRequest
+		ifNotNil: [ ^ XMLHttpRequest new ]
+		ifNil: [ self error: 'XMLHttpRequest not available.' ]
+! !
+
+!BrowserPlatform class methodsFor: 'testing'!
+
+initialize
+	self isFeasible ifTrue: [ Platform registerIfNone: self new ]
+!
+
+isFeasible
+<return typeof window !!== "undefined">
+! !
+
 Object subclass: #BrowserTerminal
 	instanceVariableNames: ''
 	package: 'Platform-Browser'!

+ 4 - 4
src/Platform-ImportExport.js

@@ -2823,12 +2823,12 @@ protocol: 'private',
 fn: function (aURL,aString,aBlock,anotherBlock){
 var self=this;
 var xhr;
-function $PlatformInterface(){return $globals.PlatformInterface||(typeof PlatformInterface=="undefined"?nil:PlatformInterface)}
+function $Platform(){return $globals.Platform||(typeof Platform=="undefined"?nil:Platform)}
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
 var $1,$4,$3,$2;
-xhr=$recv($PlatformInterface())._newXhr();
+xhr=$recv($Platform())._newXhr();
 $recv(xhr)._open_url_async_("PUT",aURL,true);
 $recv(xhr)._onreadystatechange_((function(){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
@@ -2864,8 +2864,8 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aURL", "aString", "aBlock", "anotherBlock"],
-source: "ajaxPutAt: aURL data: aString onSuccess: aBlock onError: anotherBlock\x0a\x09| xhr |\x0a\x09xhr := PlatformInterface newXhr.\x0a\x09xhr open: 'PUT' url: aURL async: true.\x0a\x09xhr onreadystatechange: [\x0a\x09\x09xhr readyState = 4 ifTrue: [\x0a\x09\x09\x09(xhr status >= 200 and: [ xhr status < 300 ])\x0a\x09\x09\x09\x09ifTrue: aBlock\x0a\x09\x09\x09\x09ifFalse: anotherBlock ]].\x0a\x09xhr send: aString",
-referencedClasses: ["PlatformInterface"],
+source: "ajaxPutAt: aURL data: aString onSuccess: aBlock onError: anotherBlock\x0a\x09| xhr |\x0a\x09xhr := Platform newXhr.\x0a\x09xhr open: 'PUT' url: aURL async: true.\x0a\x09xhr onreadystatechange: [\x0a\x09\x09xhr readyState = 4 ifTrue: [\x0a\x09\x09\x09(xhr status >= 200 and: [ xhr status < 300 ])\x0a\x09\x09\x09\x09ifTrue: aBlock\x0a\x09\x09\x09\x09ifFalse: anotherBlock ]].\x0a\x09xhr send: aString",
+referencedClasses: ["Platform"],
 //>>excludeEnd("ide");
 messageSends: ["newXhr", "open:url:async:", "onreadystatechange:", "ifTrue:", "=", "readyState", "ifTrue:ifFalse:", "and:", ">=", "status", "<", "send:"]
 }),

+ 1 - 1
src/Platform-ImportExport.st

@@ -792,7 +792,7 @@ load: aPackage
 
 ajaxPutAt: aURL data: aString onSuccess: aBlock onError: anotherBlock
 	| xhr |
-	xhr := PlatformInterface newXhr.
+	xhr := Platform newXhr.
 	xhr open: 'PUT' url: aURL async: true.
 	xhr onreadystatechange: [
 		xhr readyState = 4 ifTrue: [

+ 74 - 19
src/Platform-Services.js

@@ -1508,7 +1508,7 @@ $globals.NullProgressHandler.klass);
 
 $core.addClass('PlatformInterface', $globals.Object, [], 'Platform-Services');
 //>>excludeStart("ide", pragmas.excludeIdeData);
-$globals.PlatformInterface.comment="I am single entry point to underlying platform.\x0a\x0a## API\x0a\x0a- `PlatformInterface newXhr` returns new instance of `XMLHttpRequest`. This should be polyfilled for platforms where it does not exists, so it is always present.\x0a\x0a- `PlatformInterface globals` returns JS global object.";
+$globals.PlatformInterface.comment="Deprecated. Use `Platform` or `Terminal`.";
 //>>excludeEnd("ide");
 
 $core.addMethod(
@@ -1522,7 +1522,7 @@ function $JQuery(){return $globals.JQuery||(typeof JQuery=="undefined"?nil:JQuer
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
 var $1,$receiver;
-self._deprecatedAPI_("Use newXhr or dedicated library.");
+self._deprecatedAPI_("Use Platform newXhr or dedicated library.");
 if(($receiver = $JQuery()) == null || $receiver.isNil){
 $1=self._error_("JQuery wrapper not loaded, cannot do AJAX.");
 } else {
@@ -1535,7 +1535,7 @@ return $1;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["anObject"],
-source: "ajax: anObject\x0a\x09self deprecatedAPI: 'Use newXhr or dedicated library.'.\x0a\x09^ JQuery\x0a\x09\x09ifNotNil: [ JQuery current ajax: anObject ]\x0a\x09\x09ifNil: [ self error: 'JQuery wrapper not loaded, cannot do AJAX.' ]",
+source: "ajax: anObject\x0a\x09self deprecatedAPI: 'Use Platform newXhr or dedicated library.'.\x0a\x09^ JQuery\x0a\x09\x09ifNotNil: [ JQuery current ajax: anObject ]\x0a\x09\x09ifNil: [ self error: 'JQuery wrapper not loaded, cannot do AJAX.' ]",
 referencedClasses: ["JQuery"],
 //>>excludeEnd("ide");
 messageSends: ["deprecatedAPI:", "ifNotNil:ifNil:", "ajax:", "current", "error:"]
@@ -1635,21 +1635,24 @@ selector: "globals",
 protocol: 'accessing',
 fn: function (){
 var self=this;
+function $Platform(){return $globals.Platform||(typeof Platform=="undefined"?nil:Platform)}
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-return (new Function('return this'))();;
-return self;
+var $1;
+self._deprecatedAPI_("Use Platform globals");
+$1=$recv($Platform())._globals();
+return $1;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"globals",{},$globals.PlatformInterface.klass)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "globals\x0a\x09<return (new Function('return this'))();>",
-referencedClasses: [],
+source: "globals\x0a\x09self deprecatedAPI: 'Use Platform globals'.\x0a\x09^ Platform globals",
+referencedClasses: ["Platform"],
 //>>excludeEnd("ide");
-messageSends: []
+messageSends: ["deprecatedAPI:", "globals"]
 }),
 $globals.PlatformInterface.klass);
 
@@ -1659,28 +1662,24 @@ selector: "newXhr",
 protocol: 'actions',
 fn: function (){
 var self=this;
-function $XMLHttpRequest(){return $globals.XMLHttpRequest||(typeof XMLHttpRequest=="undefined"?nil:XMLHttpRequest)}
+function $Platform(){return $globals.Platform||(typeof Platform=="undefined"?nil:Platform)}
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1,$receiver;
-if(($receiver = $XMLHttpRequest()) == null || $receiver.isNil){
-self._error_("XMLHttpRequest not available.");
-} else {
-$1=$recv($XMLHttpRequest())._new();
+var $1;
+self._deprecatedAPI_("Use Platform newXhr");
+$1=$recv($Platform())._newXhr();
 return $1;
-};
-return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"newXhr",{},$globals.PlatformInterface.klass)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "newXhr\x0a\x09XMLHttpRequest\x0a\x09\x09ifNotNil: [ ^ XMLHttpRequest new ]\x0a\x09\x09ifNil: [ self error: 'XMLHttpRequest not available.' ]",
-referencedClasses: ["XMLHttpRequest"],
+source: "newXhr\x0a\x09self deprecatedAPI: 'Use Platform newXhr'.\x0a\x09^ Platform newXhr",
+referencedClasses: ["Platform"],
 //>>excludeEnd("ide");
-messageSends: ["ifNotNil:ifNil:", "new", "error:"]
+messageSends: ["deprecatedAPI:", "newXhr"]
 }),
 $globals.PlatformInterface.klass);
 
@@ -2010,6 +2009,62 @@ messageSends: ["inspect:", "current"]
 $globals.Inspector.klass);
 
 
+$core.addClass('Platform', $globals.Service, [], 'Platform-Services');
+//>>excludeStart("ide", pragmas.excludeIdeData);
+$globals.Platform.comment="I am bridge to JS environment.\x0a\x0a## API\x0a\x0a    Platform globals. \x22JS global object\x22\x0a    Platform newXHR \x22new XMLHttpRequest() or its shim\x22";
+//>>excludeEnd("ide");
+
+$core.addMethod(
+$core.method({
+selector: "globals",
+protocol: 'accessing',
+fn: function (){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $1;
+$1=$recv(self._current())._globals();
+return $1;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"globals",{},$globals.Platform.klass)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "globals\x0a\x09^ self current globals",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["globals", "current"]
+}),
+$globals.Platform.klass);
+
+$core.addMethod(
+$core.method({
+selector: "newXhr",
+protocol: 'accessing',
+fn: function (){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $1;
+$1=$recv(self._current())._newXhr();
+return $1;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"newXhr",{},$globals.Platform.klass)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "newXhr\x0a\x09^ self current newXhr",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["newXhr", "current"]
+}),
+$globals.Platform.klass);
+
+
 $core.addClass('ProgressHandler', $globals.Service, [], 'Platform-Services');
 //>>excludeStart("ide", pragmas.excludeIdeData);
 $globals.ProgressHandler.comment="I am used to manage progress in collection iterations, see `SequenceableCollection >> #do:displayingProgress:`.\x0a\x0aRegistered instances must implement `#do:on:displaying:`.\x0a\x0aThe default behavior is to simply iterate over the collection, using `NullProgressHandler`.";

+ 27 - 12
src/Platform-Services.st

@@ -346,24 +346,19 @@ Object subclass: #PlatformInterface
 	instanceVariableNames: ''
 	package: 'Platform-Services'!
 !PlatformInterface commentStamp!
-I am single entry point to underlying platform.
-
-## API
-
-- `PlatformInterface newXhr` returns new instance of `XMLHttpRequest`. This should be polyfilled for platforms where it does not exists, so it is always present.
-
-- `PlatformInterface globals` returns JS global object.!
+Deprecated. Use `Platform` or `Terminal`.!
 
 !PlatformInterface class methodsFor: 'accessing'!
 
 globals
-	<return (new Function('return this'))();>
+	self deprecatedAPI: 'Use Platform globals'.
+	^ Platform globals
 ! !
 
 !PlatformInterface class methodsFor: 'actions'!
 
 ajax: anObject
-	self deprecatedAPI: 'Use newXhr or dedicated library.'.
+	self deprecatedAPI: 'Use Platform newXhr or dedicated library.'.
 	^ JQuery
 		ifNotNil: [ JQuery current ajax: anObject ]
 		ifNil: [ self error: 'JQuery wrapper not loaded, cannot do AJAX.' ]
@@ -388,9 +383,8 @@ existsGlobal: aString
 !
 
 newXhr
-	XMLHttpRequest
-		ifNotNil: [ ^ XMLHttpRequest new ]
-		ifNil: [ self error: 'XMLHttpRequest not available.' ]
+	self deprecatedAPI: 'Use Platform newXhr'.
+	^ Platform newXhr
 !
 
 prompt: aString
@@ -499,6 +493,27 @@ inspect: anObject
 	^ self current inspect: anObject
 ! !
 
+Service subclass: #Platform
+	instanceVariableNames: ''
+	package: 'Platform-Services'!
+!Platform commentStamp!
+I am bridge to JS environment.
+
+## API
+
+    Platform globals. "JS global object"
+    Platform newXHR "new XMLHttpRequest() or its shim"!
+
+!Platform class methodsFor: 'accessing'!
+
+globals
+	^ self current globals
+!
+
+newXhr
+	^ self current newXhr
+! !
+
 Service subclass: #ProgressHandler
 	instanceVariableNames: ''
 	package: 'Platform-Services'!