Closed Bug 345961 Opened 18 years ago Closed 18 years ago

Array.prototype.shift does not preserve holes

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

VERIFIED FIXED

People

(Reporter: igor, Assigned: igor)

Details

(Keywords: verified1.8.1)

Consider the following test case:

var expected = false;

var array = new Array(2);
array.shift();
var actual = array.hasOwnProperty(0);

if (actual !== expected)
        print("BAD");


Currently it prints BAD when run against jsshell as Array.prototype.shift treats holes or non-existing properties as properties with value "undefined" in disagreement with ECMA-256 15.4.4.9.
Try next script at URL bar(merge to single line). 
Alert says '1/true,false' when Seamonkey trunk 2006072410 build.

javascript:var a=new Array(2);a.shift();
var x=new Array();x[0]=a.hasOwnProperty(0);x[1]=a.hasOwnProperty(1);
alert(a.length+'/'+String(x));

INVALID, as far as script statements are executed by JavaScript 1.5 or later.

> with value "undefined"

Is "undefined" really returned?
Do you put 'actual=array.hasOwnProperty(0);' in <script language='JavaScript1.X'> where X is 0 to 4?
What browser do you use? What is the version/build-ID of the browser?
Or problem when mailer of Mozilla family? 
Comment #1 is test result on MS Win-2K.
(In reply to comment #1)
> Try next script at URL bar(merge to single line). 
> Alert says '1/true,false' when Seamonkey trunk 2006072410 build.
> INVALID, as far as script statements are executed by JavaScript 1.5 or later.

The expected result according to ECMA-262 v3 should be 1/false,false as non-existing properties or holes should not be replaced with the value "unddefined". Note that Array.prototype.shift does preserve holes as after 

a=Array(1); a.shift(1); print(a.hasOwnProperty(1))
false is printed.

> What browser do you use? What is the version/build-ID of the browser?

The test case is for js shell.
OS: Linux → All
Hardware: PC → All
(In reply to comment #3)
> The expected result according to ECMA-262 v3 should be 1/false,false as
> non-existing properties
Oh, sorry for my misunderstanding of the problem and spam comments.
Fixed as part of the patch for bug 322135.
Status: NEW → RESOLVED
Closed: 18 years ago
Keywords: fixed1.8.1
Resolution: --- → FIXED
Checking in regress-345961.js;
/cvsroot/mozilla/js/tests/js1_5/Array/regress-345961.js,v  <--  regress-345961.js
initial revision: 1.1
Flags: in-testsuite+
verified fixed 1.8, 1.9 20060821 windows/mac*/linux
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.