Array.prototype.shift does not preserve holes

VERIFIED FIXED

Status

()

VERIFIED FIXED
12 years ago
12 years ago

People

(Reporter: igor, Assigned: igor)

Tracking

({verified1.8.1})

Trunk
verified1.8.1
Points:
---
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(Not tracked)

Details

(Assignee)

Description

12 years ago
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.
(Assignee)

Comment 3

12 years ago
(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.
(Assignee)

Comment 5

12 years ago
Fixed as part of the patch for bug 322135.
Status: NEW → RESOLVED
Last Resolved: 12 years ago
Keywords: fixed1.8.1
Resolution: --- → FIXED

Comment 6

12 years ago
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+

Comment 7

12 years ago
verified fixed 1.8, 1.9 20060821 windows/mac*/linux
Status: RESOLVED → VERIFIED
Keywords: fixed1.8.1 → verified1.8.1
You need to log in before you can comment on or make changes to this bug.