| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent edb194b commit 93d0beb
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -104,13 +104,14 @@ URLPatternRegexProvider::regex_search(std::string_view input, | |||
| 104 | 104 | return std::nullopt; | |
| 105 | 105 | } | |
| 106 | 106 | ||
| 107 | + // V8 checks that the regexp exec result is one of the correct types. | ||
| 108 | + DCHECK_IMPLIES(!entry->IsUndefined(), entry->IsString()); | ||
| 109 | + | ||
| 107 | 110 | if (entry->IsUndefined()) { | |
| 108 | 111 | result.emplace_back(std::nullopt); | |
| 109 | 112 | } else if (entry->IsString()) { | |
| 110 | 113 | Utf8Value utf8_entry(isolate, entry.As<String>()); | |
| 111 | 114 | result.emplace_back(utf8_entry.ToString()); | |
| 112 | - } else { | ||
| 113 | - UNREACHABLE("v8::RegExp::Exec return a non-string, non-undefined value."); | ||
| 114 | 115 | } | |
| 115 | 116 | } | |
| 116 | 117 | return result; | |
@@ -191,7 +192,8 @@ void URLPattern::New(const FunctionCallbackInfo<Value>& args) { | |||
| 191 | 192 | return; | |
| 192 | 193 | } | |
| 193 | 194 | } else { | |
| 194 | - THROW_ERR_MISSING_ARGS(env, "baseURL or options must be provided"); | ||
| 195 | + THROW_ERR_INVALID_ARG_TYPE(env, | ||
| 196 | + "second argument must be a string or object"); | ||
| 195 | 197 | return; | |
| 196 | 198 | } | |
| 197 | 199 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,46 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + | ||
| 5 | + const { URLPattern } = require('url'); | ||
| 6 | + const { throws } = require('assert'); | ||
| 7 | + | ||
| 8 | + // Verifies that calling URLPattern with no new keyword throws. | ||
| 9 | + throws(() => URLPattern(), { | ||
| 10 | + code: 'ERR_CONSTRUCT_CALL_REQUIRED', | ||
| 11 | + }); | ||
| 12 | + | ||
| 13 | + // Verifies that type checks are performed on the arguments. | ||
| 14 | + throws(() => new URLPattern(1), { | ||
| 15 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 16 | + }); | ||
| 17 | + | ||
| 18 | + throws(() => new URLPattern({}, 1), { | ||
| 19 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 20 | + }); | ||
| 21 | + | ||
| 22 | + throws(() => new URLPattern({}, '', 1), { | ||
| 23 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 24 | + }); | ||
| 25 | + | ||
| 26 | + throws(() => new URLPattern({}, { ignoreCase: '' }), { | ||
| 27 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 28 | + }); | ||
| 29 | + | ||
| 30 | + const pattern = new URLPattern(); | ||
| 31 | + | ||
| 32 | + throws(() => pattern.exec(1), { | ||
| 33 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 34 | + }); | ||
| 35 | + | ||
| 36 | + throws(() => pattern.exec('', 1), { | ||
| 37 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 38 | + }); | ||
| 39 | + | ||
| 40 | + throws(() => pattern.test(1), { | ||
| 41 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 42 | + }); | ||
| 43 | + | ||
| 44 | + throws(() => pattern.test('', 1), { | ||
| 45 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 46 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments