tor-browser

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

clone-regexp.js (1231B)


      1 // |reftest| skip-if(!xulRuntime.shell)
      2 // -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
      3 // Any copyright is dedicated to the Public Domain.
      4 // http://creativecommons.org/licenses/publicdomain/
      5 
      6 function testRegExp(b, c=b) {
      7    var a = deserialize(serialize(b));
      8    assertEq(a === b, false);
      9    assertEq(Object.getPrototypeOf(a), RegExp.prototype);
     10    assertEq(Object.prototype.toString.call(a), "[object RegExp]");
     11    for (p in a)
     12        throw new Error("cloned RegExp should have no enumerable properties");
     13 
     14    assertEq(a.source, c.source);
     15    assertEq(a.global, c.global);
     16    assertEq(a.ignoreCase, c.ignoreCase);
     17    assertEq(a.multiline, c.multiline);
     18    assertEq(a.sticky, c.sticky);
     19    assertEq("expando" in a, false);
     20 }
     21 
     22 testRegExp(RegExp(""));
     23 testRegExp(/(?:)/);
     24 testRegExp(/^(.*)$/gimy);
     25 
     26 var re = /\bx\b/gi;
     27 re.expando = true;
     28 testRegExp(re);
     29 // `source` and the flag accessors are defined on RegExp.prototype, so they're
     30 // not available after re.__proto__ has been changed. We solve that by passing
     31 // in an additional copy of the same RegExp to compare the
     32 // serialized-then-deserialized clone with."
     33 re.__proto__ = {};
     34 testRegExp(re, /\bx\b/gi);
     35 
     36 reportCompare(0, 0, 'ok');