Skip to content

Commit

Permalink
Expose default report handler.
Browse files Browse the repository at this point in the history
This will allow Gerrit to easily turn on logging without loading the
uncompiled standalone version in production.

Tested:
Ran all package tests.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=158904142
  • Loading branch information
msamuel authored and mikesamuel committed Jun 13, 2017
1 parent 5fa3683 commit 42b78e5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 20 deletions.
46 changes: 34 additions & 12 deletions polymer-resin.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,38 @@ security.polymer_resin.ReportHandler;
security.polymer_resin.ValueHandler;


/**
* A report handler that logs to the browser's developer console.
* <p>
* This report handler is used if none is explicitly specified and
* goog.DEBUG is true at install time.
* <p>
* Violations (see isViolation in ReportHandler docs) are logged as warnings.
* Logging an error while running tests causes some unit testing frameworks
* to report the test as failing. Tests that wish to assert that polymer-resin
* is denying a value can instead check for the innocuous value.
* <p>
* Exceptions thrown by a report handler will propagate out of polymer-resin
* so a test suite may install a report handler that throws if unsafe
* value assignment should correspond to test failure.
*
* @type {!security.polymer_resin.ReportHandler}
* @const
*/
security.polymer_resin.CONSOLE_LOGGING_REPORT_HANDLER =
function (isViolation, formatString, var_args) {
var consoleArgs = [formatString];
for (var i = 2, n = arguments.length; i < n; ++i) {
consoleArgs[i - 1] = arguments[i];
}
if (isViolation) {
console.warn.apply(console, consoleArgs);
} else {
console.log.apply(console, consoleArgs);
}
};


/**
* When called with (true), disallowed values will not be replaced so may reach
* unsafe browser sinks resulting in a security violation.
Expand Down Expand Up @@ -256,18 +288,8 @@ security.polymer_resin.install = function (opt_config) {

if (goog.DEBUG && security.polymer_resin.reportHandler_ === undefined
&& typeof console !== 'undefined') {
security.polymer_resin.reportHandler_ =
function (isViolation, formatString, var_args) {
var consoleArgs = [formatString];
for (var i = 2, n = arguments.length; i < n; ++i) {
consoleArgs[i - 1] = arguments[i];
}
if (isViolation) {
console.warn.apply(console, consoleArgs);
} else {
console.log.apply(console, consoleArgs);
}
};
security.polymer_resin.setReportHandler_(
security.polymer_resin.CONSOLE_LOGGING_REPORT_HANDLER);
}

// TODO: check not in IE quirks mode.
Expand Down
17 changes: 9 additions & 8 deletions standalone/polymer-resin-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -2954,6 +2954,12 @@ security.polymer_resin.classifyElement = function(name, ctor) {
}
return customElementsRegistry && customElementsRegistry.get(name) || security.polymer_resin.docRegisteredElements_[name] === security.polymer_resin.docRegisteredElements_ ? security.polymer_resin.CustomElementClassification.CUSTOM : ctor === HTMLUnknownElement ? security.polymer_resin.CustomElementClassification.LEGACY : ctor === HTMLElement && security.polymer_resin.VALID_CUSTOM_ELEMENT_NAME_REGEX_.test(name) ? security.polymer_resin.CustomElementClassification.CUSTOMIZABLE : security.polymer_resin.CustomElementClassification.BUILTIN;
};
security.polymer_resin.CONSOLE_LOGGING_REPORT_HANDLER = function(isViolation, formatString, var_args) {
for (var consoleArgs = [formatString], i = 2, n = arguments.length; i < n; ++i) {
consoleArgs[i - 1] = arguments[i];
}
isViolation ? console.warn.apply(console, consoleArgs) : console.log.apply(console, consoleArgs);
};
security.polymer_resin.UNSAFE_passThruDisallowedValues_ = function(enable) {
goog.DEBUG && (security.polymer_resin.allowUnsafeValues_ = !0 === enable);
};
Expand Down Expand Up @@ -3043,18 +3049,13 @@ security.polymer_resin.install = function(opt_config) {
var configUnsafePassThruDisallowedValues = opt_config.UNSAFE_passThruDisallowedValues, configAllowedIdentifierPrefixes = opt_config.allowedIdentifierPrefixes, configReportHandler = opt_config.reportHandler;
null != configUnsafePassThruDisallowedValues && security.polymer_resin.UNSAFE_passThruDisallowedValues_(configUnsafePassThruDisallowedValues);
if (configAllowedIdentifierPrefixes) {
for (var i$jscomp$0 = 0, n$jscomp$0 = configAllowedIdentifierPrefixes.length; i$jscomp$0 < n$jscomp$0; ++i$jscomp$0) {
security.polymer_resin.allowIdentifierWithPrefix_(configAllowedIdentifierPrefixes[i$jscomp$0]);
for (var i = 0, n = configAllowedIdentifierPrefixes.length; i < n; ++i) {
security.polymer_resin.allowIdentifierWithPrefix_(configAllowedIdentifierPrefixes[i]);
}
}
void 0 !== configReportHandler && security.polymer_resin.setReportHandler_(configReportHandler);
}
goog.DEBUG && void 0 === security.polymer_resin.reportHandler_ && "undefined" !== typeof console && (security.polymer_resin.reportHandler_ = function(isViolation, formatString, var_args) {
for (var consoleArgs = [formatString], i = 2, n = arguments.length; i < n; ++i) {
consoleArgs[i - 1] = arguments[i];
}
isViolation ? console.warn.apply(console, consoleArgs) : console.log.apply(console, consoleArgs);
});
goog.DEBUG && void 0 === security.polymer_resin.reportHandler_ && "undefined" !== typeof console && security.polymer_resin.setReportHandler_(security.polymer_resin.CONSOLE_LOGGING_REPORT_HANDLER);
security.polymer_resin.reportHandler_ && security.polymer_resin.reportHandler_(!1, "initResin");
var uncustomizedProxies = {}, VANILLA_HTML_ELEMENT_ = document.createElement("polyresinuncustomized");
if (/^1\./.test(Polymer.version)) {
Expand Down

0 comments on commit 42b78e5

Please sign in to comment.