Skip to content

Commit

Permalink
feat(Worker): add self to scope
Browse files Browse the repository at this point in the history
  • Loading branch information
jdanyow authored and gja committed Dec 3, 2018
1 parent 8c82a79 commit 996cec5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/__tests__/worker_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ describe("Workers", () => {
});

describe("Ensuring Things are in scope", () => {
test('It has self global', () => {
const worker = new Worker('foo.com', `addEventListener('test', () => self)`);
const self = worker.triggerEvent('test');
expect(self).toBeDefined();
});

test("It has Node buildins like Object in scope", () => {
const worker = new Worker("foo.com", 'addEventListener("test", () => Object.assign({}, {foo: "bar"}))');
expect(worker.triggerEvent("test").foo).toBe("bar");
Expand Down
3 changes: 2 additions & 1 deletion app/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class Worker {
Object.assign(context, kvStores, {
fetch: this.fetchUpstream.bind(this),
addEventListener: this.addEventListener.bind(this),
triggerEvent: this.triggerEvent.bind(this)
triggerEvent: this.triggerEvent.bind(this),
self: context
})
)
);
Expand Down

0 comments on commit 996cec5

Please sign in to comment.