Skip to content
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.

Commit

Permalink
Update global (#80)
Browse files Browse the repository at this point in the history
Resolves #61
  • Loading branch information
kitsonk authored Jun 28, 2017
1 parent ab8aa81 commit b4ee1eb
Show file tree
Hide file tree
Showing 28 changed files with 55 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/Map.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ArrayLike } from './interfaces';
import { hasClass } from './support/decorators';
import global from './support/global';
import global from './global';
import { forOf, Iterable, IterableIterator, ShimIterator } from './iterator';
import { is as objectIs } from './object';
import './Symbol';
Expand Down
2 changes: 1 addition & 1 deletion src/Observable.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Iterable, forOf, isIterable, isArrayLike } from './iterator';
import { hasClass } from './support/decorators';
import global from './support/global';
import global from './global';
import './Symbol';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Promise.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Thenable } from './interfaces';
import global from './support/global';
import global from './global';
import { queueMicroTask } from './support/queue';
import { forOf, Iterable } from './iterator';
import './Symbol';
Expand Down
2 changes: 1 addition & 1 deletion src/Set.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ArrayLike } from './interfaces';
import { hasClass } from './support/decorators';
import global from './support/global';
import global from './global';
import { forOf, IterableIterator, Iterable, ShimIterator } from './iterator';
import './Symbol';

Expand Down
2 changes: 1 addition & 1 deletion src/Symbol.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import has from './support/has';
import global from './support/global';
import global from './global';
import { getValueDescriptor } from './support/util';

declare global {
Expand Down
2 changes: 1 addition & 1 deletion src/WeakMap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ArrayLike } from './interfaces';
import { hasClass } from './support/decorators';
import global from './support/global';
import global from './global';
import { forOf, Iterable } from './iterator';
import './Symbol';

Expand Down
19 changes: 19 additions & 0 deletions src/global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const globalObject: any = (function (): any {

if (typeof global !== 'undefined') {
// global spec defines a reference to the global object called 'global'
// https://github.com/tc39/proposal-global
// `global` is also defined in NodeJS
return global;
}
else if (typeof window !== 'undefined') {
// window is defined in browsers
return window;
}
else if (typeof self !== 'undefined') {
// self is defined in WebWorkers
return self;
}
})();

export default globalObject;
2 changes: 1 addition & 1 deletion src/native/Map.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import global from '../support/global';
import global from '../global';

export interface Map<K, V> {
clear(): void;
Expand Down
2 changes: 1 addition & 1 deletion src/native/Promise.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import global from '../support/global';
import global from '../global';

/* tslint:disable-next-line:variable-name */
const PromiseConstructor = global.Promise;
Expand Down
2 changes: 1 addition & 1 deletion src/native/Set.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import global from '../support/global';
import global from '../global';

export interface Set<T> {
add(value: T): this;
Expand Down
2 changes: 1 addition & 1 deletion src/native/Symbol.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import global from '../support/global';
import global from '../global';
import { getValueDescriptor } from '../support/util';

/* tslint:disable-next-line:variable-name */
Expand Down
2 changes: 1 addition & 1 deletion src/native/WeakMap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import global from '../support/global';
import global from '../global';

export interface WeakMap<K, V> {
clear(): void;
Expand Down
2 changes: 1 addition & 1 deletion src/native/number.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import global from '../support/global';
import global from '../global';

/**
* The smallest interval between two representable numbers.
Expand Down
2 changes: 1 addition & 1 deletion src/number.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import global from './support/global';
import global from './global';

/**
* The smallest interval between two representable numbers.
Expand Down
9 changes: 0 additions & 9 deletions src/support/global.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/support/has.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import global from './global';
import global from '../global';
import has from '@dojo/has/has';
import { add } from '@dojo/has/has';

Expand Down
2 changes: 1 addition & 1 deletion src/support/queue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import global from './global';
import global from '../global';
import has from './has';
import { Handle } from '../interfaces';

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/all.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import './native/all';
import './support/decorators';
import './support/global';
import './support/has';
import './support/queue';
import './support/util';
import './array';
import './global';
import './iterator';
import './main';
import './Map';
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as registerSuite from 'intern!object';
import * as assert from 'intern/chai!assert';
import globalObj from '../../src/global';

registerSuite({
name: 'global',

'global references the global object for the target environment'() {
// If tests are running under CSP, unsafe eval will be denied and this test will fail
assert.strictEqual(globalObj, Function('return this')(), 'Expecting global object to be in global object');
}
});
2 changes: 1 addition & 1 deletion tests/unit/native/Map.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as registerSuite from 'intern!object';
import * as assert from 'intern/chai!assert';
import has from '../../../src/support/has';
import global from '../../../src/support/global';
import global from '../../../src/global';

registerSuite({
name: 'native/Map',
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/native/Promise.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as registerSuite from 'intern!object';
import * as assert from 'intern/chai!assert';
import has from '../../../src/support/has';
import global from '../../../src/support/global';
import global from '../../../src/global';

registerSuite({
name: 'native/Promise',
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/native/Set.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as registerSuite from 'intern!object';
import * as assert from 'intern/chai!assert';
import has from '../../../src/support/has';
import global from '../../../src/support/global';
import global from '../../../src/global';

registerSuite({
name: 'native/Set',
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/native/Symbol.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as registerSuite from 'intern!object';
import * as assert from 'intern/chai!assert';
import has from '../../../src/support/has';
import global from '../../../src/support/global';
import global from '../../../src/global';

registerSuite({
name: 'native/Symbol',
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/native/WeakMap.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as registerSuite from 'intern!object';
import * as assert from 'intern/chai!assert';
import has from '../../../src/support/has';
import global from '../../../src/support/global';
import global from '../../../src/global';

registerSuite({
name: 'native/WeakMap',
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/native/iterator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as registerSuite from 'intern!object';
import * as assert from 'intern/chai!assert';
import has, { add as hasAdd } from '../../../src/support/has';
import global from '../../../src/support/global';
import global from '../../../src/global';

hasAdd('es6-iterator', () => Boolean(global.Symbol && global.Symbol.iterator && global.Array.prototype[Symbol.iterator]));

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/native/number.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as registerSuite from 'intern!object';
import * as assert from 'intern/chai!assert';
import has, { add as hasAdd } from '../../../src/support/has';
import global from '../../../src/support/global';
import global from '../../../src/global';

hasAdd('es6-number', 'EPSILON' in global.Number);

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/native/object.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as registerSuite from 'intern!object';
import * as assert from 'intern/chai!assert';
import has, { add as hasAdd } from '../../../src/support/has';
import global from '../../../src/support/global';
import global from '../../../src/global';

hasAdd('es6-object', 'getOwnPropertySymbols' in global.Object);

Expand Down
11 changes: 0 additions & 11 deletions tests/unit/support/global.ts

This file was deleted.

0 comments on commit b4ee1eb

Please sign in to comment.