| Index: ui/webui/resources/js/cr.js
|
| diff --git a/ui/webui/resources/js/cr.js b/ui/webui/resources/js/cr.js
|
| index 7fadc2aaf54f6a5cd3191afa24039ada5a96add8..dbcbb828a5621ad664f3b685529cd16774b5ee8f 100644
|
| --- a/ui/webui/resources/js/cr.js
|
| +++ b/ui/webui/resources/js/cr.js
|
| @@ -10,7 +10,7 @@
|
| var global = this;
|
|
|
| /** Platform, package, object property, and Event support. **/
|
| -this.cr = (function() {
|
| +var cr = function() {
|
| 'use strict';
|
|
|
| /**
|
| @@ -68,7 +68,7 @@ this.cr = (function() {
|
|
|
| /**
|
| * The kind of property to define in {@code defineProperty}.
|
| - * @enum {number}
|
| + * @enum {string}
|
| * @const
|
| */
|
| var PropertyKind = {
|
| @@ -94,7 +94,7 @@ this.cr = (function() {
|
| * Helper function for defineProperty that returns the getter to use for the
|
| * property.
|
| * @param {string} name The name of the property.
|
| - * @param {cr.PropertyKind} kind The kind of the property.
|
| + * @param {PropertyKind} kind The kind of the property.
|
| * @return {function():*} The getter for the property.
|
| */
|
| function getGetter(name, kind) {
|
| @@ -115,6 +115,10 @@ this.cr = (function() {
|
| return this.hasAttribute(attributeName);
|
| };
|
| }
|
| +
|
| + // TODO(dbeam): replace with assertNotReached() in assert.js when I can coax
|
| + // the browser/unit tests to preprocess this file through grit.
|
| + throw 'not reached';
|
| }
|
|
|
| /**
|
| @@ -122,10 +126,10 @@ this.cr = (function() {
|
| * kind.
|
| * @param {string} name The name of the property we are defining the setter
|
| * for.
|
| - * @param {cr.PropertyKind} kind The kind of property we are getting the
|
| + * @param {PropertyKind} kind The kind of property we are getting the
|
| * setter for.
|
| - * @param {function(*):void} opt_setHook A function to run after the property
|
| - * is set, but before the propertyChange event is fired.
|
| + * @param {function(*, *):void=} opt_setHook A function to run after the
|
| + * property is set, but before the propertyChange event is fired.
|
| * @return {function(*):void} The function to use as a setter.
|
| */
|
| function getSetter(name, kind, opt_setHook) {
|
| @@ -172,6 +176,10 @@ this.cr = (function() {
|
| }
|
| };
|
| }
|
| +
|
| + // TODO(dbeam): replace with assertNotReached() in assert.js when I can coax
|
| + // the browser/unit tests to preprocess this file through grit.
|
| + throw 'not reached';
|
| }
|
|
|
| /**
|
| @@ -179,15 +187,15 @@ this.cr = (function() {
|
| * property change event with the type {@code name + 'Change'} is fired.
|
| * @param {!Object} obj The object to define the property for.
|
| * @param {string} name The name of the property.
|
| - * @param {cr.PropertyKind=} opt_kind What kind of underlying storage to use.
|
| - * @param {function(*):void} opt_setHook A function to run after the
|
| + * @param {PropertyKind=} opt_kind What kind of underlying storage to use.
|
| + * @param {function(*, *):void=} opt_setHook A function to run after the
|
| * property is set, but before the propertyChange event is fired.
|
| */
|
| function defineProperty(obj, name, opt_kind, opt_setHook) {
|
| if (typeof obj == 'function')
|
| obj = obj.prototype;
|
|
|
| - var kind = opt_kind || PropertyKind.JS;
|
| + var kind = /** @type {PropertyKind} */ (opt_kind || PropertyKind.JS);
|
|
|
| if (!obj.__lookupGetter__(name))
|
| obj.__defineGetter__(name, getGetter(name, kind));
|
| @@ -283,56 +291,6 @@ this.cr = (function() {
|
| };
|
| }
|
|
|
| - /**
|
| - * Initialization which must be deferred until run-time.
|
| - */
|
| - function initialize() {
|
| - // If 'document' isn't defined, then we must be being pre-compiled,
|
| - // so set a trap so that we're initialized on first access at run-time.
|
| - if (!global.document) {
|
| - var originalCr = cr;
|
| -
|
| - Object.defineProperty(global, 'cr', {
|
| - get: function() {
|
| - Object.defineProperty(global, 'cr', {value: originalCr});
|
| - originalCr.initialize();
|
| - return originalCr;
|
| - },
|
| - configurable: true
|
| - });
|
| -
|
| - return;
|
| - }
|
| -
|
| - cr.doc = document;
|
| -
|
| - /**
|
| - * Whether we are using a Mac or not.
|
| - */
|
| - cr.isMac = /Mac/.test(navigator.platform);
|
| -
|
| - /**
|
| - * Whether this is on the Windows platform or not.
|
| - */
|
| - cr.isWindows = /Win/.test(navigator.platform);
|
| -
|
| - /**
|
| - * Whether this is on chromeOS or not.
|
| - */
|
| - cr.isChromeOS = /CrOS/.test(navigator.userAgent);
|
| -
|
| - /**
|
| - * Whether this is on vanilla Linux (not chromeOS).
|
| - */
|
| - cr.isLinux = /Linux/.test(navigator.userAgent);
|
| -
|
| - /**
|
| - * Whether this uses the views toolkit or not.
|
| - */
|
| - cr.isViews = typeof chrome.getVariableValue == 'function' &&
|
| - /views/.test(chrome.getVariableValue('toolkit'));
|
| - }
|
| -
|
| return {
|
| addSingletonGetter: addSingletonGetter,
|
| createUid: createUid,
|
| @@ -341,14 +299,36 @@ this.cr = (function() {
|
| dispatchPropertyChange: dispatchPropertyChange,
|
| dispatchSimpleEvent: dispatchSimpleEvent,
|
| getUid: getUid,
|
| - initialize: initialize,
|
| - PropertyKind: PropertyKind
|
| + PropertyKind: PropertyKind,
|
| +
|
| + get doc() {
|
| + return document;
|
| + },
|
| +
|
| + /** Whether we are using a Mac or not. */
|
| + get isMac() {
|
| + return /Mac/.test(navigator.platform);
|
| + },
|
| +
|
| + /** Whether this is on the Windows platform or not. */
|
| + get isWindows() {
|
| + return /Win/.test(navigator.platform);
|
| + },
|
| +
|
| + /** Whether this is on chromeOS or not. */
|
| + get isChromeOS() {
|
| + return /CrOS/.test(navigator.userAgent);
|
| + },
|
| +
|
| + /** Whether this is on vanilla Linux (not chromeOS). */
|
| + get isLinux() {
|
| + return /Linux/.test(navigator.userAgent);
|
| + },
|
| +
|
| + /** Whether this uses the views toolkit or not. */
|
| + get isViews() {
|
| + return typeof chrome.getVariableValue == 'function' &&
|
| + /views/.test(chrome.getVariableValue('toolkit'));
|
| + },
|
| };
|
| -})();
|
| -
|
| -
|
| -/**
|
| - * TODO(kgr): Move this to another file which is to be loaded last.
|
| - * This will be done as part of future work to make this code pre-compilable.
|
| - */
|
| -cr.initialize();
|
| +}();
|
|
|