# lib/goog/reflect/reflect.js

    1// Copyright 2009 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 at6//7//      http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// 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 and13// limitations under the License.1415/**16 * @fileoverview Useful compiler idioms.17 *18 */1920goog.provide('goog.reflect');212223/**24 * Syntax for object literal casts.25 * @see http://go/jscompiler-renaming26 * @see http://code.google.com/p/closure-compiler/wiki/27 *      ExperimentalTypeBasedPropertyRenaming28 *29 * Use this if you have an object literal whose keys need to have the same names30 * as the properties of some class even after they are renamed by the compiler.31 *32 * @param {!Function} type Type to cast to.33 * @param {Object} object Object literal to cast.34 * @return {Object} The object literal.35 */36goog.reflect.object = function(type, object) {37  return object;38};394041/**42 * To assert to the compiler that an operation is needed when it would43 * otherwise be stripped. For example:44 * <code>45 *     // Force a layout46 *     goog.reflect.sinkValue(dialog.offsetHeight);47 * </code>48 * @type {!Function}49 */50goog.reflect.sinkValue = function(x) {51  goog.reflect.sinkValue[' '](x);52  return x;53};545556/**57 * The compiler should optimize this function away iff no one ever uses58 * goog.reflect.sinkValue.59 */60goog.reflect.sinkValue[' '] = goog.nullFunction;616263/**64 * Check if a property can be accessed without throwing an exception.65 * @param {Object} obj The owner of the property.66 * @param {string} prop The property name.67 * @return {boolean} Whether the property is accessible. Will also return true68 *     if obj is null.69 */70goog.reflect.canAccessProperty = function(obj, prop) {71  /** @preserveTry */72  try {73    goog.reflect.sinkValue(obj[prop]);74    return true;75  } catch (e) {}76  return false;77};