Wraps an assumed-safe JS constant.

<p>This only accepts compile-time constants, based on the assumption that scripts that are
controlled by the application (and not user input) are considered safe.
546403
public static SanitizedContent constantJs(@CompileTimeConstant final String constant) {
    return fromConstant(constant, ContentKind.JS, Dir.LTR);
  }
884939
private static Object jsConstructor(Context cx, Scriptable scope,
                                        Object[] args)
    {
        if (args.length == 0)
            return new NativeArray(0);

        // Only use 1 arg as first element for version 1.2; for
        // any other version (including 1.3) follow ECMA and use it as
        // a length.
        if (cx.getLanguageVersion() == Context.VERSION_1_2) {
            return new NativeArray(args);
        }
        Object arg0 = args[0];
        if (args.length > 1 || !(arg0 instanceof Number)) {
            return new NativeArray(args);
        }
        long len = ScriptRuntime.toUint32(arg0);
        if (len != ((Number)arg0).doubleValue()) {
            String msg = ScriptRuntime.getMessage0("msg.arraylength.bad");
            throw ScriptRuntime.constructError("RangeError", msg);
        }
        return new NativeArray(len);
    }
289365
function (name, value) {
    if (DOMProperty.isReservedProp(name)) {
      return false;
    }
    if ((name[0] === 'o' || name[0] === 'O') && (name[1] === 'n' || name[1] === 'N')) {
      return false;
    }
    if (value === null) {
      return true;
    }
    switch (typeof value) {
      case 'boolean':
        return DOMProperty.shouldAttributeAcceptBooleanValue(name);
      case 'undefined':
      case 'number':
      case 'string':
      case 'object':
        return true;
      default:
        // function, symbol
        return false;
    }
  }
285305
private void doSubstitutions(NodeTraversal t, Config config, Node n) {
    if (n.isTaggedTemplateLit()) {
      // This is currently not supported, since tagged template literals have a different calling
      // convention than ordinary functions, so it's unclear which arguments are expected to be
      // replaced. Specifically, there are no direct string arguments, and for arbitrary tag
      // functions it's not clear that it's safe to inline any constant placeholders.
      compiler.report(JSError.make(n, STRING_REPLACEMENT_TAGGED_TEMPLATE));
      return;
    }
    checkState(n.isNew() || n.isCall());

    if (!config.isReplaceAll()) {
      // Note: the first child is the function, but the parameter id is 1 based.
      for (int parameter : config.parameters) {
        Node arg = n.getChildAtIndex(parameter);
        if (arg != null) {
          replaceExpression(t, arg, n);
        }
      }
    } else {
      // Replace all parameters.
      Node firstParam = n.getSecondChild();
      for (Node arg = firstParam; arg != null; arg = arg.getNext()) {
        arg = replaceExpression(t, arg, n);
      }
    }
  }
1209988
function renderConstants(schema, constants) {
  // Replace val with constant, if it is an {$const: <key>} schema
  let substitute = (val) => {
    // Primitives and arrays shouldn't event be considered
    if (!(val instanceof Object) || val instanceof Array) {
      return undefined;
    }

    // Check if there is a key and only one key
    let key = val.$const;
    if (key === undefined || typeof key != 'string' || _.keys(val).length != 1) {
      return undefined;
    }

    // Check that there's a constant for the key
    let constant = constants[key];
    if (constant === undefined) {
      throw new Error('Warning! Undefined constant: ' + key);
    }

    // Clone constant
    return _.cloneDeepWith(constants[key], substitute);
  };
  // Do a deep clone with substitute
  return _.cloneDeepWith(schema, substitute);
}
629883
public static CompiledScript compile(ScriptEngine engine, String script) throws ScriptException {
		if (engine instanceof Compilable) {
			Compilable compEngine = (Compilable) engine;
			return compEngine.compile(script);
		}
		return null;
	}
1266462
public static ExpectedCondition<Object> jsReturnsValue(final String javaScript) {
    return new ExpectedCondition<Object>() {
      @Override
      public Object apply(WebDriver driver) {
        try {
          Object value = ((JavascriptExecutor) driver).executeScript(javaScript);

          if (value instanceof List) {
            return ((List<?>) value).isEmpty() ? null : value;
          }
          if (value instanceof String) {
            return ((String) value).isEmpty() ? null : value;
          }

          return value;
        } catch (WebDriverException e) {
          return null;
        }
      }

      @Override
      public String toString() {
        return String.format("js %s to be executable", javaScript);
      }
    };
  }
529608
public static SanitizedContent fromSafeScriptProto(SafeScriptProto script) {
    return SanitizedContent.create(
        SafeScripts.fromProto(script).getSafeScriptString(), ContentKind.JS);
  }
333517
public SafeScript toSafeScript() {
    Preconditions.checkState(
        getContentKind() == ContentKind.JS,
        "toSafeScript() only valid for SanitizedContent of kind JS, is: %s",
        getContentKind());
    return UncheckedConversions.safeScriptFromStringKnownToSatisfyTypeContract(getContent());
  }
468118
private static void htmlEncode(final CharSequence unsafeStr, final boolean turnNewlineIntoBreak,
            final StringBuilder buf) {
        for (int i = 0, n = unsafeStr.length(); i < n; i++) {
            final char c = unsafeStr.charAt(i);
            switch (c) {
            case '&':
                buf.append("&amp;");
                break;
            case '<':
                buf.append("&lt;");
                break;
            case '>':
                buf.append("&gt;");
                break;
            case '"':
                buf.append("&quot;");
                break;
            case '\'':
                buf.append("&#x27;"); // See http://goo.gl/FzoP6m
                break;
            case '\\':
                buf.append("&lsol;");
                break;
            case '/':
                buf.append("&#x2F;"); // '/' can be a dangerous char if attr values are not quoted
                break;
            // Encode a few common characters that like to get screwed up in some charset/browser variants
            case '—':
                buf.append("&mdash;");
                break;
            case '–':
                buf.append("&ndash;");
                break;
            case '“':
                buf.append("&ldquo;");
                break;
            case '”':
                buf.append("&rdquo;");
                break;
            case '‘':
                buf.append("&lsquo;");
                break;
            case '’':
                buf.append("&rsquo;");
                break;
            case '«':
                buf.append("&laquo;");
                break;
            case '»':
                buf.append("&raquo;");
                break;
            case '£':
                buf.append("&pound;");
                break;
            case '©':
                buf.append("&copy;");
                break;
            case '®':
                buf.append("&reg;");
                break;
            case (char) 0x00A0:
                buf.append("&nbsp;");
                break;
            case '\n':
                if (turnNewlineIntoBreak) {
                    buf.append("<br>");
                } else {
                    buf.append(' '); // Newlines function as whitespace in HTML text
                }
                break;
            default:
                if (c <= 32 || isUnicodeWhitespace(c)) {
                    buf.append(' ');
                } else {
                    buf.append(c);
                }
                break;
            }
        }
    }
650654
def _inject_closure_values_fix_code(c, injected, **kwargs):
    
    # Add more closure variables
    c.freevars += injected

    # Replace LOAD_GLOBAL with LOAD_DEREF (fetch from closure cells)
    # for named variables
    for i, (opcode, value) in enumerate(c.code):
        if opcode == byteplay.LOAD_GLOBAL and value in kwargs:
            c.code[i] = byteplay.LOAD_DEREF, value

    _inject_closure_values_fix_closures(c, injected, **kwargs)

    return c
745420
public static String param(JavaScriptObject js) {
    Properties prop = js.cast();
    String ret = "";
    for (String k : prop.keys()) {
      ret += ret.isEmpty() ? "" : "&";
      JsCache o = prop.getArray(k).cast();
      if (o != null) {
        for (int i = 0, l = o.length(); i < l; i++) {
          ret += i > 0 ? "&" : "";
          Properties p = o.<JsCache> cast().getJavaScriptObject(i);
          if (p != null) {
            ret += k + "[]=" + p.toJsonString();
          } else {
            ret += k + "[]=" + o.getString(i);
          }
        }
      } else {
        Properties p = prop.getJavaScriptObject(k);
        if (p != null) {
          ret += k + "=" + p.tostring();
        } else {
          String v = prop.getStr(k);
          if (v != null && !v.isEmpty() && !"null".equalsIgnoreCase(v)) {
            ret += k + "=" + v;
          }
        }
      }
    }
    return ret;
  }
467645
public function isSafeInJS()
	{
		// List of callbacks that make a value safe to be used in a script, hardcoded for
		// convenience. Technically, there are numerous built-in PHP functions that would make an
		// arbitrary value safe in JS, but only a handful have the potential to be used as an
		// attribute filter
		$safeCallbacks = [
			'urlencode',
			'strtotime',
			'rawurlencode'
		];

		if (in_array($this->callback, $safeCallbacks, true))
		{
			return true;
		}

		return $this->isSafe('InJS');
	}
51657
function (value, node) {
        var valid = false;
        if (typeof value === (node.name === "component" ? "object" : "function"))
            valid = (_cs.annotation(value, "type") === node.name);
        return valid;
    }
609543
function ensureCodeBehind(code_behind) {
    if (typeof code_behind === 'undefined')
        throw "Missing mandatory global variable CODE_BEHIND!";

    var i, funcName;
    for (i = 1; i < arguments.length; i++) {
        funcName = arguments[i];
        if (typeof code_behind[funcName] !== 'function')
            throw "Expected CODE_BEHIND." + funcName + " to be a function!";
    }
}
218563
@Nonnull
  public JSVar var (@Nonnull @Nonempty final String sName,
                    @Nullable final String sInitValue) throws JSNameAlreadyExistsException
  {
    return var (sName, sInitValue == null ? JSExpr.NULL : JSExpr.lit (sInitValue));
  }
477597
public static Object eval(String script, ScriptContext context) throws ScriptRuntimeException {
		try {
			return compile(script).eval(context);
		} catch (ScriptException e) {
			throw new ScriptRuntimeException(e);
		}
	}