瀏覽代碼

Don't check for undefined window in js.Browser (browsers have windows)

David Peek 12 年之前
父節點
當前提交
83a8e2cc81
共有 2 個文件被更改,包括 11 次插入5 次删除
  1. 1 1
      genjs.ml
  2. 10 4
      std/js/Browser.hx

+ 1 - 1
genjs.ml

@@ -79,7 +79,7 @@ let kwds =
 		"finally"; "float"; "for"; "function"; "goto"; "if"; "implements"; "import"; "in"; "instanceof"; "int";
 		"interface"; "is"; "long"; "namespace"; "native"; "new"; "null"; "package"; "private"; "protected";
 		"public"; "return"; "short"; "static"; "super"; "switch"; "synchronized"; "this"; "throw"; "throws";
-		"transient"; "true"; "try"; "typeof"; "use"; "var"; "void"; "volatile"; "while"; "with"
+		"transient"; "true"; "try"; "typeof"; "use"; "var"; "void"; "volatile"; "while"; "window"; "with";
 	];
 	h
 

+ 10 - 4
std/js/Browser.hx

@@ -25,12 +25,18 @@ import js.html.Storage;
 import js.html.XMLHttpRequest;
 
 class Browser {
+	public static var window(get, never):js.html.DOMWindow;
+	inline static function get_window() return untyped __js__("window");
 
-	public static var window(default,null) : js.html.DOMWindow = untyped __js__("typeof window != \"undefined\" ? window : null");
-	public static var document(default,null) : js.html.Document = untyped __js__("typeof window != \"undefined\" ? window.document : null");
-	public static var location(default,null) : js.html.Location = untyped __js__("typeof window != \"undefined\" ? window.location : null");
-	public static var navigator(default,null) : js.html.Navigator = untyped __js__("typeof window != \"undefined\" ? window.navigator : null");
+	public static var document(get, never):js.html.Document;
+	inline static function get_document() return untyped __js__("window.document");
 
+	public static var location(get, never):js.html.Location;
+	inline static function get_location() return untyped __js__("window.location");
+
+	public static var navigator(get, never):js.html.Navigator;
+	inline static function get_navigator() return untyped __js__("window.navigator");
+	
 	/**
 	 * Safely gets the browser's local storage, or returns null if localStorage is unsupported or
 	 * disabled.