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

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

Issue 2109583002: Fix order of conversions in String.prototype.substr. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Get s.length only once. Created 4 years, 5 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/js/string.js ('k') | test/test262/test262.status » ('j') | 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 last = z; 145 last = z;
146 cache.push(z); 146 cache.push(z);
147 offset += i; 147 offset += i;
148 } 148 }
149 for (var i = 63; i >= 0; i--) { 149 for (var i = 63; i >= 0; i--) {
150 var z = cache.pop(); 150 var z = cache.pop();
151 assertTrue(/\u2028123456789ABCDEF/.test(z)); 151 assertTrue(/\u2028123456789ABCDEF/.test(z));
152 assertEquals(xl - offset, z.length); 152 assertEquals(xl - offset, z.length);
153 offset -= i; 153 offset -= i;
154 } 154 }
155
156
157 // Order of conversions.
158 {
159 let log = [];
160 let string = {[Symbol.toPrimitive]() { log.push("this"); return "abc" }};
161 let start = {[Symbol.toPrimitive]() { log.push("start"); return 0 }};
162 let length = {[Symbol.toPrimitive]() { log.push("length"); return 1 }};
163 assertEquals("a", String.prototype.substr.call(string, start, length));
164 assertEquals(["this", "start", "length"], log);
165 }
166 {
167 let log = [];
168 let string = {[Symbol.toPrimitive]() { log.push("this"); return "abc" }};
169 let start = {[Symbol.toPrimitive]() { log.push("start"); return 0 }};
170 let length = {[Symbol.toPrimitive]() { log.push("length"); return 0 }};
171 assertEquals("", String.prototype.substr.call(string, start, length));
172 assertEquals(["this", "start", "length"], log);
173 }
OLDNEW
« no previous file with comments | « src/js/string.js ('k') | test/test262/test262.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698