string.Const Extends
Wrapper for compile-time-constant strings. Const is a wrapper for strings that can only be created from program constants (i.e., string literals). This property relies on a custom Closure compiler check that goog.string.Const.from is only invoked on compile-time-constant expressions. Const is useful in APIs whose correct and secure use requires that certain arguments are not attacker controlled: Compile-time constants are inherently under the control of the application and not under control of external attackers, and hence are safe to use in such contexts. Instances of this type must be created via its factory method goog.string.Const.from and not by invoking its constructor. The constructor intentionally takes no parameters and the type is immutable; hence only a default instance corresponding to the empty string can be obtained via constructor invocation.

Inheritance

Constructor

goog.string.Const()

Instance Methods

Public Protected Private
getTypedStringValue()
Returns this Const's value a string. IMPORTANT: In code where it is security-relevant that an object's type is indeed goog.string.Const, use goog.string.Const.unwrap instead of this method.
code »
toString()
Returns a debug-string representation of this value. To obtain the actual string value wrapped inside an object of this type, use goog.string.Const.unwrap.
code »

Instance Properties

STRING_CONST_TYPE_MARKER__GOOG_STRING_SECURITY_PRIVATE_ :
A type marker used to implement additional run-time type checking.
Code »
implementsGoogStringTypedString :
No description.
Code »
stringConstValueWithSecurityContract__googStringSecurityPrivate_ :
The wrapped value of this Const object. The field has a purposely ugly name to make (non-compiled) code that attempts to directly access this field stand out.
Code »

Static Methods

goog.string.Const.create__googStringSecurityPrivate_(s) !goog.string.Const
Utility method to create Const instances.
Arguments:
s : string
The string to initialize the Const object with.
Returns: !goog.string.Const  The initialized Const object.
code »
goog.string.Const.from(s) !goog.string.Const
Creates a Const object from a compile-time constant string. It is illegal to invoke this function on an expression whose compile-time-contant value cannot be determined by the Closure compiler. Correct invocations include,
  var s = goog.string.Const.from('hello');
  var t = goog.string.Const.from('hello' + 'world');
In contrast, the following are illegal:
  var s = goog.string.Const.from(getHello());
  var t = goog.string.Const.from('hello' + world);
TODO(user): Compile-time checks that this function is only called with compile-time constant expressions.
Arguments:
s : string
A constant string from which to create a Const.
Returns: !goog.string.Const  A Const object initialized to stringConst.
code »
goog.string.Const.unwrap(stringConst) string
Performs a runtime check that the provided object is indeed an instance of goog.string.Const, and returns its value.
Arguments:
stringConst : !goog.string.Const
The object to extract from.
Returns: string  The Const object's contained string, unless the run-time type check fails. In that case, unwrap returns an innocuous string, or, if assertions are enabled, throws goog.asserts.AssertionError.
code »

Static Properties

goog.string.Const.TYPE_MARKER_ :
Type marker for the Const type, used to implement additional run-time type checking.
Code »

Package string

Package Reference