Closed Bug 1304955 Opened 8 years ago Closed 8 years ago

Tagged template literals parses incorrect from startup cache

Categories

(Core :: JavaScript Engine, defect, P1)

51 Branch
defect

Tracking

()

RESOLVED FIXED
mozilla52
Tracking Status
firefox49 --- unaffected
firefox50 --- unaffected
firefox51 + fixed
firefox52 - fixed

People

(Reporter: zbinlin, Assigned: emilio)

References

Details

(Keywords: regression)

Attachments

(1 file)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:51.0) Gecko/20100101 Firefox/51.0
Build ID: 20160922181628

Steps to reproduce:

New file /tmp/test.js:
```javascript
function foo(val) {
	return val;
}

console.assert("bar" === foo(`bar`));
console.assert("bar" === (foo`bar`)[0]);
console.assert("bar" === foo(String.raw`bar`));
```

Load by `loadSubScriptWithOptions`:
```javascript
Services.scriptloader.loadSubScriptWithOptions("file:///tmp/test.js", {
    target: {},
    ignoreCache: false,
}); // load and cache

Services.scriptloader.loadSubScriptWithOptions("file:///tmp/test.js", {
    target: {},
    ignoreCache: false,
}); // load from startup cache
```
Looks like XDR bug around callsiteobj.

regression range:
https://hg.mozilla.org/integration/mozilla-inbound/pushloghtml?fromchange=41d8277af19246308bdf51bf0cd60da3498681b1&tochange=5c6582975b9ddaac43260767af201294849ac9a6

so this seems to be from bug 1283334.


simplified testcase for js shell:
  var code = cacheEntry("assertEq('bar', String.raw`bar`);");
  var g = newGlobal({ cloneSingletons: true });
  evaluate(code, { global: g, saveBytecode: true });
  evaluate(code, { global: g, loadBytecode: true });

the following code shows that different object is passed to function:
  var code = cacheEntry("(x => x.toSource())`bar`;");
  var g = newGlobal({ cloneSingletons: true });
  print(evaluate(code, { global: g, saveBytecode: true })); // ["bar"]
  print(evaluate(code, { global: g, loadBytecode: true })); // [,]
Blocks: 1283334
Status: UNCONFIRMED → NEW
Component: Untriaged → JavaScript Engine
Ever confirmed: true
Keywords: regression
Product: Firefox → Core
Leo, is this something we can fix in 51?
Flags: needinfo?(leo)
Not sure what the best way is to test this, any pointers arai?
Flags: needinfo?(arai.unmht)
Comment on attachment 8802764 [details]
Bug 1304955: Call site objects now store their elements as dense after bug 1283334.

https://reviewboard.mozilla.org/r/87060/#review86120

I'd forward this review to jandem.

About test, code in comment #1 will work.
  var code = cacheEntry("assertEq('bar', String.raw`bar`);");
  var g = newGlobal({ cloneSingletons: true });
  evaluate(code, { global: g, saveBytecode: true });
  evaluate(code, { global: g, loadBytecode: true });

or, change the following test to check the value of tagged template.
https://hg.mozilla.org/mozilla-central/annotate/f40960c63bfac865d510ec9da42eeed74c384082/js/src/jit-test/tests/xdr/trivial.js#l40
> // code call site object
> test = "function f(a) { return a; }; f`a${4}b`;";
> evalWithCache(test, { assertEqBytecode: true, checkFrozen: true});
Attachment #8802764 - Flags: review?(jdemooij)
Flags: needinfo?(arai.unmht)
Attachment #8802764 - Flags: review?(arai.unmht)
Comment on attachment 8802764 [details]
Bug 1304955: Call site objects now store their elements as dense after bug 1283334.

https://reviewboard.mozilla.org/r/87060/#review86552

Thanks for fixing this. r=me with comments below addressed.

::: js/src/jit-test/tests/xdr/tagged-template-literals.js:1
(Diff revision 2)
> +var code = cacheEntry("assertEq('bar', String.raw`bar`);");

Please also add a test based on the second test in comment 1, and assert the array is what we expect.

::: js/src/jsobj.cpp:1151
(Diff revision 2)
>  
>  static bool
>  GetScriptArrayObjectElements(JSContext* cx, HandleObject obj, MutableHandle<GCVector<Value>> values)
>  {
>      MOZ_ASSERT(!obj->isSingleton());
>      MOZ_ASSERT(obj->is<ArrayObject>() || obj->is<UnboxedArrayObject>());

We should assert the array has no sparse elements: MOZ_ASSERT(!obj->isIndexed());
Attachment #8802764 - Flags: review?(jdemooij) → review+
Regression, we should fix this before it's released.
Priority: -- → P1
Assignee: nobody → ecoal95
Pushed by ecoal95@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/49246df91b04
Call site objects now store their elements as dense after bug 1283334. r=jandem
https://hg.mozilla.org/mozilla-central/rev/49246df91b04
Status: NEW → RESOLVED
Closed: 8 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla52
Track 51+ as regression.

Hi :emilio,
Since this also affects 51, do you think the patch is worth uplifting to 51?
Flags: needinfo?(ecoal95)
Comment on attachment 8802764 [details]
Bug 1304955: Call site objects now store their elements as dense after bug 1283334.

Approval Request Comment
[Feature/regressing bug #]: bug 1283334
[User impact if declined]: JS regression.
[Describe test coverage new/current, TreeHerder]: Automated tests added in the patch.
[Risks and why]: Low, tested negative-diff fix.
[String/UUID change made/needed]: None
Flags: needinfo?(ecoal95)
Attachment #8802764 - Flags: approval-mozilla-aurora?
Thanks for reminding me Gerry, I meant to have done this before :)
Comment on attachment 8802764 [details]
Bug 1304955: Call site objects now store their elements as dense after bug 1283334.

Fix a regression and add tests. Take it in 51 aurora.
Attachment #8802764 - Flags: approval-mozilla-aurora? → approval-mozilla-aurora+
Tracking 52- since this is now fixed on central.
Flags: needinfo?(leo)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: