Skip to content

Commit

Permalink
Remove debugging code
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoffreyBooth committed Jan 7, 2023
1 parent 84160b5 commit 1e6c05e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 31 deletions.
15 changes: 0 additions & 15 deletions lib/internal/modules/esm/hooks.js
Expand Up @@ -498,33 +498,21 @@ class HooksProxy {
}

TypedArrayPrototypeFill(this.#data, undefined); // Erase handled request/response data
// console.log('sending request', method, args)
const request = serialize({ method, args });
TypedArrayPrototypeSet(this.#data, request);

// this.#awaitResponse();

const chunks = [];
let done = false;
try {
while (done === false) {
this.#awaitResponse();

const chunk = deserialize(this.#data);
console.log('chunk:', chunk)

if (chunk instanceof Error) { throw chunk; }

({ done } = chunk);
chunks.push(chunk.value);

console.log('awaiting next')
}
} catch (exception) {
console.log('\nmakeRequest failed!\n');
console.log(this.#data);
console.log('byteLength:', this.#data.byteLength);
console.log('this.#data[0]:', this.#data[0]);
if (this.#data[0] === 0) { // Response should not be empty
throw new ERR_INVALID_RETURN_VALUE('an object', method, undefined);
} else {
Expand All @@ -533,9 +521,6 @@ class HooksProxy {
}

const response = Buffer.concat(chunks);

console.log('[HooksProxy]::makeRequest() finished:', deserialize(response));

return response;
}

Expand Down
23 changes: 7 additions & 16 deletions lib/internal/modules/esm/worker.js
@@ -1,12 +1,5 @@
'use strict';

process.on('uncaughtException', (err) => {
process._rawDebug('process uncaughtException:', new Error().stack);
const { triggerUncaughtException } = internalBinding('errors');
releaseLock();
triggerUncaughtException(err);
});

const {
Int32Array,
ReflectApply,
Expand Down Expand Up @@ -49,7 +42,6 @@ function releaseLock() {
try {
initializeESM();
hooks = await initializeHooks();
process._rawDebug('[WORKER]:', 'hooks:', hooks);
} catch (exception) {
// If there was an error while parsing and executing a user loader, for example if because a loader contained a syntax error,
// then we need to send the error to the main thread so it can be thrown and printed.
Expand All @@ -65,7 +57,6 @@ process._rawDebug('[WORKER]:', 'hooks:', hooks);
Atomics.wait(lock, 0, 1); // This pauses the while loop

const { method, args } = deserialize(data);
process._rawDebug('[WORKER]:', 'request received:', method, args);
TypedArrayPrototypeFill(data, undefined);

// Each potential exception needs to be caught individually so that the correct error is sent to the main thread
Expand All @@ -85,26 +76,19 @@ process._rawDebug('[WORKER]:', 'hooks:', hooks);
}

try {
process._rawDebug('[WORKER]:', 'response:', response);
const serializedResponseValue = serialize(response);
const chunkCount = Math.ceil(serializedResponseValue.byteLength / CHUNK_THRESHOLD);
process._rawDebug('[WORKER]:', 'chunkCount:', chunkCount)
for (let i = 0; i < chunkCount; i++) {
const chunk = {
__proto__: null,
done: i === chunkCount - 1,
value: serializedResponseValue.slice(i),
};
process._rawDebug('[WORKER]:', 'chunk:', chunk);
const serializedChunk = serialize(chunk);
process._rawDebug('[WORKER]:', 'serializedChunk:', serializedChunk);
// Send the method response (or exception) to the main thread

TypedArrayPrototypeSet(data, serializedChunk);
// process._rawDebug('[WORKER]:', 'chunk set; releasing lock');
releaseLock();
}

} catch (exception) {
TypedArrayPrototypeSet(data, serialize(exception));
releaseLock();
Expand All @@ -118,3 +102,10 @@ process._rawDebug('[WORKER]:', 'hooks:', hooks);
releaseLock();
triggerUncaughtException(err);
});

process.on('uncaughtException', (err) => {
process._rawDebug('process uncaughtException:', new Error().stack);
const { triggerUncaughtException } = internalBinding('errors');
releaseLock();
triggerUncaughtException(err);
});

0 comments on commit 1e6c05e

Please sign in to comment.