Skip to content
This repository was archived by the owner on Aug 24, 2021. It is now read-only.

feat: add support for webworkers #14

Merged
merged 1 commit into from
Jan 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
"./src/crypto-sha1-2.js": "./src/crypto-sha1-2-browser.js"
},
"scripts": {
"test": "aegir-test",
"test:browser": "aegir-test browser",
"test": "aegir-test --webworker",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this 'just webworker'?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you are proposing to just run the tests in a webworker??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah no, sorry this means run tests also in webworker, that's why it's not --env webworker.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests now run three times, once in node, once in the browser without webworkers and once inside webworkers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aegir could use an update to something like: --runtime=node, browser, webworker

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aegir could use a proper cli interface yes...but don't know when to do things like that...

"test:browser": "aegir-test browser --webworker",
"test:node": "aegir-test node",
"lint": "aegir-lint",
"docs": "aegir-docs",
"release": "aegir-release --docs",
"release-minor": "aegir-release minor --docs",
"release-major": "aegir-release major --docs",
"release": "aegir-release --docs --webworker",
"release-minor": "aegir-release minor --docs --webworker",
"release-major": "aegir-release major --docs --webworker",
"build": "aegir-build",
"coverage": "aegir-coverage",
"coverage-publish": "aegir-coverage publish",
Expand All @@ -38,13 +38,13 @@
},
"dependencies": {
"async": "^2.1.4",
"js-sha3": "^0.5.5",
"multihashes": "^0.3.0",
"js-sha3": "^0.5.7",
"multihashes": "^0.3.2",
"nodeify": "^1.0.0"
},
"devDependencies": {
"aegir": "^9.3.0",
"benchmark": "^2.1.2",
"aegir": "^9.4.0",
"benchmark": "^2.1.3",
"chai": "^3.5.0",
"pre-commit": "^1.2.2"
},
Expand Down
68 changes: 0 additions & 68 deletions src/crypto-browser.js

This file was deleted.

21 changes: 15 additions & 6 deletions src/crypto-sha1-2-browser.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
/* global self */
'use strict'

const nodeify = require('nodeify')

const webCrypto = getWebCrypto()

function getWebCrypto () {
let globalContext

if (typeof window !== 'undefined') {
if (window.crypto) {
return window.crypto.subtle || window.crypto.webkitSubtle
}
globalContext = window
} else if (typeof self !== 'undefined') {
globalContext = self
} else {
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this throw an error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, the throwing happens below

}

if (window.msCrypto) {
return window.msCrypto.subtle
}
if (globalContext.crypto) {
return globalContext.crypto.subtle || globalContext.crypto.webkitSubtle
}

if (globalContext.msCrypto) {
return globalContext.msCrypto.subtle
}
}

Expand Down