module: throw when invalid argument is passed to enableCompileCache()

PR-URL: https://github.com/nodejs/node/pull/54971
Fixes: https://github.com/nodejs/node/issues/54770
Fixes: https://github.com/nodejs/node/issues/54465
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
Joyee Cheung 2024-09-17 11:48:56 +02:00 committed by Node.js GitHub Bot
parent 9a73aa0d15
commit 4dfed556ba
2 changed files with 15 additions and 1 deletions

View File

@ -436,10 +436,13 @@ void BindingData::GetPackageScopeConfig(
}
void EnableCompileCache(const FunctionCallbackInfo<Value>& args) {
CHECK(args[0]->IsString());
Isolate* isolate = args.GetIsolate();
Local<Context> context = isolate->GetCurrentContext();
Environment* env = Environment::GetCurrent(context);
if (!args[0]->IsString()) {
THROW_ERR_INVALID_ARG_TYPE(env, "cacheDir should be a string");
return;
}
Utf8Value value(isolate, args[0]);
CompileCacheEnableResult result = env->EnableCompileCache(*value);
std::vector<Local<Value>> values = {

View File

@ -0,0 +1,11 @@
'use strict';
// This tests module.enableCompileCache() throws when an invalid argument is passed.
require('../common');
const { enableCompileCache } = require('module');
const assert = require('assert');
for (const invalid of [0, null, false, () => {}, {}, []]) {
assert.throws(() => enableCompileCache(invalid), { code: 'ERR_INVALID_ARG_TYPE' });
}