| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 Implementation of ScreenContext class: key-value storage for | 6 * @fileoverview Implementation of ScreenContext class: key-value storage for |
| 7 * values that are shared between C++ and JS sides. | 7 * values that are shared between C++ and JS sides. |
| 8 */ | 8 */ |
| 9 cr.define('login', function() { | 9 cr.define('login', function() { |
| 10 'use strict'; | 10 'use strict'; |
| 11 | 11 |
| 12 function require(condition, message) { | 12 function require(condition, message) { |
| 13 if (!condition) { | 13 if (!condition) { |
| 14 throw Error(message); | 14 throw Error(message); |
| 15 } | 15 } |
| 16 } | 16 } |
| 17 | 17 |
| 18 function checkKeyIsValid(key) { | 18 function checkKeyIsValid(key) { |
| 19 var keyType = typeof key; | 19 var keyType = typeof key; |
| 20 require(keyType === 'string', 'Invalid type of key: "' + keyType + '".'); | 20 require(keyType === 'string', 'Invalid type of key: "' + keyType + '".'); |
| 21 } | 21 } |
| 22 | 22 |
| 23 function checkValueIsValid(value) { | 23 function checkValueIsValid(value) { |
| 24 var valueType = typeof value; | 24 var valueType = typeof value; |
| 25 require((['string', 'boolean', 'number'].indexOf(valueType) != -1 || | 25 require( |
| 26 Array.isArray(value)), | 26 (['string', 'boolean', 'number'].indexOf(valueType) != -1 || |
| 27 'Invalid type of value: "' + valueType + '".'); | 27 Array.isArray(value)), |
| 28 'Invalid type of value: "' + valueType + '".'); |
| 28 } | 29 } |
| 29 | 30 |
| 30 function ScreenContext() { | 31 function ScreenContext() { |
| 31 this.storage_ = {}; | 32 this.storage_ = {}; |
| 32 this.changes_ = {}; | 33 this.changes_ = {}; |
| 33 this.observers_ = {}; | 34 this.observers_ = {}; |
| 34 } | 35 } |
| 35 | 36 |
| 36 ScreenContext.prototype = { | 37 ScreenContext.prototype = { |
| 37 /** | 38 /** |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 * @private | 128 * @private |
| 128 */ | 129 */ |
| 129 cloneObservers_: function() { | 130 cloneObservers_: function() { |
| 130 var result = {}; | 131 var result = {}; |
| 131 for (var key in this.observers_) | 132 for (var key in this.observers_) |
| 132 result[key] = this.observers_[key].slice(); | 133 result[key] = this.observers_[key].slice(); |
| 133 return result; | 134 return result; |
| 134 } | 135 } |
| 135 }; | 136 }; |
| 136 | 137 |
| 137 return { | 138 return {ScreenContext: ScreenContext}; |
| 138 ScreenContext: ScreenContext | |
| 139 }; | |
| 140 }); | 139 }); |
| OLD | NEW |