michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * Date: 28 August 2001 michael@0: * michael@0: * SUMMARY: A [DontEnum] prop, if overridden, should appear in toSource(). michael@0: * See http://bugzilla.mozilla.org/show_bug.cgi?id=90596 michael@0: * michael@0: * NOTE: some inefficiencies in the test are made for the sake of readability. michael@0: * Sorting properties alphabetically is done for definiteness in comparisons. michael@0: */ michael@0: //----------------------------------------------------------------------------- michael@0: var UBound = 0; michael@0: var BUGNUMBER = 90596; michael@0: var summary = 'A [DontEnum] prop, if overridden, should appear in toSource()'; michael@0: var cnCOMMA = ','; michael@0: var cnLBRACE = '{'; michael@0: var cnRBRACE = '}'; michael@0: var cnLPAREN = '('; michael@0: var cnRPAREN = ')'; michael@0: var status = ''; michael@0: var statusitems = []; michael@0: var actual = ''; michael@0: var actualvalues = []; michael@0: var expect= ''; michael@0: var expectedvalues = []; michael@0: var obj = {}; michael@0: michael@0: michael@0: status = inSection(1); michael@0: obj = {toString:9}; michael@0: actual = obj.toSource(); michael@0: expect = '({toString:9})'; michael@0: addThis(); michael@0: michael@0: status = inSection(2); michael@0: obj = {hasOwnProperty:"Hi"}; michael@0: actual = obj.toSource(); michael@0: expect = '({hasOwnProperty:"Hi"})'; michael@0: addThis(); michael@0: michael@0: status = inSection(3); michael@0: obj = {toString:9, hasOwnProperty:"Hi"}; michael@0: actual = obj.toSource(); michael@0: expect = '({toString:9, hasOwnProperty:"Hi"})'; michael@0: addThis(); michael@0: michael@0: status = inSection(4); michael@0: obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}; michael@0: actual = obj.toSource(); michael@0: expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})'; michael@0: addThis(); michael@0: michael@0: michael@0: // TRY THE SAME THING IN EVAL CODE michael@0: var s = ''; michael@0: michael@0: status = inSection(5); michael@0: s = 'obj = {toString:9}'; michael@0: eval(s); michael@0: actual = obj.toSource(); michael@0: expect = '({toString:9})'; michael@0: addThis(); michael@0: michael@0: status = inSection(6); michael@0: s = 'obj = {hasOwnProperty:"Hi"}'; michael@0: eval(s); michael@0: actual = obj.toSource(); michael@0: expect = '({hasOwnProperty:"Hi"})'; michael@0: addThis(); michael@0: michael@0: status = inSection(7); michael@0: s = 'obj = {toString:9, hasOwnProperty:"Hi"}'; michael@0: eval(s); michael@0: actual = obj.toSource(); michael@0: expect = '({toString:9, hasOwnProperty:"Hi"})'; michael@0: addThis(); michael@0: michael@0: status = inSection(8); michael@0: s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}'; michael@0: eval(s); michael@0: actual = obj.toSource(); michael@0: expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})'; michael@0: addThis(); michael@0: michael@0: michael@0: // TRY THE SAME THING IN FUNCTION CODE michael@0: function A() michael@0: { michael@0: status = inSection(9); michael@0: var s = 'obj = {toString:9}'; michael@0: eval(s); michael@0: actual = obj.toSource(); michael@0: expect = '({toString:9})'; michael@0: addThis(); michael@0: } michael@0: A(); michael@0: michael@0: function B() michael@0: { michael@0: status = inSection(10); michael@0: var s = 'obj = {hasOwnProperty:"Hi"}'; michael@0: eval(s); michael@0: actual = obj.toSource(); michael@0: expect = '({hasOwnProperty:"Hi"})'; michael@0: addThis(); michael@0: } michael@0: B(); michael@0: michael@0: function C() michael@0: { michael@0: status = inSection(11); michael@0: var s = 'obj = {toString:9, hasOwnProperty:"Hi"}'; michael@0: eval(s); michael@0: actual = obj.toSource(); michael@0: expect = '({toString:9, hasOwnProperty:"Hi"})'; michael@0: addThis(); michael@0: } michael@0: C(); michael@0: michael@0: function D() michael@0: { michael@0: status = inSection(12); michael@0: var s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}'; michael@0: eval(s); michael@0: actual = obj.toSource(); michael@0: expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})'; michael@0: addThis(); michael@0: } michael@0: D(); michael@0: michael@0: michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: test(); michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: michael@0: michael@0: /* michael@0: * Sort properties alphabetically - michael@0: */ michael@0: function addThis() michael@0: { michael@0: statusitems[UBound] = status; michael@0: actualvalues[UBound] = sortThis(actual); michael@0: expectedvalues[UBound] = sortThis(expect); michael@0: UBound++; michael@0: } michael@0: michael@0: michael@0: /* michael@0: * Takes string of form '({"c", "b", "a", 2})' and returns '({"a","b","c",2})' michael@0: */ michael@0: function sortThis(sList) michael@0: { michael@0: sList = compactThis(sList); michael@0: sList = stripParens(sList); michael@0: sList = stripBraces(sList); michael@0: var arr = sList.split(cnCOMMA); michael@0: arr = arr.sort(); michael@0: var ret = String(arr); michael@0: ret = addBraces(ret); michael@0: ret = addParens(ret); michael@0: return ret; michael@0: } michael@0: michael@0: michael@0: /* michael@0: * Strips out any whitespace from the text - michael@0: */ michael@0: function compactThis(text) michael@0: { michael@0: var charCode = 0; michael@0: var ret = ''; michael@0: michael@0: for (var i=0; i