提交 02b88578 编写于 作者: A Alex Dima

Fix monaco compilation

上级 6ff5ec21
......@@ -34,7 +34,6 @@
"vs/platform/*/browser/*"
],
"exclude": [
"node_modules/*",
"vs/base/common/buffer.ts"
"node_modules/*"
]
}
......@@ -3,13 +3,20 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
declare var Buffer: any;
const hasBuffer = (typeof Buffer !== 'undefined');
export class VSBuffer {
public static alloc(byteLength: number): VSBuffer {
return new VSBuffer(Buffer.allocUnsafe(byteLength));
if (hasBuffer) {
return new VSBuffer(Buffer.allocUnsafe(byteLength));
} else {
return new VSBuffer(new Uint8Array(byteLength));
}
}
public static wrap(actual: Buffer): VSBuffer {
public static wrap(actual: Uint8Array): VSBuffer {
return new VSBuffer(actual);
}
......@@ -36,45 +43,40 @@ export class VSBuffer {
return ret;
}
private readonly _actual: Buffer;
public readonly buffer: Uint8Array;
public readonly byteLength: number;
private constructor(buffer: Buffer) {
this._actual = buffer;
this.byteLength = this._actual.byteLength;
}
public toBuffer(): Buffer {
// TODO@Alex: deprecate this usage
return this._actual;
private constructor(buffer: Uint8Array) {
this.buffer = buffer;
this.byteLength = this.buffer.byteLength;
}
public toString(): string {
return this._actual.toString();
return this.buffer.toString();
}
public slice(start?: number, end?: number): VSBuffer {
return new VSBuffer(this._actual.slice(start, end));
return new VSBuffer(this.buffer.slice(start, end));
}
public set(array: VSBuffer, offset?: number): void {
this._actual.set(array._actual, offset);
this.buffer.set(array.buffer, offset);
}
public readUint32BE(offset: number): number {
return readUint32BE(this._actual, offset);
return readUint32BE(this.buffer, offset);
}
public writeUint32BE(value: number, offset: number): void {
writeUint32BE(this._actual, value, offset);
writeUint32BE(this.buffer, value, offset);
}
public readUint8(offset: number): number {
return readUint8(this._actual, offset);
return readUint8(this.buffer, offset);
}
public writeUint8(value: number, offset: number): void {
writeUint8(this._actual, value, offset);
writeUint8(this.buffer, value, offset);
}
}
......
......@@ -7,6 +7,9 @@ import { Event, Emitter } from 'vs/base/common/event';
import { IMessagePassingProtocol, IPCClient } from 'vs/base/parts/ipc/common/ipc';
import { IDisposable, Disposable, dispose } from 'vs/base/common/lifecycle';
import { VSBuffer } from 'vs/base/common/buffer';
import * as platform from 'vs/base/common/platform';
declare var process: any;
export interface ISocket {
onData(listener: (e: VSBuffer) => void): IDisposable;
......@@ -284,7 +287,7 @@ class ProtocolWriter {
private _writeSoon(header: VSBuffer, data: VSBuffer): void {
if (this._bufferAdd(header, data)) {
setImmediate(() => {
platform.setImmediate(() => {
this._writeNow();
});
}
......@@ -402,7 +405,11 @@ function createBufferedEvent<T>(source: Event<T>): Event<T> {
// it is important to deliver these messages after this call, but before
// other messages have a chance to be received (to guarantee in order delivery)
// that's why we're using here nextTick and not other types of timeouts
process.nextTick(deliverMessages);
if (typeof process !== 'undefined') {
process.nextTick(deliverMessages);
} else {
platform.setImmediate(deliverMessages);
}
},
onLastListenerRemove: () => {
hasListeners = false;
......@@ -484,15 +491,15 @@ export class PersistentProtocol {
private _outgoingUnackMsg: Queue<ProtocolMessage>;
private _outgoingMsgId: number;
private _outgoingAckId: number;
private _outgoingAckTimeout: NodeJS.Timeout | null;
private _outgoingAckTimeout: any | null;
private _incomingMsgId: number;
private _incomingAckId: number;
private _incomingMsgLastTime: number;
private _incomingAckTimeout: NodeJS.Timeout | null;
private _incomingAckTimeout: any | null;
private _outgoingKeepAliveTimeout: NodeJS.Timeout | null;
private _incomingKeepAliveTimeout: NodeJS.Timeout | null;
private _outgoingKeepAliveTimeout: any | null;
private _incomingKeepAliveTimeout: any | null;
private _socket: ISocket;
private _socketWriter: ProtocolWriter;
......
......@@ -189,6 +189,9 @@ const BufferPresets = {
Object: createOneByteBuffer(DataType.Object),
};
declare var Buffer: any;
const hasBuffer = (typeof Buffer !== 'undefined');
function serialize(writer: IWriter, data: any): void {
if (typeof data === 'undefined') {
writer.write(BufferPresets.Undefined);
......@@ -197,7 +200,7 @@ function serialize(writer: IWriter, data: any): void {
writer.write(BufferPresets.String);
writer.write(createSizeBuffer(buffer.byteLength));
writer.write(buffer);
} else if (Buffer.isBuffer(data)) {
} else if (hasBuffer && Buffer.isBuffer(data)) {
const buffer = VSBuffer.wrap(data);
writer.write(BufferPresets.Buffer);
writer.write(createSizeBuffer(buffer.byteLength));
......@@ -227,7 +230,7 @@ function deserialize(reader: IReader): any {
switch (type) {
case DataType.Undefined: return undefined;
case DataType.String: return reader.read(readSizeBuffer(reader)).toString();
case DataType.Buffer: return reader.read(readSizeBuffer(reader)).toBuffer();
case DataType.Buffer: return reader.read(readSizeBuffer(reader)).buffer;
case DataType.VSBuffer: return reader.read(readSizeBuffer(reader));
case DataType.Array: {
const length = readSizeBuffer(reader);
......
......@@ -26,7 +26,7 @@ export class Server<TContext extends string> extends IPCServer<TContext> {
send: r => {
try {
if (process.send) {
process.send(r.toBuffer().toString('base64'));
process.send((<Buffer>r.buffer).toString('base64'));
}
} catch (e) { /* not much to do */ }
},
......@@ -215,7 +215,7 @@ export class Client implements IChannelClient, IDisposable {
});
const sender = this.options.useQueue ? createQueuedSender(this.child) : this.child;
const send = (r: VSBuffer) => this.child && this.child.connected && sender.send(r.toBuffer().toString('base64'));
const send = (r: VSBuffer) => this.child && this.child.connected && sender.send((<Buffer>r.buffer).toString('base64'));
const onMessage = onMessageEmitter.event;
const protocol = { send, onMessage };
......
......@@ -17,7 +17,7 @@ export class Protocol implements IMessagePassingProtocol {
send(message: VSBuffer): void {
try {
this.sender.send('ipc:message', message.toBuffer());
this.sender.send('ipc:message', (<Buffer>message.buffer));
} catch (e) {
// systems are going down
}
......
......@@ -14,37 +14,37 @@ import { VSBuffer } from 'vs/base/common/buffer';
import { ISocket, Protocol, Client } from 'vs/base/parts/ipc/common/ipc.net';
export class NodeSocket implements ISocket {
private readonly _socket: Socket;
public readonly socket: Socket;
constructor(socket: Socket) {
this._socket = socket;
this.socket = socket;
}
public onData(_listener: (e: VSBuffer) => void): IDisposable {
const listener = (buff: Buffer) => _listener(VSBuffer.wrap(buff));
this._socket.on('data', listener);
this.socket.on('data', listener);
return {
dispose: () => this._socket.off('data', listener)
dispose: () => this.socket.off('data', listener)
};
}
public onClose(listener: () => void): IDisposable {
this._socket.on('close', listener);
this.socket.on('close', listener);
return {
dispose: () => this._socket.off('close', listener)
dispose: () => this.socket.off('close', listener)
};
}
public onEnd(listener: () => void): IDisposable {
this._socket.on('end', listener);
this.socket.on('end', listener);
return {
dispose: () => this._socket.off('end', listener)
dispose: () => this.socket.off('end', listener)
};
}
public write(buffer: VSBuffer): void {
// return early if socket has been destroyed in the meantime
if (this._socket.destroyed) {
if (this.socket.destroyed) {
return;
}
......@@ -53,11 +53,11 @@ export class NodeSocket implements ISocket {
// > https://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback
// > However, the false return value is only advisory and the writable stream will unconditionally
// > accept and buffer chunk even if it has not not been allowed to drain.
this._socket.write(buffer.toBuffer());
this.socket.write(<Buffer>buffer.buffer);
}
public end(): void {
this._socket.end();
this.socket.end();
}
}
......
......@@ -529,7 +529,7 @@ class MessageBuffer {
public readBuffer(): Buffer {
const buffLength = this._buff.readUint32BE(this._offset); this._offset += 4;
const buff = this._buff.slice(this._offset, this._offset + buffLength); this._offset += buffLength;
return buff.toBuffer();
return <Buffer>buff.buffer;
}
public static sizeVSBuffer(buff: VSBuffer): number {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册