Skip to content

Commit 4dfed55

Browse files
joyeecheungnodejs-github-bot
authored andcommitted
module: throw when invalid argument is passed to enableCompileCache()
PR-URL: #54971 Fixes: #54770 Fixes: #54465 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 9a73aa0 commit 4dfed55

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/node_modules.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,13 @@ void BindingData::GetPackageScopeConfig(
436436
}
437437

438438
void EnableCompileCache(const FunctionCallbackInfo<Value>& args) {
439-
CHECK(args[0]->IsString());
440439
Isolate* isolate = args.GetIsolate();
441440
Local<Context> context = isolate->GetCurrentContext();
442441
Environment* env = Environment::GetCurrent(context);
442+
if (!args[0]->IsString()) {
443+
THROW_ERR_INVALID_ARG_TYPE(env, "cacheDir should be a string");
444+
return;
445+
}
443446
Utf8Value value(isolate, args[0]);
444447
CompileCacheEnableResult result = env->EnableCompileCache(*value);
445448
std::vector<Local<Value>> values = {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
// This tests module.enableCompileCache() throws when an invalid argument is passed.
4+
5+
require('../common');
6+
const { enableCompileCache } = require('module');
7+
const assert = require('assert');
8+
9+
for (const invalid of [0, null, false, () => {}, {}, []]) {
10+
assert.throws(() => enableCompileCache(invalid), { code: 'ERR_INVALID_ARG_TYPE' });
11+
}

0 commit comments

Comments
 (0)