18a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang// Copyright 2009 the V8 project authors. All rights reserved.
28a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang// Redistribution and use in source and binary forms, with or without
38a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang// modification, are permitted provided that the following conditions are
48a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang// met:
58a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang//
68a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang//     * Redistributions of source code must retain the above copyright
78a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang//       notice, this list of conditions and the following disclaimer.
88a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang//     * Redistributions in binary form must reproduce the above
98a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang//       copyright notice, this list of conditions and the following
108a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang//       disclaimer in the documentation and/or other materials provided
118a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang//       with the distribution.
128a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang//     * Neither the name of Google Inc. nor the names of its
138a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang//       contributors may be used to endorse or promote products derived
148a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang//       from this software without specific prior written permission.
158a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang//
168a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
178a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
188a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
198a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
208a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
218a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
228a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
238a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
248a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
258a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
268a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
278a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang
288a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang// See http://code.google.com/p/v8/issues/detail?id=931.
298a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang
308a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wangvar sequence = '';
318a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang
328a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wangvar o = { f: function (x, y) { return x + y; },
338a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang          2: function (x, y) { return x - y} };
348a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang
358a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wangfunction first() { sequence += "1"; return o; }
368a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wangfunction second() { sequence += "2"; return "f"; }
378a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wangfunction third() { sequence += "3"; return 3; }
388a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wangfunction fourth() { sequence += "4"; return 4; }
398a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang
408a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wangvar result = (first()[second()](third(), fourth()))
418a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) WangassertEquals(7, result);
428a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) WangassertEquals("1234", sequence);
438a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang
448a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wangfunction second_prime() { sequence += "2'"; return 2; }
458a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang
468a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wangvar result = (first()[second_prime()](third(), fourth()))
478a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) WangassertEquals(-1, result);
488a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) WangassertEquals("123412'34", sequence);
49