18defd9ff6930b4e24729971a61cf7469daf119beSteve Block// Copyright 2010 the V8 project authors. All rights reserved.
28defd9ff6930b4e24729971a61cf7469daf119beSteve Block// Redistribution and use in source and binary forms, with or without
38defd9ff6930b4e24729971a61cf7469daf119beSteve Block// modification, are permitted provided that the following conditions are
48defd9ff6930b4e24729971a61cf7469daf119beSteve Block// met:
58defd9ff6930b4e24729971a61cf7469daf119beSteve Block//
68defd9ff6930b4e24729971a61cf7469daf119beSteve Block//     * Redistributions of source code must retain the above copyright
78defd9ff6930b4e24729971a61cf7469daf119beSteve Block//       notice, this list of conditions and the following disclaimer.
88defd9ff6930b4e24729971a61cf7469daf119beSteve Block//     * Redistributions in binary form must reproduce the above
98defd9ff6930b4e24729971a61cf7469daf119beSteve Block//       copyright notice, this list of conditions and the following
108defd9ff6930b4e24729971a61cf7469daf119beSteve Block//       disclaimer in the documentation and/or other materials provided
118defd9ff6930b4e24729971a61cf7469daf119beSteve Block//       with the distribution.
128defd9ff6930b4e24729971a61cf7469daf119beSteve Block//     * Neither the name of Google Inc. nor the names of its
138defd9ff6930b4e24729971a61cf7469daf119beSteve Block//       contributors may be used to endorse or promote products derived
148defd9ff6930b4e24729971a61cf7469daf119beSteve Block//       from this software without specific prior written permission.
158defd9ff6930b4e24729971a61cf7469daf119beSteve Block//
168defd9ff6930b4e24729971a61cf7469daf119beSteve Block// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
178defd9ff6930b4e24729971a61cf7469daf119beSteve Block// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
188defd9ff6930b4e24729971a61cf7469daf119beSteve Block// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
198defd9ff6930b4e24729971a61cf7469daf119beSteve Block// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
208defd9ff6930b4e24729971a61cf7469daf119beSteve Block// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
218defd9ff6930b4e24729971a61cf7469daf119beSteve Block// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
228defd9ff6930b4e24729971a61cf7469daf119beSteve Block// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
238defd9ff6930b4e24729971a61cf7469daf119beSteve Block// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
248defd9ff6930b4e24729971a61cf7469daf119beSteve Block// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
258defd9ff6930b4e24729971a61cf7469daf119beSteve Block// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
268defd9ff6930b4e24729971a61cf7469daf119beSteve Block// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
278defd9ff6930b4e24729971a61cf7469daf119beSteve Block
288defd9ff6930b4e24729971a61cf7469daf119beSteve Blockfunction Hash() {
298defd9ff6930b4e24729971a61cf7469daf119beSteve Block  for (var i = 0; i < 100; i++) {
308defd9ff6930b4e24729971a61cf7469daf119beSteve Block    this['a' + i] = i;
318defd9ff6930b4e24729971a61cf7469daf119beSteve Block  }
328defd9ff6930b4e24729971a61cf7469daf119beSteve Block
338defd9ff6930b4e24729971a61cf7469daf119beSteve Block  delete this.a50;  // Ensure it's a normal object.
348defd9ff6930b4e24729971a61cf7469daf119beSteve Block}
358defd9ff6930b4e24729971a61cf7469daf119beSteve Block
368defd9ff6930b4e24729971a61cf7469daf119beSteve BlockHash.prototype.m = function() {
378defd9ff6930b4e24729971a61cf7469daf119beSteve Block  return 1;
388defd9ff6930b4e24729971a61cf7469daf119beSteve Block};
398defd9ff6930b4e24729971a61cf7469daf119beSteve Block
408defd9ff6930b4e24729971a61cf7469daf119beSteve Blockvar h = new Hash();
418defd9ff6930b4e24729971a61cf7469daf119beSteve Block
428defd9ff6930b4e24729971a61cf7469daf119beSteve Blockfor (var i = 1; i < 100; i++) {
438defd9ff6930b4e24729971a61cf7469daf119beSteve Block  if (i == 50) {
448defd9ff6930b4e24729971a61cf7469daf119beSteve Block    h.m = function() {
458defd9ff6930b4e24729971a61cf7469daf119beSteve Block      return 2;
468defd9ff6930b4e24729971a61cf7469daf119beSteve Block    };
478defd9ff6930b4e24729971a61cf7469daf119beSteve Block  } else if (i == 70) {
488defd9ff6930b4e24729971a61cf7469daf119beSteve Block    delete h.m;
498defd9ff6930b4e24729971a61cf7469daf119beSteve Block  }
508defd9ff6930b4e24729971a61cf7469daf119beSteve Block  assertEquals(i < 50 || i >= 70 ? 1 : 2, h.m());
518defd9ff6930b4e24729971a61cf7469daf119beSteve Block}
523bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch
533bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch
543bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdochvar nonsymbol = 'wwwww '.split(' ')[0];
553bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben MurdochHash.prototype.wwwww = Hash.prototype.m;
563bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch
573bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdochfor (var i = 1; i < 100; i++) {
583bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  if (i == 50) {
593bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch    h[nonsymbol] = function() {
603bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch      return 2;
613bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch    };
623bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  } else if (i == 70) {
633bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch    delete h[nonsymbol];
643bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  }
653bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  assertEquals(i < 50 || i >= 70 ? 1 : 2, h.wwwww());
663bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch}
67