Skip to content

Commit

Permalink
Issue #386 [Enhancement][WIP] Add configuration switches to exclude u…
Browse files Browse the repository at this point in the history
…nnecessary functions from hook-callback.js
  • Loading branch information
t2ym committed Sep 18, 2020
1 parent 3d1f75e commit a481728
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
11 changes: 11 additions & 0 deletions demo-config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ class TargetConfig extends Configurable(GulpDefaultRegistry, 'thin-hook') {
}),
},
},
policy: {
// @ifdef arguments to include/exclude hook callback functions in hook-callback.js
__hook__: true, // undefined to skip including plugins/policy/__hook__.js
__hook__acl: true, // undefined to skip including plugins/policy/__hook__acl.js
__hook__min: true, // undefined to skip including plugins/policy/__hook__min.js
// @ifdef argument to include/exclude hookBenchmark() in hook-callback.js
hookBenchmark: true, // undefined to exclude hookBenchmark()
// postfix to the hook callback function name __hook__
__hook__callback: 'acl', // '': __hook__, 'acl': __hook__acl, 'min': __hook__min
// any custom parameters can be used for this.path.config/policy/policy.js and its dependencies as well
},
'no-hook-authorization': {
hash: {
"https://cdnjs.cloudflare.com/ajax/libs/vis/4.18.1/vis.min.js": "db82c32a68bc3ddbb2232a947c3cdeb88f5ee7ba41d05d686146507687a6897f", // TODO: generate from URL response
Expand Down
2 changes: 2 additions & 0 deletions plugins/policy/configurator.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const configurator = function (targetConfig) {
EQUAL: '=',
SEMICOLON: ';',
enableDebugging: typeof enableDebugging === 'undefined' ? 'false' : enableDebugging,
...this[pluginName],
},
{
type: 'js',
Expand All @@ -44,6 +45,7 @@ const configurator = function (targetConfig) {
SPACE: ' ',
EQUAL: '=',
SEMICOLON: ';',
...this[pluginName],
},
{
type: 'js',
Expand Down
16 changes: 15 additions & 1 deletion plugins/policy/hook-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,27 +257,41 @@ else {
const GeneratorFunction = (function * () {}).constructor;
const AsyncFunction = (async function () {}).constructor;
const FunctionPrototype = Function.prototype;
/* @ifdef __hook__ */
/* @include __hook__.js */
/* @endif */
/* @ifdef __hook__acl */
/* @include __hook__acl.js */
/* @endif */
function showContextStackLog() {
let asyncCalls = Object.keys(contextStackLog).filter(c => c.match(/(setTimeout|setInterval|Promise)/g));
console.log(asyncCalls);
}

/* @ifdef __hook__min */
/* @include __hook__min.js */
/* @endif */
const hookCallbacks = {
/* @ifdef __hook__ */
__hook__, // full features (acl + contextStack + graph)
/* @endif */
/* @ifdef __hook__acl */
__hook__acl, // acl only (acl + contextStack)
/* @endif */
/* @ifdef __hook__min */
__hook__min, // minimal (no acl)
/* @endif */
};

Object.defineProperty(_global, '__hook__', { configurable: false, enumerable: false, writable: false, value: hookCallbacks.__hook__acl });
Object.defineProperty(_global, '__hook__', { configurable: false, enumerable: false, writable: false, value: hookCallbacks.__hook__/* @echo __hook__callback */ });
_globalObjects.set(_global.__hook__, '__hook__');

hook.hookCallbackCompatibilityTest();
hookCallbackCompatibilityTestDone = true;

/* @ifdef hookBenchmark */
/* @include hookBenchmark.js */
/* @endif */
/* @include mutation-observer.js */
/* @include hook-native-api.js */
}

0 comments on commit a481728

Please sign in to comment.