Skip to content

Commit f383395

Browse files
committed
Added jshint and fixed small bug
0 parents  commit f383395

File tree

6 files changed

+114
-0
lines changed

6 files changed

+114
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
*.log
3+
.DS_Store

.jshintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"esversion": 6,
3+
"node": true
4+
}

JavaScript/README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
## Description
2+
3+
Purpose: learn how to create sandboxed context for modues to separate them and
4+
minimize cross-modules code coupling, extracting at least two abstraction layers
5+
(applied and system) and how to execute applied code in virtual environment,
6+
changing its behavior using IoC from system layer.
7+
8+
## Files
9+
10+
* `framework.js` - small piece of the framework, just to demonstrate IoC
11+
* `application.js` - small piece of the application, also for IoC demonstration
12+
13+
## How to execute
14+
15+
From the command line, type: `node ./framework.js` or `node framework`
16+
17+
## Tasks
18+
19+
You may select at least one of the following tasks, make a fork of this
20+
repository and implement your solution there. If those tasks are simple
21+
for somebody, please see additional tasks below.
22+
23+
1. Add `setTimeout` and `setInterval` to the application context and use them
24+
printing something from the timer function using console.log()
25+
26+
2. Inject a link to `util` library into the application context and make a few
27+
calls to its functions from applied code
28+
29+
3. Implement the ability to run different applications inside framework, using
30+
command line option, e.g.: `node framework <applicationName>`
31+
32+
4. Wrap or intercept `console.log()` call to add more info into console output
33+
in the following format: `<applicationName> <time> <message>`
34+
35+
5. Wrap or intercept `console.log()` in the sandboxed application logging all
36+
console output into a file in the format: `<applicationName> <time> <message>`
37+
38+
6. Give a link to `require` function to the application, add call to it and
39+
wrap it for logging to a file in the format: `<time> <module name>`
40+
41+
7. Export a hash from `application.js` with multiple functions and variables,
42+
print the list with types from framework
43+
44+
8. Export a function from `application.js` and print its parameter count and
45+
source code from the framework
46+
47+
9. Print a list of everything from the application global context (application
48+
sandbox) with the data types specified
49+
50+
10. Compare an application sandboxed context keys before application loaded and
51+
after, print it from the framework and find a difference (keys added / deleted)
52+
53+
## Additional tasks
54+
55+
11. You can combine several tasks (listed above) in your code, implement a more
56+
complex example of interaction between framework and application, preparing
57+
run-time environment (sandbox) and/or improving CLI (command line interface)
58+
59+
12. Implement a similar example in another programming language
60+
61+
13. Improve and/or optimize Impress Application Server code, specifically
62+
everything related to sandboxing, see:
63+
[/lib/impress.application.js](https://github.com/tshemsedinov/impress/blob/master/lib/impress.application.js)
64+
65+
14. Use IoC and code isolation principles using sandboxed context and/or other
66+
similar technique in your projects (any technological stack) to demonstrate its
67+
use and the effect of such use

JavaScript/application.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// File contains a small piece of the source to demonstrate main module
2+
// of a sample application to be executed in the sandboxed context by
3+
// another pice of code from `framework.js`. Read README.md for tasks.
4+
5+
// Print from the global context of application module
6+
console.log('From application global context');
7+
8+
module.exports = function() {
9+
// Print from the exported function context
10+
console.log('From application exported function');
11+
};

JavaScript/framework.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Example showing us how the framework creates an environment (sandbox) for
2+
// appication runtime, load an application code and passes a sandbox into app
3+
// as a global context and receives exported application interface
4+
5+
// The framework can require core libraries
6+
global.api = {};
7+
api.fs = require('fs');
8+
api.vm = require('vm');
9+
10+
// Create a hash and turn it into the sandboxed context which will be
11+
// the global context of an application
12+
let context = { module: {}, console: console };
13+
context.global = context;
14+
let sandbox = api.vm.createContext(context);
15+
16+
// Read an application source code from the file
17+
let fileName = './application.js';
18+
api.fs.readFile(fileName, (err, src) => {
19+
// We need to handle errors here
20+
21+
// Run an application in sandboxed context
22+
let script = api.vm.createScript(src, fileName);
23+
script.runInNewContext(sandbox);
24+
25+
// We can access a link to exported interface from sandbox.module.exports
26+
// to execute, save to the cache, print to console, etc.
27+
});

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Sandboxes
2+
===============

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy