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

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

Issue 3291015: Custom call IC for String.fromCharCode. (Closed)
Patch Set: Removed todo Created 10 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
« src/x64/stub-cache-x64.cc ('K') | « src/x64/stub-cache-x64.cc ('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
(Empty)
1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
27
28 // Test String.fromCharCode.
29
30
31 // Test various receivers and arguments passed to String.fromCharCode.
32
33 Object.prototype.fromCharCode = function(x) { return this; };
34
35 var fcc = String.fromCharCode;
36 var fcc2 = fcc;
37
38 function constFun(x) { return function(y) { return x; }; }
39
40 function test(num) {
41 assertEquals(" ", String.fromCharCode(0x20));
42 assertEquals(" ", String.fromCharCode(0x20 + 0x10000));
43 assertEquals(" ", String.fromCharCode(0x20 - 0x10000));
44 assertEquals(" ", String.fromCharCode(0x20 + 0.5));
45
46 assertEquals("\u1234", String.fromCharCode(0x1234));
47 assertEquals("\u1234", String.fromCharCode(0x1234 + 0x10000));
48 assertEquals("\u1234", String.fromCharCode(0x1234 - 0x10000));
49 assertEquals("\u1234", String.fromCharCode(0x1234 + 0.5));
50
51 assertEquals(" ", String.fromCharCode(0x20, 0x20));
52 assertEquals(" ", String.fromCharCode(0x20 + 0.5, 0x20));
53
54 assertEquals(" ", fcc(0x20));
55 assertEquals(" ", fcc(0x20 + 0x10000));
56 assertEquals(" ", fcc(0x20 - 0x10000));
57 assertEquals(" ", fcc(0x20 + 0.5));
58
59 assertEquals("\u1234", fcc(0x1234));
60 assertEquals("\u1234", fcc(0x1234 + 0x10000));
61 assertEquals("\u1234", fcc(0x1234 - 0x10000));
62 assertEquals("\u1234", fcc(0x1234 + 0.5));
63
64 assertEquals(" ", fcc(0x20, 0x20));
65 assertEquals(" ", fcc(0x20 + 0.5, 0x20));
66
67 var receiver = (num < 5) ? String : (num < 9) ? "dummy" : 42;
68 fcc2 = (num < 5) ? fcc : (num < 9) ? constFun("dummy") : constFun(42);
69 var expected = (num < 5) ? " " : (num < 9) ? "dummy" : 42;
70 assertEquals(expected, receiver.fromCharCode(0x20));
71 assertEquals(expected, receiver.fromCharCode(0x20 - 0x10000));
72 assertEquals(expected, receiver.fromCharCode(0x20 + 0.5));
73 assertEquals(expected, fcc2(0x20));
74 assertEquals(expected, fcc2(0x20 - 0x10000));
75 assertEquals(expected, fcc2(0x20 + 0.5));
76 }
77
78 // Use loop to test the custom IC.
79 for (var i = 0; i < 10; i++) {
80 test(i);
81 }
82
83
84 // Test the custom IC works correctly when the map changes.
85 for (var i = 0; i < 10; i++) {
86 var expected = (i < 5) ? " " : 42;
87 if (i == 5) String.fromCharCode = function() { return 42; };
88 assertEquals(expected, String.fromCharCode(0x20));
89 }
OLDNEW
« src/x64/stub-cache-x64.cc ('K') | « src/x64/stub-cache-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698