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

Unified Diff: extensions/renderer/resources/utils.js

Issue 1915753002: Sanitize inheritance in callers of utils.expose (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit: space after ':' Created 4 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
Index: extensions/renderer/resources/utils.js
diff --git a/extensions/renderer/resources/utils.js b/extensions/renderer/resources/utils.js
index fd70c603ddffe295c6dc31d8efe495ca82c0760b..26aa5e8ed3e4b30bae4ccde6ab0dddaad5583671 100644
--- a/extensions/renderer/resources/utils.js
+++ b/extensions/renderer/resources/utils.js
@@ -64,6 +64,23 @@ function loadTypeSchema(typeName, defaultSchema) {
}
/**
+ * Sets a property |value| on |obj| with property name |key|. Like
+ *
+ * obj[key] = value;
+ *
+ * but without triggering setters.
+ */
+function defineProperty(obj, key, value) {
+ $Object.defineProperty(obj, key, {
+ __proto__: null,
+ configurable: true,
+ enumerable: true,
+ writable: true,
+ value: value,
+ });
+}
+
+/**
* Takes a private class implementation |privateClass| and exposes a subset of
* its methods |functions| and properties |properties| and |readonly| to a
* public wrapper class that should be passed in. Within bindings code, you can
@@ -90,8 +107,7 @@ function loadTypeSchema(typeName, defaultSchema) {
* properties and |readonly| are read-only properties.
*/
function expose(publicClass, privateClass, exposed) {
- // TODO(robwu): Fix callers and uncomment this assertion.
- // DCHECK(!(privateClass instanceof $Object.self));
+ DCHECK(!(privateClass.prototype instanceof $Object.self));
$Object.setPrototypeOf(exposed, null);
@@ -218,6 +234,7 @@ function promise(func) {
exports.$set('forEach', forEach);
exports.$set('loadTypeSchema', loadTypeSchema);
exports.$set('lookup', lookup);
+exports.$set('defineProperty', defineProperty);
exports.$set('expose', expose);
exports.$set('deepCopy', deepCopy);
exports.$set('promise', promise);
« no previous file with comments | « extensions/renderer/resources/messaging.js ('k') | extensions/renderer/resources/web_request_internal_custom_bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698