Closed Bug 1773882 Opened 3 years ago Closed 3 years ago

setter & getter of an array are displayed as undefined

Categories

(DevTools :: Shared Components, defect, P3)

Firefox 101
defect

Tracking

(firefox103 fixed)

RESOLVED FIXED
103 Branch
Tracking Status
firefox103 --- fixed

People

(Reporter: Krischna, Assigned: arai)

Details

Attachments

(2 files)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:101.0) Gecko/20100101 Firefox/101.0

Steps to reproduce:

  1. Go into the console.
  2. Execute this snippet:
var arr1=[],obj1={}
Object.defineProperty(arr1,0,{get: ()=>"Value"})
Object.defineProperty(obj1,"a",{get: ()=>"Value"})
var arr2=[],obj2={}
Object.defineProperty(arr2,0,{get: ()=>"Value", enumerable: true})
Object.defineProperty(obj2,"a",{get: ()=>"Value", enumerable: true})
console.log(arr1,obj1)
console.log(arr2,obj2)
console.log([...arr1],{...obj1})
console.log([...arr2],{...obj2})

Getters may also be replaced with setters. It has the same effect.

Actual results:

The getter in the arrays are displayed as undefined. Though they behave like getters.
Array [ undefined ] Object { … }
Array [ undefined ] Object { a: Getter }
Array [ "Value" ] Object { }
Array [ "Value" ] Object { a: "Value" }

Expected results:

The setter in the array should be displayed as such.
NodeJS, as an example, gets it right:
[ [Setter] ] {}
[ [Setter] ] { a: [Setter] }
[ undefined ] {}
[ undefined ] { a: undefined }

Edit:
copypasted the wrong output from NodeJS and I can't seem to be able to edit the post.
Here the correct output from NodeJS:

[ [Getter] ] {}
[ [Getter] ] { a: [Getter] }
[ 'Value' ] {}
[ 'Value' ] { a: 'Value' }

The formatting is done in DevTools, grip-array.js and accessor.js

Component: JavaScript Engine → Shared Components
Product: Core → DevTools

The undefined comes from the following:

https://searchfox.org/mozilla-central/rev/a8bdd0feeb7ae596a202333ee324a68153f9f4c4/devtools/server/actors/object/previewers.js#197-198,213-214,221-222,226,228-229

Array: [
  function({ obj, hooks }, grip) {
...
    for (let i = 0; i < length; ++i) {
      if (raw && !isWorker) {
...
        const desc = Object.getOwnPropertyDescriptor(Cu.waiveXrays(raw), i);
        if (desc && !desc.get && !desc.set) {
...
        } else if (!desc) {
...
        } else {
          items.push(hooks.createValueGrip(undefined));
Assignee: nobody → arai.unmht
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Severity: -- → S3
Priority: -- → P3
Pushed by arai_a@mac.com: https://hg.mozilla.org/integration/autoland/rev/0646b8bb3ec5 Show getter/setter in array element. r=nchevobbe https://hg.mozilla.org/integration/autoland/rev/e033ff580f53 Part 2: Add more testcase. r=nchevobbe
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 103 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: