Skip to content

Commit e8565e2

Browse files
committed
Initial commit
0 parents  commit e8565e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+16552
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist
2+
dist-transpiled
3+
node_modules

browser-test/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var rollup = require( 'rollup' );
2+
var nodePolyfills = require('..');
3+
rollup.rollup({
4+
entry: 'browser-test/main.js',
5+
plugins: [
6+
nodePolyfills(),
7+
]
8+
}).then( function ( bundle ) {
9+
return bundle.write({
10+
dest: 'browser-test/dist/bundle.js'
11+
});
12+
}).then(function () {
13+
console.log('done');
14+
process.exit();
15+
}).catch(function (e) {
16+
console.log('oh noes!');
17+
console.log(e);
18+
process.exit(1);
19+
});

browser-test/main.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {get} from 'http';
2+
import {createContext, runInContext} from 'vm';
3+
import {equal, deepEqual} from 'assert';
4+
5+
get('foo.json', function (res) {
6+
console.log('status', res.statusCode);
7+
var data = '';
8+
res.on('data', function (d) {
9+
data += d.toString();
10+
}).on('error', function (e) {
11+
console.log('error', e);
12+
}).on('end', function () {
13+
console.log(data);
14+
if (global.document) {
15+
afterMain();
16+
} else {
17+
afterWorker();
18+
}
19+
});
20+
})
21+
function afterMain() {
22+
var context = createContext();
23+
24+
runInContext('var x = 1', context);
25+
deepEqual(context, { x: 1 });
26+
27+
runInContext('var y = 2;', context);
28+
var x = runInContext('++x', context);
29+
equal(x, 2);
30+
equal(context.x, 2);
31+
equal(context.x, context.y);
32+
console.log('ok main');
33+
}
34+
function afterWorker() {
35+
var context = createContext({x: 0});
36+
37+
runInContext('x++', context);
38+
deepEqual(context, { x: 1 });
39+
40+
var x = runInContext('++x', context);
41+
equal(x, 2);
42+
equal(context.x, 2);
43+
console.log('ok worker');
44+
}

0 commit comments

Comments
 (0)