| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7d505f4 commit a5df778
31 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,6 +56,7 @@ function embedderRunCjs(content) { | |||
| 56 | 56 | function: compiledWrapper, | |
| 57 | 57 | cachedDataRejected, | |
| 58 | 58 | sourceMapURL, | |
| 59 | + sourceURL, | ||
| 59 | 60 | } = compileFunctionForCJSLoader( | |
| 60 | 61 | content, | |
| 61 | 62 | filename, | |
@@ -69,7 +70,7 @@ function embedderRunCjs(content) { | |||
| 69 | 70 | content, | |
| 70 | 71 | customModule, | |
| 71 | 72 | false, // isGeneratedSource | |
| 72 | - undefined, // sourceURL, TODO(joyeecheung): should be extracted by V8 | ||
| 73 | + sourceURL, | ||
| 73 | 74 | sourceMapURL, | |
| 74 | 75 | ); | |
| 75 | 76 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1636,9 +1636,9 @@ function wrapSafe(filename, content, cjsModuleInstance, format) { | |||
| 1636 | 1636 | ); | |
| 1637 | 1637 | ||
| 1638 | 1638 | // Cache the source map for the module if present. | |
| 1639 | - const { sourceMapURL } = script; | ||
| 1639 | + const { sourceMapURL, sourceURL } = script; | ||
| 1640 | 1640 | if (sourceMapURL) { | |
| 1641 | - maybeCacheSourceMap(filename, content, cjsModuleInstance, false, undefined, sourceMapURL); | ||
| 1641 | + maybeCacheSourceMap(filename, content, cjsModuleInstance, false, sourceURL, sourceMapURL); | ||
| 1642 | 1642 | } | |
| 1643 | 1643 | ||
| 1644 | 1644 | return { | |
@@ -1663,7 +1663,7 @@ function wrapSafe(filename, content, cjsModuleInstance, format) { | |||
| 1663 | 1663 | ||
| 1664 | 1664 | // Cache the source map for the module if present. | |
| 1665 | 1665 | if (result.sourceMapURL) { | |
| 1666 | - maybeCacheSourceMap(filename, content, cjsModuleInstance, false, undefined, result.sourceMapURL); | ||
| 1666 | + maybeCacheSourceMap(filename, content, cjsModuleInstance, false, result.sourceURL, result.sourceMapURL); | ||
| 1667 | 1667 | } | |
| 1668 | 1668 | ||
| 1669 | 1669 | return result; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -120,10 +120,10 @@ translators.set('module', function moduleStrategy(url, source, isMain) { | |||
| 120 | 120 | function loadCJSModule(module, source, url, filename, isMain) { | |
| 121 | 121 | const compileResult = compileFunctionForCJSLoader(source, filename, false /* is_sea_main */, false); | |
| 122 | 122 | ||
| 123 | - const { function: compiledWrapper, sourceMapURL } = compileResult; | ||
| 123 | + const { function: compiledWrapper, sourceMapURL, sourceURL } = compileResult; | ||
| 124 | 124 | // Cache the source map for the cjs module if present. | |
| 125 | 125 | if (sourceMapURL) { | |
| 126 | - maybeCacheSourceMap(url, source, module, false, undefined, sourceMapURL); | ||
| 126 | + maybeCacheSourceMap(url, source, module, false, sourceURL, sourceMapURL); | ||
| 127 | 127 | } | |
| 128 | 128 | ||
| 129 | 129 | const cascadedLoader = require('internal/modules/esm/loader').getOrInitializeCascadedLoader(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -348,7 +348,7 @@ function compileSourceTextModule(url, source, cascadedLoader) { | |||
| 348 | 348 | } | |
| 349 | 349 | // Cache the source map for the module if present. | |
| 350 | 350 | if (wrap.sourceMapURL) { | |
| 351 | - maybeCacheSourceMap(url, source, wrap, false, undefined, wrap.sourceMapURL); | ||
| 351 | + maybeCacheSourceMap(url, source, wrap, false, wrap.sourceURL, wrap.sourceMapURL); | ||
| 352 | 352 | } | |
| 353 | 353 | return wrap; | |
| 354 | 354 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -139,7 +139,9 @@ function extractSourceMapURLMagicComment(content) { | |||
| 139 | 139 | } | |
| 140 | 140 | ||
| 141 | 141 | /** | |
| 142 | - * Caches the source map if it is present in the content, with the given filename, moduleInstance, and sourceURL. | ||
| 142 | + * Caches the source map, with the given filename, moduleInstance, sourceURL and sourceMapURL. | ||
| 143 | + * This function does not automatically extract the source map from the content. The caller should either | ||
| 144 | + * extract the source map from the content via V8 API or use {@link extractSourceURLMagicComment} explicitly. | ||
| 143 | 145 | * @param {string} filename - the actual filename | |
| 144 | 146 | * @param {string} content - the actual source content | |
| 145 | 147 | * @param {import('internal/modules/cjs/loader').Module | ModuleWrap} moduleInstance - a module instance that | |
@@ -162,20 +164,13 @@ function maybeCacheSourceMap(filename, content, moduleInstance, isGeneratedSourc | |||
| 162 | 164 | return; | |
| 163 | 165 | } | |
| 164 | 166 | ||
| 165 | - if (sourceMapURL === undefined) { | ||
| 166 | - sourceMapURL = extractSourceMapURLMagicComment(content); | ||
| 167 | - } | ||
| 168 | - | ||
| 169 | 167 | // Bail out when there is no source map url. | |
| 170 | 168 | if (typeof sourceMapURL !== 'string') { | |
| 171 | 169 | return; | |
| 172 | 170 | } | |
| 173 | 171 | ||
| 174 | - // FIXME: callers should obtain sourceURL from v8 and pass it | ||
| 175 | - // rather than leaving it undefined and extract by regex. | ||
| 176 | - if (sourceURL === undefined) { | ||
| 177 | - sourceURL = extractSourceURLMagicComment(content); | ||
| 178 | - } | ||
| 172 | + // Normalize the sourceURL to a file URL if it is a path. | ||
| 173 | + sourceURL = normalizeReferrerURL(sourceURL); | ||
| 179 | 174 | ||
| 180 | 175 | const data = dataFromUrl(filename, sourceMapURL); | |
| 181 | 176 | // `data` could be null if the source map is invalid. | |
@@ -192,9 +187,6 @@ function maybeCacheSourceMap(filename, content, moduleInstance, isGeneratedSourc | |||
| 192 | 187 | ||
| 193 | 188 | if (isGeneratedSource) { | |
| 194 | 189 | generatedSourceMapCache.set(filename, entry); | |
| 195 | - if (sourceURL) { | ||
| 196 | - generatedSourceMapCache.set(sourceURL, entry); | ||
| 197 | - } | ||
| 198 | 190 | return; | |
| 199 | 191 | } | |
| 200 | 192 | // If it is not a generated source, we assume we are in a "cjs/esm" | |
@@ -215,8 +207,14 @@ function maybeCacheGeneratedSourceMap(content) { | |||
| 215 | 207 | if (sourceURL === null) { | |
| 216 | 208 | return; | |
| 217 | 209 | } | |
| 210 | + const sourceMapURL = extractSourceMapURLMagicComment(content); | ||
| 211 | + if (sourceMapURL === null) { | ||
| 212 | + return; | ||
| 213 | + } | ||
| 214 | + | ||
| 218 | 215 | try { | |
| 219 | - maybeCacheSourceMap(sourceURL, content, null, true, sourceURL); | ||
| 216 | + // Use the sourceURL as the filename, and do not create a duplicate entry. | ||
| 217 | + maybeCacheSourceMap(sourceURL, content, null, true, undefined /** no duplicated sourceURL */, sourceMapURL); | ||
| 220 | 218 | } catch (err) { | |
| 221 | 219 | // This can happen if the filename is not a valid URL. | |
| 222 | 220 | // If we fail to cache the source map, we should not fail the whole process. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -354,6 +354,7 @@ | |||
| 354 | 354 | V(sni_context_string, "sni_context") \ | |
| 355 | 355 | V(source_string, "source") \ | |
| 356 | 356 | V(source_map_url_string, "sourceMapURL") \ | |
| 357 | + V(source_url_string, "sourceURL") \ | ||
| 357 | 358 | V(specifier_string, "specifier") \ | |
| 358 | 359 | V(stack_string, "stack") \ | |
| 359 | 360 | V(standard_name_string, "standardName") \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -305,6 +305,13 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) { | |||
| 305 | 305 | return; | |
| 306 | 306 | } | |
| 307 | 307 | ||
| 308 | + if (that->Set(context, | ||
| 309 | + realm->env()->source_url_string(), | ||
| 310 | + module->GetUnboundModuleScript()->GetSourceURL()) | ||
| 311 | + .IsNothing()) { | ||
| 312 | + return; | ||
| 313 | + } | ||
| 314 | + | ||
| 308 | 315 | if (that->Set(context, | |
| 309 | 316 | realm->env()->source_map_url_string(), | |
| 310 | 317 | module->GetUnboundModuleScript()->GetSourceMappingURL()) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1107,6 +1107,13 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) { | |||
| 1107 | 1107 | return; | |
| 1108 | 1108 | } | |
| 1109 | 1109 | ||
| 1110 | + if (args.This() | ||
| 1111 | + ->Set(env->context(), | ||
| 1112 | + env->source_url_string(), | ||
| 1113 | + v8_script->GetSourceURL()) | ||
| 1114 | + .IsNothing()) | ||
| 1115 | + return; | ||
| 1116 | + | ||
| 1110 | 1117 | if (args.This() | |
| 1111 | 1118 | ->Set(env->context(), | |
| 1112 | 1119 | env->source_map_url_string(), | |
@@ -1565,12 +1572,23 @@ MaybeLocal<Object> ContextifyFunction::CompileFunctionAndCacheResult( | |||
| 1565 | 1572 | Local<Object> result = Object::New(isolate); | |
| 1566 | 1573 | if (result->Set(parsing_context, env->function_string(), fn).IsNothing()) | |
| 1567 | 1574 | return {}; | |
| 1575 | + | ||
| 1576 | + // ScriptOrigin::ResourceName() returns SourceURL magic comment content if | ||
| 1577 | + // present. | ||
| 1578 | + if (result | ||
| 1579 | + ->Set(parsing_context, | ||
| 1580 | + env->source_url_string(), | ||
| 1581 | + fn->GetScriptOrigin().ResourceName()) | ||
| 1582 | + .IsNothing()) { | ||
| 1583 | + return {}; | ||
| 1584 | + } | ||
| 1568 | 1585 | if (result | |
| 1569 | 1586 | ->Set(parsing_context, | |
| 1570 | 1587 | env->source_map_url_string(), | |
| 1571 | 1588 | fn->GetScriptOrigin().SourceMapUrl()) | |
| 1572 | - .IsNothing()) | ||
| 1589 | + .IsNothing()) { | ||
| 1573 | 1590 | return {}; | |
| 1591 | + } | ||
| 1574 | 1592 | ||
| 1575 | 1593 | std::unique_ptr<ScriptCompiler::CachedData> new_cached_data; | |
| 1576 | 1594 | if (produce_cached_data) { | |
@@ -1808,12 +1826,16 @@ static void CompileFunctionForCJSLoader( | |||
| 1808 | 1826 | Local<Name> names[] = { | |
| 1809 | 1827 | env->cached_data_rejected_string(), | |
| 1810 | 1828 | env->source_map_url_string(), | |
| 1829 | + env->source_url_string(), | ||
| 1811 | 1830 | env->function_string(), | |
| 1812 | 1831 | FIXED_ONE_BYTE_STRING(isolate, "canParseAsESM"), | |
| 1813 | 1832 | }; | |
| 1814 | 1833 | Local<Value> values[] = { | |
| 1815 | 1834 | Boolean::New(isolate, cache_rejected), | |
| 1816 | 1835 | fn.IsEmpty() ? undefined : fn->GetScriptOrigin().SourceMapUrl(), | |
| 1836 | + // ScriptOrigin::ResourceName() returns SourceURL magic comment content if | ||
| 1837 | + // present. | ||
| 1838 | + fn.IsEmpty() ? undefined : fn->GetScriptOrigin().ResourceName(), | ||
| 1817 | 1839 | fn.IsEmpty() ? undefined : fn.As<Value>(), | |
| 1818 | 1840 | Boolean::New(isolate, can_parse_as_esm), | |
| 1819 | 1841 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,6 +16,10 @@ function replaceStackTrace(str, replacement = '$1*$7$8\n') { | |||
| 16 | 16 | return str.replace(stackFramesRegexp, replacement); | |
| 17 | 17 | } | |
| 18 | 18 | ||
| 19 | + function replaceInternalStackTrace(str) { | ||
| 20 | + return str.replaceAll(/(\W+).*node:internal.*/g, '$1*'); | ||
| 21 | + } | ||
| 22 | + | ||
| 19 | 23 | function replaceWindowsLineEndings(str) { | |
| 20 | 24 | return str.replace(windowNewlineRegexp, ''); | |
| 21 | 25 | } | |
@@ -24,8 +28,11 @@ function replaceWindowsPaths(str) { | |||
| 24 | 28 | return common.isWindows ? str.replaceAll(path.win32.sep, path.posix.sep) : str; | |
| 25 | 29 | } | |
| 26 | 30 | ||
| 27 | - function replaceFullPaths(str) { | ||
| 28 | - return str.replaceAll('\\\'', "'").replaceAll(path.resolve(__dirname, '../..'), ''); | ||
| 31 | + function transformProjectRoot(replacement = '') { | ||
| 32 | + const projectRoot = path.resolve(__dirname, '../..'); | ||
| 33 | + return (str) => { | ||
| 34 | + return str.replaceAll('\\\'', "'").replaceAll(projectRoot, replacement); | ||
| 35 | + }; | ||
| 29 | 36 | } | |
| 30 | 37 | ||
| 31 | 38 | function transform(...args) { | |
@@ -94,11 +101,12 @@ async function spawnAndAssert(filename, transform = (x) => x, { tty = false, ... | |||
| 94 | 101 | module.exports = { | |
| 95 | 102 | assertSnapshot, | |
| 96 | 103 | getSnapshotPath, | |
| 97 | - replaceFullPaths, | ||
| 98 | 104 | replaceNodeVersion, | |
| 99 | 105 | replaceStackTrace, | |
| 106 | + replaceInternalStackTrace, | ||
| 100 | 107 | replaceWindowsLineEndings, | |
| 101 | 108 | replaceWindowsPaths, | |
| 102 | 109 | spawnAndAssert, | |
| 103 | 110 | transform, | |
| 111 | + transformProjectRoot, | ||
| 104 | 112 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,12 +1,12 @@ | |||
| 1 | 1 | Error: an error! | |
| 2 | - at functionD (*enclosing-call-site-min.js:1:156) | ||
| 3 | - at functionC (*enclosing-call-site-min.js:1:97) | ||
| 4 | - at functionB (*enclosing-call-site-min.js:1:60) | ||
| 5 | - at functionA (*enclosing-call-site-min.js:1:26) | ||
| 6 | - at Object.<anonymous> (*enclosing-call-site-min.js:1:199) | ||
| 2 | + at functionD (*/test/fixtures/source-map/enclosing-call-site-min.js:1:156) | ||
| 3 | + at functionC (*/test/fixtures/source-map/enclosing-call-site-min.js:1:97) | ||
| 4 | + at functionB (*/test/fixtures/source-map/enclosing-call-site-min.js:1:60) | ||
| 5 | + at functionA (*/test/fixtures/source-map/enclosing-call-site-min.js:1:26) | ||
| 6 | + at Object.<anonymous> (*/test/fixtures/source-map/enclosing-call-site-min.js:1:199) | ||
| 7 | 7 | Error: an error! | |
| 8 | - at functionD (*enclosing-call-site.js:16:17) | ||
| 9 | - at functionC (*enclosing-call-site.js:10:3) | ||
| 10 | - at functionB (*enclosing-call-site.js:6:3) | ||
| 11 | - at functionA (*enclosing-call-site.js:2:3) | ||
| 12 | - at Object.<anonymous> (*enclosing-call-site.js:24:3) | ||
| 8 | + at functionD (*/test/fixtures/source-map/enclosing-call-site.js:16:17) | ||
| 9 | + at functionC (*/test/fixtures/source-map/enclosing-call-site.js:10:3) | ||
| 10 | + at functionB (*/test/fixtures/source-map/enclosing-call-site.js:6:3) | ||
| 11 | + at functionA (*/test/fixtures/source-map/enclosing-call-site.js:2:3) | ||
| 12 | + at Object.<anonymous> (*/test/fixtures/source-map/enclosing-call-site.js:24:3) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments