OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 11 matching lines...) Expand all Loading... | |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Flags: --expose-gc --allow-natives-syntax | 28 // Flags: --expose-gc --allow-natives-syntax |
29 | 29 |
30 function test() { | 30 function test() { |
31 var s1 = %NewString(26, true); | 31 var s1 = %NewString(26, true); |
32 for (i = 0; i < 26; i++) %_OneByteSeqStringSetChar(s1, i, 65); | |
33 assertEquals("AAAAAAAAAAAAAAAAAAAAAAAAAA", s1); | |
34 %_OneByteSeqStringSetChar(s1, 25, 66); | |
35 assertEquals("AAAAAAAAAAAAAAAAAAAAAAAAAB", s1); | |
32 for (i = 0; i < 26; i++) %_OneByteSeqStringSetChar(s1, i, i+65); | 36 for (i = 0; i < 26; i++) %_OneByteSeqStringSetChar(s1, i, i+65); |
33 assertEquals("ABCDEFGHIJKLMNOPQRSTUVWXYZ", s1); | 37 assertEquals("ABCDEFGHIJKLMNOPQRSTUVWXYZ", s1); |
34 s1 = %TruncateString(s1, 13); | 38 s1 = %TruncateString(s1, 13); |
35 assertEquals("ABCDEFGHIJKLM", s1); | 39 assertEquals("ABCDEFGHIJKLM", s1); |
36 | 40 |
37 var s2 = %NewString(26, false); | 41 var s2 = %NewString(26, false); |
42 for (i = 0; i < 26; i++) %_TwoByteSeqStringSetChar(s2, i, 65); | |
43 assertEquals("AAAAAAAAAAAAAAAAAAAAAAAAAA", s2); | |
44 %_TwoByteSeqStringSetChar(s2, 25, 66); | |
45 assertEquals("AAAAAAAAAAAAAAAAAAAAAAAAAB", s2); | |
Yang
2013/11/06 09:55:09
Please also add a test that tests non-latin1 chara
Benedikt Meurer
2013/11/06 10:06:36
That's done below with s3 already.
| |
38 for (i = 0; i < 26; i++) %_TwoByteSeqStringSetChar(s2, i, i+65); | 46 for (i = 0; i < 26; i++) %_TwoByteSeqStringSetChar(s2, i, i+65); |
39 assertEquals("ABCDEFGHIJKLMNOPQRSTUVWXYZ", s2); | 47 assertEquals("ABCDEFGHIJKLMNOPQRSTUVWXYZ", s2); |
40 s2 = %TruncateString(s1, 13); | 48 s2 = %TruncateString(s2, 13); |
41 assertEquals("ABCDEFGHIJKLM", s2); | 49 assertEquals("ABCDEFGHIJKLM", s2); |
42 | 50 |
43 var s3 = %NewString(26, false); | 51 var s3 = %NewString(26, false); |
44 for (i = 0; i < 26; i++) %_TwoByteSeqStringSetChar(s3, i, i+1000); | 52 for (i = 0; i < 26; i++) %_TwoByteSeqStringSetChar(s3, i, i+1000); |
45 for (i = 0; i < 26; i++) assertEquals(s3[i], String.fromCharCode(i+1000)); | 53 for (i = 0; i < 26; i++) assertEquals(s3[i], String.fromCharCode(i+1000)); |
46 | 54 |
47 var a = []; | 55 var a = []; |
48 for (var i = 0; i < 1000; i++) { | 56 for (var i = 0; i < 1000; i++) { |
49 var s = %NewString(10000, i % 2 == 1); | 57 var s = %NewString(10000, i % 2 == 1); |
50 a.push(s); | 58 a.push(s); |
(...skipping 12 matching lines...) Expand all Loading... | |
63 assertEquals(5000, a[i].length); | 71 assertEquals(5000, a[i].length); |
64 } | 72 } |
65 } | 73 } |
66 | 74 |
67 | 75 |
68 test(); | 76 test(); |
69 test(); | 77 test(); |
70 %OptimizeFunctionOnNextCall(test); | 78 %OptimizeFunctionOnNextCall(test); |
71 test(); | 79 test(); |
72 | 80 |
OLD | NEW |