Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: messageResponder.js

Issue 29339076: Noissue - Avoid try/catch triggering a deoptimization in message listener (Closed)
Patch Set: Created March 24, 2016, 6:19 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: messageResponder.js
===================================================================
--- a/messageResponder.js
+++ b/messageResponder.js
@@ -40,6 +40,22 @@
var DownloadableSubscription = subscriptionClasses.DownloadableSubscription;
var SpecialSubscription = subscriptionClasses.SpecialSubscription;
+ // Some modules doesn't exist on Firefox. Moreover,
+ // require() throws an exception on Firefox in that case.
+ // However, try/catch causes the whole function to to be
+ // deoptimized on V8. So we wrap it into another function.
+ function tryRequire(module)
+ {
+ try
+ {
+ return require(module);
+ }
+ catch (e)
+ {
+ return null;
+ }
+ }
+
function convertObject(keys, obj)
{
var result = {};
@@ -138,16 +154,7 @@
case "app.get":
if (message.what == "issues")
{
- var subscriptionInit;
- try
- {
- subscriptionInit = require("subscriptionInit");
- }
- catch (e)
- {
- // Expected exception, this module doesn't exist on Firefox
- }
-
+ var subscriptionInit = tryRequire("subscriptionInit");
callback({
filterlistsReinitialized: subscriptionInit ? subscriptionInit.reinitialized : false,
legacySafariVersion: (info.platform == "safari" && (
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld