/* | |
* Copyright 2010 Google Inc. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
* use this file except in compliance with the License. You may obtain a copy of | |
* the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |
* License for the specific language governing permissions and limitations under | |
* the License. | |
*/ | |
// Deferred-binding mapper function. Sets a value into the several-level-deep | |
// answers map. The keys are specified by a non-zero-length propValArray, | |
// which should be a flat array target property values. Used by the generated | |
// PERMUTATIONS code. | |
// | |
function unflattenKeylistIntoAnswers(propValArray, value) { | |
var answer = answers; | |
for (var i = 0, n = propValArray.length - 1; i < n; ++i) { | |
// lazy initialize an empty object for the current key if needed | |
answer = answer[propValArray[i]] || (answer[propValArray[i]] = []); | |
} | |
// set the final one to the value | |
answer[propValArray[n]] = value; | |
} | |
// Computes the value of a given property. propName must be a valid property | |
// name. Used by the generated PERMUTATIONS code. | |
// | |
function computePropValue(propName) { | |
var value = providers[propName](), allowedValuesMap = values[propName]; | |
if (value in allowedValuesMap) { | |
return value; | |
} | |
var allowedValuesList = []; | |
for (var k in allowedValuesMap) { | |
allowedValuesList[allowedValuesMap[k]] = k; | |
} | |
if (propertyErrorFunc) { | |
propertyErrorFunc(propName, allowedValuesList, value); | |
} | |
throw null; | |
} |