Skip to content

Commit 6e4e3f0

Browse files
committed
Misc compatibility fixes (fixes string_decoder)
1 parent 3cc652f commit 6e4e3f0

File tree

4 files changed

+215
-24
lines changed

4 files changed

+215
-24
lines changed

0.10/node.d.ts

Lines changed: 88 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,81 @@
55

66
/************************************************
77
* *
8-
* Node.js v0.10.1 API *
8+
* Node.js v0.10.x API *
99
* *
1010
************************************************/
1111

12+
interface NodeError {
13+
/**
14+
* Returns a string describing the point in the code at which the Error was instantiated.
15+
*
16+
* For example:
17+
*
18+
* ```
19+
* Error: Things keep happening!
20+
* at /home/gbusey/file.js:525:2
21+
* at Frobnicator.refrobulate (/home/gbusey/business-logic.js:424:21)
22+
* at Actor.<anonymous> (/home/gbusey/actors.js:400:8)
23+
* at increaseSynergy (/home/gbusey/actors.js:701:6)
24+
* ```
25+
*
26+
* The first line is formatted as <error class name>: <error message>, and is followed by a series of stack frames (each line beginning with "at "). Each frame describes a call site within the code that lead to the error being generated. V8 attempts to display a name for each function (by variable name, function name, or object method name), but occasionally it will not be able to find a suitable name. If V8 cannot determine a name for the function, only location information will be displayed for that frame. Otherwise, the determined function name will be displayed with location information appended in parentheses.
27+
*/
28+
stack?: string;
29+
30+
/**
31+
* Returns the string description of error as set by calling new Error(message). The message passed to the constructor will also appear in the first line of the stack trace of the Error, however changing this property after the Error object is created may not change the first line of the stack trace.
32+
*
33+
* ```
34+
* const err = new Error('The message');
35+
* console.log(err.message);
36+
* // Prints: The message
37+
* ```
38+
*/
39+
message: string;
40+
}
41+
42+
interface Error extends NodeError { }
43+
44+
interface ErrorConstructor {
45+
/**
46+
* Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()`` was called.
47+
*
48+
* ```js
49+
* const myObject = {};
50+
* Error.captureStackTrace(myObject);
51+
* myObject.stack // similar to `new Error().stack`
52+
* ```
53+
*
54+
* The first line of the trace, instead of being prefixed with `ErrorType : message`, will be the result of calling `targetObject.toString()``.
55+
*
56+
* The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.
57+
*
58+
* The constructorOpt argument is useful for hiding implementation details of error generation from an end user. For instance:
59+
*
60+
* ```js
61+
* function MyError() {
62+
* Error.captureStackTrace(this, MyError);
63+
* }
64+
*
65+
* // Without passing MyError to captureStackTrace, the MyError
66+
* // frame would should up in the .stack property. by passing
67+
* // the constructor, we omit that frame and all frames above it.
68+
* new MyError().stack
69+
* ```
70+
*/
71+
captureStackTrace<T extends { stack?: string }>(targetObject: T, constructorOpt?: new () => T): void;
72+
73+
/**
74+
* The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj))``.
75+
*
76+
* The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.
77+
*
78+
* If set to a non-number value, or set to a negative number, stack traces will not capture any frames.
79+
*/
80+
stackTraceLimit: number;
81+
}
82+
1283
/************************************************
1384
* *
1485
* GLOBAL *
@@ -232,6 +303,7 @@ declare namespace NodeJS {
232303
ares: string;
233304
uv: string;
234305
zlib: string;
306+
modules: string;
235307
openssl: string;
236308
};
237309
config: {
@@ -1035,6 +1107,7 @@ declare module "fs" {
10351107
bytesRead: number;
10361108
path: string;
10371109
close(): void;
1110+
destroy(): void;
10381111
}
10391112

10401113
export class WriteStream extends stream.Writable implements
@@ -1582,13 +1655,22 @@ declare module "path" {
15821655
}
15831656

15841657
declare module "string_decoder" {
1585-
export interface NodeStringDecoder {
1658+
import * as buffer from "buffer";
1659+
1660+
export class StringDecoder {
1661+
/**
1662+
* @param encoding The character encoding the `StringDecoder` will use. Defaults to `'utf8'`.
1663+
*/
1664+
constructor(encoding?: buffer.Encoding);
1665+
/**
1666+
* Returns a decoded string.
1667+
*/
15861668
write(buffer: Buffer): string;
1587-
detectIncompleteChar(buffer: Buffer): number;
1669+
/**
1670+
* Returns any trailing bytes that were left in the buffer.
1671+
*/
1672+
end(buffer?: Buffer): string;
15881673
}
1589-
export var StringDecoder: {
1590-
new (encoding: string): NodeStringDecoder;
1591-
};
15921674
}
15931675

15941676
declare module "tls" {

0.12/node.d.ts

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
/************************************************
77
* *
8-
* Node.js v0.12.0 API *
8+
* Node.js v0.12.x API *
99
* *
1010
************************************************/
1111

@@ -38,8 +38,48 @@ interface NodeError {
3838
*/
3939
message: string;
4040
}
41+
4142
interface Error extends NodeError { }
4243

44+
interface ErrorConstructor {
45+
/**
46+
* Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()`` was called.
47+
*
48+
* ```js
49+
* const myObject = {};
50+
* Error.captureStackTrace(myObject);
51+
* myObject.stack // similar to `new Error().stack`
52+
* ```
53+
*
54+
* The first line of the trace, instead of being prefixed with `ErrorType : message`, will be the result of calling `targetObject.toString()``.
55+
*
56+
* The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.
57+
*
58+
* The constructorOpt argument is useful for hiding implementation details of error generation from an end user. For instance:
59+
*
60+
* ```js
61+
* function MyError() {
62+
* Error.captureStackTrace(this, MyError);
63+
* }
64+
*
65+
* // Without passing MyError to captureStackTrace, the MyError
66+
* // frame would should up in the .stack property. by passing
67+
* // the constructor, we omit that frame and all frames above it.
68+
* new MyError().stack
69+
* ```
70+
*/
71+
captureStackTrace<T extends { stack?: string }>(targetObject: T, constructorOpt?: new () => T): void;
72+
73+
/**
74+
* The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj))``.
75+
*
76+
* The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.
77+
*
78+
* If set to a non-number value, or set to a negative number, stack traces will not capture any frames.
79+
*/
80+
stackTraceLimit: number;
81+
}
82+
4383
// compat for TypeScript 1.5.3
4484
// if you use with --target es3 or --target es5 and use below definitions,
4585
// use the lib.es6.d.ts that is bundled with TypeScript 1.5.3.
@@ -335,6 +375,7 @@ declare namespace NodeJS {
335375
ares: string;
336376
uv: string;
337377
zlib: string;
378+
modules: string;
338379
openssl: string;
339380
};
340381
config: {
@@ -1325,6 +1366,7 @@ declare module "fs" {
13251366
bytesRead: number;
13261367
path: string;
13271368
close(): void;
1369+
destroy(): void;
13281370
}
13291371

13301372
export class WriteStream extends stream.Writable implements
@@ -2021,13 +2063,22 @@ declare module "path" {
20212063
}
20222064

20232065
declare module "string_decoder" {
2024-
export interface NodeStringDecoder {
2066+
import * as buffer from "buffer";
2067+
2068+
export class StringDecoder {
2069+
/**
2070+
* @param encoding The character encoding the `StringDecoder` will use. Defaults to `'utf8'`.
2071+
*/
2072+
constructor(encoding?: buffer.Encoding);
2073+
/**
2074+
* Returns a decoded string.
2075+
*/
20252076
write(buffer: Buffer): string;
2026-
detectIncompleteChar(buffer: Buffer): number;
2077+
/**
2078+
* Returns any trailing bytes that were left in the buffer.
2079+
*/
2080+
end(buffer?: Buffer): string;
20272081
}
2028-
export var StringDecoder: {
2029-
new (encoding: string): NodeStringDecoder;
2030-
};
20312082
}
20322083

20332084
declare module "tls" {

4.0/node.d.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ interface NodeError {
3838
*/
3939
message: string;
4040
}
41+
4142
interface Error extends NodeError { }
4243

4344
interface ErrorConstructor {
@@ -513,6 +514,7 @@ declare namespace NodeJS {
513514
ares: string;
514515
uv: string;
515516
zlib: string;
517+
modules: string;
516518
openssl: string;
517519
};
518520
config: {
@@ -1570,6 +1572,7 @@ declare module "fs" {
15701572
bytesRead: number;
15711573
path: string;
15721574
close(): void;
1575+
destroy(): void;
15731576
}
15741577

15751578
export class WriteStream extends stream.Writable implements
@@ -2272,13 +2275,22 @@ declare module "path" {
22722275
}
22732276

22742277
declare module "string_decoder" {
2275-
export interface NodeStringDecoder {
2278+
import * as buffer from "buffer";
2279+
2280+
export class StringDecoder {
2281+
/**
2282+
* @param encoding The character encoding the `StringDecoder` will use. Defaults to `'utf8'`.
2283+
*/
2284+
constructor(encoding?: buffer.Encoding);
2285+
/**
2286+
* Returns a decoded string.
2287+
*/
22762288
write(buffer: Buffer): string;
2277-
detectIncompleteChar(buffer: Buffer): number;
2289+
/**
2290+
* Returns any trailing bytes that were left in the buffer.
2291+
*/
2292+
end(buffer?: Buffer): string;
22782293
}
2279-
export var StringDecoder: {
2280-
new (encoding: string): NodeStringDecoder;
2281-
};
22822294
}
22832295

22842296
declare module "tls" {

0 commit comments

Comments
 (0)