File tree 2 files changed +21
-2
lines changed
2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -279,4 +279,21 @@ describe('Observable.fromEvent', () => {
279
279
280
280
send ( 1 , 2 , 3 ) ;
281
281
} ) ;
282
+
283
+ it ( 'should not throw an exception calling toString on obj with a null prototype' , ( done : MochaDone ) => {
284
+ // NOTE: Can not test with Object.create(null) or `class Foo extends null`
285
+ // due to TypeScript bug. https://github.com/Microsoft/TypeScript/issues/1108
286
+ class NullProtoEventTarget {
287
+ on ( ) { /*noop*/ }
288
+ off ( ) { /*noop*/ }
289
+ }
290
+ NullProtoEventTarget . prototype . toString = null ;
291
+ const obj : NullProtoEventTarget = new NullProtoEventTarget ( ) ;
292
+
293
+ expect ( ( ) => {
294
+ Observable . fromEvent ( obj , 'foo' ) . subscribe ( ) ;
295
+ done ( ) ;
296
+ } ) . to . not . throw ( TypeError ) ;
297
+ } ) ;
298
+
282
299
} ) ;
Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ import { errorObject } from '../util/errorObject';
5
5
import { Subscription } from '../Subscription' ;
6
6
import { Subscriber } from '../Subscriber' ;
7
7
8
+ const toString : Function = Object . prototype . toString ;
9
+
8
10
export type NodeStyleEventEmmitter = {
9
11
addListener : ( eventName : string , handler : Function ) => void ;
10
12
removeListener : ( eventName : string , handler : Function ) => void ;
@@ -22,11 +24,11 @@ function isJQueryStyleEventEmitter(sourceObj: any): sourceObj is JQueryStyleEven
22
24
}
23
25
24
26
function isNodeList ( sourceObj : any ) : sourceObj is NodeList {
25
- return ! ! sourceObj && sourceObj . toString ( ) === '[object NodeList]' ;
27
+ return ! ! sourceObj && toString . call ( sourceObj ) === '[object NodeList]' ;
26
28
}
27
29
28
30
function isHTMLCollection ( sourceObj : any ) : sourceObj is HTMLCollection {
29
- return ! ! sourceObj && sourceObj . toString ( ) === '[object HTMLCollection]' ;
31
+ return ! ! sourceObj && toString . call ( sourceObj ) === '[object HTMLCollection]' ;
30
32
}
31
33
32
34
function isEventTarget ( sourceObj : any ) : sourceObj is EventTarget {
You can’t perform that action at this time.
0 commit comments