Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ea9c8d
commit 3ccf558
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
|
||
var QUnit = require('../../test-wrapper'); | ||
var isWebWorker = require('./is-web-worker'); | ||
|
||
QUnit.module("can-globals/is-web-worker/is-web-worker"); | ||
|
||
QUnit.test("basics", function(){ | ||
equal(typeof isWebWorker(), "boolean"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
var globals = require('can-globals/can-globals-instance'); | ||
|
||
/* globals WorkerGlobalScope */ | ||
// A bit of weirdness to avoid complaining linters | ||
var funcConstructor = Function; | ||
|
||
|
||
/** | ||
* @module {function} can-globals/is-browser-window/is-web-worker is-web-worker | ||
* @parent can-globals/modules | ||
* @signature `isWebWorker()` | ||
* | ||
* Returns `true` if the code is running within a [web worker](https://developer.mozilla.org/en-US/docs/Web/API/Worker). | ||
* | ||
* ```js | ||
* var isWebWorker = require("can-globals/is-web-worker/is-web-worker"); | ||
* var GLOBAL = require("can-globals/global/global"); | ||
* | ||
* if(isWebWorker()) { | ||
* ... | ||
* } | ||
* ``` | ||
* | ||
* @return {Boolean} True if the environment is a web worker. | ||
*/ | ||
|
||
globals.define('isWebWorker', function(){ | ||
var global = funcConstructor('return this')(); | ||
return typeof WorkerGlobalScope !== "undefined" && | ||
(global instanceof WorkerGlobalScope); | ||
}); | ||
|
||
module.exports = globals.makeExport('isWebWorker'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters