Closed Bug 646599 Opened 13 years ago Closed 12 years ago

Constant folding should happen before deciding whether to turn obj["A"] into obj.A

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla17

People

(Reporter: jruderman, Assigned: evilpie)

Details

(Keywords: testcase)

Attachments

(1 file, 1 obsolete file)

jsfunfuzz's round-trip checker caught this:

js> (function() { return t["a" + "b"]; })
(function () {return t["ab"];})
js> (function () {return t["ab"];})
(function () {return t.ab;})
OS: Mac OS X → All
Hardware: x86 → All
Another instance:

js> (function() { return t[true ? 'a' : 'b']; })
(function () {return t["a"];})
js> (function () {return t["a"];})
(function () {return t.a;})
Attached patch v1 (obsolete) — Splinter Review
Just do the folding manually before we decide whether to use obj.prop or obj[prop].

Really short patch, I hope this is okay for you Jeff.
Assignee: general → evilpies
Status: NEW → ASSIGNED
Attachment #642207 - Flags: review?(jwalden+bmo)
Attached patch v1 with testsSplinter Review
Sorry forgot to hg add the test.
Attachment #642207 - Attachment is obsolete: true
Attachment #642207 - Flags: review?(jwalden+bmo)
Attachment #642208 - Flags: review?(jwalden+bmo)
Comment on attachment 642208 [details] [diff] [review]
v1 with tests

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

::: js/src/frontend/Parser.cpp
@@ +5833,5 @@
>                  }
>              } else if (propExpr->isKind(PNK_NUMBER)) {
> +                Value number = NumberValue(propExpr->pn_dval);
> +                uint32_t dummy;
> +                if (!IsDefinitelyIndex(number, &dummy)) {

Please use (propExpr->pn_dval == ToUint32(propExpr->pn_dval)) to check for index-ness -- much better than relying on a method that sometimes gives the wrong answer and must itself be double-checked.

::: js/src/jit-test/tests/basic/testFoldPropertyAccess.js
@@ +17,5 @@
> +    }
> +]
> +
> +for (var i = 0; i < cases.length; i++) {
> +    dis(cases[i]);

Remove this.
Attachment #642208 - Flags: review?(jwalden+bmo) → review+
https://hg.mozilla.org/mozilla-central/rev/28711b9f49cd
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla17
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: