Skip to content

Commit 8b0e307

Browse files
committed
Issue #266. Cache RegExp matching whitelist to full matching whitelist to reduce overheads
1 parent 13c8403 commit 8b0e307

10 files changed

+29
-63
lines changed

demo/cache-bundle.json

+7-7
Large diffs are not rendered by default.

demo/empty-document.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<html>
77
<head>
88
<meta charset="utf-8">
9-
<script src="../../thin-hook/hook.min.js?no-hook=true&hook-name=__hook__&context-generator-name=method&discard-hook-errors=false&fallback-page=index-fb.html&hook-property=true&hook-global=true&hook-prefix=_pp_&compact=true&no-hook-authorization=f851122c4816daca0d0aa2b5fc55f7662c27206af4ae1f3eae22f65f285c7684,log-no-hook-authorization"></script>
9+
<script src="../../thin-hook/hook.min.js?no-hook=true&hook-name=__hook__&context-generator-name=method&discard-hook-errors=false&fallback-page=index-fb.html&hook-property=true&hook-global=true&hook-prefix=_pp_&compact=true&no-hook-authorization=4311a3f0706f822621228e0a5a10dc5e8500863614efcff5c43e1761350b9a99,log-no-hook-authorization"></script>
1010
<script context-generator src="no-hook-authorization.js?no-hook=true"></script>
1111
<script context-generator src="context-generator.js?no-hook=true"></script>
1212
<script context-generator src="bootstrap.js?no-hook=true"></script>

demo/hook-callback.js

+13-47
Original file line numberDiff line numberDiff line change
@@ -7584,28 +7584,17 @@ Copyright (c) 2017, 2018, Tetsuya Mori <[email protected]>. All rights reserv
75847584
const origin = location.origin;
75857585
const noHookAuthorization = hook.parameters.noHookAuthorizationParameter;
75867586
[
7587-
`at _iframeContentWindowAcl (${origin}/components/thin-hook/demo/hook-callback.js?no-hook=true:2117:54)`,
7588-
`at write2 (${origin}/components/thin-hook/demo/:129:14355)`,
7589-
`at write4 (${origin}/components/thin-hook/demo/:129:15472)`,
7590-
`at writeln2 (${origin}/components/thin-hook/demo/:131:40)`,
7591-
`at writeln4 (${origin}/components/thin-hook/demo/:133:45)`,
7592-
`at ${origin}/components/thin-hook/demo/webpack-es6-module.js?no-hook=true:445:3`,
7593-
`at ${origin}/components/thin-hook/demo/webpack-es6-module.js?no-hook=true:66:10`,
7594-
`at https://www.gstatic.com/charts/loader.js:226:323`,
7595-
`at https://cdnjs.cloudflare.com/ajax/libs/vis/4.18.1/vis.min.js?cors=true&no-hook=true:25:200`,
7596-
`at https://cdnjs.cloudflare.com/ajax/libs/vis/4.18.1/vis.min.js?cors=true&no-hook=true:41:2497`,
7597-
`at https://cdnjs.cloudflare.com/ajax/libs/vis/4.18.1/vis.min.js?cors=true&no-hook=true:42:4192`,
7598-
`at HTMLCanvasElement.<anonymous> (https://cdnjs.cloudflare.com/ajax/libs/vis/4.18.1/vis.min.js?cors=true&no-hook=true:42:8417)`,
75997587
].forEach(url => whitelist.add(url));
76007588
const wildcardWhitelist = [
76017589
new RegExp('^at ([^(]* [(])?' + 'https://cdnjs.cloudflare.com/ajax/libs/vis/4[.]18[.]1/vis[.]min[.]js'),
7602-
new RegExp('^at ([^(]* [(])?' + origin + '/components/thin-hook/demo/hook-callback[.]js'),
7603-
new RegExp('^at ([^(]* [(])?' + origin + '/components/thin-hook/hook[.]min[.]js'),
7604-
new RegExp('^at ([^(]* [(])?' + origin + '/components/thin-hook/demo/view3:1:'),
7605-
new RegExp('^at ([^(]* [(])?' + origin + '/components/thin-hook/demo/disable-devtools[.]js'),
7606-
new RegExp('^at ([^(]* [(])?' + origin + '/components/thin-hook/demo/cache-bundle[.]js'),
7590+
new RegExp('^at ([^(]* [(])?' + 'https://www.gstatic.com/charts/loader[.]js'),
7591+
new RegExp('^at ([^(]* [(])?' + origin + '/components/thin-hook/demo/'), // trust the site contents
7592+
new RegExp('^at ([^(]* [(])?' + origin + '/components/thin-hook/hook[.]min[.]js'), // trust thin-hook
76077593
];
7608-
//console.error(whitelist);
7594+
const excludes = new Set();
7595+
[
7596+
'Math', // for vis.min.js to work in decent speed
7597+
].forEach(name => excludes.add(name));
76097598
if (typeof window === 'object') {
76107599
const _Object = Object;
76117600
const _window = window;
@@ -7617,16 +7606,17 @@ Copyright (c) 2017, 2018, Tetsuya Mori <[email protected]>. All rights reserv
76177606
return true;
76187607
}
76197608
for (let i = 0; i < wildcardWhitelist.length; i++) {
7620-
if (top.match(wildcardWhitelist[i]) || bottom.match(wildcardWhitelist)) {
7609+
if (top.match(wildcardWhitelist[i])) {
7610+
whitelist.add(top); // cache whitelist result
7611+
return true;
7612+
}
7613+
else if (bottom.match(wildcardWhitelist[i])) {
7614+
whitelist.add(bottom); // cache whitelist result
76217615
return true;
76227616
}
76237617
}
76247618
return false;
76257619
};
7626-
const excludes = new Set();
7627-
[
7628-
'Math', // for vis.min.js to work in a decent speed
7629-
].forEach(name => excludes.add(name));
76307620
_Object.getOwnPropertyNames(_window).forEach(name => {
76317621
if (excludes.has(name)) {
76327622
return;
@@ -7725,29 +7715,5 @@ Copyright (c) 2017, 2018, Tetsuya Mori <[email protected]>. All rights reserv
77257715
// window.name is not configurable
77267716
}
77277717
});
7728-
7729-
}
7730-
/*
7731-
if (typeof navigator === 'object' && typeof window === 'object') {
7732-
let desc = _Object.getOwnPropertyDescriptor(window, 'navigator');
7733-
_Object.defineProperty(window, 'navigator', {
7734-
configurable: true,
7735-
enumerable: desc.enumerable,
7736-
get: function get() {
7737-
if (contextStack.isEmpty()) {
7738-
Error.stackTraceLimit = Infinity;
7739-
let error = new Error();
7740-
let bottom = error.stack.split(/\n/).pop().trim();
7741-
if (!whitelist.has(bottom)) {
7742-
console.error('access to window.navigator \n', 'this = ', this, '\n', error.stack, '\n', 'bottom = ', '"' + bottom + '"', '\n', contextStack.toString(2));
7743-
}
7744-
else {
7745-
console.error('bottom = ', bottom);
7746-
}
7747-
}
7748-
return desc.get.call(this);
7749-
}
7750-
})
77517718
}
7752-
*/
77537719
}

demo/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<html lang="en">
1616
<head>
1717
<meta charset="utf-8">
18-
<script src="../../thin-hook/hook.min.js?version=496&no-hook-authorization=f851122c4816daca0d0aa2b5fc55f7662c27206af4ae1f3eae22f65f285c7684,a578e741369d927f693fedc88c75b1a90f1a79465e2bb9774a3f68ffc6e011e6,log-no-hook-authorization&sw-root=/&no-hook=true&hook-name=__hook__&context-generator-name=method&discard-hook-errors=false&fallback-page=index-fb.html&hook-property=true&hook-global=true&hook-prefix=_pp_&compact=true&service-worker-ready=false"></script></head></html><!--
18+
<script src="../../thin-hook/hook.min.js?version=496&no-hook-authorization=4311a3f0706f822621228e0a5a10dc5e8500863614efcff5c43e1761350b9a99,a578e741369d927f693fedc88c75b1a90f1a79465e2bb9774a3f68ffc6e011e6,log-no-hook-authorization&sw-root=/&no-hook=true&hook-name=__hook__&context-generator-name=method&discard-hook-errors=false&fallback-page=index-fb.html&hook-property=true&hook-global=true&hook-prefix=_pp_&compact=true&service-worker-ready=false"></script></head></html><!--
1919
<script context-generator src="no-hook-authorization.js?no-hook=true"></script>
2020
<script context-generator src="disable-devtools.js?no-hook=true"></script>
2121
<script context-generator src="context-generator.js?no-hook=true"></script>

demo/no-hook-authorization.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
// hook.parameters.noHookAuthorizationFailed
1010
// JSONs are output to console in the learning mode
1111
//'*': true,
12-
"b147b2e6128f4021df937e9b33ae7b7c3d056f9d0d3d6d7b6bf12083a063cd8c": true, // hook.min.js
12+
"88fc75a80dc353e55ce35927ce7821e9ae73daf0f53ed5f6706b793aefc44e45": true, // hook.min.js
1313
"ba451c60ef71c0df971d17a7f84b0d35327042e8284b4372eb38ce73c6aa16e7": true, // demo/disable-devtools.js
1414
"7e0fcbf73f8a30d98082c497e4bec73f2b49e5bee70605bb8838aed035763868": true, // demo/context-generator.js
1515
"327fd7be041eb9f731b01fa2caa29dd96a43ae3702c5bfb2b20563f837612084": true, // demo/bootstrap.js
16-
"4c5a8543e05c0dcddb9dfeed64e544e906b492255e875dc1bd66370a8a9ac016": true, // demo/hook-callback.js
16+
"9067a46dbfcd69d6404bd6a9b03b8fe97ad9edfe432ce9f2a9f9e5bf3d925e28": true, // demo/hook-callback.js
1717
"dce33a4bedd381a2dbad931ddd93c959730cced16f5cab1379968896854c2573": true, // demo/hook-native-api.js
1818
"e2e42b1f8c6c518b5878b5bd95d34c0f15e139a1afb6ab6a6642b6e81219d2c5": true, // demo/hook-worker.js
1919
"163ba1450660d02306936ad39a0b5977e042ba3270eca749fc30d98170e9be03": true, // demo/cache-bundle.js

demo/original-index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<html lang="en">
1616
<head>
1717
<meta charset="utf-8">
18-
<script src="../../thin-hook/hook.min.js?version=496&no-hook-authorization=f851122c4816daca0d0aa2b5fc55f7662c27206af4ae1f3eae22f65f285c7684,a578e741369d927f693fedc88c75b1a90f1a79465e2bb9774a3f68ffc6e011e6,log-no-hook-authorization&sw-root=/&no-hook=true&hook-name=__hook__&context-generator-name=method&discard-hook-errors=false&fallback-page=index-fb.html&hook-property=true&hook-global=true&hook-prefix=_pp_&compact=true&service-worker-ready=true"></script>
18+
<script src="../../thin-hook/hook.min.js?version=496&no-hook-authorization=4311a3f0706f822621228e0a5a10dc5e8500863614efcff5c43e1761350b9a99,a578e741369d927f693fedc88c75b1a90f1a79465e2bb9774a3f68ffc6e011e6,log-no-hook-authorization&sw-root=/&no-hook=true&hook-name=__hook__&context-generator-name=method&discard-hook-errors=false&fallback-page=index-fb.html&hook-property=true&hook-global=true&hook-prefix=_pp_&compact=true&service-worker-ready=true"></script>
1919
<script context-generator src="no-hook-authorization.js?no-hook=true"></script>
2020
<script context-generator src="disable-devtools.js?no-hook=true"></script>
2121
<script context-generator src="context-generator.js?no-hook=true"></script>

demo/sub-document.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<html lang="en">
77
<head>
88
<meta charset="utf-8">
9-
<script src="../../thin-hook/hook.min.js?no-hook=true&no-hook-authorization=f851122c4816daca0d0aa2b5fc55f7662c27206af4ae1f3eae22f65f285c7684,log-no-hook-authorization"></script>
9+
<script src="../../thin-hook/hook.min.js?no-hook=true&no-hook-authorization=4311a3f0706f822621228e0a5a10dc5e8500863614efcff5c43e1761350b9a99,log-no-hook-authorization"></script>
1010
<script context-generator src="no-hook-authorization.js?no-hook=true"></script>
1111
<script context-generator src="context-generator.js?no-hook=true"></script>
1212
<script context-generator src='bootstrap.js?no-hook=true'></script>

demo/sub-sub-document.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<html lang="en">
77
<head>
88
<meta charset="utf-8">
9-
<script src="../../thin-hook/hook.min.js?no-hook=true&no-hook-authorization=f851122c4816daca0d0aa2b5fc55f7662c27206af4ae1f3eae22f65f285c7684,log-no-hook-authorization"></script>
9+
<script src="../../thin-hook/hook.min.js?no-hook=true&no-hook-authorization=4311a3f0706f822621228e0a5a10dc5e8500863614efcff5c43e1761350b9a99,log-no-hook-authorization"></script>
1010
<script context-generator src="no-hook-authorization.js?no-hook=true"></script>
1111
<script context-generator src="context-generator.js?no-hook=true"></script>
1212
<script context-generator src='bootstrap.js?no-hook=true'></script>

hook.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/hook.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)