Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2dcf70c

Browse filesBrowse files
joyeecheungtargos
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 f9b19d7 commit 2dcf70c
Copy full SHA for 2dcf70c

File tree

Expand file treeCollapse file tree

2 files changed

+15
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-1
lines changed
Open diff view settings
Collapse file

‎src/node_modules.cc‎

Copy file name to clipboardExpand all lines: src/node_modules.cc
+4-1Lines changed: 4 additions & 1 deletion
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 = {
Collapse file
+11Lines changed: 11 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.