tor-browser

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

from-regexp-like.js (1755B)


      1 // Copyright (C) 2015 the V8 project authors. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 description: Initialization from a RegExp-like object
      6 es6id: 21.2.3.1
      7 info: |
      8    1. Let patternIsRegExp be IsRegExp(pattern).
      9    [...]
     10    6. Else if patternIsRegExp is true, then
     11       a. Let P be Get(pattern, "source").
     12       b. ReturnIfAbrupt(P).
     13       c. If flags is undefined, then
     14          i. Let F be Get(pattern, "flags").
     15          ii. ReturnIfAbrupt(F).
     16       d. Else, let F be flags.
     17    [...]
     18    10. Return RegExpInitialize(O, P, F).
     19 features: [Symbol, Symbol.match]
     20 ---*/
     21 
     22 var obj = {
     23  source: 'source text',
     24  flags: 'i'
     25 };
     26 var result;
     27 
     28 obj[Symbol.match] = true;
     29 result = new RegExp(obj);
     30 assert.sameValue(Object.getPrototypeOf(result), RegExp.prototype);
     31 assert.sameValue(result.source, 'source text');
     32 assert.sameValue(result.flags, 'i');
     33 
     34 obj[Symbol.match] = 'string';
     35 result = new RegExp(obj);
     36 assert.sameValue(Object.getPrototypeOf(result), RegExp.prototype);
     37 assert.sameValue(result.source, 'source text');
     38 assert.sameValue(result.flags, 'i');
     39 
     40 obj[Symbol.match] = [];
     41 result = new RegExp(obj);
     42 assert.sameValue(Object.getPrototypeOf(result), RegExp.prototype);
     43 assert.sameValue(result.source, 'source text');
     44 assert.sameValue(result.flags, 'i');
     45 
     46 obj[Symbol.match] = Symbol();
     47 result = new RegExp(obj);
     48 assert.sameValue(Object.getPrototypeOf(result), RegExp.prototype);
     49 assert.sameValue(result.source, 'source text');
     50 assert.sameValue(result.flags, 'i');
     51 
     52 obj[Symbol.match] = 86;
     53 result = new RegExp(obj);
     54 assert.sameValue(Object.getPrototypeOf(result), RegExp.prototype);
     55 assert.sameValue(result.source, 'source text');
     56 assert.sameValue(result.flags, 'i');
     57 
     58 reportCompare(0, 0);