NASHORN-760.js revision 2:da1e581c933b
162321Salfred/*
262321Salfred * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
362321Salfred * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
462321Salfred *
562321Salfred * This code is free software; you can redistribute it and/or modify it
662321Salfred * under the terms of the GNU General Public License version 2 only, as
762321Salfred * published by the Free Software Foundation.
862321Salfred *
962321Salfred * This code is distributed in the hope that it will be useful, but WITHOUT
1062321Salfred * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1162321Salfred * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1262321Salfred * version 2 for more details (a copy is included in the LICENSE file that
1362321Salfred * accompanied this code).
1462321Salfred *
1562321Salfred * You should have received a copy of the GNU General Public License version
1662321Salfred * 2 along with this work; if not, write to the Free Software Foundation,
1762321Salfred * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1862321Salfred *
1962321Salfred * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2062321Salfred * or visit www.oracle.com if you need additional information or have any
2162321Salfred * questions.
2262321Salfred */
2362321Salfred
2462321Salfred/**
2592941Sobrien * NASHORN-111 :  ClassCastException from JSON.stringify
2692941Sobrien *
2762321Salfred * @test
2862321Salfred * @run
2962321Salfred */
3062321Salfred// problem 1
3162321Salfred// the conversions in TernaryNode are not necessary, but they should not cause problems. They did
3292905Sobrien// this was because the result of Global.allocate(Object[])Object which returns a NativeObject.
3362321Salfred// was tracked as an object type on our stack. The type system did not recognize this as an array.
3462321Salfred// Then the explicit conversions became "convert NativeArray->Object[]" which is a checkccast Object[]
3562321Salfred// which naturally failed.
3662321Salfred
3762321Salfred// I pushed the appropriate arraytype on the stack for Global.allocate.
3862321Salfred
3962321Salfred// I also removed the conversions in CodeGen, all conversions should be done in Lower, as
4062321Salfred// NASHORN-706 states.
4162321Salfred
4262321Salfredvar silent = false;
4362321Salfredvar stdio = silent ? ['pipe', 'pipe', 'pipe', 'ipc'] : [0, 1, 2, 'ipc'];
4462321Salfred
4562321Salfred// This made the test pass, but it's still not correct to pick widest types for array
4662321Salfred// and primitives. Widest(Object[], int) gave us Object[] which makes no sense. This is used
4762321Salfred// by lower to type the conversions, so function b below also failed until I made a change
4862321Salfred// ty type widest to actually return the widest common denominator, if both aren't arrays
4962321Salfred
5062321Salfredfunction b() {
5162321Salfred    var silent2 = false;
5262321Salfred    var stdio2 = silent2 ? [1,2,3] : 17;
5392905Sobrien}
5462321Salfred
5562321Salfred