Skip to content

Commit

Permalink
shell.js: Handle if location object does not exist
Browse files Browse the repository at this point in the history
When compiling with the options introduced in [this comment](#13190 (comment)), the `ENVIRONMENT_IS_WORKER` value is set to `true`.
In Deno, the value of `self.location` is `undefined` when the `deno run` command is executed without the `--location` CLI argument.
In the scenario of creating the Deno library, it is difficult to tell the library user to input the `--location` CLI argument, so I modified it to handle fallback at this level.
  • Loading branch information
disjukr committed Jun 28, 2022
1 parent ae675c6 commit 66e32a7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ var _scriptDir = import.meta.url;
var _scriptDir = (typeof document != 'undefined' && document.currentScript) ? document.currentScript.src : undefined;

if (ENVIRONMENT_IS_WORKER) {
_scriptDir = self.location.href;
_scriptDir = self.location == null ? '' : self.location.href;
}
#if ENVIRONMENT_MAY_BE_NODE
else if (ENVIRONMENT_IS_NODE) {
Expand Down Expand Up @@ -362,7 +362,7 @@ if (ENVIRONMENT_IS_SHELL) {
#if ENVIRONMENT_MAY_BE_WEB || ENVIRONMENT_MAY_BE_WORKER
if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
if (ENVIRONMENT_IS_WORKER) { // Check worker, not web, since window could be polyfilled
scriptDirectory = self.location.href;
scriptDirectory = self.location == null ? '' : self.location.href;
} else if (typeof document != 'undefined' && document.currentScript) { // web
scriptDirectory = document.currentScript.src;
}
Expand Down

0 comments on commit 66e32a7

Please sign in to comment.