archives

« Bugzilla Issues Index

#2639 — Insufficiently severe restriction in KeyedDestructuringAssignmentEvaluation


The 12.14.5.4 section 4.b restricts Object type is only allowed in destructuring assignment.
e.g.
```javascript
let {text: {length}} = {text: "string"}
```
is invalid due this restriction.

But before 12.14.5.4 section 1 there is no such check and this code:
```javascript
let {length} = "string"
```
is valid.

So I think it should be:
12.14.5.4 Runtime Semantics: KeyedDestructuringAssignmentEvaluation
with parameters obj and propertyName
AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt
1. If Type(obj) is not Object, then throw a TypeError exception.
2. Let v be Get(obj, name)

IMHO: this restriction is killing the free spirit of javascript


see 12.14.4 step 6


@Allen Wirfs-Brock
> see 12.14.4 step 6
step 6 in wich section?
"AssignmentExpression[In, Yield] : LeftHandSideExpression[?Yield] = AssignmentExpression[?In, ?Yield]" or in "AssignmentExpression : LeftHandSideExpression AssignmentOperator AssignmentExpression" ?
Neither of them does not fit the:
```javascript
let {length} = "string";
```


"12.14.5 Destructuring Assignment" does not apply to `let {...} = ...`. Instead you need to look at "13.2.3 Destructuring Binding Patterns".

`let {text: {length}} = {text: "string"}` throws a TypeError per "13.2.3.7 Runtime Semantics: KeyedBindingInitialization".

`let {length} = "string"` throws a TypeError per "13.2.1.4 Runtime Semantics: Evaluation".