diff --git a/src/node_modules.cc b/src/node_modules.cc index 3bedd2dfecb49c..721b5e1e4b457d 100644 --- a/src/node_modules.cc +++ b/src/node_modules.cc @@ -436,10 +436,13 @@ void BindingData::GetPackageScopeConfig( } void EnableCompileCache(const FunctionCallbackInfo& args) { - CHECK(args[0]->IsString()); Isolate* isolate = args.GetIsolate(); Local 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> values = { diff --git a/test/parallel/test-compile-cache-api-error.js b/test/parallel/test-compile-cache-api-error.js new file mode 100644 index 00000000000000..580c8f756a0f04 --- /dev/null +++ b/test/parallel/test-compile-cache-api-error.js @@ -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' }); +}