+261
-140
lines changedFilter options
+261
-140
lines 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
@@ -1640,9 +1640,9 @@ function wrapSafe(filename, content, cjsModuleInstance, format) {
1640
1640
);
1641
1641
1642
1642
// Cache the source map for the module if present.
1643
-
const { sourceMapURL } = script;
1643
+
const { sourceMapURL, sourceURL } = script;
1644
1644
if (sourceMapURL) {
1645
-
maybeCacheSourceMap(filename, content, cjsModuleInstance, false, undefined, sourceMapURL);
1645
+
maybeCacheSourceMap(filename, content, cjsModuleInstance, false, sourceURL, sourceMapURL);
1646
1646
}
1647
1647
1648
1648
return {
@@ -1667,7 +1667,7 @@ function wrapSafe(filename, content, cjsModuleInstance, format) {
1667
1667
1668
1668
// Cache the source map for the module if present.
1669
1669
if (result.sourceMapURL) {
1670
-
maybeCacheSourceMap(filename, content, cjsModuleInstance, false, undefined, result.sourceMapURL);
1670
+
maybeCacheSourceMap(filename, content, cjsModuleInstance, false, result.sourceURL, result.sourceMapURL);
1671
1671
}
1672
1672
1673
1673
return result;
Original file line number Diff line number Diff line change
@@ -122,10 +122,10 @@ translators.set('module', function moduleStrategy(url, source, isMain) {
122
122
function loadCJSModule(module, source, url, filename, isMain) {
123
123
const compileResult = compileFunctionForCJSLoader(source, filename, false /* is_sea_main */, false);
124
124
125
-
const { function: compiledWrapper, sourceMapURL } = compileResult;
125
+
const { function: compiledWrapper, sourceMapURL, sourceURL } = compileResult;
126
126
// Cache the source map for the cjs module if present.
127
127
if (sourceMapURL) {
128
-
maybeCacheSourceMap(url, source, module, false, undefined, sourceMapURL);
128
+
maybeCacheSourceMap(url, source, module, false, sourceURL, sourceMapURL);
129
129
}
130
130
131
131
const cascadedLoader = require('internal/modules/esm/loader').getOrInitializeCascadedLoader();
Original file line number Diff line number Diff line change
@@ -361,7 +361,7 @@ function compileSourceTextModule(url, source, cascadedLoader, context = kEmptyOb
361
361
362
362
// Cache the source map for the module if present.
363
363
if (wrap.sourceMapURL) {
364
-
maybeCacheSourceMap(url, source, wrap, false, undefined, wrap.sourceMapURL);
364
+
maybeCacheSourceMap(url, source, wrap, false, wrap.sourceURL, wrap.sourceMapURL);
365
365
}
366
366
return wrap;
367
367
}
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
@@ -363,6 +363,7 @@
363
363
V(sni_context_string, "sni_context") \
364
364
V(source_string, "source") \
365
365
V(source_map_url_string, "sourceMapURL") \
366
+
V(source_url_string, "sourceURL") \
366
367
V(specifier_string, "specifier") \
367
368
V(stack_string, "stack") \
368
369
V(standard_name_string, "standardName") \
Original file line number Diff line number Diff line change
@@ -308,6 +308,13 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) {
308
308
return;
309
309
}
310
310
311
+
if (that->Set(context,
312
+
realm->env()->source_url_string(),
313
+
module->GetUnboundModuleScript()->GetSourceURL())
314
+
.IsNothing()) {
315
+
return;
316
+
}
317
+
311
318
if (that->Set(context,
312
319
realm->env()->source_map_url_string(),
313
320
module->GetUnboundModuleScript()->GetSourceMappingURL())
Original file line number Diff line number Diff line change
@@ -1105,6 +1105,13 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
1105
1105
return;
1106
1106
}
1107
1107
1108
+
if (args.This()
1109
+
->Set(env->context(),
1110
+
env->source_url_string(),
1111
+
v8_script->GetSourceURL())
1112
+
.IsNothing())
1113
+
return;
1114
+
1108
1115
if (args.This()
1109
1116
->Set(env->context(),
1110
1117
env->source_map_url_string(),
@@ -1571,12 +1578,23 @@ MaybeLocal<Object> ContextifyFunction::CompileFunctionAndCacheResult(
1571
1578
Local<Object> result = Object::New(isolate);
1572
1579
if (result->Set(parsing_context, env->function_string(), fn).IsNothing())
1573
1580
return {};
1581
+
1582
+
// ScriptOrigin::ResourceName() returns SourceURL magic comment content if
1583
+
// present.
1584
+
if (result
1585
+
->Set(parsing_context,
1586
+
env->source_url_string(),
1587
+
fn->GetScriptOrigin().ResourceName())
1588
+
.IsNothing()) {
1589
+
return {};
1590
+
}
1574
1591
if (result
1575
1592
->Set(parsing_context,
1576
1593
env->source_map_url_string(),
1577
1594
fn->GetScriptOrigin().SourceMapUrl())
1578
-
.IsNothing())
1595
+
.IsNothing()) {
1579
1596
return {};
1597
+
}
1580
1598
1581
1599
std::unique_ptr<ScriptCompiler::CachedData> new_cached_data;
1582
1600
if (produce_cached_data) {
@@ -1814,12 +1832,16 @@ static void CompileFunctionForCJSLoader(
1814
1832
Local<Name> names[] = {
1815
1833
env->cached_data_rejected_string(),
1816
1834
env->source_map_url_string(),
1835
+
env->source_url_string(),
1817
1836
env->function_string(),
1818
1837
FIXED_ONE_BYTE_STRING(isolate, "canParseAsESM"),
1819
1838
};
1820
1839
Local<Value> values[] = {
1821
1840
Boolean::New(isolate, cache_rejected),
1822
1841
fn.IsEmpty() ? undefined : fn->GetScriptOrigin().SourceMapUrl(),
1842
+
// ScriptOrigin::ResourceName() returns SourceURL magic comment content if
1843
+
// present.
1844
+
fn.IsEmpty() ? undefined : fn->GetScriptOrigin().ResourceName(),
1823
1845
fn.IsEmpty() ? undefined : fn.As<Value>(),
1824
1846
Boolean::New(isolate, can_parse_as_esm),
1825
1847
};
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)
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4