Skip to content

Commit

Permalink
module: throw when invalid argument is passed to enableCompileCache()
Browse files Browse the repository at this point in the history
PR-URL: #54971
Fixes: #54770
Fixes: #54465
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
  • Loading branch information
joyeecheung authored and nodejs-github-bot committed Sep 20, 2024
1 parent 9a73aa0 commit 4dfed55
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/node_modules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-compile-cache-api-error.js
Original file line number Diff line number Diff line change
@@ -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' });
}

0 comments on commit 4dfed55

Please sign in to comment.