Closed Bug 526979 Opened 15 years ago Closed 15 years ago

unexpected shared property value between object instance

Categories

(Core :: JavaScript Engine, defect)

x86
Windows XP
defect
Not set
major

Tracking

()

RESOLVED INVALID

People

(Reporter: soubok, Unassigned)

Details

Attachments

(1 file)

The *vp value of a property getter seems to not be stored on the obj object.

In the following case:
  var oa = new MyClass;
  Print(oa.myProperty); // prints 1
  var ob = new MyClass;
  Print(ob.myProperty); // prints 1, expect 2

myProperty is define like this:
JSBool MyProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) {
  if ( *vp != JSVAL_VOID )
    return JS_TRUE;
  *vp = INT_TO_JSVAL(index);
  index++;
  return JS_TRUE;
}
Attached file testcase
The value is stored on the object's prototype.
(In reply to comment #2)
> The value is stored on the object's prototype.

That's where you defined the property, and your MyProperty getter did nothing to override in the obj instance. Fix it to JS_SetProperty(cx, obj, id, vp) and you get what you want.

/be
Status: NEW → RESOLVED
Closed: 15 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: