Typed array constructors should not work without "new" per spec

RESOLVED FIXED in Firefox 44

Status

()

defect
RESOLVED FIXED
5 years ago
4 years ago

People

(Reporter: bzbarsky, Assigned: evilpie)

Tracking

({dev-doc-complete, site-compat})

unspecified
mozilla44
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(firefox44 fixed)

Details

(Whiteboard: [DocArea=JS])

Attachments

(1 attachment)

Per current ES6 spec, this expression:

  Uint8Array()

at global scope should throw, because the this object will not be a Uint8Array object.

Currently Chrome and Safari do what the spec says.  We and IE treat it the same as "new Uint8Array()".

We should either fix this or get the spec fixed (e.g. for Array() the spec allows the variant without "new").

Note that there are extension compat problems here, by the way; the Add-On SDK has stuff like:

  return Uint8Array(TextEncoder(encoding).encode(subject).buffer);
Blocks: es6
Keywords: dev-doc-needed
Whiteboard: [DocArea=JS]
Filed bug 980962 to get our own house in order.
Depends on: 980962
(In reply to Boris Zbarsky [:bz] from comment #0)
> Note that there are extension compat problems here, by the way; the Add-On
> SDK has stuff like:
> 
>   return Uint8Array(TextEncoder(encoding).encode(subject).buffer);

this shouldn't be too big of a problem. this issue is:

a) localized to one module file (plus a unit test)
b) relatively new, "shipped" less then 3 months ago with SDK 1.15
a) in a low-level module, with lesser guarantees for stability (marked 'experimental')
c) introduced with SDK 1.15, which (by default) creates addons that use modules built into firefox

so in my estimate, fixing one file and uplifting it to firefox should not result in too big compat problems.
Depends on: 980989
Ah, didn't realize this part of the SDK was new.  Hopefully none of the addons that include that are using it, then.

Note that I plan to fix this tree-wide in bug 980962.
ah, the product/component of bug 980962 threw me off.

ok, removing dependance and renaming 980989 to our "sync up trees" bug..
No longer depends on: 980989
OS: Mac OS X → All
Hardware: x86 → All
Depends on: 997973
Depends on: 1108261
No longer blocks: es6
Chrome already requires `new`. So maybe we can do this now?
Assignee: nobody → evilpies
Depends on: 1120432
Try push https://treeherder.mozilla.org/#/jobs?repo=try&revision=14da7f820040 looks good to me. I hope we can land this without breaking the internet :)
Attachment #8673883 - Flags: review?(efaustbmo)
Comment on attachment 8673883 [details] [diff] [review]
Throw when invoking a typed array constructor without new

Review of attachment 8673883 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks!
Attachment #8673883 - Flags: review?(efaustbmo) → review+
https://hg.mozilla.org/mozilla-central/rev/31561a5ce4de
https://hg.mozilla.org/mozilla-central/rev/f7e8784f32b9
Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla44
You need to log in before you can comment on or make changes to this bug.