LEFT | RIGHT |
(no file at all) | |
| 1 // Copyright 2012 the v8-i18n authors. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the 'License'); |
| 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an 'AS IS' BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 // Test that we always use original Intl.Constructors for toLocaleString calls. |
| 16 |
| 17 function throwError() { |
| 18 throw new Error('Malicious method invoked.'); |
| 19 } |
| 20 |
| 21 Intl.Collator = Intl.NumberFormat = Intl.DateTimeFormat = throwError; |
| 22 |
| 23 Intl.Collator.prototype.compare = throwError; |
| 24 Intl.NumberFormat.prototype.format = throwError; |
| 25 Intl.DateTimeFormat.prototype.format = throwError; |
| 26 |
| 27 // Make sure constructors actually throw now. |
| 28 assertThrows('new Intl.Collator()'); |
| 29 assertThrows('new Intl.NumberFormat()'); |
| 30 assertThrows('new Intl.DateTimeFormat()'); |
| 31 |
| 32 // None of these should throw. |
| 33 assertDoesNotThrow('new Date().toLocaleString()'); |
| 34 assertDoesNotThrow('new Date().toLocaleDateString()'); |
| 35 assertDoesNotThrow('new Date().toLocaleTimeString()'); |
| 36 assertDoesNotThrow('new Number(12345.412).toLocaleString()'); |
| 37 assertDoesNotThrow('new String(\'abc\').localeCompare(\'bcd\')'); |
LEFT | RIGHT |