-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Enhancement][acl] Support ES modules (separated from #191 Support modules) #376
Labels
Comments
TasksIssues
import '@spectrum-web-components/theme/sp-theme.js';
import '@spectrum-web-components/theme/src/themes.js';
Tests
Documentation
Consistency
Support Routines
Refactoring
Optimization
|
t2ym
added a commit
that referenced
this issue
Aug 16, 2020
t2ym
added a commit
that referenced
this issue
Aug 16, 2020
t2ym
added a commit
that referenced
this issue
Aug 16, 2020
…gress) - Add DistinctSet class to store distinct object names for ACL - Add GlobalMethodsWrapper class to integrate _globalMethods with _globalObjects - Declare acl at an earlier place and put Object.assign(acl, { ACL POLICY OBJECTS }) for the original place - Skip redundant entries for _globalObjects now that _globalMethods object is integrated - Declare new symbols: S_MODULE, S_TYPE, S_NAMESPACE, S_CLASS, and S_PROXY - Add operators for ES modules to operatorNormalizer and targetNormalizer - Add contexts for ES modules to contextNormalizer - Resolve bare specifiers for ES modules in contextNormalizer - Construct prefixed module context object for indexing ES modules for contextNormalizer - Add a type guard to Policy.trackClass() - Add a redundant registration guard to Policy.trackClass() - Support multiple ACLs for a single global method in Policy.globalAcl() and Policy.defaultAcl() - Chain acl to acl.EventTarget[S_PROTOTYPE][S_INSTANCE] - Add ACL entries for ES modules (draft) - Support [S_CHAIN]: S_OBJECT and S_FUNCTION in acl - Add mergeAcl(target, source) to merge ACL objects - Add proxyAcl() to merge and replace ACL objects with [S_PROXY] - Add resolveBareSpecifierAcl() to resolve bare specifiers in ACL entries - Add generatePrefixedModuleNames() for constructing an index object for wildcard ACL names (not used; work in progress) - Add flattenAcl() to flatten ACL entires for module variables - Support bare specifiers in applyAcl() - Support ES modules in hook callback functions __hook__, __hook__acl, __hook__min
t2ym
added a commit
that referenced
this issue
Aug 16, 2020
t2ym
added a commit
that referenced
this issue
Aug 16, 2020
t2ym
added a commit
that referenced
this issue
Aug 16, 2020
t2ym
added a commit
that referenced
this issue
Aug 16, 2020
t2ym
added a commit
that referenced
this issue
Aug 16, 2020
t2ym
added a commit
that referenced
this issue
Aug 16, 2020
t2ym
added a commit
that referenced
this issue
Aug 16, 2020
t2ym
added a commit
that referenced
this issue
Aug 16, 2020
t2ym
added a commit
that referenced
this issue
Aug 16, 2020
t2ym
added a commit
that referenced
this issue
Aug 17, 2020
t2ym
added a commit
that referenced
this issue
Aug 17, 2020
…ing it by sp-theme element from @spectrum-web-components/theme
t2ym
added a commit
that referenced
this issue
Aug 18, 2020
…duplicate definitions of custom elements via modules/module1.js
t2ym
added a commit
that referenced
this issue
Aug 18, 2020
…duleDependencies.json to make the output deterministic
|
t2ym
added a commit
that referenced
this issue
Aug 27, 2020
…k-scoped functions to Policy class methods (in progress) Note: git diff is corrupted due to the significant amount of movements in the file but acl is not changed in this commit Policy class methods/properties replacing block-scoped functions/objects - Policy.tagToElementClass - Policy.protectGlobalVariableAcl() - Policy.chainAcl() - Policy.proxyAcl() - Policy.resolveBareSpecifierAcl() - Policy.generatePrefixedModuleNames() - Policy.flattenAcl() - Policy.getApplyAcl() - Policy.detectName()
t2ym
added a commit
that referenced
this issue
Aug 27, 2020
…k.js] Move some block-scoped functions to Policy class methods (in progress)
t2ym
added a commit
that referenced
this issue
Aug 27, 2020
…k-scoped objects/funtcions Move contextNormalizer contents just before acl contents (transitional) Make contexts a block-scoped variable Policy class methods/properties - Policy.operatorNormalizer - Policy.targetNormalizer - Policy.getTargetNormalizerMap() - Policy.getTargetNormalizerMapObject() - Policy.getIsSuperOperator() - Policy.resolveBareSpecifierContextNormalizer() - Policy.getPrefixedModuleContexts() - Policy.getPrefixedContexts() - Policy.opTypeMap - Policy.isGlobalScopeObject
t2ym
added a commit
that referenced
this issue
Aug 27, 2020
…k.js] Move some block-scoped objects/funtcions
t2ym
added a commit
that referenced
this issue
Aug 27, 2020
… the current monolithic policy Note: Modular policies have not been verified yet. Only monolithic policy is tested - Policy.mergePolicyModules({ contextNormalizer, acl }, ...policyModules)
t2ym
added a commit
that referenced
this issue
Aug 27, 2020
…k (in progress) with the current monolithic policy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[Enhancement][acl] Support ES modules (separated from #191 Support modules)
Support ES Modules
Design Principles
Upper Compatible
acl
andcontextNormalizer
) for the current version 0.4.0-alpha.27 works as it isOptional
Flexible
Fast
Comprehensive
import
/export
declarations are supported, excluding a few newly introduced uncommon syntax (though standardized)Mitigated Hassles
Features
Bare Specifiers Infrastructure
package.json
at the top directory of the GitHub repo and removing a few Node.js assertion statements) of the reference implementation is used for resolution"/node_modules/module-name/main.js"
)@jsenv/node-module-import-map
package.json
for frontend node moduleshook.parameters.importMapper(specifier, scriptURL)
bootstrap.js
hook.utils.importMaps.parseFromString()
hook.utils.importMaps.resolve()
hook.parameters.importMapsJson
as a JSON string<script type="importmap">{ import map }</script>
<script type="importmap" src="module.importmap"></script>
Specifiers in ACL
contextNormalizer
for ACL"module-name": "@module-name"
"module-name/": "@module-name"
"module-name": "@module-name"
"module-name,*": "@module-name"
"module-name/*": "@module-name"
"module-name/lib/*": "@module-name"
contextNormalizer
for ACL"./modules/module1.js": "@module1"
"./modules/module1.js,*": "@module1"
acl
"module-name": {}
->"/modules/module-name/main.js": {}
"module-name/": {}
->"/modules/module-name/main.js": {}
"module-name": {}
with no risks of name collision"module-name/lib/path.js": {}
->"/modules/module-name/lib/path.js": {}
"./modules/module1.js": {}
->"/modules/module1.js": {}
hook.parameters.baseURL
)"module-name/*": {}
->"/modules/module-name/path/*.js": {}
Specifiers in ES modules
"module-name"
->"/modules/module-name/main.js"
import localName from “module-name”
import { default as localName } from “module-name”
import * as localName from “module-name”
import { localName } from “module-name”
import { importedName as localName } from “module-name”
import “module-name”
import("module-name")
export { exportedName as reexportedName } from “module-name”
export { default as reexportedName } from “module-name”
export { reexportedName } from “module-name”
export * from “module-name”
export * as exportedName from “module-name”
export { default } from “module-name”
export { exportedName as default } from “module-name”
"module-name/lib/path.js"
->"/modules/module-name/lib/path.js"
"./modules/module1.js"
->"/modules/module1.js"
(In research) Specifiers in bundled ES modules
rollup-plugin-node-resolve
Hooking ES modules
dummy item for indentation"R"
operation for importing modules"W"
operation for exporting modulesIdentify module variables
import localName from “module-name”
import { default as localName } from “module-name”
import * as localName from “module-name”
import { localName } from “module-name”
import { importedName as localName } from “module-name”
export let localName = value
export function localName() {}
export class localName {}
export { localName as exportedName }; let localName = value
export { localName }; let localName = value
export { exportedName as reexportedName } from “module-name”
"/module/this-module/main.js,reexportedName"
?export { default as reexportedName } from “module-name”
"/module/this-module/main.js,reexportedName"
?export { reexportedName } from “module-name”
"/module/module-name/main.js,reexportedName"
export default expression
"*,default"
export { localName as default }; let localName = value
export * from “module-name”
"/module/module-name/main.js,*"
export * as exportedName from “module-name”
export { default } from “module-name”
export { exportedName as default } from “module-name”
import localName from “module-name”; export { localName }
import localName from “module-name”; export { localName as exportedName }
import localName from “module-name”; export { localName as default }
import localName from “module-name”; export default localName
import { default as localName } from “module-name”; export { localName }
import { default as localName } from “module-name”; export { localName as exportedName }
import { default as localName } from “module-name”; export { localName as default }
import { default as localName } from “module-name”; export default localName;
import * as localName from “module-name”; export { localName }
import * as localName from “module-name”; export { localName as exportedName }
import * as localName from “module-name”; export { localName as default }
import * as localName from “module-name”; export default localName;
import { localName } from “module-name”; export { localName }
import { localName } from “module-name”; export { localName as exportedName }
import { localName } from “module-name”; export { localName as default }
import { localName } from “module-name”; export default localName;
import { importedName as localName } from “module-name”; export { localName }
import { importedName as localName } from “module-name”; export { localName as exportedName }
import { importedName as localName } from “module-name”; export { localName as default }
import { importedName as localName } from “module-name”; export default localName;
export const localName = value
export var localName = value
export let [ localName ] = value
export let [ localName = value ] = value2
export let { localName } = value
export let { prop: localName } = value
export let { prop: localName = value } = value2
export let [ ...localName ] = value
export let { ...localName } = value
export let localName = value; export { localName as exportedName }
export let localName = value; export { localName as exportedName, localName as exportedName2 }
export let localName = value; export { localName as default }
export let localName = value; export default localName
let localName = value; export { localName }
let localName = value; export { localName as exportedName }
let localName = value; export { localName as exportedName, localName as exportedName2 }
let localName = value; export { localName as default }
let localName = value; export default localName;
import(“module-name”).then(localName => {})
Associate a unique virtual name to each module variable
"module-name,variable"
is attached for such variablesModule variables
"/full/path/to/module.js,variable"
is associated to each variableS_PROXY
section)export let mutable = class A {}; mutable = class B {};
a
__hook__('m', a, [_c_[n]], _c_[0], null)
f(...Args)
__hook__('m()', f, [_c_[n], [...Args], (...args)=>f(...args)], _c_[0], null)
new f(...Args)
__hook__('mnew', f, [_c_[n], [...Args], (...args)=>new f(...args)], _c_[0], null)
a++
__hook__('m++', a, [_c_[n], ()=>a++], _c_[0], null)
__hook__('++m', a, [_c_[n], ()=>++a], _c_[0], null)
__hook__('m--', a, [_c_[n], ()=>a--], _c_[0], null)
__hook__('--m', a, [_c_[n], ()=>--a], _c_[0], null)
typeof a
__hook__('mtypeof', a, [_c_[n], ()=>typeof a], _c_[0], null)
a
for (a of o)
[a]=[v]
[...a]=[v]
({p:a}={p:v})
({...a}={p:v})
__hook__('m.=',a, [_c_[n], (cb) => ({set ['='](v){a=v;cb(v);}, get ['='](){return a;}})], _c_[0], null)
a=v
__hook__('m=', a, [_c_[n],v,v=>a=v], _c_[0], null)
a+=v
a-=v
a*=v
a/=v
a%=v
a**=v
a<<=v
a>>=v
a>>>=v
a&=v
a^=v
a|=v
__hook__('m{OP}=', a, [_c_[n],v,v=>a{OP}=v], _c_[0], null)
ACL for ES modules
[S_TYPE]: S_NAMESPACE
[S_TYPE]
prorperties as beforeacl["module-name"].export1
is defined, a new ACL entryacl["/resolved/module-name/main.js,export1"]: acl["/resolved/module-name/main.js"].export1
is created for the module variableexport1
dummy item for indentation[S_TYPE]: S_CLASS
self.crypto.subtle
[S_PROXY]
properties[S_CHAIN]
is inappropriate for combining multiple ACLs for such module variables[S_PROXY]: () => acl["base-module"].baseName
to merge ACLs into a single ACL so thatapplyAcl()
can apply a single ACL for the target module variable which is reexportedacl[S_MODULE]
to define default ACL for module namespace objects(In Research) Modular Policies
demo-config/policy/policy.js
- import and merge policy modulesdemo-config/policy/basePolicyModule.js
- dedicated script file for the base policy module(In Research) Baseline ACL Generation
hook.parameters.moduleDependencies = {}
is defined, module dependencies are registered to the object like thisTracking ES module objects
_globalObjects
has entries based on a newly introducedDistinctSet
class instancesDistinctSet
classDistinctSet
classthis.target === acl
_globalObjects.get(variable)
returns an instance ofDistinctSet
class, which enumerates only a single entry for each ACL group combined by[S_PROXY]
applyAcl()
can validate ACL against the single ACL entry and skip investigating redundant entriesGlobalMethodsWrapper
class_globalMethods
Map
object instance with_globalObjects
SetMap
objectGlobalMethodsWrapper
redirects access to the wrapped_globalMethods
instance to_globalObjects
"/module/module-name/main.js,variable"
can be seen as["/module/module-name/main.js", "variable"]
via the wrapper classThe text was updated successfully, but these errors were encountered: