| 1 |
// Copyright 2007 The Closure Library Authors. All Rights Reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS-IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
/** |
| 16 |
* @fileoverview Detection of JScript version. |
| 17 |
* |
| 18 |
* @author [email protected] (Erik Arvidsson) |
| 19 |
*/ |
| 20 |
|
| 21 |
|
| 22 |
goog.provide('goog.userAgent.jscript'); |
| 23 |
|
| 24 |
goog.require('goog.string'); |
| 25 |
|
| 26 |
|
| 27 |
/** |
| 28 |
* @define {boolean} True if it is known at compile time that the runtime |
| 29 |
* environment will not be using JScript. |
| 30 |
*/ |
| 31 |
goog.define('goog.userAgent.jscript.ASSUME_NO_JSCRIPT', false); |
| 32 |
|
| 33 |
|
| 34 |
/** |
| 35 |
* Whether we detect that the user agent is using Microsoft JScript. |
| 36 |
* @type {boolean} |
| 37 |
*/ |
| 38 |
goog.userAgent.jscript.HAS_JSCRIPT = false; |
| 39 |
|
| 40 |
|
| 41 |
/** |
| 42 |
* The installed version of JScript. |
| 43 |
* @type {string} |
| 44 |
*/ |
| 45 |
goog.userAgent.jscript.VERSION = '0'; |
| 46 |
|
| 47 |
|
| 48 |
/** |
| 49 |
* Initializer for goog.userAgent.jscript. Detects if the user agent is using |
| 50 |
* Microsoft JScript and which version of it. |
| 51 |
* |
| 52 |
* This is a named function so that it can be stripped via the jscompiler |
| 53 |
* option for stripping types. |
| 54 |
* @package |
| 55 |
*/ |
| 56 |
goog.userAgent.jscript.init = function() { |
| 57 |
var hasScriptEngine = 'ScriptEngine' in goog.global; |
| 58 |
goog.userAgent.jscript.HAS_JSCRIPT = |
| 59 |
hasScriptEngine && goog.global['ScriptEngine']() == 'JScript'; |
| 60 |
if (goog.userAgent.jscript.HAS_JSCRIPT) { |
| 61 |
goog.userAgent.jscript.VERSION = goog.global['ScriptEngineMajorVersion']() + |
| 62 |
'.' + goog.global['ScriptEngineMinorVersion']() + '.' + |
| 63 |
goog.global['ScriptEngineBuildVersion'](); |
| 64 |
} |
| 65 |
}; |
| 66 |
|
| 67 |
if (!goog.userAgent.jscript.ASSUME_NO_JSCRIPT) { |
| 68 |
goog.userAgent.jscript.init(); |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Whether the installed version of JScript is as new or newer than a given |
| 73 |
* version. |
| 74 |
* @param {string} version The version to check. |
| 75 |
* @return {boolean} Whether the installed version of JScript is as new or |
| 76 |
* newer than the given version. |
| 77 |
*/ |
| 78 |
goog.userAgent.jscript.isVersion = function(version) { |
| 79 |
return goog.string.compareVersions(goog.userAgent.jscript.VERSION, version) >= |
| 80 |
0; |
| 81 |
}; |