mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
src,test: expand test coverage for urlpattern and fix error
PR-URL: https://github.com/nodejs/node/pull/56878 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
This commit is contained in:
1 parent
a091f4890e
commit
eb11adfc02
2 files changed
+51
-3
No files matched your search
@@ -104,13 +104,14 @@ URLPatternRegexProvider::regex_search(std::string_view input,
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// V8 checks that the regexp exec result is one of the correct types.
|
||||
DCHECK_IMPLIES(!entry->IsUndefined(), entry->IsString());
|
||||
|
||||
if (entry->IsUndefined()) {
|
||||
result.emplace_back(std::nullopt);
|
||||
} else if (entry->IsString()) {
|
||||
Utf8Value utf8_entry(isolate, entry.As<String>());
|
||||
result.emplace_back(utf8_entry.ToString());
|
||||
} else {
|
||||
UNREACHABLE("v8::RegExp::Exec return a non-string, non-undefined value.");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -191,7 +192,8 @@ void URLPattern::New(const FunctionCallbackInfo<Value>& args) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
THROW_ERR_MISSING_ARGS(env, "baseURL or options must be provided");
|
||||
THROW_ERR_INVALID_ARG_TYPE(env,
|
||||
"second argument must be a string or object");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
|
||||
const { URLPattern } = require('url');
|
||||
const { throws } = require('assert');
|
||||
|
||||
// Verifies that calling URLPattern with no new keyword throws.
|
||||
throws(() => URLPattern(), {
|
||||
code: 'ERR_CONSTRUCT_CALL_REQUIRED',
|
||||
});
|
||||
|
||||
// Verifies that type checks are performed on the arguments.
|
||||
throws(() => new URLPattern(1), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
|
||||
throws(() => new URLPattern({}, 1), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
|
||||
throws(() => new URLPattern({}, '', 1), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
|
||||
throws(() => new URLPattern({}, { ignoreCase: '' }), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
|
||||
const pattern = new URLPattern();
|
||||
|
||||
throws(() => pattern.exec(1), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
|
||||
throws(() => pattern.exec('', 1), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
|
||||
throws(() => pattern.test(1), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
|
||||
throws(() => pattern.test('', 1), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
Reference in new issue
Block a user