Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(431)

Unified Diff: ios/web/web_state/js/resources/common.js

Issue 2807213003: Move stringify, form, navigation and scroll methods out of core.js. (Closed)
Patch Set: Re-upload patch after rebase-update in local branch Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/web/web_state/js/core_js_unittest.mm ('k') | ios/web/web_state/js/resources/core.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/web_state/js/resources/common.js
diff --git a/ios/web/web_state/js/resources/common.js b/ios/web/web_state/js/resources/common.js
index 56adb250ff7019be9cc1ec763fcc2b014c187381..81d0df149cdc2ed5a7975d4af07266ea093a312d 100644
--- a/ios/web/web_state/js/resources/common.js
+++ b/ios/web/web_state/js/resources/common.js
@@ -26,6 +26,7 @@ __gCrWeb['common'] = __gCrWeb.common;
/* Beginning of anonymous object. */
(function() {
+
/**
* JSON safe object to protect against custom implementation of Object.toJSON
* in host pages.
@@ -46,6 +47,31 @@ __gCrWeb['common'] = __gCrWeb.common;
__gCrWeb.common.JSONStringify = JSON.stringify;
/**
+ * Returns a string that is formatted according to the JSON syntax rules.
+ * This is equivalent to the built-in JSON.stringify() function, but is
+ * less likely to be overridden by the website itself. Prefer the private
+ * {@code __gcrWeb.common.JSONStringify} whenever possible instead of using
+ * this public function. The |__gCrWeb| object itself does not use it; it uses
+ * its private counterpart instead.
+ */
+ __gCrWeb['stringify'] = function(value) {
+ if (value === null)
+ return 'null';
+ if (value === undefined)
+ return 'undefined';
+ if (typeof(value.toJSON) == 'function') {
+ // Prevents websites from changing stringify's behavior by adding the
+ // method toJSON() by temporarily removing it.
+ var originalToJSON = value.toJSON;
+ value.toJSON = undefined;
+ var stringifiedValue = __gCrWeb.common.JSONStringify(value);
+ value.toJSON = originalToJSON;
+ return stringifiedValue;
+ }
+ return __gCrWeb.common.JSONStringify(value);
+ };
+
+ /**
* Prefix used in references to form elements that have no 'id' or 'name'
*/
__gCrWeb.common.kNamelessFormIDPrefix = 'gChrome~';
@@ -689,4 +715,5 @@ __gCrWeb['common'] = __gCrWeb.common;
}
return false;
};
+
}()); // End of anonymous object
« no previous file with comments | « ios/web/web_state/js/core_js_unittest.mm ('k') | ios/web/web_state/js/resources/core.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698