Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #22025

Re: How to feature test for window.ActiveXObject?

Message-ID <1581559.TFT1m0cKLP@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2013-11-17 00:08 +0100
Subject Re: How to feature test for window.ActiveXObject?
Newsgroups comp.lang.javascript
References <5287c664$0$9504$9b4e6d93@newsspool1.arcor-online.net>

Show all headers | View raw


Christoph Michael Becker wrote:

> In IE11

Fascinating.

> (JScript 11.0? -- I was not able to find out the exact version)

Relevant JScript versions for which results have been submitted to the 
ECMAScript Support Matrix are so far

- Version 11.0.16412 in "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0;
  Touch; rv:11.0) like Gecko"

  (presumably, Internet Explorer 11 on a smartphone or tablet, as indicated
  by “Touch”)

- Version 11.0.16428 in
  "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"

  (presumably, Internet Explorer 11 on a PC without a touchscreen)

You can use (much like I did)

  ScriptEngine() + " " + [
    ScriptEngineMajorVersion(),
    ScriptEngineMinorVersion(),
    ScriptEngineBuildVersion()
  ].join(".")

See also <http://PointedEars.de/es-matrix#footnote-this-impl>, and the 
corresponding test cases.

> the following is true[1]:
> 
>   typeof window.ActiveXObject == "undefined"

You should not presume that “ActiveXObject” is a property of the object 
referred to by “window”.  In general, “window” should not be used for a 
reference to the ECMAScript Global Object (use “this” in the global 
execution context instead).  Test for exactly that which you are using 
later.  If you want to call “new ActiveXObject” later, test for 
“ActiveXObject”, not “window.ActiveXObject”.

That said, is “new ActiveXObject(…)” or “new window.ActiveXObject(…)” 
supported then?  If not, everything works as designed.  “ActiveXObject” is a 
very old feature which repeatedly introduced security leaks in MSHTML-based 
applications and Windows; I would not be surprised if it was finally removed 
from the JScript language as a result.  For example, “file:” URIs aside, you 
do not need “ActiveXObject” for XHR in recent JScript versions; use “new 
XMLHttpRequest()” instead (like almost everywhere else).
 
> This causes isHostMethod()[2] to fail.

AFAICS (I have just tested this positive in IE 6.0.2800.1106 on Wine XP 
which can create, for example, "Microsoft.XMLHTTP" objects), “ActiveXObject” 
always referred to a *native* method, and yielded "function" (not "unknown") 
as result of a “typeof“ operation.  AFAIK it is a built-in JScript feature 
even though it creates only host objects, and is therefore tested with the 
ES Matrix.

> Is there a reliable solution to detect if the window object has an
> ActiveXObject method, without actually /try/ing to instantiate a new
> ActiveXObject?

Depends.  try…catch at least is the only reliable way to determine whether a 
host object of a certain class (sic!; as in CLSID) can be successfully 
created when “ActiveXObject” is called as a constructor where try…catch is 
supported (that would apply to these versions of JScript).
 
> [1] <http://msdn.microsoft.com/en-us/library/ff955298(v=vs.85).aspx>
> [2]
> <http://michaux.ca/articles/feature-detection-state-of-the-art-browser-scripting>

There are three versions of isHostMethod() there – which one have you used? 
JSX:object.js has another one.  However, following my argument above, Peter 
Michaux’s argument is flawed and none of those methods should be used on 
“ActiveXObject”.

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to feature test for window.ActiveXObject? Christoph Michael Becker <cmbecker69@arcor.de> - 2013-11-16 20:24 +0100
  Re: How to feature test for window.ActiveXObject? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-17 00:08 +0100
    Re: How to feature test for window.ActiveXObject? Christoph Michael Becker <cmbecker69@arcor.de> - 2013-11-18 13:25 +0100
      Re: How to feature test for window.ActiveXObject? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-18 18:52 +0100
        Re: How to feature test for window.ActiveXObject? Christoph Michael Becker <cmbecker69@arcor.de> - 2013-11-21 23:44 +0100
          Re: How to feature test for window.ActiveXObject? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-22 00:32 +0100
      Re: How to feature test for window.ActiveXObject? Martin Honnen <mahotrash@yahoo.de> - 2013-11-18 19:29 +0100
        Re: How to feature test for window.ActiveXObject? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-18 19:35 +0100
    Re: How to feature test for window.ActiveXObject? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-11-21 19:13 -0800
      Re: How to feature test for window.ActiveXObject? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-22 11:56 +0100
        Re: How to feature test for window.ActiveXObject? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-11-22 06:33 -0800
          Re: How to feature test for window.ActiveXObject? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-22 15:51 +0100
            Re: How to feature test for window.ActiveXObject? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-11-22 07:44 -0800
  Re: How to feature test for window.ActiveXObject? JJ <duh@nah.meh> - 2013-11-17 07:27 +0700
    Re: How to feature test for window.ActiveXObject? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-11-21 18:38 -0800

csiph-web