js/src/tests/js1_5/extensions/regress-90596-002.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_5/extensions/regress-90596-002.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,265 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + * Date: 28 August 2001
    1.11 + *
    1.12 + * SUMMARY: A [DontEnum] prop, if overridden, should appear in uneval().
    1.13 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=90596
    1.14 + *
    1.15 + * NOTE: some inefficiencies in the test are made for the sake of readability.
    1.16 + * Sorting properties alphabetically is done for definiteness in comparisons.
    1.17 + */
    1.18 +//-----------------------------------------------------------------------------
    1.19 +var UBound = 0;
    1.20 +var BUGNUMBER = 90596;
    1.21 +var summary = 'A [DontEnum] prop, if overridden, should appear in uneval()';
    1.22 +var cnCOMMA = ',';
    1.23 +var cnLBRACE = '{';
    1.24 +var cnRBRACE = '}';
    1.25 +var cnLPAREN = '(';
    1.26 +var cnRPAREN = ')';
    1.27 +var status = '';
    1.28 +var statusitems = [];
    1.29 +var actual = '';
    1.30 +var actualvalues = [];
    1.31 +var expect= '';
    1.32 +var expectedvalues = [];
    1.33 +var obj = {};
    1.34 +
    1.35 +
    1.36 +status = inSection(1);
    1.37 +obj = {toString:9};
    1.38 +actual = uneval(obj);
    1.39 +expect = '({toString:9})';
    1.40 +addThis();
    1.41 +
    1.42 +status = inSection(2);
    1.43 +obj = {hasOwnProperty:"Hi"};
    1.44 +actual = uneval(obj);
    1.45 +expect = '({hasOwnProperty:"Hi"})';
    1.46 +addThis();
    1.47 +
    1.48 +status = inSection(3);
    1.49 +obj = {toString:9, hasOwnProperty:"Hi"};
    1.50 +actual = uneval(obj);
    1.51 +expect = '({toString:9, hasOwnProperty:"Hi"})';
    1.52 +addThis();
    1.53 +
    1.54 +status = inSection(4);
    1.55 +obj = {prop1:1, toString:9, hasOwnProperty:"Hi"};
    1.56 +actual = uneval(obj);
    1.57 +expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
    1.58 +addThis();
    1.59 +
    1.60 +
    1.61 +// TRY THE SAME THING IN EVAL CODE
    1.62 +var s = '';
    1.63 +
    1.64 +status = inSection(5);
    1.65 +s = 'obj = {toString:9}';
    1.66 +eval(s);
    1.67 +actual = uneval(obj);
    1.68 +expect = '({toString:9})';
    1.69 +addThis();
    1.70 +
    1.71 +status = inSection(6);
    1.72 +s = 'obj = {hasOwnProperty:"Hi"}';
    1.73 +eval(s);
    1.74 +actual = uneval(obj);
    1.75 +expect = '({hasOwnProperty:"Hi"})';
    1.76 +addThis();
    1.77 +
    1.78 +status = inSection(7);
    1.79 +s = 'obj = {toString:9, hasOwnProperty:"Hi"}';
    1.80 +eval(s);
    1.81 +actual = uneval(obj);
    1.82 +expect = '({toString:9, hasOwnProperty:"Hi"})';
    1.83 +addThis();
    1.84 +
    1.85 +status = inSection(8);
    1.86 +s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
    1.87 +eval(s);
    1.88 +actual = uneval(obj);
    1.89 +expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
    1.90 +addThis();
    1.91 +
    1.92 +
    1.93 +// TRY THE SAME THING IN FUNCTION CODE
    1.94 +function A()
    1.95 +{
    1.96 +  status = inSection(9);
    1.97 +  var s = 'obj = {toString:9}';
    1.98 +  eval(s);
    1.99 +  actual = uneval(obj);
   1.100 +  expect = '({toString:9})';
   1.101 +  addThis();
   1.102 +}
   1.103 +A();
   1.104 +
   1.105 +function B()
   1.106 +{
   1.107 +  status = inSection(10);
   1.108 +  var s = 'obj = {hasOwnProperty:"Hi"}';
   1.109 +  eval(s);
   1.110 +  actual = uneval(obj);
   1.111 +  expect = '({hasOwnProperty:"Hi"})';
   1.112 +  addThis();
   1.113 +}
   1.114 +B();
   1.115 +
   1.116 +function C()
   1.117 +{
   1.118 +  status = inSection(11);
   1.119 +  var s = 'obj = {toString:9, hasOwnProperty:"Hi"}';
   1.120 +  eval(s);
   1.121 +  actual = uneval(obj);
   1.122 +  expect = '({toString:9, hasOwnProperty:"Hi"})';
   1.123 +  addThis();
   1.124 +}
   1.125 +C();
   1.126 +
   1.127 +function D()
   1.128 +{
   1.129 +  status = inSection(12);
   1.130 +  var s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
   1.131 +  eval(s);
   1.132 +  actual = uneval(obj);
   1.133 +  expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
   1.134 +  addThis();
   1.135 +}
   1.136 +D();
   1.137 +
   1.138 +
   1.139 +
   1.140 +//-----------------------------------------------------------------------------
   1.141 +test();
   1.142 +//-----------------------------------------------------------------------------
   1.143 +
   1.144 +
   1.145 +
   1.146 +/*
   1.147 + * Sort properties alphabetically -
   1.148 + */
   1.149 +function addThis()
   1.150 +{
   1.151 +  statusitems[UBound] = status;
   1.152 +  actualvalues[UBound] = sortThis(actual);
   1.153 +  expectedvalues[UBound] = sortThis(expect);
   1.154 +  UBound++;
   1.155 +}
   1.156 +
   1.157 +
   1.158 +/*
   1.159 + * Takes string of form '({"c", "b", "a", 2})' and returns '({"a","b","c",2})'
   1.160 + */
   1.161 +function sortThis(sList)
   1.162 +{
   1.163 +  sList = compactThis(sList);
   1.164 +  sList = stripParens(sList);
   1.165 +  sList = stripBraces(sList);
   1.166 +  var arr = sList.split(cnCOMMA);
   1.167 +  arr = arr.sort();
   1.168 +  var ret = String(arr);
   1.169 +  ret = addBraces(ret);
   1.170 +  ret = addParens(ret);
   1.171 +  return ret;
   1.172 +}
   1.173 +
   1.174 +
   1.175 +/*
   1.176 + * Strips out any whitespace from the text -
   1.177 + */
   1.178 +function compactThis(text)
   1.179 +{
   1.180 +  var charCode = 0;
   1.181 +  var ret = '';
   1.182 +
   1.183 +  for (var i=0; i<text.length; i++)
   1.184 +  {
   1.185 +    charCode = text.charCodeAt(i);
   1.186 +
   1.187 +    if (!isWhiteSpace(charCode))
   1.188 +      ret += text.charAt(i);
   1.189 +  }
   1.190 +
   1.191 +  return ret;
   1.192 +}
   1.193 +
   1.194 +
   1.195 +function isWhiteSpace(charCode)
   1.196 +{
   1.197 +  switch (charCode)
   1.198 +  {
   1.199 +  case (0x0009):
   1.200 +  case (0x000B):
   1.201 +  case (0x000C):
   1.202 +  case (0x0020):
   1.203 +  case (0x000A):  // '\n'
   1.204 +  case (0x000D):  // '\r'
   1.205 +    return true;
   1.206 +    break;
   1.207 +
   1.208 +  default:
   1.209 +    return false;
   1.210 +  }
   1.211 +}
   1.212 +
   1.213 +
   1.214 +/*
   1.215 + * strips off parens at beginning and end of text -
   1.216 + */
   1.217 +function stripParens(text)
   1.218 +{
   1.219 +  // remember to escape the parens...
   1.220 +  var arr = text.match(/^\((.*)\)$/);
   1.221 +
   1.222 +  // defend against a null match...
   1.223 +  if (arr != null && arr[1] != null)
   1.224 +    return arr[1];
   1.225 +  return text;
   1.226 +}
   1.227 +
   1.228 +
   1.229 +/*
   1.230 + * strips off braces at beginning and end of text -
   1.231 + */
   1.232 +function stripBraces(text)
   1.233 +{
   1.234 +  // remember to escape the braces...
   1.235 +  var arr = text.match(/^\{(.*)\}$/);
   1.236 +
   1.237 +  // defend against a null match...
   1.238 +  if (arr != null && arr[1] != null)
   1.239 +    return arr[1];
   1.240 +  return text;
   1.241 +}
   1.242 +
   1.243 +
   1.244 +function addBraces(text)
   1.245 +{
   1.246 +  return cnLBRACE + text + cnRBRACE;
   1.247 +}
   1.248 +
   1.249 +
   1.250 +function addParens(text)
   1.251 +{
   1.252 +  return cnLPAREN + text + cnRPAREN;
   1.253 +}
   1.254 +
   1.255 +
   1.256 +function test()
   1.257 +{
   1.258 +  enterFunc ('test');
   1.259 +  printBugNumber(BUGNUMBER);
   1.260 +  printStatus (summary);
   1.261 +
   1.262 +  for (var i=0; i<UBound; i++)
   1.263 +  {
   1.264 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   1.265 +  }
   1.266 +
   1.267 +  exitFunc ('test');
   1.268 +}

mercurial