string-comparison-opt.js 6.02 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
// Copyright 2018 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.

// Flags: --allow-natives-syntax

(()=> {
  function f(a) {
    return a.charAt(1) == "";
  }
11
  %PrepareFunctionForOptimization(f);
12 13 14 15 16 17 18 19 20
  assertEquals(false, f("aaa"));
  %OptimizeFunctionOnNextCall(f);
  assertEquals(false, f("aaa"));
})();

(()=> {
  function f(a) {
    return a.charAt(1) < "";
  }
21
  %PrepareFunctionForOptimization(f);
22 23 24 25 26 27 28 29 30
  assertEquals(false, f("aaa"));
  %OptimizeFunctionOnNextCall(f);
  assertEquals(false, f("aaa"));
})();

(()=> {
  function f(a) {
    return a.charAt(1) <= "";
  }
31
  %PrepareFunctionForOptimization(f);
32 33 34 35 36 37 38 39 40
  assertEquals(false, f("aaa"));
  %OptimizeFunctionOnNextCall(f);
  assertEquals(false, f("aaa"));
})();

(()=> {
  function f(a) {
    return a.charAt(1) > "";
  }
41
  %PrepareFunctionForOptimization(f);
42 43 44 45 46 47 48 49 50
  assertEquals(true, f("aaa"));
  %OptimizeFunctionOnNextCall(f);
  assertEquals(true, f("aaa"));
})();

(()=> {
  function f(a) {
    return a.charAt(1) >= "";
  }
51
  %PrepareFunctionForOptimization(f);
52 53 54 55 56 57 58 59 60 61
  assertEquals(true, f("aaa"));
  %OptimizeFunctionOnNextCall(f);
  assertEquals(true, f("aaa"));
})();


(()=> {
  function f(a) {
    return a.charAt(1) == a.charAt(2);
  }
62
  %PrepareFunctionForOptimization(f);
63 64 65 66 67 68 69 70 71 72 73 74 75
  assertEquals(false, f("aab"));
  assertEquals(true, f("aaa"));
  assertEquals(false, f("acb"));
  %OptimizeFunctionOnNextCall(f);
  assertEquals(false, f("aab"));
  assertEquals(true, f("aaa"));
  assertEquals(false, f("acb"));
})();

(()=> {
  function f(a) {
    return a.charAt(1) < a.charAt(2);
  }
76
  %PrepareFunctionForOptimization(f);
77 78 79 80 81 82 83 84 85 86 87 88 89
  assertEquals(true, f("aab"));
  assertEquals(false, f("aaa"));
  assertEquals(false, f("acb"));
  %OptimizeFunctionOnNextCall(f);
  assertEquals(true, f("aab"));
  assertEquals(false, f("aaa"));
  assertEquals(false, f("acb"));
})();

(()=> {
  function f(a) {
    return a.charAt(1) <= a.charAt(2);
  }
90
  %PrepareFunctionForOptimization(f);
91 92 93 94 95 96 97 98 99 100 101 102 103
  assertEquals(true, f("aab"));
  assertEquals(true, f("aaa"));
  assertEquals(false, f("acb"));
  %OptimizeFunctionOnNextCall(f);
  assertEquals(true, f("aab"));
  assertEquals(true, f("aaa"));
  assertEquals(false, f("acb"));
})();

(()=> {
  function f(a) {
    return a.charAt(1) > a.charAt(2);
  }
104
  %PrepareFunctionForOptimization(f);
105 106 107 108 109 110 111 112 113 114 115 116 117
  assertEquals(false, f("aab"));
  assertEquals(false, f("aaa"));
  assertEquals(true, f("acb"));
  %OptimizeFunctionOnNextCall(f);
  assertEquals(false, f("aab"));
  assertEquals(false, f("aaa"));
  assertEquals(true, f("acb"));
})();

(()=> {
  function f(a) {
    return a.charAt(1) >= a.charAt(2);
  }
118
  %PrepareFunctionForOptimization(f);
119 120 121 122 123 124 125 126 127 128 129 130 131 132
  assertEquals(false, f("aab"));
  assertEquals(true, f("aaa"));
  assertEquals(true, f("acb"));
  %OptimizeFunctionOnNextCall(f);
  assertEquals(false, f("aab"));
  assertEquals(true, f("aaa"));
  assertEquals(true, f("acb"));
})();


(()=> {
  function f(a) {
    return a.charAt(1) == "b";
  }
133
  %PrepareFunctionForOptimization(f);
134 135 136 137 138 139 140 141 142 143 144 145 146
  assertEquals(false, f("aaa"));
  assertEquals(true, f("bbb"));
  assertEquals(false, f("ccc"));
  %OptimizeFunctionOnNextCall(f);
  assertEquals(false, f("aaa"));
  assertEquals(true, f("bbb"));
  assertEquals(false, f("ccc"));
})();

(()=> {
  function f(a) {
    return a.charAt(1) == "bb";
  }
147
  %PrepareFunctionForOptimization(f);
148 149 150 151 152 153 154 155 156 157
  assertEquals(false, f("aaa"));
  %OptimizeFunctionOnNextCall(f);
  assertEquals(false, f("aaa"));
})();


(()=> {
  function f(a) {
    return a.charAt(1) < "b";
  }
158
  %PrepareFunctionForOptimization(f);
159 160 161 162 163 164 165 166 167 168 169 170 171
  assertEquals(true, f("aaa"));
  assertEquals(false, f("bbb"));
  assertEquals(false, f("ccc"));
  %OptimizeFunctionOnNextCall(f);
  assertEquals(true, f("aaa"));
  assertEquals(false, f("bbb"));
  assertEquals(false, f("ccc"));
})();

(()=> {
  function f(a) {
    return a.charAt(1) < "bb";
  }
172
  %PrepareFunctionForOptimization(f);
173 174 175 176 177 178 179 180 181 182 183 184 185 186
  assertEquals(true, f("aaa"));
  assertEquals(true, f("bbb"));
  assertEquals(false, f("ccc"));
  %OptimizeFunctionOnNextCall(f);
  assertEquals(true, f("aaa"));
  assertEquals(true, f("bbb"));
  assertEquals(false, f("ccc"));
})();


(()=> {
  function f(a) {
    return a.charAt(1) <= "b";
  }
187
  %PrepareFunctionForOptimization(f);
188 189 190 191 192 193 194 195 196 197 198 199 200
  assertEquals(true, f("aaa"));
  assertEquals(true, f("bbb"));
  assertEquals(false, f("ccc"));
  %OptimizeFunctionOnNextCall(f);
  assertEquals(true, f("aaa"));
  assertEquals(true, f("bbb"));
  assertEquals(false, f("ccc"));
})();

(()=> {
  function f(a) {
    return a.charAt(1) <= "bb";
  }
201
  %PrepareFunctionForOptimization(f);
202 203 204 205 206 207 208 209 210 211 212 213 214 215
  assertEquals(true, f("aaa"));
  assertEquals(true, f("bbb"));
  assertEquals(false, f("ccc"));
  %OptimizeFunctionOnNextCall(f);
  assertEquals(true, f("aaa"));
  assertEquals(true, f("bbb"));
  assertEquals(false, f("ccc"));
})();


(()=> {
  function f(a) {
    return a.charAt(1) > "b";
  }
216
  %PrepareFunctionForOptimization(f);
217 218 219 220 221 222 223 224 225 226 227 228 229
  assertEquals(false, f("aaa"));
  assertEquals(false, f("bbb"));
  assertEquals(true, f("ccc"));
  %OptimizeFunctionOnNextCall(f);
  assertEquals(false, f("aaa"));
  assertEquals(false, f("bbb"));
  assertEquals(true, f("ccc"));
})();

(()=> {
  function f(a) {
    return a.charAt(1) > "bb";
  }
230
  %PrepareFunctionForOptimization(f);
231 232 233 234 235 236 237 238 239 240 241 242 243 244
  assertEquals(false, f("aaa"));
  assertEquals(false, f("bbb"));
  assertEquals(true, f("ccc"));
  %OptimizeFunctionOnNextCall(f);
  assertEquals(false, f("aaa"));
  assertEquals(false, f("bbb"));
  assertEquals(true, f("ccc"));
})();


(()=> {
  function f(a) {
    return a.charAt(1) >= "b";
  }
245
  %PrepareFunctionForOptimization(f);
246 247 248 249 250 251 252 253 254 255 256 257 258
  assertEquals(false, f("aaa"));
  assertEquals(true, f("bbb"));
  assertEquals(true, f("ccc"));
  %OptimizeFunctionOnNextCall(f);
  assertEquals(false, f("aaa"));
  assertEquals(true, f("bbb"));
  assertEquals(true, f("ccc"));
})();

(()=> {
  function f(a) {
    return a.charAt(1) >= "bb";
  }
259
  %PrepareFunctionForOptimization(f);
260 261 262 263 264 265 266 267
  assertEquals(false, f("aaa"));
  assertEquals(false, f("bbb"));
  assertEquals(true, f("ccc"));
  %OptimizeFunctionOnNextCall(f);
  assertEquals(false, f("aaa"));
  assertEquals(false, f("bbb"));
  assertEquals(true, f("ccc"));
})();