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

Unified Diff: safari/ext/background.js

Issue 6595500853690368: Issue 2172 - Parse URLs lazily on Safari to fix initlization on Safari <=6 (Closed)
Patch Set: Created March 19, 2015, 11:37 a.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: safari/ext/background.js
===================================================================
--- a/safari/ext/background.js
+++ b/safari/ext/background.js
@@ -167,11 +167,34 @@
var pages = Object.create(null);
var pageCounter = 0;
+ var Frame = function(url, parent)
+ {
+ this._urlString = url;
+ this._urlObj = null;
+
+ this.parent = parent;
+ }
+ Frame.prototype = {
+ get url()
+ {
+ // On Safari 6 and before, the URL constuctor doesn't exist.
+ // The "urls" module provides a polifill, but it might not
+ // be loaded yet. So we have to lazily parse URLs.
+ if (!this._urlObj)
+ {
+ this._urlObj = new URL(this._urlString);
+ this._urlString = null;
kzar 2015/03/19 15:35:10 Nit: Shouldn't we do `delete this._urlString` here
Sebastian Noack 2015/03/19 16:45:12 I try to be careful not to mess with the optimizer
+ }
+
+ return this._urlObj;
+ }
+ };
+
var Page = function(id, tab, url)
{
this._id = id;
this._tab = tab;
- this._frames = [{url: new URL(url), parent: null}];
+ this._frames = [new Frame(url, null)];
if (tab.page)
this._messageProxy = new ext._MessageProxy(tab.page);
@@ -616,7 +639,7 @@
}
frameId = page._frames.length;
- page._frames.push({url: new URL(message.url), parent: parentFrame});
+ page._frames.push(new Frame(message.url, parentFrame));
}
event.message = {pageId: pageId, frameId: frameId};
break;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld