OLD | NEW |
---|---|
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 |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
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: --allow-natives-syntax | |
29 | |
28 // Test date construction from other dates. | 30 // Test date construction from other dates. |
29 var date0 = new Date(1111); | 31 var date0 = new Date(1111); |
30 var date1 = new Date(date0); | 32 var date1 = new Date(date0); |
31 assertEquals(1111, date0.getTime()); | 33 assertEquals(1111, date0.getTime()); |
32 assertEquals(date0.getTime(), date1.getTime()); | 34 assertEquals(date0.getTime(), date1.getTime()); |
33 var date2 = new Date(date0.toString()); | 35 var date2 = new Date(date0.toString()); |
34 assertEquals(1000, date2.getTime()); | 36 assertEquals(1000, date2.getTime()); |
35 | 37 |
36 // Test that dates may contain commas. | 38 // Test that dates may contain commas. |
37 var date0 = Date.parse("Dec 25 1995 1:30"); | 39 var date0 = Date.parse("Dec 25 1995 1:30"); |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 var hh = (i < 10) ? "0" + i : "" + i; | 314 var hh = (i < 10) ? "0" + i : "" + i; |
313 for (var j = 0; j < 60; j += 15) { | 315 for (var j = 0; j < 60; j += 15) { |
314 var mm = (j < 10) ? "0" + j : "" + j; | 316 var mm = (j < 10) ? "0" + j : "" + j; |
315 var ms = (i * 60 + j) * 60000; | 317 var ms = (i * 60 + j) * 60000; |
316 var string = "1972-03-28T23:50:03.500-" + hh + ":" + mm; | 318 var string = "1972-03-28T23:50:03.500-" + hh + ":" + mm; |
317 assertEquals(70674603500 + ms, Date.parse(string), string); | 319 assertEquals(70674603500 + ms, Date.parse(string), string); |
318 string = "1972-03-28T23:50:03.500+" + hh + ":" + mm; | 320 string = "1972-03-28T23:50:03.500+" + hh + ":" + mm; |
319 assertEquals(70674603500 - ms, Date.parse(string), string); | 321 assertEquals(70674603500 - ms, Date.parse(string), string); |
320 } | 322 } |
321 } | 323 } |
324 | |
325 assertThrows('Date.prototype.setTime.call("", 1);', TypeError); | |
326 assertThrows('Date.prototype.setYear.call("", 1);', TypeError); | |
327 assertThrows('Date.prototype.setHours.call("", 1, 2, 3, 4);', TypeError); | |
328 assertThrows('Date.prototype.getDate.call("");', TypeError); | |
329 assertThrows('Date.prototype.getUTCDate.call("");', TypeError); | |
330 | |
331 var date = new Date(); | |
332 date.getTime(); | |
333 date.getTime(); | |
334 %OptimizeFunctionOnNextCall(Date.prototype.getTime); | |
335 assertThrows(function() { Date.prototype.getTime.call(""); }, TypeError); | |
Erik Corry
2012/09/07 09:22:33
Are you sure you are getting a deopt here? There'
| |
336 | |
337 date.getYear(); | |
338 date.getYear(); | |
339 %OptimizeFunctionOnNextCall(Date.prototype.getYear); | |
340 assertThrows(function() { Date.prototype.getYear.call(""); }, TypeError); | |
OLD | NEW |