string-html.tq 4.6 KB
Newer Older
1 2 3 4 5 6 7 8
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

namespace string_html {
  extern runtime StringEscapeQuotes(Context, String): String;

  // https://tc39.github.io/ecma262/#sec-createhtml
9
  transitioning builtin CreateHTML(implicit context: Context)(
10 11 12 13 14 15 16 17 18 19 20 21 22 23
      receiver: Object, methodName: String, tagName: String, attr: String,
      attrValue: Object): String {
    const tagContents: String = ToThisString(receiver, methodName);
    let result = '<' + tagName;
    if (attr != kEmptyString) {
      const attrStringValue: String =
          StringEscapeQuotes(context, ToString_Inline(context, attrValue));
      result = result + ' ' + attr + '=\"' + attrStringValue + '\"';
    }

    return result + '>' + tagContents + '</' + tagName + '>';
  }

  // https://tc39.github.io/ecma262/#sec-string.prototype.anchor
24
  transitioning javascript builtin StringPrototypeAnchor(
25 26 27 28 29 30
      context: Context, receiver: Object, ...arguments): String {
    return CreateHTML(
        receiver, 'String.prototype.anchor', 'a', 'name', arguments[0]);
  }

  // https://tc39.github.io/ecma262/#sec-string.prototype.big
31
  transitioning javascript builtin
32 33 34 35 36 37
  StringPrototypeBig(context: Context, receiver: Object, ...arguments): String {
    return CreateHTML(
        receiver, 'String.prototype.big', 'big', kEmptyString, kEmptyString);
  }

  // https://tc39.github.io/ecma262/#sec-string.prototype.blink
38
  transitioning javascript builtin
39 40 41 42 43 44 45 46
  StringPrototypeBlink(context: Context, receiver: Object, ...arguments):
      String {
    return CreateHTML(
        receiver, 'String.prototype.blink', 'blink', kEmptyString,
        kEmptyString);
  }

  // https://tc39.github.io/ecma262/#sec-string.prototype.bold
47
  transitioning javascript builtin
48 49 50 51 52 53 54
  StringPrototypeBold(context: Context, receiver: Object, ...arguments):
      String {
    return CreateHTML(
        receiver, 'String.prototype.bold', 'b', kEmptyString, kEmptyString);
  }

  // https://tc39.github.io/ecma262/#sec-string.prototype.fontcolor
55
  transitioning javascript builtin
56 57 58 59 60 61 62
  StringPrototypeFontcolor(context: Context, receiver: Object, ...arguments):
      String {
    return CreateHTML(
        receiver, 'String.prototype.fontcolor', 'font', 'color', arguments[0]);
  }

  // https://tc39.github.io/ecma262/#sec-string.prototype.fontsize
63
  transitioning javascript builtin
64 65 66 67 68 69 70
  StringPrototypeFontsize(context: Context, receiver: Object, ...arguments):
      String {
    return CreateHTML(
        receiver, 'String.prototype.fontsize', 'font', 'size', arguments[0]);
  }

  // https://tc39.github.io/ecma262/#sec-string.prototype.fixed
71
  transitioning javascript builtin
72 73 74 75 76 77 78
  StringPrototypeFixed(context: Context, receiver: Object, ...arguments):
      String {
    return CreateHTML(
        receiver, 'String.prototype.fixed', 'tt', kEmptyString, kEmptyString);
  }

  // https://tc39.github.io/ecma262/#sec-string.prototype.italics
79
  transitioning javascript builtin
80 81 82 83 84 85 86
  StringPrototypeItalics(context: Context, receiver: Object, ...arguments):
      String {
    return CreateHTML(
        receiver, 'String.prototype.italics', 'i', kEmptyString, kEmptyString);
  }

  // https://tc39.github.io/ecma262/#sec-string.prototype.link
87
  transitioning javascript builtin
88 89 90 91 92 93 94
  StringPrototypeLink(context: Context, receiver: Object, ...arguments):
      String {
    return CreateHTML(
        receiver, 'String.prototype.link', 'a', 'href', arguments[0]);
  }

  // https://tc39.github.io/ecma262/#sec-string.prototype.small
95
  transitioning javascript builtin
96 97 98 99 100 101 102 103
  StringPrototypeSmall(context: Context, receiver: Object, ...arguments):
      String {
    return CreateHTML(
        receiver, 'String.prototype.small', 'small', kEmptyString,
        kEmptyString);
  }

  // https://tc39.github.io/ecma262/#sec-string.prototype.strike
104
  transitioning javascript builtin
105 106 107 108 109 110 111 112
  StringPrototypeStrike(context: Context, receiver: Object, ...arguments):
      String {
    return CreateHTML(
        receiver, 'String.prototype.strike', 'strike', kEmptyString,
        kEmptyString);
  }

  // https://tc39.github.io/ecma262/#sec-string.prototype.sub
113
  transitioning javascript builtin
114 115 116 117 118 119
  StringPrototypeSub(context: Context, receiver: Object, ...arguments): String {
    return CreateHTML(
        receiver, 'String.prototype.sub', 'sub', kEmptyString, kEmptyString);
  }

  // https://tc39.github.io/ecma262/#sec-string.prototype.sup
120
  transitioning javascript builtin
121 122 123 124 125
  StringPrototypeSup(context: Context, receiver: Object, ...arguments): String {
    return CreateHTML(
        receiver, 'String.prototype.sup', 'sup', kEmptyString, kEmptyString);
  }
}