Closed Bug 952403 Opened 11 years ago Closed 11 years ago

Unable to augment "native" JS objects (like Uint8Array instances) with new properties

Categories

(Core :: JavaScript Engine, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 695438

People

(Reporter: feross, Unassigned)

Details

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 Steps to reproduce: Create a new Uint8Array instance and set a property named "foo" on it. Then, try to access it. It doesn't stick. It always returns "undefined". var x = new Uint8Array(4); x.foo = 5; console.log(x.foo); // prints "undefined" x.bar = function () { return 42; } x.bar(); // throws "TypeError: x.b is not a function" Actual results: It appears to be impossible to add properties to certain "native" object instances. It's like Uint8Array instances are special and can't be augmented with properties. This isn't to spec and breaks one of JavaScripts main selling points -- it's flexibility. Specifically, it's making life hard for the "browserify" project. This problem doesn't exist in Chrome, Safari, or IE. Only Firefox. Any idea what design decision is causing this? Can this be fixed? Expected results: Uint8Arrays should behave like every other JS object and be extensible like everything that is `instanceof Object`. This should happen: var x = new Uint8Array(4); x.foo = 5; console.log(x.foo); // prints "5" x.bar = function () { return 42; } x.bar(); // returns 42
Yes, it can be fixed: Typed Arrays used to be specified as non-extensible, so this used to be the specified behavior. However, after some discussions, the specification has been changed, and our implementation will, too. This is tracked in bug 695438.
Status: UNCONFIRMED → RESOLVED
Closed: 11 years ago
Resolution: --- → DUPLICATE
No longer blocks: 939927
You need to log in before you can comment on or make changes to this bug.