nashorn/test/script/basic/JDK-8011382.js
author sundar
Thu, 13 Mar 2014 15:58:24 +0530
changeset 23374 f470afc89c6c
parent 16771 9dd31b14e47c
child 24778 2ff5d7041566
permissions -rw-r--r--
8015958: DataView constructor is not defined Reviewed-by: attila, hannesw, lagergren
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16771
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
     1
/*
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
     4
 * 
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
     8
 * 
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    13
 * accompanied this code).
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    14
 * 
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    18
 * 
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    21
 * questions.
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    22
 */
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    23
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    24
/**
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    25
 * JDK-8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec. 
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    26
 *
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    27
 * @test
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    28
 * @run
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    29
 */
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    30
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    31
var yearValueOf = 0;
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    32
var monthValueOf = 0;
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    33
var dayValueOf = 0;
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    34
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    35
var d = new Date(
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    36
    {
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    37
        valueOf: function() { yearValueOf++; return NaN; }
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    38
    },
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    39
    {
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    40
        valueOf: function() { monthValueOf++; return NaN; }
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    41
    },
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    42
    {
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    43
        valueOf: function() { dayValueOf++; return NaN; }
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    44
    }
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    45
);
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    46
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    47
if (yearValueOf !== 1) {
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    48
    fail("Date constructor does not call valueOf on year argument once");
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    49
}
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    50
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    51
if (monthValueOf !== 1) {
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    52
    fail("Date constructor does not call valueOf on month argument once");
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    53
}
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    54
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    55
if (dayValueOf !== 1) {
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    56
    fail("Date constructor does not call valueOf on day argument once");
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    57
}
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    58
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    59
yearValueOf = 0;
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    60
monthValueOf = 0;
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    61
dayValueOf = 0;
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    62
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    63
d = new Date();
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    64
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    65
d.setFullYear(
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    66
    {
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    67
        valueOf: function() { yearValueOf++; return NaN; }
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    68
    },
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    69
    {
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    70
        valueOf: function() { monthValueOf++; return NaN; }
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    71
    },
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    72
    {
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    73
        valueOf: function() { dayValueOf++; return NaN; }
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    74
    }
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    75
);
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    76
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    77
if (yearValueOf !== 1) {
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    78
    fail("Date setFullYear does not call valueOf on year argument once");
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    79
}
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    80
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    81
if (monthValueOf !== 1) {
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    82
    fail("Date setFullYear does not call valueOf on month argument once");
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    83
}
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    84
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    85
if (dayValueOf !== 1) {
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    86
    fail("Date setFullYear does not call valueOf on day argument once");
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    87
}
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    88
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    89
// check toJSON calls toISOString override
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    90
var toISOStringCalled = 0;
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    91
d = new Date();
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    92
d.toISOString = function() {
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    93
    toISOStringCalled++;
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    94
};
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    95
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    96
d.toJSON();
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    97
if (toISOStringCalled !== 1) {
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    98
    fail("toISOString was not called by Date.prototype.toJSON once");
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
    99
}
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
   100
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
   101
toISOStringCalled = 0;
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
   102
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
   103
// toJSON is generic - try for non-Date object
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
   104
Date.prototype.toJSON.call({
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
   105
    toISOString: function() {
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
   106
        toISOStringCalled++;
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
   107
    },
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
   108
    valueOf: function() {
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
   109
        return 12;
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
   110
    }
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
   111
});
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
   112
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
   113
if (toISOStringCalled !== 1) {
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
   114
    fail("toISOString was not called by Date.prototype.toJSON once");
9dd31b14e47c 8011382: Data prototype methods and constructor do not call user defined toISOString, valueOf methods per spec.
sundar
parents:
diff changeset
   115
}