def toJsString(s):
    """
    This function converts a string to the Javascript literal syntax
    """

    # [MTAB-366]
    # If we have unicode entities in this attribute value we must replace
    # the corresponding unicode character with the javascript escape sequence
    result = "\""

    for c in s:
        if c=='\"':
            result += "\\\""
        elif ord(c)>=32 and ord(c)<=126:
            result += c
        else:
            result += "\\u"+("%0.4X" % ord(c))

    result += "\""
    return result