tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

testStringMatch.js (1096B)


      1 setJitCompilerOption("ion.warmup.trigger", 4);
      2 
      3 function testBasic() {
      4  var f = function() {
      5    var result = "abc".match("b");
      6    assertEq(result.length, 1);
      7    assertEq(result.index, 1);
      8    assertEq(result[0], "b");
      9  };
     10  for (var i = 0; i < 40; i++) {
     11    f();
     12  }
     13 }
     14 testBasic();
     15 
     16 function testMod(apply, unapply) {
     17  var f = function(applied) {
     18    var result = "abc".match("b");
     19    assertEq(result.length, 1);
     20    if (applied) {
     21      assertEq(result[0], "mod");
     22    } else {
     23      assertEq(result.index, 1);
     24      assertEq(result[0], "b");
     25    }
     26  };
     27  var applied = false;
     28  for (var i = 0; i < 120; i++) {
     29    f(applied);
     30    if (i == 40) {
     31      apply();
     32      applied = true;
     33    }
     34    if (i == 80) {
     35      unapply();
     36      applied = false;
     37    }
     38  }
     39 }
     40 
     41 var orig_exec = RegExp.prototype.exec;
     42 testMod(() => {
     43  RegExp.prototype.exec = () => ["mod"];
     44 }, () => {
     45  RegExp.prototype.exec = orig_exec;
     46 });
     47 
     48 var orig_match = RegExp.prototype[Symbol.match];
     49 testMod(() => {
     50  RegExp.prototype[Symbol.match] = () => ["mod"];
     51 }, () => {
     52  RegExp.prototype[Symbol.match] = orig_match;
     53 });