-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport from 1.2 branch. - The Snowboard and PluginLoader objects are now frozen and cannot be modified. - Added a Proxy in front of Snowboard to handle plugin loading - Plugin "Snowboard" instances are blocked from running certain methods - Update tests to check hardening
- Loading branch information
1 parent
107e1d0
commit bce4b59
Showing
20 changed files
with
395 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
modules/system/assets/js/snowboard/build/snowboard.base.debug.js
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
modules/system/assets/js/snowboard/build/snowboard.data-attr.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
modules/system/assets/js/snowboard/main/InnerProxyHandler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Internal proxy for Snowboard. | ||
* | ||
* This handler wraps the Snowboard instance that is passed to the constructor of plugin instances. | ||
* It prevents access to the following methods: | ||
* - `attachAbstracts`: No need to attach abstracts again. | ||
* - `loadUtilties`: No need to load utilities again. | ||
* - `initialise`: Snowboard is already initialised. | ||
* - `initialiseSingletons`: Singletons are already initialised. | ||
*/ | ||
export default { | ||
get(target, prop, receiver) { | ||
if (typeof prop === 'string') { | ||
const propLower = prop.toLowerCase(); | ||
|
||
if (['attachAbstracts', 'loadUtilities', 'initialise', 'initialiseSingletons'].includes(prop)) { | ||
throw new Error(`You cannot use the "${prop}" Snowboard method within a plugin.`); | ||
} | ||
|
||
if (target.hasPlugin(propLower)) { | ||
return (...params) => Reflect.get(target, 'plugins')[propLower].getInstance(...params); | ||
} | ||
} | ||
|
||
return Reflect.get(target, prop, receiver); | ||
}, | ||
|
||
has(target, prop) { | ||
if (typeof prop === 'string') { | ||
const propLower = prop.toLowerCase(); | ||
|
||
if (['attachAbstracts', 'loadUtilities', 'initialise', 'initialiseSingletons'].includes(prop)) { | ||
return false; | ||
} | ||
|
||
if (target.hasPlugin(propLower)) { | ||
return true; | ||
} | ||
} | ||
|
||
return Reflect.has(target, prop); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export default { | ||
get(target, prop, receiver) { | ||
if (typeof prop === 'string') { | ||
const propLower = prop.toLowerCase(); | ||
|
||
if (target.hasPlugin(propLower)) { | ||
return (...params) => Reflect.get(target, 'plugins')[propLower].getInstance(...params); | ||
} | ||
} | ||
|
||
return Reflect.get(target, prop, receiver); | ||
}, | ||
|
||
has(target, prop) { | ||
if (typeof prop === 'string') { | ||
const propLower = prop.toLowerCase(); | ||
|
||
if (target.hasPlugin(propLower)) { | ||
return true; | ||
} | ||
} | ||
|
||
return Reflect.has(target, prop); | ||
}, | ||
}; |
Oops, something went wrong.