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

Side by Side Diff: test/mjsunit/string-externalize.js

Issue 559913002: Rename ascii to one-byte where applicable. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 18 matching lines...) Expand all
29 29
30 var size = 1024; 30 var size = 1024;
31 31
32 function test() { 32 function test() {
33 var str = ""; 33 var str = "";
34 34
35 // Build an ascii cons string. 35 // Build an ascii cons string.
36 for (var i = 0; i < size; i++) { 36 for (var i = 0; i < size; i++) {
37 str += String.fromCharCode(i & 0x7f); 37 str += String.fromCharCode(i & 0x7f);
38 } 38 }
39 assertTrue(isAsciiString(str)); 39 assertTrue(isOneByteString(str));
40 40
41 var twoByteExternalWithAsciiData = 41 var twoByteExternalWithOneByteData =
42 "AA" + (function() { return "A"; })(); 42 "AA" + (function() { return "A"; })();
43 externalizeString(twoByteExternalWithAsciiData, true /* force two-byte */); 43 externalizeString(twoByteExternalWithOneByteData, true /* force two-byte */);
44 assertFalse(isAsciiString(twoByteExternalWithAsciiData)); 44 assertFalse(isOneByteString(twoByteExternalWithOneByteData));
45 45
46 var realTwoByteExternalString = 46 var realTwoByteExternalString =
47 "\u1234\u1234\u1234\u1234" + (function() { return "\u1234"; })(); 47 "\u1234\u1234\u1234\u1234" + (function() { return "\u1234"; })();
48 externalizeString(realTwoByteExternalString); 48 externalizeString(realTwoByteExternalString);
49 assertFalse(isAsciiString(realTwoByteExternalString)); 49 assertFalse(isOneByteString(realTwoByteExternalString));
50 50
51 assertTrue(isAsciiString(["a", twoByteExternalWithAsciiData].join(""))); 51 assertTrue(isOneByteString(["a", twoByteExternalWithOneByteData].join("")));
52 52
53 // Appending a two-byte string that contains only ascii chars should 53 // Appending a two-byte string that contains only ascii chars should
54 // still produce an ascii cons. 54 // still produce an ascii cons.
55 var str1 = str + twoByteExternalWithAsciiData; 55 var str1 = str + twoByteExternalWithOneByteData;
56 assertTrue(isAsciiString(str1)); 56 assertTrue(isOneByteString(str1));
57 57
58 // Force flattening of the string. 58 // Force flattening of the string.
59 var old_length = str1.length - twoByteExternalWithAsciiData.length; 59 var old_length = str1.length - twoByteExternalWithOneByteData.length;
60 for (var i = 0; i < old_length; i++) { 60 for (var i = 0; i < old_length; i++) {
61 assertEquals(String.fromCharCode(i & 0x7f), str1[i]); 61 assertEquals(String.fromCharCode(i & 0x7f), str1[i]);
62 } 62 }
63 for (var i = old_length; i < str1.length; i++) { 63 for (var i = old_length; i < str1.length; i++) {
64 assertEquals("A", str1[i]); 64 assertEquals("A", str1[i]);
65 } 65 }
66 66
67 // Flattened string should still be ascii. 67 // Flattened string should still be ascii.
68 assertTrue(isAsciiString(str1)); 68 assertTrue(isOneByteString(str1));
69 69
70 // Lower-casing an ascii string should produce ascii. 70 // Lower-casing an ascii string should produce ascii.
71 assertTrue(isAsciiString(str1.toLowerCase())); 71 assertTrue(isOneByteString(str1.toLowerCase()));
72 72
73 assertFalse(isAsciiString(["a", realTwoByteExternalString].join(""))); 73 assertFalse(isOneByteString(["a", realTwoByteExternalString].join("")));
74 74
75 // Appending a real two-byte string should produce a two-byte cons. 75 // Appending a real two-byte string should produce a two-byte cons.
76 var str2 = str + realTwoByteExternalString; 76 var str2 = str + realTwoByteExternalString;
77 assertFalse(isAsciiString(str2)); 77 assertFalse(isOneByteString(str2));
78 78
79 // Force flattening of the string. 79 // Force flattening of the string.
80 old_length = str2.length - realTwoByteExternalString.length; 80 old_length = str2.length - realTwoByteExternalString.length;
81 for (var i = 0; i < old_length; i++) { 81 for (var i = 0; i < old_length; i++) {
82 assertEquals(String.fromCharCode(i & 0x7f), str2[i]); 82 assertEquals(String.fromCharCode(i & 0x7f), str2[i]);
83 } 83 }
84 for (var i = old_length; i < str.length; i++) { 84 for (var i = old_length; i < str.length; i++) {
85 assertEquals("\u1234", str2[i]); 85 assertEquals("\u1234", str2[i]);
86 } 86 }
87 87
88 // Flattened string should still be two-byte. 88 // Flattened string should still be two-byte.
89 assertFalse(isAsciiString(str2)); 89 assertFalse(isOneByteString(str2));
90 } 90 }
91 91
92 // Run the test many times to ensure IC-s don't break things. 92 // Run the test many times to ensure IC-s don't break things.
93 for (var i = 0; i < 10; i++) { 93 for (var i = 0; i < 10; i++) {
94 test(); 94 test();
95 } 95 }
96 96
97 // Clean up string to make Valgrind happy. 97 // Clean up string to make Valgrind happy.
98 gc(); 98 gc();
99 gc(); 99 gc();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698