Ver Fonte

Answer a new Environment where there is no DOM.

HLModel >> environment falls back to HLManager >> defaultEnvironment,
which looked for a parent window through window opener and window
parent. Outside the browser there is no window, so it threw a
ReferenceError instead of answering the Environment new it answers for
a window without a parent; under Node, the HLSUnitModelTest cases that
ask the model for its test packages errored on it.

PlatformDom isFeasible is how contrib-web's HTMLSnippet class tells the
browser apart, too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Herby Vojčík há 1 dia atrás
pai
commit
e125398452
2 ficheiros alterados com 13 adições e 5 exclusões
  1. 12 5
      src/Helios-Core.js
  2. 1 0
      src/Helios-Core.st

+ 12 - 5
src/Helios-Core.js

@@ -5195,11 +5195,11 @@ selector: "defaultEnvironment",
 protocol: "defaults",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "defaultEnvironment\x0a\x09\x22If helios is loaded from within a frame, answer the parent window environment\x22\x0a\x09\x0a\x09| parent parentSmalltalkGlobals |\x0a\x09\x0a\x09parent := window opener ifNil: [ window parent ].\x0a\x09parent ifNil: [ ^ Environment new ].\x0a\x09\x0a\x09parentSmalltalkGlobals := ((parent at: 'requirejs') value: 'amber/boot') at: 'globals'.\x0a\x09parentSmalltalkGlobals ifNil: [ ^ Environment new ].\x0a\x09\x0a\x09self handleLossOfEnvironmentWithParent: parent.\x0a\x09\x0a\x09^ (parentSmalltalkGlobals at: 'Environment') new",
-referencedClasses: ["Environment"],
+source: "defaultEnvironment\x0a\x09\x22If helios is loaded from within a frame, answer the parent window environment\x22\x0a\x09\x0a\x09| parent parentSmalltalkGlobals |\x0a\x09\x0a\x09PlatformDom isFeasible ifFalse: [ ^ Environment new ].\x0a\x09parent := window opener ifNil: [ window parent ].\x0a\x09parent ifNil: [ ^ Environment new ].\x0a\x09\x0a\x09parentSmalltalkGlobals := ((parent at: 'requirejs') value: 'amber/boot') at: 'globals'.\x0a\x09parentSmalltalkGlobals ifNil: [ ^ Environment new ].\x0a\x09\x0a\x09self handleLossOfEnvironmentWithParent: parent.\x0a\x09\x0a\x09^ (parentSmalltalkGlobals at: 'Environment') new",
+referencedClasses: ["PlatformDom", "Environment"],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["ifNil:", "opener", "parent", "new", "at:", "value:", "handleLossOfEnvironmentWithParent:"]
+messageSends: ["ifFalse:", "isFeasible", "new", "ifNil:", "opener", "parent", "at:", "value:", "handleLossOfEnvironmentWithParent:"]
 }, function ($methodClass){ return function (){
 var self=this,$self=this;
 var parent,parentSmalltalkGlobals;
@@ -5207,6 +5207,13 @@ var parent,parentSmalltalkGlobals;
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
 var $1,$2,$3;
+if(!$core.assert($recv($globals.PlatformDom)._isFeasible())){
+return [$recv($globals.Environment)._new()
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["new"]=1
+//>>excludeEnd("ctx");
+][0];
+}
 $1=$recv(window)._opener();
 if($1 == null || $1.a$nil){
 parent=$recv(window)._parent();
@@ -5217,7 +5224,7 @@ $2=parent;
 if($2 == null || $2.a$nil){
 return [$recv($globals.Environment)._new()
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-,$ctx1.sendIdx["new"]=1
+,$ctx1.sendIdx["new"]=2
 //>>excludeEnd("ctx");
 ][0];
 } else {
@@ -5236,7 +5243,7 @@ $3=parentSmalltalkGlobals;
 if($3 == null || $3.a$nil){
 return [$recv($globals.Environment)._new()
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-,$ctx1.sendIdx["new"]=2
+,$ctx1.sendIdx["new"]=3
 //>>excludeEnd("ctx");
 ][0];
 } else {

+ 1 - 0
src/Helios-Core.st

@@ -1329,6 +1329,7 @@ defaultEnvironment
 	
 	| parent parentSmalltalkGlobals |
 	
+	PlatformDom isFeasible ifFalse: [ ^ Environment new ].
 	parent := window opener ifNil: [ window parent ].
 	parent ifNil: [ ^ Environment new ].