OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview This file defines a singleton which provides access to all data | 6 * @fileoverview This file defines a singleton which provides access to all data |
7 * that is available as soon as the page's resources are loaded (before DOM | 7 * that is available as soon as the page's resources are loaded (before DOM |
8 * content has finished loading). This data includes both localized strings and | 8 * content has finished loading). This data includes both localized strings and |
9 * any data that is important to have ready from a very early stage (e.g. things | 9 * any data that is important to have ready from a very early stage (e.g. things |
10 * that must be displayed right away). | 10 * that must be displayed right away). |
11 */ | 11 */ |
12 | 12 |
13 var loadTimeData; | 13 var loadTimeData; |
14 | 14 |
15 // Expose this type globally as a temporary work around until | 15 // Expose this type globally as a temporary work around until |
16 // https://github.com/google/closure-compiler/issues/544 is fixed. | 16 // https://github.com/google/closure-compiler/issues/544 is fixed. |
17 /** @constructor */ | 17 /** @constructor */ |
18 function LoadTimeData() {} | 18 function LoadTimeData() {} |
19 | 19 |
20 (function() { | 20 (function() { |
21 'use strict'; | 21 'use strict'; |
22 | 22 |
23 LoadTimeData.prototype = { | 23 LoadTimeData.prototype = { |
24 /** | 24 /** |
25 * Sets the backing object. | 25 * Sets the backing object. |
26 * | |
27 * Note that there is no getter for |data_| to discourage abuse of the form: | |
28 * | |
29 * var value = loadTimeData.data()['key']; | |
30 * | |
26 * @param {Object} value The de-serialized page data. | 31 * @param {Object} value The de-serialized page data. |
27 */ | 32 */ |
28 set data(value) { | 33 set data(value) { |
29 expect(!this.data_, 'Re-setting data.'); | 34 expect(!this.data_, 'Re-setting data.'); |
30 this.data_ = value; | 35 this.data_ = value; |
31 }, | 36 }, |
32 | 37 |
33 /** | 38 /** |
39 * Returns a JsEvalContext for |data_|. | |
Dan Beam
2014/09/23 05:30:39
@returns {JsEvalContext}
Evan Stade
2014/09/23 17:35:07
Done.
| |
40 */ | |
41 getJsEvalContext: function() { | |
Dan Beam
2014/09/23 05:30:39
nit: createJsEvalContext
Evan Stade
2014/09/23 17:35:07
Done.
| |
42 return new JsEvalContext(this.data_); | |
43 }, | |
44 | |
45 /** | |
34 * @param {string} id An ID of a value that might exist. | 46 * @param {string} id An ID of a value that might exist. |
35 * @return {boolean} True if |id| is a key in the dictionary. | 47 * @return {boolean} True if |id| is a key in the dictionary. |
36 */ | 48 */ |
37 valueExists: function(id) { | 49 valueExists: function(id) { |
38 return id in this.data_; | 50 return id in this.data_; |
39 }, | 51 }, |
40 | 52 |
41 /** | 53 /** |
42 * Fetches a value, expecting that it exists. | 54 * Fetches a value, expecting that it exists. |
43 * @param {string} id The key that identifies the desired value. | 55 * @param {string} id The key that identifies the desired value. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 * @param {string} type The type we expect |value| to be. | 147 * @param {string} type The type we expect |value| to be. |
136 */ | 148 */ |
137 function expectIsType(id, value, type) { | 149 function expectIsType(id, value, type) { |
138 expect(typeof value == type, '[' + value + '] (' + id + | 150 expect(typeof value == type, '[' + value + '] (' + id + |
139 ') is not a ' + type); | 151 ') is not a ' + type); |
140 } | 152 } |
141 | 153 |
142 expect(!loadTimeData, 'should only include this file once'); | 154 expect(!loadTimeData, 'should only include this file once'); |
143 loadTimeData = new LoadTimeData; | 155 loadTimeData = new LoadTimeData; |
144 })(); | 156 })(); |
OLD | NEW |