Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove code trying to handle the error
With newer versions of v8 this doesn't seem to be needed
  • Loading branch information
watson committed Jun 2, 2023
commit 063d8b60f09dd10103c28e4485ec5ef7ecba28f0
11 changes: 0 additions & 11 deletions src/node_process_methods.cc
Original file line number Diff line number Diff line change
Expand Up @@ -480,19 +480,8 @@ static v8::ModifyCodeGenerationFromStringsResult CodeGenCallback(
Local<Value> source,
bool is_code_like) {
Environment* env = Environment::GetCurrent(context);
TryCatchScope try_catch(env);

ProcessEmit(env, "codeGenerationFromString", source);

// V8 does not expect this callback to have a scheduled exceptions once it
// returns, so we print them out in a best effort to do something about it
// without failing silently and without crashing the process.
if (try_catch.HasCaught() && !try_catch.HasTerminated()) {
Isolate* isolate = env->isolate();
fprintf(stderr, "Exception in codeGenerationFromString event callback:\n");
PrintCaughtException(isolate, env->context(), try_catch);
}

// returning {true, val} where val.IsEmpty() makes v8
// use the orignal value passed to `eval` which does not impact
// calls as `eval({})`
Expand Down
24 changes: 7 additions & 17 deletions test/parallel/test-process-codegen-from-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,22 @@ eval('++item.foo');

assert.strictEqual(item.foo, 1);

process.on('codeGenerationFromString', common.mustCall(handleError((code) => {
// Basic eval() test
process.on('codeGenerationFromString', common.mustCall((code) => {
assert.strictEqual(code, 'item.foo++');
})));
}));

eval('item.foo++');
assert.strictEqual(item.foo, 2);

process.removeAllListeners('codeGenerationFromString');

process.on('codeGenerationFromString', common.mustCall(handleError((code) => {
// Basic Function() test
process.on('codeGenerationFromString', common.mustCall((code) => {
assert.strictEqual(code, '(function anonymous(a,b\n) {\nreturn a + b\n})');
})));
}));

const fct = new Function('a', 'b', 'return a + b');
assert.strictEqual(fct(1, 2), 3);

function handleError(fn) {
return (...args) => {
try {
fn(...args);
} catch (err) {
// The C++ code will just log the error to stderr and continue with the
// flow of the program. Set the exit code manually to ensure the test
// script fails in case of an error.
process.exitCode = 1;
throw err;
}
};
}
process.removeAllListeners('codeGenerationFromString');