فهرست منبع

[js] Enable js.Browser to work with WebWorkers (#9167)

* [js] add js.Browser.self, closes #4435

* change self type to common root: WorkerGlobalScope

* [js] add type-hint for get_self

* [js] Switch from untyped to js.Syntax.code

* Use js.Lib.global in place of self to avoid possible local var conflict

* Replace usage of window with js.Lib.global where API is available in a worker context

* Correct comment
George Corney 5 سال پیش
والد
کامیت
bed92f594a
1فایلهای تغییر یافته به همراه10 افزوده شده و 3 حذف شده
  1. 10 3
      std/js/Browser.hx

+ 10 - 3
std/js/Browser.hx

@@ -26,6 +26,13 @@ import js.html.Storage;
 import js.html.XMLHttpRequest;
 import js.html.XMLHttpRequest;
 
 
 class Browser {
 class Browser {
+	/** The global scope typed with fields available only in a worker context. */
+	public static var self(get, never):js.html.WorkerGlobalScope;
+
+	static inline function get_self():js.html.WorkerGlobalScope {
+		return js.Lib.global;
+	}
+
 	/** The global window object. */
 	/** The global window object. */
 	public static var window(get, never):js.html.Window;
 	public static var window(get, never):js.html.Window;
 
 
@@ -42,19 +49,19 @@ class Browser {
 	public static var location(get, never):js.html.Location;
 	public static var location(get, never):js.html.Location;
 
 
 	extern inline static function get_location()
 	extern inline static function get_location()
-		return window.location;
+		return js.Lib.global.location;
 
 
 	/** Shortcut to Window.navigator. */
 	/** Shortcut to Window.navigator. */
 	public static var navigator(get, never):js.html.Navigator;
 	public static var navigator(get, never):js.html.Navigator;
 
 
 	extern inline static function get_navigator()
 	extern inline static function get_navigator()
-		return window.navigator;
+		return js.Lib.global.navigator;
 
 
 	/** Shortcut to Window.console. */
 	/** Shortcut to Window.console. */
 	public static var console(get, never):js.html.ConsoleInstance;
 	public static var console(get, never):js.html.ConsoleInstance;
 
 
 	extern inline static function get_console()
 	extern inline static function get_console()
-		return window.console;
+		return js.Lib.global.console;
 
 
 	/**
 	/**
 	 * True if a window object exists, false otherwise.
 	 * True if a window object exists, false otherwise.