Skip to content

Commit

Permalink
Fix standalone JS
Browse files Browse the repository at this point in the history
It's surprisingly hard to test precompiled JS using the internal build rules
so I plan to figure out how to do the test process below as a sh_test.

There are a few issues addressed here:
1. This fixes compiled code envelopes to be compatible with strict mode.

    In strict mode, a `this` value of null is not replaced with the
    global object.

    goog.global = this;

    and goog.exportSymbol installs the symbols into goog.global
    by default.
2. Exports need to happen after definition.
3. The curated polymer-1.0 externs do not include some symbols
   leading to renaming of those symbols in standalone/polymer-resin.js.
Tested:
Built //third_party/javascript/security/polymer_resin:all,
copied the public tarball to a temp directory and did
$ tar xf polymer_resin_public.tar
$ npm install bower web-component-tester; bower install
$ ./run_tests.sh -l chrome

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=159026669
  • Loading branch information
msamuel authored and mikesamuel committed Jun 14, 2017
1 parent 67dd0bf commit de72ae9
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 32 deletions.
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"**/.*",
"**/*~",
"**/*.md",
"*-test.html",
"*-test.js",
"**/*-test.html",
"**/*-test.js",
"run_tests.sh",
"images/**",
"node_modules",
Expand Down
24 changes: 11 additions & 13 deletions polymer-resin.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,6 @@ security.polymer_resin.setReportHandler_ = function (reportHandler) {
security.polymer_resin.reportHandler_ = reportHandler || null;
};



if (security.polymer_resin.STANDALONE) {
goog.exportSymbol(
'security.polymer_resin.install',
security.polymer_resin.install);

goog.exportSymbol(
'security.polymer_resin.CONSOLE_LOGGING_REPORT_HANDLER',
security.polymer_resin.CONSOLE_LOGGING_REPORT_HANDLER);
}


/**
* @type {!RegExp}
* @private
Expand Down Expand Up @@ -788,3 +775,14 @@ security.polymer_resin.VALUE_HANDLERS_[
typeToUnwrap: goog.string.Const,
unwrap: goog.string.Const.unwrap
};


if (security.polymer_resin.STANDALONE) {
goog.exportSymbol(
'security.polymer_resin.install',
security.polymer_resin.install);

goog.exportSymbol(
'security.polymer_resin.CONSOLE_LOGGING_REPORT_HANDLER',
security.polymer_resin.CONSOLE_LOGGING_REPORT_HANDLER);
}
7 changes: 5 additions & 2 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export TEST_ROOT_DIR="$(mktemp -d "$TMPDIR"/wct_root.XXXXXXXXXX)"
[ -d "$TEST_ROOT_DIR" ]


# `copy_over $d $f` copies $f to the relative path $d/$f under the
# test root creating parent directories as necessary.
function copy_over() {
local D="$1"
local F="$2"
Expand All @@ -31,7 +33,7 @@ function copy_over() {

pushd "$SRC_DIR"

for f in *test.{html,js}
for f in *test.{html,js} standalone/*.{html,js}
do
copy_over polymer-resin "$f"
done
Expand All @@ -53,7 +55,8 @@ echo '
WCT.loadSuites([' \
> "$TEST_SUITE_HTML"

for f in *test.html; do
for f in *test.html standalone/*test.html
do
echo " '../$f'," >> "$TEST_SUITE_HTML"
done

Expand Down
4 changes: 2 additions & 2 deletions standalone/polymer-resin-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -2954,7 +2954,7 @@ 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.STANDALONE = !0;
security.polymer_resin.STANDALONE = !1;
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];
Expand All @@ -2970,7 +2970,6 @@ security.polymer_resin.allowIdentifierWithPrefix_ = function(prefix) {
security.polymer_resin.setReportHandler_ = function(reportHandler) {
security.polymer_resin.reportHandler_ = reportHandler || null;
};
security.polymer_resin.STANDALONE && (goog.exportSymbol("security.polymer_resin.install", security.polymer_resin.install), goog.exportSymbol("security.polymer_resin.CONSOLE_LOGGING_REPORT_HANDLER", security.polymer_resin.CONSOLE_LOGGING_REPORT_HANDLER));
security.polymer_resin.allowedIdentifierPattern_ = /^$/;
security.polymer_resin.allowUnsafeValues_ = !1;
security.polymer_resin.reportHandler_ = void 0;
Expand Down Expand Up @@ -3116,4 +3115,5 @@ security.polymer_resin.VALUE_HANDLERS_[security.html.contracts.AttrType.COMPILE_
security.polymer_resin.VALUE_HANDLERS_[security.html.contracts.AttrType.IDENTIFIER] = {filter:function(e, a, v) {
return security.polymer_resin.allowedIdentifierPattern_.test(v) ? v : security.polymer_resin.INNOCUOUS_STRING_;
}, safeReplacement:security.polymer_resin.INNOCUOUS_STRING_, typeToUnwrap:goog.string.Const, unwrap:goog.string.Const.unwrap};
security.polymer_resin.STANDALONE && (goog.exportSymbol("security.polymer_resin.install", security.polymer_resin.install), goog.exportSymbol("security.polymer_resin.CONSOLE_LOGGING_REPORT_HANDLER", security.polymer_resin.CONSOLE_LOGGING_REPORT_HANDLER));

Loading

0 comments on commit de72ae9

Please sign in to comment.