mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
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:
parent
9a73aa0d15
commit
4dfed556ba
@ -436,10 +436,13 @@ void BindingData::GetPackageScopeConfig(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EnableCompileCache(const FunctionCallbackInfo<Value>& args) {
|
void EnableCompileCache(const FunctionCallbackInfo<Value>& args) {
|
||||||
CHECK(args[0]->IsString());
|
|
||||||
Isolate* isolate = args.GetIsolate();
|
Isolate* isolate = args.GetIsolate();
|
||||||
Local<Context> context = isolate->GetCurrentContext();
|
Local<Context> context = isolate->GetCurrentContext();
|
||||||
Environment* env = Environment::GetCurrent(context);
|
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]);
|
Utf8Value value(isolate, args[0]);
|
||||||
CompileCacheEnableResult result = env->EnableCompileCache(*value);
|
CompileCacheEnableResult result = env->EnableCompileCache(*value);
|
||||||
std::vector<Local<Value>> values = {
|
std::vector<Local<Value>> values = {
|
||||||
|
11
test/parallel/test-compile-cache-api-error.js
Normal file
11
test/parallel/test-compile-cache-api-error.js
Normal 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' });
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user