Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: test/mjsunit/regexp.js

Issue 3778004: Restructure RegExp exec cache code. (Closed)
Patch Set: Addressed review comments. Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/string.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 assertEquals("xyz", res[0]); 495 assertEquals("xyz", res[0]);
496 assertEquals("y", res[1]); 496 assertEquals("y", res[1]);
497 assertEquals(1, res.index); 497 assertEquals(1, res.index);
498 assertEquals("axyzb", res.input); 498 assertEquals("axyzb", res.input);
499 assertEquals(undefined, res.foobar); 499 assertEquals(undefined, res.foobar);
500 500
501 res.foobar = "Arglebargle"; 501 res.foobar = "Arglebargle";
502 res[3] = "Glopglyf"; 502 res[3] = "Glopglyf";
503 assertEquals("Arglebargle", res.foobar); 503 assertEquals("Arglebargle", res.foobar);
504 } 504 }
505
506 // Test that we perform the spec required conversions in the correct order.
507 var log;
508 var string = "the string";
509 var fakeLastIndex = {
510 valueOf: function() {
511 log.push("li");
512 return 0;
513 }
514 };
515 var fakeString = {
516 toString: function() {
517 log.push("ts");
518 return string;
519 },
520 length: 0
521 };
522
523 var re = /str/;
524 log = [];
525 re.lastIndex = fakeLastIndex;
526 var result = re.exec(fakeString);
527 assertEquals(["str"], result);
528 assertEquals(["ts", "li"], log);
529
530 // Again, to check if caching interferes.
531 log = [];
532 re.lastIndex = fakeLastIndex;
533 result = re.exec(fakeString);
534 assertEquals(["str"], result);
535 assertEquals(["ts", "li"], log);
536
537 // And one more time, just to be certain.
538 log = [];
539 re.lastIndex = fakeLastIndex;
540 result = re.exec(fakeString);
541 assertEquals(["str"], result);
542 assertEquals(["ts", "li"], log);
543
544 // Now with a global regexp, where lastIndex is actually used.
545 re = /str/g;
546 log = [];
547 re.lastIndex = fakeLastIndex;
548 var result = re.exec(fakeString);
549 assertEquals(["str"], result);
550 assertEquals(["ts", "li"], log);
551
552 // Again, to check if caching interferes.
553 log = [];
554 re.lastIndex = fakeLastIndex;
555 result = re.exec(fakeString);
556 assertEquals(["str"], result);
557 assertEquals(["ts", "li"], log);
558
559 // And one more time, just to be certain.
560 log = [];
561 re.lastIndex = fakeLastIndex;
562 result = re.exec(fakeString);
563 assertEquals(["str"], result);
564 assertEquals(["ts", "li"], log);
565
566
567 // Check that properties of RegExp have the correct permissions.
568 var re = /x/g;
569 var desc = Object.getOwnPropertyDescriptor(re, "global");
570 assertEquals(true, desc.value);
571 assertEquals(false, desc.configurable);
572 assertEquals(false, desc.enumerable);
573 assertEquals(false, desc.writable);
574
575 desc = Object.getOwnPropertyDescriptor(re, "multiline");
576 assertEquals(false, desc.value);
577 assertEquals(false, desc.configurable);
578 assertEquals(false, desc.enumerable);
579 assertEquals(false, desc.writable);
580
581 desc = Object.getOwnPropertyDescriptor(re, "ignoreCase");
582 assertEquals(false, desc.value);
583 assertEquals(false, desc.configurable);
584 assertEquals(false, desc.enumerable);
585 assertEquals(false, desc.writable);
586
587 desc = Object.getOwnPropertyDescriptor(re, "lastIndex");
588 assertEquals(0, desc.value);
589 assertEquals(false, desc.configurable);
590 assertEquals(false, desc.enumerable);
591 assertEquals(true, desc.writable);
OLDNEW
« no previous file with comments | « src/string.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698